Author: Timm Baeder
Date: 2026-09-03T11:09:52+02:00
New Revision: 026e3f3cc5f73072cc55a7228e64b9d0db5938b5

URL: 
https://github.com/llvm/llvm-project/commit/026e3f3cc5f73072cc55a7228e64b9d0db5938b5
DIFF: 
https://github.com/llvm/llvm-project/commit/026e3f3cc5f73072cc55a7228e64b9d0db5938b5.diff

LOG: [clang][bytecode] Check strcmp input for unknown-size arrays (#220835)

The later calls to getNumElems() will fail for them.

Added: 
    

Modified: 
    clang/lib/AST/ByteCode/InterpBuiltin.cpp
    clang/test/AST/ByteCode/builtin-functions.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index 91d6a32c136ac..b78ce614e290d 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -306,7 +306,9 @@ static bool interp__builtin_strcmp(InterpState &S, CodePtr 
OpPC,
 
   if (!A.isReadablePointerType() || !B.isReadablePointerType())
     return false;
-  if (A.isDummy() || B.isDummy())
+
+  if (A.isDummy() || B.isDummy() || A.isUnknownSizeArray() ||
+      B.isUnknownSizeArray())
     return false;
 
   bool IsWide = ID == Builtin::BIwcscmp || ID == Builtin::BIwcsncmp ||

diff  --git a/clang/test/AST/ByteCode/builtin-functions.cpp 
b/clang/test/AST/ByteCode/builtin-functions.cpp
index 47a1c23d77799..51e1b6cde4779 100644
--- a/clang/test/AST/ByteCode/builtin-functions.cpp
+++ b/clang/test/AST/ByteCode/builtin-functions.cpp
@@ -132,6 +132,12 @@ namespace strcmp {
   static_assert(__builtin_strncmp("abaa", "abba", 0) == 0);
   static_assert(__builtin_strncmp(0, 0, 0) == 0);
   static_assert(__builtin_strncmp("abab\0banana", "abab\0canada", 100) == 0);
+
+
+  constexpr char missingInit[] = bar__; // both-error {{use of undeclared 
identifier 'bar__'}} \
+                                        // ref-note {{declared here}}
+  static_assert(__builtin_strcmp(missingInit, "bar") == 0, ""); // both-error 
{{not an integral constant expression}} \
+                                                                // ref-note 
{{initializer of 'missingInit' is unknown}}
 }
 
 namespace WcsCmp {


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

Reply via email to