Author: Timm Baeder Date: 2026-03-28T06:13:18+01:00 New Revision: 097abb3d645851e8148a05e6ead3ed4c361a7ca1
URL: https://github.com/llvm/llvm-project/commit/097abb3d645851e8148a05e6ead3ed4c361a7ca1 DIFF: https://github.com/llvm/llvm-project/commit/097abb3d645851e8148a05e6ead3ed4c361a7ca1.diff LOG: [clang][bytecode] Handle strcmp() not pointing to primitive arrays (#188917) Added: Modified: clang/lib/AST/ByteCode/InterpBuiltin.cpp clang/test/AST/ByteCode/builtins.c Removed: ################################################################################ diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp index 214013396e885..e7b3ef6ce1510 100644 --- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp +++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp @@ -283,6 +283,9 @@ static bool interp__builtin_strcmp(InterpState &S, CodePtr OpPC, return false; if (!A.isBlockPointer() || !B.isBlockPointer()) return false; + if (!A.getFieldDesc()->isPrimitiveArray() || + !B.getFieldDesc()->isPrimitiveArray()) + return false; bool IsWide = ID == Builtin::BIwcscmp || ID == Builtin::BIwcsncmp || ID == Builtin::BI__builtin_wcscmp || diff --git a/clang/test/AST/ByteCode/builtins.c b/clang/test/AST/ByteCode/builtins.c index 2d19ccb51de03..ecaafd6ce1282 100644 --- a/clang/test/AST/ByteCode/builtins.c +++ b/clang/test/AST/ByteCode/builtins.c @@ -22,3 +22,15 @@ _Static_assert(__atomic_is_lock_free(4, (void*)2), ""); // both-error {{not an i _Static_assert(__builtin_strlen((void*)0 + 1) == 2, ""); // both-error {{not an integral constant expression}} \ // both-note {{cannot perform pointer arithmetic on null pointer}} + + +int strcmp(const char *, const char *); +#define S "\x01\x02" + +const char _str[] = {S[0], S[1]}; +const union u { + int a; + char b[2]; +} _str2[] = {S[0], S[1]}; + +const int compared = strcmp(_str, (const char *)_str2); // both-error {{initializer element is not a compile-time constant}} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
