Skip to content

Commit 301a5bb

Browse files
committed
Change the metadata for heapallocsite calls when the type is cast.
llvm-svn: 359823
1 parent 8ccb8f8 commit 301a5bb

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

clang/lib/CodeGen/CGCall.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4370,7 +4370,6 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
43704370
}
43714371

43724372
// Add metadata for calls to MSAllocator functions
4373-
// FIXME: Get the type that the return value is cast to.
43744373
if (getDebugInfo() && TargetDecl &&
43754374
TargetDecl->hasAttr<MSAllocatorAttr>())
43764375
getDebugInfo()->addHeapAllocSiteMetadata(CI, RetTy, Loc);

clang/lib/CodeGen/CGExprScalar.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2063,6 +2063,12 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
20632063
}
20642064
}
20652065

2066+
// Update heapallocsite metadata when there is an explicit cast.
2067+
if (llvm::CallInst *CI = dyn_cast<llvm::CallInst>(Src))
2068+
if (CI->getMetadata("heapallocsite") && isa<ExplicitCastExpr>(CE))
2069+
CGF.getDebugInfo()->
2070+
addHeapAllocSiteMetadata(CI, CE->getType(), CE->getExprLoc());
2071+
20662072
return Builder.CreateBitCast(Src, DstTy);
20672073
}
20682074
case CK_AddressSpaceConversion: {
Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,23 @@
11
// RUN: %clang_cc1 -triple x86_64-windows-msvc -debug-info-kind=limited -gcodeview -fdeclspec -S -emit-llvm < %s | FileCheck %s
22

3-
struct Foo {
4-
int x;
5-
};
3+
struct Foo;
4+
struct Bar;
65

76
__declspec(allocator) void *alloc_void();
8-
__declspec(allocator) struct Foo *alloc_foo();
97

10-
void call_alloc_void() {
11-
struct Foo *p = (struct Foo*)alloc_void();
8+
void call_alloc() {
9+
struct Foo *p = alloc_void();
10+
struct Foo *q = (struct Foo*)alloc_void();
11+
struct Foo *r = (struct Foo*)(struct Bar*)alloc_void();
1212
}
1313

14-
void call_alloc_foo() {
15-
struct Foo *p = alloc_foo();
16-
}
17-
18-
// CHECK-LABEL: define {{.*}}void @call_alloc_void
14+
// CHECK-LABEL: define {{.*}}void @call_alloc
1915
// CHECK: call i8* {{.*}}@alloc_void{{.*}} !heapallocsite [[DBG1:!.*]]
20-
21-
// CHECK-LABEL: define {{.*}}void @call_alloc_foo
22-
// CHECK: call %struct.Foo* {{.*}}@alloc_foo{{.*}} !heapallocsite [[DBG2:!.*]]
16+
// CHECK: call i8* {{.*}}@alloc_void{{.*}} !heapallocsite [[DBG2:!.*]]
17+
// CHECK: call i8* {{.*}}@alloc_void{{.*}} !heapallocsite [[DBG3:!.*]]
2318

2419
// CHECK: [[DBG1]] = !{}
25-
// CHECK: [[DBG2]] = distinct !DICompositeType(tag: DW_TAG_structure_type,
20+
// CHECK: [[DBG2]] = !DICompositeType(tag: DW_TAG_structure_type,
2621
// CHECK-SAME: name: "Foo"
27-
22+
// CHECK: [[DBG3]] = !DICompositeType(tag: DW_TAG_structure_type,
23+
// CHECK-SAME: name: "Bar"

0 commit comments

Comments
 (0)