Author: Timm Baeder Date: 2026-05-30T16:41:02+02:00 New Revision: ef6a217703a8738b89e22a19d3daca06b0028da0
URL: https://github.com/llvm/llvm-project/commit/ef6a217703a8738b89e22a19d3daca06b0028da0 DIFF: https://github.com/llvm/llvm-project/commit/ef6a217703a8738b89e22a19d3daca06b0028da0.diff LOG: [clang][bytecode] Fix a crash with an empty InitListExpr (#200366) Fixes https://github.com/llvm/llvm-project/issues/200295 Added: Modified: clang/lib/AST/ByteCode/Compiler.cpp clang/test/AST/ByteCode/new-delete.cpp Removed: ################################################################################ diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp index 30002103a4649..70507d577dd11 100644 --- a/clang/lib/AST/ByteCode/Compiler.cpp +++ b/clang/lib/AST/ByteCode/Compiler.cpp @@ -4058,7 +4058,7 @@ bool Compiler<Emitter>::VisitCXXNewExpr(const CXXNewExpr *E) { if (const auto *ILE = dyn_cast<InitListExpr>(Init)) { if (ILE->hasArrayFiller()) DynamicInit = ILE->getArrayFiller(); - else if (isa<StringLiteral>(ILE->getInit(0))) + else if (StaticInitElems > 0 && isa<StringLiteral>(ILE->getInit(0))) ElemT = classifyPrim(CAT->getElementType()); } } diff --git a/clang/test/AST/ByteCode/new-delete.cpp b/clang/test/AST/ByteCode/new-delete.cpp index b6e6d333a4bcb..930e090dd5bce 100644 --- a/clang/test/AST/ByteCode/new-delete.cpp +++ b/clang/test/AST/ByteCode/new-delete.cpp @@ -29,6 +29,9 @@ struct S { static_assert(((delete[] (new int[true])), true)); static_assert(((delete[] (new S[true])), true)); +static_assert((new int[]{})[0] == 0); // both-error {{not an integral constant expression}} \ + // both-note {{read of dereferenced one-past-the-end pointer}} + constexpr int a() { new int(12); // both-note {{allocation performed here was not deallocated}} return 1; _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
