Author: Timm Baeder Date: 2024-09-27T17:48:43+02:00 New Revision: d9b377d8b12aaa3345eaa0d1b93dc3915baba013
URL: https://github.com/llvm/llvm-project/commit/d9b377d8b12aaa3345eaa0d1b93dc3915baba013 DIFF: https://github.com/llvm/llvm-project/commit/d9b377d8b12aaa3345eaa0d1b93dc3915baba013.diff LOG: [clang][bytecode] Don't produce a null type when checking new exprs (#110252) getType() might give us the right type already, so use that instead of calling getPointeeType() for all CXXNewExprs. Added: Modified: clang/lib/AST/ByteCode/Interp.cpp clang/test/AST/ByteCode/placement-new.cpp Removed: ################################################################################ diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp index c43f64901909ce..798e0f3e96fa09 100644 --- a/clang/lib/AST/ByteCode/Interp.cpp +++ b/clang/lib/AST/ByteCode/Interp.cpp @@ -1322,7 +1322,8 @@ bool CheckNewTypeMismatch(InterpState &S, CodePtr OpPC, const Expr *E, const auto *NewExpr = cast<CXXNewExpr>(E); QualType StorageType = Ptr.getType(); - if (isa_and_nonnull<CXXNewExpr>(Ptr.getFieldDesc()->asExpr())) { + if (isa_and_nonnull<CXXNewExpr>(Ptr.getFieldDesc()->asExpr()) && + StorageType->isPointerType()) { // FIXME: Are there other cases where this is a problem? StorageType = StorageType->getPointeeType(); } diff --git a/clang/test/AST/ByteCode/placement-new.cpp b/clang/test/AST/ByteCode/placement-new.cpp index 1ff6ff3ac19223..caf3ac97fd1c04 100644 --- a/clang/test/AST/ByteCode/placement-new.cpp +++ b/clang/test/AST/ByteCode/placement-new.cpp @@ -271,3 +271,18 @@ namespace ConstructAt { // both-note {{in call}} } + +namespace UsedToCrash { + struct S { + int* i; + constexpr S() : i(new int(42)) {} // #no-deallocation + constexpr ~S() {delete i;} + }; + consteval void alloc() { + S* s = new S(); + s->~S(); + new (s) S(); + delete s; + } + int alloc1 = (alloc(), 0); +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits