[PATCH] Context of DW_TAG_member

Hi,

When generating debugging information for a data member (e.g., a struct field), Clang doesn't set the member's context to the enclosed class/struct/union type --- it currently sets the context to the file instead. The attached patch corrects this. Thanks.

- xi

clang.diff (3.22 KB)

llvm.diff (2.8 KB)

Do you have a test case ?
Please update createMemberType() directly, instead of creating new overloaded createMemberType().
Thanks,

Hi,

When generating debugging information for a data member (e.g., a struct field), Clang doesn't set the member's context to the enclosed class/struct/union type --- it currently sets the context to the file instead. The attached patch corrects this. Thanks.

Do you have a test case ?

I guess the following case should be able to demonstrate the problem.

// RUN: %clang_cc1 -emit-llvm -g < %s | grep DW_TAG_member | grep \!3

struct A { int x; } a;

Compile it with -g. `grep DW_TAG_member' should give the line

!5 = metadata !{i32 589837, metadata !2, metadata !"x", metadata !2, i32 2, i64 32, i64 32, i64 0, i32 0, metadata !6} ; [ DW_TAG_member ]

Currently the second entry of the tuple is !2 (the file), which should have been !3 (the struct A).

Please update createMemberType() directly, instead of creating new overloaded createMemberType().

You are right. The ideal fix would be adding a "Context" parameter to createMemberType(). However doing so would require a lot of changes in CGDebugInfo.cpp because most calls to createMemberType (in CGDebugInfo.cpp) do not provide a context at all. If a large fix sounds ok I will make a new patch.

- xi

Hi,

When generating debugging information for a data member (e.g., a struct field), Clang doesn't set the member's context to the enclosed class/struct/union type --- it currently sets the context to the file instead. The attached patch corrects this. Thanks.

Do you have a test case ?

I guess the following case should be able to demonstrate the problem.

// RUN: %clang_cc1 -emit-llvm -g < %s | grep DW_TAG_member | grep \!3

struct A { int x; } a;

Compile it with -g. `grep DW_TAG_member' should give the line

!5 = metadata !{i32 589837, metadata !2, metadata !"x", metadata !2, i32 2, i64 32, i64 32, i64 0, i32 0, metadata !6} ; [ DW_TAG_member ]

Currently the second entry of the tuple is !2 (the file), which should have been !3 (the struct A).

That works. Actually, I was curious, how did you run into this issue ?

Please update createMemberType() directly, instead of creating new overloaded createMemberType().

You are right. The ideal fix would be adding a "Context" parameter to createMemberType(). However doing so would require a lot of changes in CGDebugInfo.cpp because most calls to createMemberType (in CGDebugInfo.cpp) do not provide a context at all. If a large fix sounds ok I will make a new patch.

Large fix OK. Please include test case in new patch.
Thanks,

That works. Actually, I was curious, how did you run into this issue ?

I was trying to print a struct field from the debugging information. However it doesn't refer to the struct at all.

Large fix OK. Please include test case in new patch.

A new patch along with a test is attached.

1) A scope parameter is added to DIBuilder::createMemberType.

2) In CGDebugInfo, a record/struct type parameter is also added to related functions.

Thanks.

- xi

member-clang.diff (8.9 KB)

member-llvm.diff (1.97 KB)

Looks good. I applied your patch. r133829.
Thanks!