Author: Timm Baeder Date: 2026-01-06T07:49:32+01:00 New Revision: cf8d4d40698503bb20da4e5a576cc048524bc8eb
URL: https://github.com/llvm/llvm-project/commit/cf8d4d40698503bb20da4e5a576cc048524bc8eb DIFF: https://github.com/llvm/llvm-project/commit/cf8d4d40698503bb20da4e5a576cc048524bc8eb.diff LOG: [clang][bytecode] Fix a crash in `CheckExtern()` (#174428) Check if the pointer field descriptor can be accessed at all before calling `isInitialized()`, which relies on that. Fixes https://github.com/llvm/llvm-project/issues/174382 Added: Modified: clang/lib/AST/ByteCode/Interp.cpp clang/test/AST/ByteCode/typeid.cpp Removed: ################################################################################ diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp index 966c9d9b5bf66..fe3069a4d8ef8 100644 --- a/clang/lib/AST/ByteCode/Interp.cpp +++ b/clang/lib/AST/ByteCode/Interp.cpp @@ -390,8 +390,9 @@ bool CheckExtern(InterpState &S, CodePtr OpPC, const Pointer &Ptr) { if (!Ptr.isExtern()) return true; - if (Ptr.isInitialized() || - (Ptr.getDeclDesc()->asVarDecl() == S.EvaluatingDecl)) + if (!Ptr.isPastEnd() && + (Ptr.isInitialized() || + (Ptr.getDeclDesc()->asVarDecl() == S.EvaluatingDecl))) return true; if (S.checkingPotentialConstantExpression() && S.getLangOpts().CPlusPlus && diff --git a/clang/test/AST/ByteCode/typeid.cpp b/clang/test/AST/ByteCode/typeid.cpp index 7f282653e9a34..f529fb3b7a533 100644 --- a/clang/test/AST/ByteCode/typeid.cpp +++ b/clang/test/AST/ByteCode/typeid.cpp @@ -83,3 +83,13 @@ namespace GH173950 { // This used to crash with: Assertion `IsInitialized' failed in invokeDtor() const std::type_info &a_ti = typeid(a); } + +namespace MissingInitalizer { + struct Item { + const std::type_info &ti; + }; + extern constexpr Item items[] = ; // both-error {{expected expression}} \ + // both-note {{declared here}} + constexpr auto &x = items[0].ti; // both-error {{must be initialized by a constant expression}} \ + // both-note {{initializer of 'items' is unknown}} +} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
