diff options
author | Jakub Jelinek <jakub@redhat.com> | 2020-04-27 16:05:03 +0200 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2020-04-27 16:10:24 +0200 |
commit | 26d76be7af6db75aaab662f4e93395f4ff8acb38 (patch) | |
tree | c00ee59fc9ba9b3a2acb841a5d3d8f0fd371055a | |
parent | 6b6a77d25e83e071ba5d08648c5bd3953d8a0c03 (diff) | |
download | gcc-26d76be7af6db75aaab662f4e93395f4ff8acb38.zip gcc-26d76be7af6db75aaab662f4e93395f4ff8acb38.tar.gz gcc-26d76be7af6db75aaab662f4e93395f4ff8acb38.tar.bz2 |
c-family: Fix ICE on __builtin_speculation_safe_value () [PR94755]
When this builtin has no parameters, speculation_safe_value_resolve_call
returns BUILT_IN_NONE, but resolve_overloaded_builtin uselessly
dereferences the first param just to return error_mark_node immediately.
The following patch rearranges it so that we only read the first parameter
if fncode is not BUILT_IN_NONE.
2020-04-27 Jakub Jelinek <jakub@redhat.com>
PR c/94755
* c-common.c (resolve_overloaded_builtin): Return error_mark_node for
fncode == BUILT_IN_NONE before initialization of first_param.
* c-c++-common/pr94755.c: New test.
-rw-r--r-- | gcc/c-family/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/c-family/c-common.c | 6 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/c-c++-common/pr94755.c | 11 |
4 files changed, 26 insertions, 2 deletions
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index 55e6eb8..973dc70 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,9 @@ +2020-04-27 Jakub Jelinek <jakub@redhat.com> + + PR c/94755 + * c-common.c (resolve_overloaded_builtin): Return error_mark_node for + fncode == BUILT_IN_NONE before initialization of first_param. + 2020-04-23 Marek Polacek <polacek@redhat.com> PR c++/94733 diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index 8e5a924..4e46178 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -7402,9 +7402,11 @@ resolve_overloaded_builtin (location_t loc, tree function, enum built_in_function fncode = speculation_safe_value_resolve_call (function, params);; + if (fncode == BUILT_IN_NONE) + return error_mark_node; + first_param = (*params)[0]; - if (fncode == BUILT_IN_NONE - || !speculation_safe_value_resolve_params (loc, function, params)) + if (!speculation_safe_value_resolve_params (loc, function, params)) return error_mark_node; if (targetm.have_speculation_safe_value (true)) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index f61955d..5a85af4 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2020-04-27 Jakub Jelinek <jakub@redhat.com> + + PR c/94755 + * c-c++-common/pr94755.c: New test. + 2020-04-27 Felix Yang <felix.yang@huawei.com> PR tree-optimization/94784 diff --git a/gcc/testsuite/c-c++-common/pr94755.c b/gcc/testsuite/c-c++-common/pr94755.c new file mode 100644 index 0000000..3520864 --- /dev/null +++ b/gcc/testsuite/c-c++-common/pr94755.c @@ -0,0 +1,11 @@ +/* PR c/94755 */ +/* { dg-do compile } */ + +extern void foo (void); + +void +bar (double x) +{ + if (x == __builtin_speculation_safe_value ()) /* { dg-error "too few arguments to function" } */ + foo (); +} |