Author: Timm Baeder Date: 2026-08-25T07:06:57+02:00 New Revision: 3ea7897fa702b5bb8d7bc8448d49b43d483b7a25
URL: https://github.com/llvm/llvm-project/commit/3ea7897fa702b5bb8d7bc8448d49b43d483b7a25 DIFF: https://github.com/llvm/llvm-project/commit/3ea7897fa702b5bb8d7bc8448d49b43d483b7a25.diff LOG: [clang][bytecode] Protect evaluateString() from invalid pointers (#218411) We can't call `Pointer::getNumElems()` on pointers to unknown size arrays. Added: Modified: clang/lib/AST/ByteCode/Context.cpp clang/test/AST/ByteCode/invalid.cpp Removed: ################################################################################ diff --git a/clang/lib/AST/ByteCode/Context.cpp b/clang/lib/AST/ByteCode/Context.cpp index 96f26a6a7a083..96cf6ac8d3d88 100644 --- a/clang/lib/AST/ByteCode/Context.cpp +++ b/clang/lib/AST/ByteCode/Context.cpp @@ -284,6 +284,9 @@ bool Context::evaluateString(State &Parent, const Expr *E, if (!Ptr.isConst()) return false; + if (Ptr.isDummy() || Ptr.isUnknownSizeArray() || Ptr.isPastEnd()) + return false; + unsigned N = Ptr.getNumElems(); if (Ptr.elemSize() == 1 /* bytes */) { diff --git a/clang/test/AST/ByteCode/invalid.cpp b/clang/test/AST/ByteCode/invalid.cpp index 247c8ad732708..67c82cb352d90 100644 --- a/clang/test/AST/ByteCode/invalid.cpp +++ b/clang/test/AST/ByteCode/invalid.cpp @@ -247,3 +247,12 @@ namespace InvalidStaticInvoker { constexpr int (*baz)(int) = foo; int i = baz(42); } + +namespace UnknownSizeArrayInEvaluateString { + void foo() { + constexpr char K[] = {'\0'; // both-error {{expected '}'}} \ + // both-note {{to match this}} + __builtin_verbose_trap("bar", K); // both-error {{argument to __builtin_verbose_trap must be a pointer to a constant string}} + } + } +} // both-error {{extraneous closing brace}} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
