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]

Silence redundant ODR violation warnings


Hi,
Firefox contains ODR violations in some of bigger classes which we
report correctly during ODR type merging but then find it necessary to
complain about every single method during symbol table merging. This
patch silences the later warning since having one is enough.

Bootstrapped/regtested x86_64-linux, comitted.

	* lto-symtab.c (lto_symtab_merge_decls_2): Do not report ODR violations
	for method whose basetype was already reported.

	* ipa-devirt.c (odr_type_violation_reported_p): New.
	* ipa-utils.h (odr_type_violation_reported_p): Declare.
Index: lto/lto-symtab.c
===================================================================
--- lto/lto-symtab.c	(revision 267377)
+++ lto/lto-symtab.c	(working copy)
@@ -697,10 +697,21 @@ lto_symtab_merge_decls_2 (symtab_node *f
 	{
 	  bool diag = false;
 	  if (level & 2)
-	    diag = warning_at (DECL_SOURCE_LOCATION (decl),
-			       OPT_Wodr,
-			       "%qD violates the C++ One Definition Rule",
-			       decl);
+	    {
+	      /* Silence warning for method and variables which belong
+	         to types which already have ODR violation reported.  Complaining
+		 once is enough.  */
+	      if (TREE_CODE (decl) != FUNCTION_DECL
+		  || TREE_CODE (TREE_TYPE (decl)) != METHOD_TYPE
+		  || !TYPE_METHOD_BASETYPE (TREE_TYPE (decl))
+		  || !odr_type_p (TYPE_METHOD_BASETYPE (TREE_TYPE (decl)))
+		  || !odr_type_violation_reported_p 
+			(TYPE_METHOD_BASETYPE (TREE_TYPE (decl))))
+		diag = warning_at (DECL_SOURCE_LOCATION (decl),
+				   OPT_Wodr,
+				   "%qD violates the C++ One Definition Rule",
+				   decl);
+	    }
 	  if (!diag && (level & 1))
 	    diag = warning_at (DECL_SOURCE_LOCATION (decl),
 			       OPT_Wlto_type_mismatch,
Index: ipa-devirt.c
===================================================================
--- ipa-devirt.c	(revision 267377)
+++ ipa-devirt.c	(working copy)
@@ -2152,6 +2152,12 @@ get_odr_type (tree type, bool insert)
   return val;
 }
 
+bool
+odr_type_violation_reported_p (tree type)
+{
+  return get_odr_type (type, false)->odr_violated;
+}
+
 /* Add TYPE od ODR type hash.  */
 
 void
Index: ipa-utils.h
===================================================================
--- ipa-utils.h	(revision 267377)
+++ ipa-utils.h	(working copy)
@@ -90,6 +91,7 @@ void warn_types_mismatch (tree t1, tree
 			  location_t loc2 = UNKNOWN_LOCATION);
 bool odr_or_derived_type_p (const_tree t);
 bool odr_types_equivalent_p (tree type1, tree type2);
+bool odr_type_violation_reported_p (tree type);
 
 /* Return vector containing possible targets of polymorphic call E.
    If COMPLETEP is non-NULL, store true if the list is complete. 


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