False ODR violation positives on anonymous namespace types

Jan Hubicka hubicka@ucw.cz
Tue May 12 14:13:00 GMT 2015


> On 05/11/2015 04:39 PM, Jan Hubicka wrote:
> >What happens in LTO is that lto-symtab decide to merge the two declarations of
> >foo.  At this time it has chance to output the warning.  For that it needs to
> >be able to work out that these declarations are having different types, but
> >because LTO merge canonical types on structural basis, types_compatible_p
> >(long, int) will return true.
> 
> OK.  So I guess it makes sense to check built-in integer types as
> well, but compound types should be compared structurally.

Yes, agreed. 
  if (flag_lto_odr_type_mering
      && TREE_CODE (decl) == TYPE_DECL
      && DECL_NAME (decl)
      && decl == TYPE_NAME (TREE_TYPE (decl))
      && !is_lang_specific (TREE_TYPE (decl))
      /* Save some work. Names of builtin types are always derived from
         properties of its main variant.  A special case are integer types
         where mangling do make differences between char/signed char/unsigned
         char etc.  Storing name for these makes e.g.
         -fno-signed-char/-fsigned-char mismatches to be handled well.

         See cp/mangle.c:write_builtin_type for details.  */
      && (TREE_CODE (TREE_TYPE (decl)) != VOID_TYPE
          && TREE_CODE (TREE_TYPE (decl)) != BOOLEAN_TYPE
          && TREE_CODE (TREE_TYPE (decl)) != REAL_TYPE
          && TREE_CODE (TREE_TYPE (decl)) != FIXED_POINT_TYPE)
      && !TYPE_ARTIFICIAL (TREE_TYPE (decl))
      && !variably_modified_type_p (TREE_TYPE (decl), NULL_TREE)
      && !type_in_anonymous_namespace_p (TREE_TYPE (decl)))

I probably want to check

      /* Record, union and enumeration type have linkage that allows use
	 to check type_in_anonymous_namespace_p. Compound types
	 can be always compared structurally.
	 To save some work we compare builtin types properties of its main
	 variant.  A special case are integer types where mangling do make
	 differences between char/signed char/unsigned char etc.  Storing name
	 for these makes e.g.  -fno-signed-char/-fsigned-char mismatches to be
	 handled well.

         See cp/mangle.c:write_builtin_type for details.  */
      && ((RECORD_OR_UNION_TYPE_P (TREE_TYPE (decl))
	   || TREE_CODE (TREE_TYPE (decl)) == ENUMERATION_TIME
	  && !type_in_anonymous_namespace_p (TREE_TYPE (decl)))
	  || TREE_CODE (TREE_TYPE (decl)) == INTEGER_TYPE)

I will test this.  Thank you!
Honza
> 
> Jason



More information about the Gcc-patches mailing list