re PR middle-end/80163 (ICE on hopefully valid code)
authorJakub Jelinek <jakub@redhat.com>
Fri, 31 Mar 2017 06:32:46 +0000 (08:32 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 31 Mar 2017 06:32:46 +0000 (08:32 +0200)
PR middle-end/80163
* varasm.c (initializer_constant_valid_p_1): Disallow sign-extending
conversions to integer types wider than word and pointer.

* gcc.dg/pr80163.c: New test.

From-SVN: r246607

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr80163.c [new file with mode: 0644]
gcc/varasm.c

index 1dca2cfb1963b72e061ff3a5d26bb62346f0fa7e..65aaca777060a3712576615b8b2182a21c3f0b5b 100644 (file)
@@ -1,5 +1,9 @@
 2017-03-31  Jakub Jelinek  <jakub@redhat.com>
 
+       PR middle-end/80163
+       * varasm.c (initializer_constant_valid_p_1): Disallow sign-extending
+       conversions to integer types wider than word and pointer.
+
        PR debug/80025
        * cselib.h (rtx_equal_for_cselib_1): Add depth argument.
        (rtx_equal_for_cselib_p): Pass 0 to it.
index 1b30193e01b927241648e0b36f1d057c1d6f0c84..af79d42596fca23a80fd22972febfb0ac89b4a45 100644 (file)
@@ -1,5 +1,8 @@
 2017-03-31  Jakub Jelinek  <jakub@redhat.com>
 
+       PR middle-end/80163
+       * gcc.dg/pr80163.c: New test.
+
        PR debug/80025
        * gcc.dg/torture/pr80025.c: New test.
 
diff --git a/gcc/testsuite/gcc.dg/pr80163.c b/gcc/testsuite/gcc.dg/pr80163.c
new file mode 100644 (file)
index 0000000..37a7abd
--- /dev/null
@@ -0,0 +1,22 @@
+/* PR middle-end/80163 */
+/* { dg-do compile { target int128 } } */
+/* { dg-options "-O0" } */
+
+void bar (void);
+
+__int128_t *
+foo (void)
+{
+a:
+  bar ();
+b:;
+  static __int128_t d = (long) &&a - (long) &&b;       /* { dg-error "initializer element is not computable at load time" } */
+  return &d;
+}
+
+__int128_t *
+baz (void)
+{
+  static __int128_t d = (long) (3 * 4);
+  return &d;
+}
index 11a8ac4bc8c0e30d78f11b2977b0fccfc9d305fe..05e48a5b894b1e35e8f8a286022798e92894b734 100644 (file)
@@ -4472,8 +4472,15 @@ initializer_constant_valid_p_1 (tree value, tree endtype, tree *cache)
          return initializer_constant_valid_p_1 (src, endtype, cache);
 
        /* Allow conversions between other integer types only if
-          explicit value.  */
-       if (INTEGRAL_TYPE_P (dest_type) && INTEGRAL_TYPE_P (src_type))
+          explicit value.  Don't allow sign-extension to a type larger
+          than word and pointer, there aren't relocations that would
+          allow to sign extend it to a wider type.  */
+       if (INTEGRAL_TYPE_P (dest_type)
+           && INTEGRAL_TYPE_P (src_type)
+           && (TYPE_UNSIGNED (src_type)
+               || TYPE_PRECISION (dest_type) <= TYPE_PRECISION (src_type)
+               || TYPE_PRECISION (dest_type) <= BITS_PER_WORD
+               || TYPE_PRECISION (dest_type) <= POINTER_SIZE))
          {
            tree inner = initializer_constant_valid_p_1 (src, endtype, cache);
            if (inner == null_pointer_node)