This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[lto] Reset diagnostic hooks after removing language data


After we run pass_ipa_free_lang_specifics, the diagnostic
machinery from the front ends cannot access anything that has
been freed up.  In particular, trying to print mangled symbols
will not work.

This patch resets the diagnostic hooks to the default ones.  This
is suboptimal as messages coming from the optimizers will not
pretty print all function names.  For instance, for the attached
case we'll now emit:

20090121-1.C: In member function '__comp_ctor ':
20090121-1.C:7: warning: 'x' is used uninitialized in this function

instead of the friendlier:

20090121-1.C: In constructor 'A::A()':
20090121-1.C:7: warning: 'x' is used uninitialized in this function

The long term solution is to implement gimple variants of these
hooks and teach them to access mangled names.  For now, this will
at least stops us from ICEing on warnings.

Tested on x86_64.


Diego.


	* tree.c: Include diagnostic.h.
	(free_lang_specifics): Reset diagnostic hooks to the
	default hooks.
	* diagnostic.h (default_tree_printer): Declare.
	* toplev.c (default_tree_printer): Make extern.
	* Makefile.in (tree.o): Add dependency on $(DIAGNOSTIC_H)

testsuite/ChangeLog.lto

	* g++.dg/20090121-1.C: New.

Index: tree.c
===================================================================
--- tree.c	(revision 143548)
+++ tree.c	(working copy)
@@ -53,6 +53,7 @@ along with GCC; see the file COPYING3.  
 #include "fixed-value.h"
 #include "tree-pass.h"
 #include "langhooks-def.h"
+#include "diagnostic.h"
 
 /* Tree code classes.  */
 
@@ -4165,6 +4166,12 @@ free_lang_specifics (void)
      new decls. */
   lang_hooks.set_decl_assembler_name = lhd_set_decl_assembler_name;
 
+  /* FIXME lto: We should implement a diagnostic machinery for GIMPLE
+     that can unmangle symbols and types.  For now, the default hooks
+     work but will not be able to print C++ symbols.  */
+  diagnostic_initialize (global_dc);
+  diagnostic_format_decoder (global_dc) = default_tree_printer;
+
   return 0;
 }
 
Index: diagnostic.h
===================================================================
--- diagnostic.h	(revision 143548)
+++ diagnostic.h	(working copy)
@@ -233,4 +233,8 @@ extern void print_gimple_stmt (FILE *, g
 extern void print_gimple_expr (FILE *, gimple, int, int);
 extern void dump_gimple_stmt (pretty_printer *, gimple, int, int);
 
+/* In toplev.c  */
+extern bool default_tree_printer (pretty_printer *, text_info *, const char *,
+				  int, bool, bool, bool);
+
 #endif /* ! GCC_DIAGNOSTIC_H */
Index: toplev.c
===================================================================
--- toplev.c	(revision 143548)
+++ toplev.c	(working copy)
@@ -1505,7 +1505,7 @@ default_pch_valid_p (const void *data_p,
 }
 
 /* Default tree printer.   Handles declarations only.  */
-static bool
+bool
 default_tree_printer (pretty_printer *pp, text_info *text, const char *spec,
 		      int precision, bool wide, bool set_locus, bool hash)
 {
Index: testsuite/g++.dg/20090121-1.C
===================================================================
--- testsuite/g++.dg/20090121-1.C	(revision 0)
+++ testsuite/g++.dg/20090121-1.C	(revision 0)
@@ -0,0 +1,18 @@
+// { dg-do compile }
+// { dg-options "-fwhopr -Wuninitialized -O2" }
+class A
+{
+private:
+  int y;
+
+public:
+  A () { int x; y = x + 1; } /* { dg-warning "'x' is used uninitialized in this function" }  */
+  int get_y () { return y; }
+};
+
+int foo()
+{
+  A a;
+  return a.get_y ();
+}
+
Index: Makefile.in
===================================================================
--- Makefile.in	(revision 143548)
+++ Makefile.in	(working copy)
@@ -2134,7 +2134,8 @@ tree.o : tree.c $(CONFIG_H) $(SYSTEM_H) 
    all-tree.def $(FLAGS_H) $(FUNCTION_H) $(PARAMS_H) \
    $(TOPLEV_H) $(GGC_H) $(HASHTAB_H) $(TARGET_H) output.h $(TM_P_H) langhooks.h \
    $(REAL_H) gt-tree.h tree-iterator.h $(BASIC_BLOCK_H) $(TREE_FLOW_H) \
-   $(OBSTACK_H) pointer-set.h fixed-value.h tree-pass.h langhooks-def.h
+   $(OBSTACK_H) pointer-set.h fixed-value.h tree-pass.h langhooks-def.h \
+   $(DIAGNOSTIC_H)
 tree-dump.o: tree-dump.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \
    $(TREE_H) langhooks.h $(TOPLEV_H) $(SPLAY_TREE_H) $(TREE_DUMP_H) \
    tree-iterator.h tree-pass.h $(DIAGNOSTIC_H) $(REAL_H) fixed-value.h


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]