c-family: Fix ICE on __builtin_speculation_safe_value () [PR94755]
authorJakub Jelinek <jakub@redhat.com>
Mon, 27 Apr 2020 14:05:03 +0000 (16:05 +0200)
committerJakub Jelinek <jakub@redhat.com>
Mon, 27 Apr 2020 14:10:24 +0000 (16:10 +0200)
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.

gcc/c-family/ChangeLog
gcc/c-family/c-common.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/pr94755.c [new file with mode: 0644]

index 55e6eb8ae4504ab041858e57f5526f46435c1b22..973dc701c2a41028916ff8a35cb7d4b3f92b7d45 100644 (file)
@@ -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
index 8e5a92438270f854ba12859ff756f1bcc9295812..4e46178d595d33ea7b447bb5eceb8eaae1921317 100644 (file)
@@ -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))
index f61955dabb94f0497401833ef6fc328931773a3d..5a85af479c8ab21cb787cdc3c70fd2d139fb0e16 100644 (file)
@@ -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 (file)
index 0000000..3520864
--- /dev/null
@@ -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 ();
+}