[clang][bytecode] Handle strcmp() not pointing to primitive arrays#188917
Merged
[clang][bytecode] Handle strcmp() not pointing to primitive arrays#188917
Conversation
Member
|
@llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) ChangesFull diff: https://github.com/llvm/llvm-project/pull/188917.diff 2 Files Affected:
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}}
|
🐧 Linux x64 Test Results
✅ The build succeeded and all tests passed. |
Aadarsh-Keshri
pushed a commit
to Aadarsh-Keshri/llvm-project
that referenced
this pull request
Mar 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.