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

Timm Baeder via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 27 00:26:56 PDT 2026


https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/188917

None

>From 4e790a8884f6e124e1528f469a50602d17bb5287 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Fri, 27 Mar 2026 08:24:02 +0100
Subject: [PATCH] [clang][bytecode] Handle strcmp() not point to primitive
 arrays

---
 clang/lib/AST/ByteCode/InterpBuiltin.cpp |  3 +++
 clang/test/AST/ByteCode/builtins.c       | 12 ++++++++++++
 2 files changed, 15 insertions(+)

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}}



More information about the cfe-commits mailing list