public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Fix lto-symtab ICE during Ada LTO bootstrap
@ 2015-11-21 18:35 Jan Hubicka
  2015-11-22 14:46 ` Eric Botcazou
  0 siblings, 1 reply; 25+ messages in thread
From: Jan Hubicka @ 2015-11-21 18:35 UTC (permalink / raw)
  To: gcc-patches, ebotcazou

Hi,
this patch fixes an ICE seen with Ada LTO bootstrap in reporting type mismatches
and it also makes us to stop complaining about C++ ODR violation.  The warnings
are however correct.  I looked at few:

../../libiberty/xstrerror.c:40:14: warning: type of �strerror� does not match original declaration [-Wlto-type-mismatch]
 extern char *strerror (int);
              ^

../../gcc/ada/s-os_lib.adb:1007:16: note: return value type mismatch
       function strerror (errnum : Integer) return System.Address;
                ^

../../gcc/ada/s-os_lib.adb:1007:16: note: �system__os_lib__errno_message__strerror� was previously declared here

Here we have function returning pointer WRT function returning integer:

 <function_decl 0x7ffff5865a80 strerror
    type <function_type 0x7ffff58660a8
        type <pointer_type 0x7ffff5808e70 type <integer_type 0x7ffff57dac78 char>
            public unsigned DI
            size <integer_cst 0x7ffff6ad7bb8 constant 64>
            unit size <integer_cst 0x7ffff6ad7bd0 constant 8>
            align 64 symtab 0 alias set -1 structural equality context <translation_unit_decl 0x7ffff579fac8 D.59070>
            pointer_to_this <pointer_type 0x7ffff584e1f8>>
        QI
        size <integer_cst 0x7ffff6ad7ca8 constant 8>
        unit size <integer_cst 0x7ffff6ad7cc0 constant 1>
        align 8 symtab 0 alias set 0 structural equality
        arg-types <tree_list 0x7ffff6910848 value <integer_type 0x7ffff6adb7e0 int>
            chain <tree_list 0x7ffff6ae99b0 value <void_type 0x7ffff6af0150 void>>>
        pointer_to_this <pointer_type 0x7ffff5866690>>
    addressable public external QI file ../../libiberty/xstrerror.c line 40 col 14 align 8 context <translation_unit_decl 0x7ffff5842d20 D.60311>>
 <function_decl 0x7ffff5ce6c40 system__os_lib__errno_message__strerror
    type <function_type 0x7ffff5ce5f18
        type <integer_type 0x7ffff6cc7d20 system__address public unsigned DI
            size <integer_cst 0x7ffff6ad7bb8 constant 64>
            unit size <integer_cst 0x7ffff6ad7bd0 constant 8>
            align 64 symtab 0 alias set -1 canonical type 0x7ffff6adb930 precision 64 min <integer_cst 0x7ffff6cb3cc0 0> max <integer_cst 0x7ffff6cbe2e0 18446744073709551615> context <translation_unit_decl 0x7ffff6ae1168 D.3880>
            pointer_to_this <pointer_type 0x7ffff5d08498> chain <type_decl 0x7ffff6cc6260 system__address>>
        QI
        size <integer_cst 0x7ffff6ad7ca8 constant 8>
        unit size <integer_cst 0x7ffff6ad7cc0 constant 1>
        align 8 symtab 0 alias set 0 structural equality
        arg-types <tree_list 0x7ffff6cc55a0 value <integer_type 0x7ffff6cc7930 integer>
            chain <tree_list 0x7ffff6ae99b0 value <void_type 0x7ffff6af0150 void>>>
        pointer_to_this <pointer_type 0x7ffff5d02bd0>>
    addressable public external QI file ../../gcc/ada/s-os_lib.adb line 1007 col 16 align 8 context <translation_unit_decl 0x7ffff6095f78 D.32418>>
$7 = void

<built-in>: warning: type of �__builtin_strlen� does not match original declaration [-Wlto-type-mismatch]
../../gcc/ada/osint.adb:422:19: note: return value type mismatch
../../gcc/ada/osint.adb:422:19: note: type �integer� should match type �long unsigned int�

Here the signedness of integer does not match:

 <integer_type 0x7ffff6adb9d8 long unsigned int public unsigned DI
    size <integer_cst 0x7ffff6ad7bb8 type <integer_type 0x7ffff6adb2a0 bitsizetype> constant 64>
    unit size <integer_cst 0x7ffff6ad7bd0 type <integer_type 0x7ffff6adb1f8 sizetype> constant 8>
    align 64 symtab 0 alias set -1 canonical type 0x7ffff6adb930 precision 64 min <integer_cst 0x7ffff6ad7e88 0> max <integer_cst 0x7ffff6ae64c0 18446744073709551615>
    pointer_to_this <pointer_type 0x7ffff59d2930>>
 <integer_type 0x7ffff6cc7930 integer
    type <integer_type 0x7ffff6adb7e0 int public SI
        size <integer_cst 0x7ffff6ad7df8 constant 32>
        unit size <integer_cst 0x7ffff6ad7e10 constant 4>
        align 32 symtab 0 alias set -1 canonical type 0x7ffff6adb7e0 precision 32 min <integer_cst 0x7ffff6ad7db0 -2147483648> max <integer_cst 0x7ffff6ad7dc8 2147483647>
        pointer_to_this <pointer_type 0x7ffff6af0930>>
    public SI size <integer_cst 0x7ffff6ad7df8 32> unit size <integer_cst 0x7ffff6ad7e10 4>
    align 32 symtab 0 alias set -1 canonical type 0x7ffff6adb7e0 precision 32 min <integer_cst 0x7ffff6cb3c78 -2147483648> max <integer_cst 0x7ffff6cb3c60 2147483647> context <translation_unit_decl 0x7ffff6ae1168 D.3880>
    pointer_to_this <pointer_type 0x7ffff614c9d8> chain <type_decl 0x7ffff6cc6130 integer>>
$17 = void

../../gcc/ada/s-os_lib.ads:1053:4: warning: type of �system__os_lib__directory_separator� does not match original declaration [-Wlto-type-mismatch]
    Directory_Separator : constant Character;
    ^

../../gcc/ada/adaint.c:225:6: note: type �char� should match type �volatile character�
 char __gnat_dir_separator = DIR_SEPARATOR;
      ^

Here we get difference in  signedness and volatility:

 <var_decl 0x7ffff69871b0 __gnat_dir_separator
    type <integer_type 0x7ffff6964738 char public string-flag QI
        size <integer_cst 0x7ffff6ad7ca8 constant 8>
        unit size <integer_cst 0x7ffff6ad7cc0 constant 1>
        align 8 symtab 0 alias set 0 canonical type 0x7ffff6adb5e8 precision 8 min <integer_cst 0x7ffff6936810 -128> max <integer_cst 0x7ffff6936828 127>
        pointer_to_this <pointer_type 0x7ffff576be70> reference_to_this <reference_type 0x7ffff5a00dc8>>
    addressable public static QI file ../../gcc/ada/adaint.c line 225 col 6 size <integer_cst 0x7ffff6ad7ca8 8> unit size <integer_cst 0x7ffff6ad7cc0 1>
    align 8 context <translation_unit_decl 0x7ffff6ae1708 D.5140> initial <integer_cst 0x7ffff6936f90 47>>
$18 = void
(gdb) p debug_tree (decl)
 <var_decl 0x7ffff5f86c60 system__os_lib__directory_separator
    type <integer_type 0x7ffff6ccf150 character volatile unsigned string-flag QI
        size <integer_cst 0x7ffff6ad7ca8 constant 8>
        unit size <integer_cst 0x7ffff6ad7cc0 constant 1>
        align 8 symtab 0 alias set -1 canonical type 0x7ffff6adb5e8 precision 8 min <integer_cst 0x7ffff6ad7cd8 0> max <integer_cst 0x7ffff6ad7c78 255> context <translation_unit_decl 0x7ffff6ae1168 D.3880>
        pointer_to_this <pointer_type 0x7ffff68e32a0>>
    side-effects addressable volatile public unsigned external QI file ../../gcc/ada/s-os_lib.ads line 1053 col 4 size <integer_cst 0x7ffff6ad7ca8 8> unit size <integer_cst 0x7ffff6ad7cc0 1>
    align 8 context <translation_unit_decl 0x7ffff5ee2780 D.29282>>
$19 = void

All those types will lead to wrong code if ever written to same memory location
because of TBAA.  Eric, does Ada need all this types to be TBAA compatible?
If so, we need to implement more strict globbing as we did for Fortran and we
probably finally need to make the globbing aware of languages involved (we
definitly don't want to glob pointers and integers for C/C++ programs)

Eric, it would be great to have a stand alone testcases in style of
gcc/testsuite/gfortran.dg/lto/bind_c-*
which stores and reads the same memory location in same alias set and thus
trigger the undefined behvaiour.

Bootstrapped/regtested x86_64-linux, will commit it shortly.

Honza

	* lto-symtab.c (warn_type_compatibility_p): Do not set ODR mismatch
	flag for types that are not ODR; fix loop walking parameters.
Index: lto-symtab.c
===================================================================
--- lto-symtab.c	(revision 230683)
+++ lto-symtab.c	(working copy)
@@ -180,16 +180,26 @@ lto_varpool_replace_node (varpool_node *
 /* Return non-zero if we want to output waring about T1 and T2.
    Return value is a bitmask of reasons of violation:
    Bit 0 indicates that types are not compatible of memory layout.
-   Bot 1 indicates that types are not compatible because of C++ ODR rule.  */
+   Bit 1 indicates that types are not compatible because of C++ ODR rule.  */
 
 static int
 warn_type_compatibility_p (tree prevailing_type, tree type)
 {
   int lev = 0;
+
+  /* Get complete type.
+     ???  We might want to emit a warning here if type qualification
+     differences were spotted.  Do not do this unconditionally though.  */
+  type = TYPE_MAIN_VARIANT (type);
+  prevailing_type = TYPE_MAIN_VARIANT (prevailing_type);
+  if (prevailing_type == type)
+    return 0;
+
+  bool odr_p = odr_or_derived_type_p (prevailing_type)
+	       && odr_or_derived_type_p (type);
   /* C++ provide a robust way to check for type compatibility via the ODR
      rule.  */
-  if (odr_or_derived_type_p (prevailing_type) && odr_or_derived_type_p (type)
-      && !odr_types_equivalent_p (prevailing_type, type))
+  if (odr_p && !odr_types_equivalent_p (prevailing_type, type))
     lev = 2;
 
   /* Function types needs special care, because types_compatible_p never
@@ -209,15 +219,15 @@ warn_type_compatibility_p (tree prevaili
 	  for (parm1 = TYPE_ARG_TYPES (prevailing_type),
 	       parm2 = TYPE_ARG_TYPES (type);
 	       parm1 && parm2;
-	       parm1 = TREE_CHAIN (prevailing_type),
-	       parm2 = TREE_CHAIN (type))
+	       parm1 = TREE_CHAIN (parm1),
+	       parm2 = TREE_CHAIN (parm2))
 	    lev |= warn_type_compatibility_p (TREE_VALUE (parm1),
 					      TREE_VALUE (parm2));
 	  if (parm1 || parm2)
-	    lev = 3;
+	    lev = odr_p ? 3 : 1;
 	}
       if (comp_type_attributes (prevailing_type, type) == 0)
-	lev = 3;
+	lev = odr_p ? 3 : 1;
       return lev;
     }
   /* Sharing a global symbol is a strong hint that two types are
@@ -270,9 +280,6 @@ warn_type_compatibility_p (tree prevaili
       /* Fallthru.  Compatible enough.  */
     }
 
-  /* ???  We might want to emit a warning here if type qualification
-     differences were spotted.  Do not do this unconditionally though.  */
-
   return lev;
 }
 

^ permalink raw reply	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2015-12-21 15:16 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-21 18:35 Fix lto-symtab ICE during Ada LTO bootstrap Jan Hubicka
2015-11-22 14:46 ` Eric Botcazou
2015-11-22 15:17   ` Arnaud Charlet
2015-11-23  1:24     ` Jan Hubicka
2015-11-23  9:59       ` Arnaud Charlet
2015-11-23 11:13         ` Eric Botcazou
2015-11-23 11:24           ` Arnaud Charlet
2015-11-23 12:00             ` Eric Botcazou
2015-11-23 13:35               ` Richard Biener
2015-11-23 16:05                 ` Eric Botcazou
2015-11-23 16:17                   ` H.J. Lu
2015-11-23 16:26                     ` Eric Botcazou
2015-11-23 16:31                       ` Arnaud Charlet
2015-11-23 19:05                       ` Jan Hubicka
2015-11-23 22:29                         ` Eric Botcazou
2015-11-23 22:53                           ` Jan Hubicka
2015-11-23 23:09                             ` Jan Hubicka
2015-12-20  6:54                         ` Jan Hubicka
2015-12-20  8:14                           ` Eric Botcazou
2015-12-20 22:20                         ` Eric Botcazou
2015-12-21 10:20                           ` Eric Botcazou
2015-12-21 14:19                             ` Jan Hubicka
2015-12-21 15:16                               ` Eric Botcazou
2015-12-21 14:20                             ` Jan Hubicka
2015-11-22 18:49   ` Jan Hubicka

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).