Skip to content

[clang][bytecode] Handle strcmp() not pointing to primitive arrays#188917

Merged
tbaederr merged 2 commits intollvm:mainfrom
tbaederr:strcmp
Mar 28, 2026
Merged

[clang][bytecode] Handle strcmp() not pointing to primitive arrays#188917
tbaederr merged 2 commits intollvm:mainfrom
tbaederr:strcmp

Conversation

@tbaederr
Copy link
Copy Markdown
Contributor

No description provided.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:bytecode Issues for the clang bytecode constexpr interpreter labels Mar 27, 2026
@llvmbot
Copy link
Copy Markdown
Member

llvmbot commented Mar 27, 2026

@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/188917.diff

2 Files Affected:

  • (modified) clang/lib/AST/ByteCode/InterpBuiltin.cpp (+3)
  • (modified) clang/test/AST/ByteCode/builtins.c (+12)
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}}

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 27, 2026

🐧 Linux x64 Test Results

  • 115231 tests passed
  • 4511 tests skipped

✅ The build succeeded and all tests passed.

@tbaederr tbaederr changed the title [clang][bytecode] Handle strcmp() not point to primitive arrays [clang][bytecode] Handle strcmp() not pointing to primitive arrays Mar 28, 2026
@tbaederr tbaederr merged commit 097abb3 into llvm:main Mar 28, 2026
10 checks passed
Aadarsh-Keshri pushed a commit to Aadarsh-Keshri/llvm-project that referenced this pull request Mar 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:bytecode Issues for the clang bytecode constexpr interpreter clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants