[PATCH] Fix PR debug/49130

Dodji Seketeli dodji@redhat.com
Tue May 31 17:43:00 GMT 2011


Hello,

In this PR an integer constant which type is a typedef based on an
integer might be pretty-printed differently from the way the mangler
would have represented it.  As a result, the DW_AT_name representing
the constant might be gratuitously be different from the linkage name.

In the example accompanying the patch:

The DW_AT_name of S<foo> is "S<2048u>", whereas the name of S<foo>.f
(as demangled from the linkage name) is S<2048ul>::f(unsigned long),
rightfully implying that the name of S<foo> should be "2048ul" instead
of "2048u".

The reason of this is that pp_c_integer_constant compares the type to
pretty print with a set of integer constant types, using pointer
comparison.  When the type to pretty print is actually a typedef, that
pointer comparison can fail even if the types are otherwise
equivalent.

Thus the patch considers the canonical type of the type to
pretty-print, when it is present.

Tested on x86_64-unknown-linux-gnu against trunk.

gcc/c-family/

	* c-pretty-print.c (pp_c_integer_constant): Consider the canonical
	type when using pointer comparison to compare types.

gcc/testsuite/

	* g++.dg/debug/dwarf2/integer-typedef.C: New test.
---
 gcc/c-family/c-pretty-print.c                      |    7 ++++-
 .../g++.dg/debug/dwarf2/integer-typedef.C          |   28 ++++++++++++++++++++
 2 files changed, 34 insertions(+), 1 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/debug/dwarf2/integer-typedef.C

diff --git a/gcc/c-family/c-pretty-print.c b/gcc/c-family/c-pretty-print.c
index e418903..518b373 100644
--- a/gcc/c-family/c-pretty-print.c
+++ b/gcc/c-family/c-pretty-print.c
@@ -901,7 +901,12 @@ pp_c_string_literal (c_pretty_printer *pp, tree s)
 static void
 pp_c_integer_constant (c_pretty_printer *pp, tree i)
 {
-  tree type = TREE_TYPE (i);
+  /* We are going to compare the type of I to other types using
+     pointer comparison so we need to use its canonical type.  */
+  tree type =
+    TYPE_CANONICAL (TREE_TYPE (i))
+    ? TYPE_CANONICAL (TREE_TYPE (i))
+    : TREE_TYPE (i);
 
   if (TREE_INT_CST_HIGH (i) == 0)
     pp_wide_integer (pp, TREE_INT_CST_LOW (i));
diff --git a/gcc/testsuite/g++.dg/debug/dwarf2/integer-typedef.C b/gcc/testsuite/g++.dg/debug/dwarf2/integer-typedef.C
new file mode 100644
index 0000000..42b3c99
--- /dev/null
+++ b/gcc/testsuite/g++.dg/debug/dwarf2/integer-typedef.C
@@ -0,0 +1,28 @@
+// Origin: PR debug/49130
+// { dg-options "-g -dA" }
+
+typedef long unsigned int size_t;
+static const size_t foo = 2048;
+
+template<size_t size>
+struct S
+{
+  void f(size_t);
+};
+
+template<size_t size>
+inline void
+S<size>::f(size_t)
+{
+  size_t i = size;
+}
+
+int
+main()
+{
+  S<foo> s1;
+  s1.f(10);
+}
+
+// { dg-final {scan-assembler-times "\[^\n\r\]*DW_AT_name: \"S<2048ul>\"" 1 } }
+// { dg-final {scan-assembler-times "\[^\n\r\]*DW_AT_MIPS_linkage_name: \"_ZN1SILm2048EE1fEm\"" 1 } }
-- 
		Dodji



More information about the Gcc-patches mailing list