From 7d9cf8015969054f044ee815f0308e7130c59b83 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Tue, 20 Sep 2016 15:48:40 +0200 Subject: [PATCH] re PR middle-end/77624 (ICE on x86_64-linux-gnu (internal compiler error: in fold_builtin_atomic_always_lock_free, at builtins.c:5583)) 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 | 6 ++++++ gcc/builtins.c | 6 ++++-- gcc/testsuite/ChangeLog | 6 ++++++ gcc/testsuite/c-c++-common/pr77624-1.c | 14 ++++++++++++++ gcc/testsuite/c-c++-common/pr77624-2.c | 26 ++++++++++++++++++++++++++ 5 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/c-c++-common/pr77624-1.c create mode 100644 gcc/testsuite/c-c++-common/pr77624-2.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 7ab0b82009e..fbc0724fc2b 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2016-09-20 Jakub Jelinek + + 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 PR tree-optimization/77646 diff --git a/gcc/builtins.c b/gcc/builtins.c index 189aeac6912..9a19a75cc8e 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -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); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index dc99d913daa..d434027b52b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2016-09-20 Jakub Jelinek + + 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 * 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 index 00000000000..f3c095649aa --- /dev/null +++ b/gcc/testsuite/c-c++-common/pr77624-1.c @@ -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 index 00000000000..64d20e0eb6a --- /dev/null +++ b/gcc/testsuite/c-c++-common/pr77624-2.c @@ -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); +} -- 2.30.2