Author: Timm Baeder Date: 2026-02-04T13:55:50+01:00 New Revision: cd31effb0aac9afde43a64b236c5fc95717c255c
URL: https://github.com/llvm/llvm-project/commit/cd31effb0aac9afde43a64b236c5fc95717c255c DIFF: https://github.com/llvm/llvm-project/commit/cd31effb0aac9afde43a64b236c5fc95717c255c.diff LOG: [clang][bytecode] Reject invalid CXXNewExprs (#179629) If they contain errors, we can't rely on any of their API returning sane values. Added: Modified: clang/lib/AST/ByteCode/Compiler.cpp clang/test/AST/ByteCode/placement-new.cpp Removed: ################################################################################ diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp index af076f90733df..7401eccb4dbdd 100644 --- a/clang/lib/AST/ByteCode/Compiler.cpp +++ b/clang/lib/AST/ByteCode/Compiler.cpp @@ -3598,6 +3598,9 @@ bool Compiler<Emitter>::VisitCXXNewExpr(const CXXNewExpr *E) { const Expr *PlacementDest = nullptr; bool IsNoThrow = false; + if (E->containsErrors()) + return false; + if (PlacementArgs != 0) { // FIXME: There is no restriction on this, but it's not clear that any // other form makes any sense. We get here for cases such as: diff --git a/clang/test/AST/ByteCode/placement-new.cpp b/clang/test/AST/ByteCode/placement-new.cpp index f458ea17b6cc6..503e456565f5d 100644 --- a/clang/test/AST/ByteCode/placement-new.cpp +++ b/clang/test/AST/ByteCode/placement-new.cpp @@ -522,3 +522,5 @@ constexpr int intDestArray() { static_assert(intDestArray() == 0); // both-error {{not an integral constant expression}} \ // both-note {{in call to}} +constexpr void invalidDest() { new (undefinedfunction()) int; } // both-error {{use of undeclared identifier 'undefinedfunction'}} +static_assert((invalidDest(), true)); // both-error {{not an integral constant expression}} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
