Author: Timm Baeder
Date: 2026-10-09T12:51:04+02:00
New Revision: 07b499be38892d180a42a1c495baba389f9f9f28

URL: 
https://github.com/llvm/llvm-project/commit/07b499be38892d180a42a1c495baba389f9f9f28
DIFF: 
https://github.com/llvm/llvm-project/commit/07b499be38892d180a42a1c495baba389f9f9f28.diff

LOG: [clang][bytecode] Reject strcmp with non-primitive element types (#230396)

Added: 
    

Modified: 
    clang/lib/AST/ByteCode/InterpBuiltin.cpp
    clang/test/AST/ByteCode/c.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index 5f3f59ae24245..4a5c691d390a7 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -325,7 +325,8 @@ static bool interp__builtin_strcmp(InterpState &S, CodePtr 
OpPC,
 
   QualType ElemTy = getElemType(A);
   // Different element types shouldn't happen, but with casts they can.
-  if (!S.getASTContext().hasSameUnqualifiedType(ElemTy, getElemType(B)))
+  if (!S.getASTContext().hasSameUnqualifiedType(ElemTy, getElemType(B)) ||
+      !S.getContext().canClassify(ElemTy))
     return false;
 
   PrimType ElemT = *S.getContext().classify(ElemTy);

diff  --git a/clang/test/AST/ByteCode/c.c b/clang/test/AST/ByteCode/c.c
index 7dd3f667559ed..e431691ed190d 100644
--- a/clang/test/AST/ByteCode/c.c
+++ b/clang/test/AST/ByteCode/c.c
@@ -486,3 +486,9 @@ Parse sqlite3Prepare_sParse;
 void sqlite3Prepare(void) {
   memset( ((char *)&sqlite3Prepare_sParse) + sizeof(int), 0, sizeof(int));
 }
+
+int strcmp(const char *, const char *);
+const union u {
+  char c[2];
+} str[] = {"", ""};
+const int strcmpFoo = strcmp((const char *)str, (const char *)str); // 
all-error {{not a compile-time constant}}


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

Reply via email to