r236110 - Revert "Debug Info: Represent local anonymous unions as anonymous unions"
Adrian Prantl
aprantl at apple.com
Wed Apr 29 08:05:50 PDT 2015
Author: adrian
Date: Wed Apr 29 10:05:50 2015
New Revision: 236110
URL: http://llvm.org/viewvc/llvm-project?rev=236110&view=rev
Log:
Revert "Debug Info: Represent local anonymous unions as anonymous unions"
This reverts commit r236059 as it breaks the gdb buildbot.
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=236110&r1=236109&r2=236110&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Wed Apr 29 10:05:50 2015
@@ -2835,6 +2835,31 @@ void CGDebugInfo::EmitDeclare(const VarD
return;
} else if (isa<VariableArrayType>(VD->getType()))
Expr.push_back(llvm::dwarf::DW_OP_deref);
+ } else if (const RecordType *RT = dyn_cast<RecordType>(VD->getType())) {
+ // If VD is an anonymous union then Storage represents value for
+ // all union fields.
+ const RecordDecl *RD = cast<RecordDecl>(RT->getDecl());
+ if (RD->isUnion() && RD->isAnonymousStructOrUnion()) {
+ for (const auto *Field : RD->fields()) {
+ llvm::MDType *FieldTy = getOrCreateType(Field->getType(), Unit);
+ StringRef FieldName = Field->getName();
+
+ // Ignore unnamed fields. Do not ignore unnamed records.
+ if (FieldName.empty() && !isa<RecordType>(Field->getType()))
+ continue;
+
+ // Use VarDecl's Tag, Scope and Line number.
+ auto *D = DBuilder.createLocalVariable(
+ Tag, Scope, FieldName, Unit, Line, FieldTy,
+ CGM.getLangOpts().Optimize, Flags, ArgNo);
+
+ // Insert an llvm.dbg.declare into the current block.
+ DBuilder.insertDeclare(Storage, D, DBuilder.createExpression(Expr),
+ llvm::DebugLoc::get(Line, Column, Scope),
+ Builder.GetInsertBlock());
+ }
+ return;
+ }
}
// Create the descriptor for the variable.
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=236110&r1=236109&r2=236110&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/debug-info-anon-union-vars.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/debug-info-anon-union-vars.cpp Wed Apr 29 10:05:50 2015
@@ -21,26 +21,8 @@ int test_it() {
return (c == 1);
}
-// This is not necessary (and actually harmful because it breaks IR assumptions)
-// for local variables.
-void foo() {
- union {
- int i;
- char c;
- };
- i = 8;
-}
-
// CHECK: [[FILE:.*]] = !MDFile(filename: "{{.*}}debug-info-anon-union-vars.cpp",
// CHECK: !MDGlobalVariable(name: "c",{{.*}} file: [[FILE]], line: 6,{{.*}} isLocal: true, isDefinition: true
// CHECK: !MDGlobalVariable(name: "d",{{.*}} file: [[FILE]], line: 6,{{.*}} isLocal: true, isDefinition: true
// CHECK: !MDGlobalVariable(name: "a",{{.*}} file: [[FILE]], line: 6,{{.*}} isLocal: true, isDefinition: true
// CHECK: !MDGlobalVariable(name: "b",{{.*}} file: [[FILE]], line: 6,{{.*}} isLocal: true, isDefinition: true
-// CHECK: !MDLocalVariable(
-// CHECK-NOT: name:
-// CHECK: type: ![[UNION:[0-9]+]]
-// CHECK: ![[UNION]] = !MDCompositeType(tag: DW_TAG_union_type,
-// CHECK-NOT: name:
-// CHECK: elements
-// CHECK: !MDDerivedType(tag: DW_TAG_member, name: "i", scope: ![[UNION]],
-// CHECK: !MDDerivedType(tag: DW_TAG_member, name: "c", scope: ![[UNION]],
More information about the cfe-commits
mailing list