Hi!

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.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2020-04-25  Jakub Jelinek  <ja...@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/c-common.c.jj  2020-03-21 18:29:58.989160193 +0100
+++ gcc/c-family/c-common.c     2020-04-25 10:13:14.158722031 +0200
@@ -7402,9 +7402,11 @@ resolve_overloaded_builtin (location_t l
        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))
--- gcc/testsuite/c-c++-common/pr94755.c.jj     2020-04-25 10:17:53.297502562 
+0200
+++ gcc/testsuite/c-c++-common/pr94755.c        2020-04-25 10:18:32.261916902 
+0200
@@ -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 ();
+}

        Jakub

Reply via email to