Author: Douglas Yung
Date: 2026-10-11T06:22:39-04:00
New Revision: 88c3bf7bb5c44e22ba0a57d9e0b807de1b2a3082

URL: 
https://github.com/llvm/llvm-project/commit/88c3bf7bb5c44e22ba0a57d9e0b807de1b2a3082
DIFF: 
https://github.com/llvm/llvm-project/commit/88c3bf7bb5c44e22ba0a57d9e0b807de1b2a3082.diff

LOG: Fix test added in #229871 to work in C++20 mode. (#230875)

Our downstream compiler defaults to c++20 mode for the compiler, so this
newly added test from #229871 failed because in C++20 mode there are a
different set of warnings/notes emitted by the compiler.

This PR adds testing for both c++17 and c++20 modes and adds the
appropriate checks for both modes.

Added: 
    

Modified: 
    clang/test/SemaCXX/warn-unsafe-buffer-usage-main-argv.cpp

Removed: 
    


################################################################################
diff  --git a/clang/test/SemaCXX/warn-unsafe-buffer-usage-main-argv.cpp 
b/clang/test/SemaCXX/warn-unsafe-buffer-usage-main-argv.cpp
index fc4297b33033f..cd2a65fb9dd98 100644
--- a/clang/test/SemaCXX/warn-unsafe-buffer-usage-main-argv.cpp
+++ b/clang/test/SemaCXX/warn-unsafe-buffer-usage-main-argv.cpp
@@ -1,23 +1,36 @@
-// RUN: %clang_cc1 -Wunsafe-buffer-usage -fsafe-buffer-usage-suggestions 
-verify=expected,both %s
-// RUN: %clang_cc1 -Wunsafe-buffer-usage -Wno-unsafe-buffer-usage-main-argv 
-fsafe-buffer-usage-suggestions -verify=both %s
+// RUN: %clang_cc1 -std=c++17 -Wunsafe-buffer-usage 
-fsafe-buffer-usage-suggestions -verify=expected-17,both-17 %s
+// RUN: %clang_cc1 -std=c++17 -Wunsafe-buffer-usage 
-Wno-unsafe-buffer-usage-main-argv -fsafe-buffer-usage-suggestions 
-verify=both-17 %s
+// RUN: %clang_cc1 -std=c++20 -Wunsafe-buffer-usage 
-fsafe-buffer-usage-suggestions -verify=expected-20,both-20 %s
+// RUN: %clang_cc1 -std=c++20 -Wunsafe-buffer-usage 
-Wno-unsafe-buffer-usage-main-argv -fsafe-buffer-usage-suggestions 
-verify=both-20 %s
 
+// expected-20-warning@+1{{unsafe pointer used for buffer access}}
 int main(int argc, char **argv) {
-  // expected-warning@+1{{unsafe buffer access}}
+  // expected-17-warning@+2{{unsafe buffer access}}
+  // expected-20-note@+1{{used in buffer access here}}
   char c = argv[1][0];
 
-  // expected-warning@+1{{unsafe pointer arithmetic}}
+  // expected-17-warning@+2{{unsafe pointer arithmetic}}
+  // expected-20-note@+1{{used in pointer arithmetic here}}
   char **ptr1 = argv + 1;
-  // expected-warning@+1{{unsafe pointer arithmetic}}
+  // expected-17-warning@+2{{unsafe pointer arithmetic}}
+  // expected-20-note@+1{{used in pointer arithmetic here}}
   argv++;
-  // expected-warning@+1{{unsafe pointer arithmetic}}
+  // expected-17-warning@+2{{unsafe pointer arithmetic}}
+  // expected-20-note@+1{{used in pointer arithmetic here}}
   argv += 1;
 
+  // both-20-warning@+2{{unsafe pointer used for buffer access}}
+  // both-20-note@+1{{change type of 'p' to 'std::span' to preserve bounds 
information}}
   int *p = nullptr;
-  // both-warning@+1{{unsafe buffer access}}
+  // both-17-warning@+2{{unsafe buffer access}}
+  // both-20-note@+1{{used in buffer access here}}
   return p[5];
 }
 
+// both-20-warning@+2{{unsafe pointer used for buffer access}}
+// both-20-note@+1{{change type of 'argv' to 'std::span' to preserve bounds 
information}}
 int other_func(int argc, char **argv) {
-  // both-warning@+1{{unsafe buffer access}}
+  // both-17-warning@+2{{unsafe buffer access}}
+  // both-20-note@+1{{used in buffer access here}}
   return argv[1][0];
 }


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to