[clang] 585f62b - CodeGen: correct handling of debug info generation for aliases

Saleem Abdulrasool via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 16 14:27:18 PDT 2022


Author: Saleem Abdulrasool
Date: 2022-08-16T21:27:05Z
New Revision: 585f62be1a438ca132aa443e556d102bc908a072

URL: https://github.com/llvm/llvm-project/commit/585f62be1a438ca132aa443e556d102bc908a072
DIFF: https://github.com/llvm/llvm-project/commit/585f62be1a438ca132aa443e556d102bc908a072.diff

LOG: CodeGen: correct handling of debug info generation for aliases

When aliasing a static array, the aliasee is going to be a GEP which
points to the value.  We should strip pointer casts before forming the
reference.  This was occluded by the use of opaque pointers.

This problem has existed since the introduction of the debug info
generation for aliases in b1ea0191a42074341847d767609f66a26b6d5a41.  The
test case would assert due to the invalid cast with or without
`-no-opaque-pointers` at that revision.

Fixes: #57179

Added: 
    clang/test/CodeGen/debug-info-alias-pointer.c

Modified: 
    clang/lib/CodeGen/CodeGenModule.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index c30bccb1bbd30..0921008e254c3 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -5338,7 +5338,7 @@ void CodeGenModule::EmitAliasDefinition(GlobalDecl GD) {
   // Emit global alias debug information.
   if (isa<VarDecl>(D))
     if (CGDebugInfo *DI = getModuleDebugInfo())
-      DI->EmitGlobalAlias(cast<llvm::GlobalValue>(GA->getAliasee()), GD);
+      DI->EmitGlobalAlias(cast<llvm::GlobalValue>(GA->getAliasee()->stripPointerCasts()), GD);
 }
 
 void CodeGenModule::emitIFuncDefinition(GlobalDecl GD) {

diff  --git a/clang/test/CodeGen/debug-info-alias-pointer.c b/clang/test/CodeGen/debug-info-alias-pointer.c
new file mode 100644
index 0000000000000..507a101fe0dc5
--- /dev/null
+++ b/clang/test/CodeGen/debug-info-alias-pointer.c
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-windows-msvc -emit-llvm -debug-info-kind=limited %s -o - | FileCheck %s
+// REQUIRES: asserts
+
+struct S {
+  void *p;
+};
+
+struct S s[] = {
+  { .p = (void *)0, },
+};
+
+extern struct S t __attribute__((__alias__("s")));
+
+// CHECK: !DIImportedEntity(tag: DW_TAG_imported_declaration, name: "t", scope: {{.*}}, entity: {{.*}}, file: {{.*}}, line: 12)


        


More information about the cfe-commits mailing list