[clang] [clang][bytecode] Reject strcmp with non-primitive element types (PR #230396)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 9 01:18:40 PDT 2026
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/230396
None
>From 04fc6dc9c63fce276e58245335bc7effa97a937b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Fri, 9 Oct 2026 10:16:09 +0200
Subject: [PATCH] [clang][bytecode] Reject strcmp with non-primitive element
types
---
clang/lib/AST/ByteCode/InterpBuiltin.cpp | 3 ++-
clang/test/AST/ByteCode/c.c | 6 ++++++
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index 5f3f59ae242456..4a5c691d390a71 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 7dd3f667559ed9..e431691ed190d8 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}}
More information about the cfe-commits
mailing list