Author: rnk Date: Fri Nov 20 11:41:12 2015 New Revision: 253680 URL: http://llvm.org/viewvc/llvm-project?rev=253680&view=rev Log: [DebugInfo] Look through type sugar on union types when casting
Fixes PR25584. Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp cfe/trunk/test/CodeGenCXX/debug-info-anon-union-vars.cpp Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=253680&r1=253679&r2=253680&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original) +++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Fri Nov 20 11:41:12 2015 @@ -3329,7 +3329,7 @@ void CGDebugInfo::EmitGlobalVariable(llv // 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); Modified: cfe/trunk/test/CodeGenCXX/debug-info-anon-union-vars.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-anon-union-vars.cpp?rev=253680&r1=253679&r2=253680&view=diff ============================================================================== --- cfe/trunk/test/CodeGenCXX/debug-info-anon-union-vars.cpp (original) +++ cfe/trunk/test/CodeGenCXX/debug-info-anon-union-vars.cpp Fri Nov 20 11:41:12 2015 @@ -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( _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits