Skip to content

Commit 004231a

Browse files
authored
[clang][bytecode] Check strlen impl for primitive arrays (#157494)
Fixes #157428
1 parent 33757cd commit 004231a

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,9 @@ static bool interp__builtin_strlen(InterpState &S, CodePtr OpPC,
300300
if (!CheckDummy(S, OpPC, StrPtr.block(), AK_Read))
301301
return false;
302302

303+
if (!StrPtr.getFieldDesc()->isPrimitiveArray())
304+
return false;
305+
303306
assert(StrPtr.getFieldDesc()->isPrimitiveArray());
304307
unsigned ElemSize = StrPtr.getFieldDesc()->getElemSize();
305308

clang/test/AST/ByteCode/builtins.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %clang_cc1 -fexperimental-new-constant-interpreter %s -verify
2+
// RUN: %clang_cc1 %s -verify=ref
3+
4+
// expected-no-diagnostics
5+
// ref-no-diagnostics
6+
7+
extern __SIZE_TYPE__ strlen(const char *);
8+
9+
struct str_t {
10+
char s1[sizeof("a")];
11+
};
12+
static const struct str_t str1 = {"a"};
13+
#define str ((const char *)&str1)
14+
int structStrlen(void) {
15+
if (strlen(str) == 1)
16+
return 0;
17+
return 1;
18+
}
19+

0 commit comments

Comments
 (0)