re PR middle-end/77624 (ICE on x86_64-linux-gnu (internal compiler error: in fold_bui...
authorJakub Jelinek <jakub@redhat.com>
Tue, 20 Sep 2016 13:48:40 +0000 (15:48 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 20 Sep 2016 13:48:40 +0000 (15:48 +0200)
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: r240263

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 7ab0b82..fbc0724 100644 (file)
@@ -1,3 +1,9 @@
+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-20  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/77646
index 189aeac..9a19a75 100644 (file)
@@ -5575,8 +5575,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 dc99d91..d434027 100644 (file)
@@ -1,3 +1,9 @@
+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-20  Andre Vehreschild  <vehre@gcc.gnu.org>
 
        * gfortran.dg/coarray_allocate_7.f08: Using + instead of fixed number
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);
+}