]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR middle-end/77624 (ICE on x86_64-linux-gnu (internal compiler error...
authorJakub Jelinek <jakub@redhat.com>
Tue, 30 May 2017 07:26:43 +0000 (09:26 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 30 May 2017 07:26:43 +0000 (09:26 +0200)
Backported from mainline
2016-09-20  Jakub Jelinek  <jakub@redhat.com>

PR middle-end/77624
* builtins.c (fold_builtin_atomic_always_lock_free): Only look through
cast to void * if the cast is from some other pointer type.

* c-c++-common/pr77624-1.c: New test.
* c-c++-common/pr77624-2.c: New test.

From-SVN: r248610

gcc/ChangeLog
gcc/builtins.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/pr77624-1.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/pr77624-2.c [new file with mode: 0644]

index e0684313adbbdac8d4afd4d6b291865525c2eeed..df789e32f24f3446552344c510a2a2d23ee6688f 100644 (file)
@@ -1,6 +1,12 @@
 2017-05-30  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2016-09-20  Jakub Jelinek  <jakub@redhat.com>
+
+       PR middle-end/77624
+       * builtins.c (fold_builtin_atomic_always_lock_free): Only look through
+       cast to void * if the cast is from some other pointer type.
+
        2016-09-19  Jakub Jelinek  <jakub@redhat.com>
                    Jan Hubicka  <jh@suse.cz>
 
index f6a7f21da4d48174e1fe5bcf209fef91fb8fb5bd..d408c7a53ad1a684fe589b9dfff3ef32ab8478b6 100644 (file)
@@ -5719,8 +5719,10 @@ fold_builtin_atomic_always_lock_free (tree arg0, tree arg1)
         end before anything else has a chance to look at it.  The pointer
         parameter at this point is usually cast to a void *, so check for that
         and look past the cast.  */
-      if (CONVERT_EXPR_P (arg1) && POINTER_TYPE_P (ttype)
-         && VOID_TYPE_P (TREE_TYPE (ttype)))
+      if (CONVERT_EXPR_P (arg1)
+         && POINTER_TYPE_P (ttype)
+         && VOID_TYPE_P (TREE_TYPE (ttype))
+         && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (arg1, 0))))
        arg1 = TREE_OPERAND (arg1, 0);
 
       ttype = TREE_TYPE (arg1);
index 5bec5e04d6aea15789f41eb85603197a312b45f2..7a2b4bc8c68227c30d8312ff433daca6b1cad427 100644 (file)
@@ -1,6 +1,12 @@
 2017-05-30  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2016-09-20  Jakub Jelinek  <jakub@redhat.com>
+
+       PR middle-end/77624
+       * c-c++-common/pr77624-1.c: New test.
+       * c-c++-common/pr77624-2.c: New test.
+
        2016-09-19  Jakub Jelinek  <jakub@redhat.com>
                    Jan Hubicka  <jh@suse.cz>
 
diff --git a/gcc/testsuite/c-c++-common/pr77624-1.c b/gcc/testsuite/c-c++-common/pr77624-1.c
new file mode 100644 (file)
index 0000000..f3c0956
--- /dev/null
@@ -0,0 +1,14 @@
+/* PR middle-end/77624 */
+/* { dg-do compile } */
+
+int
+foo (int a)
+{
+  return __atomic_is_lock_free (2, a);         /* { dg-warning "pointer from integer" "" { target c } } */
+}                                              /* { dg-error "invalid conversion" "" { target c++ } 7 } */
+
+int
+bar (int a)
+{
+  return __atomic_always_lock_free (2, a);     /* { dg-warning "pointer from integer" "" { target c } } */
+}                                              /* { dg-error "invalid conversion" "" { target c++ } 13 } */
diff --git a/gcc/testsuite/c-c++-common/pr77624-2.c b/gcc/testsuite/c-c++-common/pr77624-2.c
new file mode 100644 (file)
index 0000000..64d20e0
--- /dev/null
@@ -0,0 +1,26 @@
+/* PR middle-end/77624 */
+/* { dg-do compile } */
+
+void
+foo (int *a)
+{
+  double b = 0;
+  __atomic_is_lock_free (2, a, 2);     /* { dg-error "too many arguments" } */
+  __atomic_is_lock_free (2);           /* { dg-error "too few arguments" } */
+  __atomic_is_lock_free (2, b);                /* { dg-error "incompatible type" "" { target c } } */
+                                       /* { dg-message "expected" "" { target c } 10 } */
+                                       /* { dg-error "convert" "" { target c++ } 10 } */
+  __atomic_is_lock_free (2, 0);
+}
+
+void
+bar (int *a)
+{
+  double b = 0;
+  __atomic_always_lock_free (2, a, 2); /* { dg-error "too many arguments" } */
+  __atomic_always_lock_free (2);       /* { dg-error "too few arguments" } */
+  __atomic_always_lock_free (2, b);    /* { dg-error "incompatible type" "" { target c } } */
+                                       /* { dg-message "expected" "" { target c } 22 } */
+                                       /* { dg-error "convert" "" { target c++ } 22 } */
+  __atomic_always_lock_free (2, 0);
+}