Author: Timm Baeder Date: 2026-08-03T14:46:27+02:00 New Revision: fccabca20c732cc93b018effa7381e2e2a6f9506
URL: https://github.com/llvm/llvm-project/commit/fccabca20c732cc93b018effa7381e2e2a6f9506 DIFF: https://github.com/llvm/llvm-project/commit/fccabca20c732cc93b018effa7381e2e2a6f9506.diff LOG: [clang][bytecode] Protect against invalid C++26 string repr (#213639) We can't call `getNumElems()` for unknown-size arrays. Added: Modified: clang/lib/AST/ByteCode/Context.cpp clang/test/AST/ByteCode/cxx26.cpp Removed: ################################################################################ diff --git a/clang/lib/AST/ByteCode/Context.cpp b/clang/lib/AST/ByteCode/Context.cpp index b913d2a9f539c..9f1d9b899052d 100644 --- a/clang/lib/AST/ByteCode/Context.cpp +++ b/clang/lib/AST/ByteCode/Context.cpp @@ -208,7 +208,8 @@ bool Context::evaluateStringRepr(State &Parent, const Expr *SizeExpr, return false; } - if (!Ptr.isLive() || !Ptr.getFieldDesc()->isPrimitiveArray()) + if (!Ptr.isLive() || !Ptr.isInitialized() || Ptr.isUnknownSizeArray() || + !Ptr.getFieldDesc()->isPrimitiveArray()) return false; // Must be char. diff --git a/clang/test/AST/ByteCode/cxx26.cpp b/clang/test/AST/ByteCode/cxx26.cpp index 769deb28cdf50..9dc6270b9d551 100644 --- a/clang/test/AST/ByteCode/cxx26.cpp +++ b/clang/test/AST/ByteCode/cxx26.cpp @@ -91,3 +91,15 @@ namespace ConstexprUnknownReference { } } + +namespace UnknownSizeArrayString { + constexpr const char foo[] = {bar}; // both-error {{use of undeclared identifier}} \ + // ref-note {{declared here}} + struct S { + constexpr int size() const { return 4; } + constexpr const char *data() const { return foo; } + }; + static_assert(false, S{}); // both-error {{the message in a static assertion must be produced by a constant expression}} \ + // ref-note {{initializer of 'foo' is unknown}} \ + // both-error {{static assertion failed}} +} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
