llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) <details> <summary>Changes</summary> 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 --- Full diff: https://github.com/llvm/llvm-project/pull/174428.diff 2 Files Affected: - (modified) clang/lib/AST/ByteCode/Interp.cpp (+3-2) - (modified) clang/test/AST/ByteCode/typeid.cpp (+10) ``````````diff 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}} +} `````````` </details> https://github.com/llvm/llvm-project/pull/174428 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
