[PATCH] D35994: Debug info for variables whos type is shrinked to bool

Nikola Prica via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 28 07:01:11 PDT 2017


NikolaPrica created this revision.
Herald added a subscriber: aprantl.

During the globalopt transformation, when shrinking variable type into boolean, debug information for static global variables is dispatched. As a result there is no DW_AT_location and they debugger is not able to read such variables.


https://reviews.llvm.org/D35994

Files:
  lib/Transforms/IPO/GlobalOpt.cpp
  test/Transforms/GlobalOpt/static-global-boolean-dwarf.c


Index: test/Transforms/GlobalOpt/static-global-boolean-dwarf.c
===================================================================
--- /dev/null
+++ test/Transforms/GlobalOpt/static-global-boolean-dwarf.c
@@ -0,0 +1,37 @@
+// RUN: clang -g -O2 -c %s -o %t
+// RUN: llvm-dwarfdump %t | FileCheck %s
+
+
+enum myboolean {TRUE,FALSE};
+typedef enum myboolean boolean;
+
+
+static boolean foo;
+
+boolean get_foo(void){ return (foo);}
+
+void
+init_boolean(int arg){
+  if(arg == 1){
+    foo = FALSE;
+    arg++;
+  } else {
+    foo = TRUE;
+    arg--;
+  }
+}
+
+
+int main(int argc, char *argv[])
+{
+  init_boolean(argc == 2);
+  return 0;
+}
+
+
+
+// CHECK:   DW_AT_name [DW_FORM_strp] {{.*}} "foo"
+// CHECK-NEXT:   DW_AT_type
+// CHECK-NEXT:   DW_AT_decl_file
+// CHECK-NEXT:   DW_AT_decl_line
+// CHECK-NEXT:   DW_AT_location
Index: lib/Transforms/IPO/GlobalOpt.cpp
===================================================================
--- lib/Transforms/IPO/GlobalOpt.cpp
+++ lib/Transforms/IPO/GlobalOpt.cpp
@@ -1570,6 +1570,12 @@
                                              GV->getThreadLocalMode(),
                                              GV->getType()->getAddressSpace());
   NewGV->copyAttributesFrom(GV);
+
+  SmallVector<DIGlobalVariableExpression *, 1> GVs;
+  GV->getDebugInfo(GVs);
+  for(auto *GV : GVs)
+    NewGV->addDebugInfo(GV);
+
   GV->getParent()->getGlobalList().insert(GV->getIterator(), NewGV);
 
   Constant *InitVal = GV->getInitializer();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D35994.108641.patch
Type: text/x-patch
Size: 1477 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170728/00a464e0/attachment.bin>


More information about the llvm-commits mailing list