diff options
| author | Reid Kleckner <rnk@google.com> | 2015-11-20 17:41:12 +0000 |
|---|---|---|
| committer | Reid Kleckner <rnk@google.com> | 2015-11-20 17:41:12 +0000 |
| commit | 43ecd7c71d690a18e655d6c88d6a6333cf750e7f (patch) | |
| tree | 9f92537d9cf3fdf02a2369c75a8b3e1c68194d68 | |
| parent | 4c152690be6986a69602977a3bac250efeb5bb11 (diff) | |
| download | bcm5719-llvm-43ecd7c71d690a18e655d6c88d6a6333cf750e7f.tar.gz bcm5719-llvm-43ecd7c71d690a18e655d6c88d6a6333cf750e7f.zip | |
[DebugInfo] Look through type sugar on union types when casting
Fixes PR25584.
llvm-svn: 253680
| -rw-r--r-- | clang/lib/CodeGen/CGDebugInfo.cpp | 2 | ||||
| -rw-r--r-- | clang/test/CodeGenCXX/debug-info-anon-union-vars.cpp | 17 |
2 files changed, 18 insertions, 1 deletions
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index 582fb730779..4305280a0c8 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -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); diff --git a/clang/test/CodeGenCXX/debug-info-anon-union-vars.cpp b/clang/test/CodeGenCXX/debug-info-anon-union-vars.cpp index 3d3dff7a5ed..5b0370eb749 100644 --- a/clang/test/CodeGenCXX/debug-info-anon-union-vars.cpp +++ b/clang/test/CodeGenCXX/debug-info-anon-union-vars.cpp @@ -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( |

