Author: Nikita Popov Date: 2023-05-09T09:49:42+02:00 New Revision: cac4d7ff4652815e12132c990a62d68873ba4b9e
URL: https://github.com/llvm/llvm-project/commit/cac4d7ff4652815e12132c990a62d68873ba4b9e DIFF: https://github.com/llvm/llvm-project/commit/cac4d7ff4652815e12132c990a62d68873ba4b9e.diff LOG: [CodeGen] Only consider innermost cast for !heapallocsite Without opaque pointers, this code determined !heapallocsite based on the innermost cast of the allocation call. With opaque pointers, the casts no longer generate an instruction, so the outermost cast is used. Add an explicit check for nested casts to prevent this. Differential Revision: https://reviews.llvm.org/D145788 Added: Modified: clang/lib/CodeGen/CGExprScalar.cpp clang/test/CodeGen/debug-info-codeview-heapallocsite.c Removed: ################################################################################ diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp index 2243c75ed2608..cf24e3211dbc3 100644 --- a/clang/lib/CodeGen/CGExprScalar.cpp +++ b/clang/lib/CodeGen/CGExprScalar.cpp @@ -2098,7 +2098,8 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) { // Update heapallocsite metadata when there is an explicit pointer cast. if (auto *CI = dyn_cast<llvm::CallBase>(Src)) { - if (CI->getMetadata("heapallocsite") && isa<ExplicitCastExpr>(CE)) { + if (CI->getMetadata("heapallocsite") && isa<ExplicitCastExpr>(CE) && + !isa<CastExpr>(E)) { QualType PointeeType = DestTy->getPointeeType(); if (!PointeeType.isNull()) CGF.getDebugInfo()->addHeapAllocSiteMetadata(CI, PointeeType, diff --git a/clang/test/CodeGen/debug-info-codeview-heapallocsite.c b/clang/test/CodeGen/debug-info-codeview-heapallocsite.c index a8cae112dcec2..6cc34f688e4dc 100644 --- a/clang/test/CodeGen/debug-info-codeview-heapallocsite.c +++ b/clang/test/CodeGen/debug-info-codeview-heapallocsite.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -no-opaque-pointers -triple x86_64-windows-msvc -debug-info-kind=limited -gcodeview -fdeclspec -S -emit-llvm %s -o - | FileCheck %s +// RUN: %clang_cc1 -triple x86_64-windows-msvc -debug-info-kind=limited -gcodeview -fdeclspec -S -emit-llvm %s -o - | FileCheck %s struct Foo; struct Bar; @@ -14,10 +14,10 @@ void call_alloc(void) { } // CHECK-LABEL: define {{.*}}void @call_alloc -// CHECK: call i8* {{.*}}@alloc_void{{.*}} !heapallocsite [[DBG1:!.*]] -// CHECK: call %struct.Foo* {{.*}}@alloc_foo{{.*}} !heapallocsite [[DBG2:!.*]] -// CHECK: call i8* {{.*}}@alloc_void{{.*}} !heapallocsite [[DBG2]] -// CHECK: call i8* {{.*}}@alloc_void{{.*}} !heapallocsite [[DBG3:!.*]] +// CHECK: call ptr {{.*}}@alloc_void{{.*}} !heapallocsite [[DBG1:!.*]] +// CHECK: call ptr {{.*}}@alloc_foo{{.*}} !heapallocsite [[DBG2:!.*]] +// CHECK: call ptr {{.*}}@alloc_void{{.*}} !heapallocsite [[DBG2]] +// CHECK: call ptr {{.*}}@alloc_void{{.*}} !heapallocsite [[DBG3:!.*]] // CHECK: [[DBG2]] = !DICompositeType(tag: DW_TAG_structure_type, // CHECK-SAME: name: "Foo" _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits