https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/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 >From d0009e9d4fbb72710f99b25bd58e7983b51100a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]> Date: Mon, 5 Jan 2026 16:57:28 +0100 Subject: [PATCH] [clang][bytecode] --- clang/lib/AST/ByteCode/Interp.cpp | 5 +++-- clang/test/AST/ByteCode/typeid.cpp | 10 ++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp index 889ac1e1a9a7e..0cdb0eecd8b44 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
