[clang][bytecode] Check strlen impl for primitive arrays (#157494)

Fixes #157428
This commit is contained in:
Timm Baeder 2025-09-11 05:08:08 +02:00 committed by GitHub
parent 33757cdda8
commit 004231aaeb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 0 deletions

View File

@ -300,6 +300,9 @@ static bool interp__builtin_strlen(InterpState &S, CodePtr OpPC,
if (!CheckDummy(S, OpPC, StrPtr.block(), AK_Read))
return false;
if (!StrPtr.getFieldDesc()->isPrimitiveArray())
return false;
assert(StrPtr.getFieldDesc()->isPrimitiveArray());
unsigned ElemSize = StrPtr.getFieldDesc()->getElemSize();

View File

@ -0,0 +1,19 @@
// RUN: %clang_cc1 -fexperimental-new-constant-interpreter %s -verify
// RUN: %clang_cc1 %s -verify=ref
// expected-no-diagnostics
// ref-no-diagnostics
extern __SIZE_TYPE__ strlen(const char *);
struct str_t {
char s1[sizeof("a")];
};
static const struct str_t str1 = {"a"};
#define str ((const char *)&str1)
int structStrlen(void) {
if (strlen(str) == 1)
return 0;
return 1;
}