[PATCH] D103131: support debug info for alias variable
kamlesh kumar via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed May 26 03:25:17 PDT 2021
kamleshbhalui updated this revision to Diff 347883.
kamleshbhalui retitled this revision from "support debug info for alias variable " to "support debug info for alias variable".
kamleshbhalui added a comment.
removed unnecessary code.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D103131/new/
https://reviews.llvm.org/D103131
Files:
clang/lib/CodeGen/CGDebugInfo.cpp
clang/lib/CodeGen/CGDebugInfo.h
clang/lib/CodeGen/CodeGenModule.cpp
clang/test/CodeGen/debug-info-alias.c
Index: clang/test/CodeGen/debug-info-alias.c
===================================================================
--- /dev/null
+++ clang/test/CodeGen/debug-info-alias.c
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited -triple x86_64-linux-unknown %s -o - | FileCheck %s
+
+// CHECK: !DIImportedEntity(tag: DW_TAG_imported_declaration, scope:{{.*}}, entity: ![[VAR:[0-9]+]]
+// CHECK: ![[VAR]] = !DIGlobalVariable(name: "newname"
+
+int oldname = 1;
+extern int newname __attribute__((alias("oldname")));
Index: clang/lib/CodeGen/CodeGenModule.cpp
===================================================================
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -4922,6 +4922,12 @@
setTLSMode(GA, *VD);
SetCommonAttributes(GD, GA);
+
+ // Emit global alias debug information.
+ if (const auto *VD = dyn_cast<VarDecl>(D)) {
+ if (CGDebugInfo *DI = getModuleDebugInfo())
+ DI->EmitGlobalAlias(VD);
+ }
}
void CodeGenModule::emitIFuncDefinition(GlobalDecl GD) {
Index: clang/lib/CodeGen/CGDebugInfo.h
===================================================================
--- clang/lib/CodeGen/CGDebugInfo.h
+++ clang/lib/CodeGen/CGDebugInfo.h
@@ -493,6 +493,9 @@
/// Emit information about an external variable.
void EmitExternalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl);
+ /// Emit information about global alias.
+ void EmitGlobalAlias(const VarDecl *Decl);
+
/// Emit C++ using directive.
void EmitUsingDirective(const UsingDirectiveDecl &UD);
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===================================================================
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -4945,6 +4945,19 @@
Var->addDebugInfo(GVE);
}
+void CGDebugInfo::EmitGlobalAlias(const VarDecl *D) {
+ if (!CGM.getCodeGenOpts().hasReducedDebugInfo())
+ return;
+
+ llvm::DIFile *Unit = getOrCreateFile(D->getLocation());
+ llvm::DIScope *DContext = getDeclContextDescriptor(D);
+ if (llvm::DINode *Target = getDeclarationOrDefinition(D)) {
+ auto Loc = D->getLocation();
+ DBuilder.createImportedDeclaration(DContext, Target, Unit,
+ getLineNumber(Loc));
+ }
+}
+
llvm::DIScope *CGDebugInfo::getCurrentContextDescriptor(const Decl *D) {
if (!LexicalBlockStack.empty())
return LexicalBlockStack.back();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D103131.347883.patch
Type: text/x-patch
Size: 2418 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210526/b8cb3a08/attachment.bin>
More information about the cfe-commits
mailing list