https://github.com/Serosh-commits updated https://github.com/llvm/llvm-project/pull/180261
>From 03c4427a4a8e3cddf016fb6c66d86f3d3764af14 Mon Sep 17 00:00:00 2001 From: Serosh-commits <[email protected]> Date: Sat, 7 Feb 2026 01:08:19 +0530 Subject: [PATCH] [clang][bytecode] fix assertion failure on invalid init list (gh175432) this patch fixes a crash/assertion failure in the new constant interpreter when handling invalid initializer lists or expressions containing errors. we guard the entry points of the compiler (visitinitlist, visitcastexpr) to emit an error opcode if the expression contains errors. this prevents execution of invalid nodes (avoiding crash) while allowing compilation of dead code containing errors. fixes #175432 --- clang/lib/AST/ByteCode/Compiler.cpp | 8 ++++++-- clang/test/AST/ByteCode/gh175432.cpp | 4 ++++ 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 clang/test/AST/ByteCode/gh175432.cpp diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp index a0138c402e143..52f023e7c3cef 100644 --- a/clang/lib/AST/ByteCode/Compiler.cpp +++ b/clang/lib/AST/ByteCode/Compiler.cpp @@ -211,6 +211,9 @@ template <class Emitter> class LocOverrideScope final { template <class Emitter> bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) { + if (CE->containsErrors()) + return this->emitError(CE); + const Expr *SubExpr = CE->getSubExpr(); if (DiscardResult) @@ -477,8 +480,6 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) { return this->delegate(SubExpr); case CK_BitCast: { - if (CE->containsErrors()) - return false; QualType CETy = CE->getType(); // Reject bitcasts to atomic types. if (CETy->isAtomicType()) { @@ -1836,6 +1837,9 @@ bool Compiler<Emitter>::VisitArraySubscriptExpr(const ArraySubscriptExpr *E) { template <class Emitter> bool Compiler<Emitter>::visitInitList(ArrayRef<const Expr *> Inits, const Expr *ArrayFiller, const Expr *E) { + if (E->containsErrors()) + return this->emitError(E); + InitLinkScope<Emitter> ILS(this, InitLink::InitList()); QualType QT = E->getType(); diff --git a/clang/test/AST/ByteCode/gh175432.cpp b/clang/test/AST/ByteCode/gh175432.cpp new file mode 100644 index 0000000000000..e185ddc3fa16f --- /dev/null +++ b/clang/test/AST/ByteCode/gh175432.cpp @@ -0,0 +1,4 @@ +// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify %s + +constexpr const int *foo[][2] = { {nullptr, int}, }; // expected-error {{expected expression}} +static_assert(foo[0][0] == nullptr, ""); // expected-error {{constant expression}} expected-note {{initializer of 'foo' is not a constant expression}} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
