https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/187988
None >From 61837b3c4224c5d86dd4d7234ad66f2d999c5b82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]> Date: Mon, 23 Mar 2026 08:34:36 +0100 Subject: [PATCH] [clang][bytecode] Check for block pointers in __builtin_strlen() --- clang/lib/AST/ByteCode/InterpBuiltin.cpp | 3 +++ clang/test/AST/ByteCode/builtins.c | 3 +++ 2 files changed, 6 insertions(+) diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp index fcd11ee9089c0..17a1ad6f4fa73 100644 --- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp +++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp @@ -357,6 +357,9 @@ static bool interp__builtin_strlen(InterpState &S, CodePtr OpPC, if (!CheckLive(S, OpPC, StrPtr, AK_Read)) return false; + if (!StrPtr.isBlockPointer()) + return false; + if (!CheckDummy(S, OpPC, StrPtr.block(), AK_Read)) return false; diff --git a/clang/test/AST/ByteCode/builtins.c b/clang/test/AST/ByteCode/builtins.c index 5630a36e1c05b..2d19ccb51de03 100644 --- a/clang/test/AST/ByteCode/builtins.c +++ b/clang/test/AST/ByteCode/builtins.c @@ -19,3 +19,6 @@ void f2() { __builtin_memchr(f2, 0, 1); } _Static_assert(__atomic_is_lock_free(4, (void*)2), ""); // both-error {{not an integral constant expression}} + +_Static_assert(__builtin_strlen((void*)0 + 1) == 2, ""); // both-error {{not an integral constant expression}} \ + // both-note {{cannot perform pointer arithmetic on null pointer}} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
