Skip to content

Commit

Permalink
[DebugInfo] Look through type sugar on union types when casting
Browse files Browse the repository at this point in the history
Fixes PR25584.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@253680 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
rnk committed Nov 20, 2015
1 parent 24d8ca5 commit da953be
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/CodeGen/CGDebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3329,7 +3329,7 @@ void CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var,
// variable for each member of the anonymous union so that it's possible
// to find the name of any field in the union.
if (T->isUnionType() && DeclName.empty()) {
const RecordDecl *RD = cast<RecordType>(T)->getDecl();
const RecordDecl *RD = T->castAs<RecordType>()->getDecl();
assert(RD->isAnonymousStructOrUnion() &&
"unnamed non-anonymous struct or union?");
GV = CollectAnonRecordDecls(RD, Unit, LineNo, LinkageName, Var, DContext);
Expand Down
17 changes: 17 additions & 0 deletions test/CodeGenCXX/debug-info-anon-union-vars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,28 @@ void foo() {
i = 8;
}

// A funky reinterpret cast idiom that we used to crash on.
template <class T>
unsigned char *buildBytes(const T v) {
static union {
unsigned char result[sizeof(T)];
T value;
};
value = v;
return result;
}

void instantiate(int x) {
buildBytes(x);
}

// CHECK: [[FILE:.*]] = !DIFile(filename: "{{.*}}debug-info-anon-union-vars.cpp",
// CHECK: !DIGlobalVariable(name: "c",{{.*}} file: [[FILE]], line: 6,{{.*}} isLocal: true, isDefinition: true
// CHECK: !DIGlobalVariable(name: "d",{{.*}} file: [[FILE]], line: 6,{{.*}} isLocal: true, isDefinition: true
// CHECK: !DIGlobalVariable(name: "a",{{.*}} file: [[FILE]], line: 6,{{.*}} isLocal: true, isDefinition: true
// CHECK: !DIGlobalVariable(name: "b",{{.*}} file: [[FILE]], line: 6,{{.*}} isLocal: true, isDefinition: true
// CHECK: !DIGlobalVariable(name: "result", {{.*}} isLocal: false, isDefinition: true
// CHECK: !DIGlobalVariable(name: "value", {{.*}} isLocal: false, isDefinition: true
// CHECK: !DILocalVariable(name: "i", {{.*}}, flags: DIFlagArtificial
// CHECK: !DILocalVariable(name: "c", {{.*}}, flags: DIFlagArtificial
// CHECK: !DILocalVariable(
Expand Down

0 comments on commit da953be

Please sign in to comment.