Skip to content

Commit cac4d7f

Browse files
committed
[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
1 parent 0c852dc commit cac4d7f

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

clang/lib/CodeGen/CGExprScalar.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -2098,7 +2098,8 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
20982098

20992099
// Update heapallocsite metadata when there is an explicit pointer cast.
21002100
if (auto *CI = dyn_cast<llvm::CallBase>(Src)) {
2101-
if (CI->getMetadata("heapallocsite") && isa<ExplicitCastExpr>(CE)) {
2101+
if (CI->getMetadata("heapallocsite") && isa<ExplicitCastExpr>(CE) &&
2102+
!isa<CastExpr>(E)) {
21022103
QualType PointeeType = DestTy->getPointeeType();
21032104
if (!PointeeType.isNull())
21042105
CGF.getDebugInfo()->addHeapAllocSiteMetadata(CI, PointeeType,

clang/test/CodeGen/debug-info-codeview-heapallocsite.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -no-opaque-pointers -triple x86_64-windows-msvc -debug-info-kind=limited -gcodeview -fdeclspec -S -emit-llvm %s -o - | FileCheck %s
1+
// RUN: %clang_cc1 -triple x86_64-windows-msvc -debug-info-kind=limited -gcodeview -fdeclspec -S -emit-llvm %s -o - | FileCheck %s
22

33
struct Foo;
44
struct Bar;
@@ -14,10 +14,10 @@ void call_alloc(void) {
1414
}
1515

1616
// CHECK-LABEL: define {{.*}}void @call_alloc
17-
// CHECK: call i8* {{.*}}@alloc_void{{.*}} !heapallocsite [[DBG1:!.*]]
18-
// CHECK: call %struct.Foo* {{.*}}@alloc_foo{{.*}} !heapallocsite [[DBG2:!.*]]
19-
// CHECK: call i8* {{.*}}@alloc_void{{.*}} !heapallocsite [[DBG2]]
20-
// CHECK: call i8* {{.*}}@alloc_void{{.*}} !heapallocsite [[DBG3:!.*]]
17+
// CHECK: call ptr {{.*}}@alloc_void{{.*}} !heapallocsite [[DBG1:!.*]]
18+
// CHECK: call ptr {{.*}}@alloc_foo{{.*}} !heapallocsite [[DBG2:!.*]]
19+
// CHECK: call ptr {{.*}}@alloc_void{{.*}} !heapallocsite [[DBG2]]
20+
// CHECK: call ptr {{.*}}@alloc_void{{.*}} !heapallocsite [[DBG3:!.*]]
2121

2222
// CHECK: [[DBG2]] = !DICompositeType(tag: DW_TAG_structure_type,
2323
// CHECK-SAME: name: "Foo"

0 commit comments

Comments
 (0)