[PATCH] Improve error on invalid call to __builtin_cexpi (PR31161)

Richard Guenther rguenther@suse.de
Wed Mar 14 16:05:00 GMT 2007


This improves user experience by issueing a sorry() call instead of
ICEing with gcc_assert (or possibly failing with --disable-checking).

Bootstrapped and tested on x86_64-unknown-linux-gnu.

Is this a reasonable thing to do?

The underlying problem is that we cannot hide the builtin declaration
from the user (aka, error()ing from the frontend if __builtin_cexpi is
called) -- there is simply no way to specify this behavior currently.
We would need to separate declaring the middle-end function decls from
declaring the frontend visible variants.  Now of course for the C
languages there's an overlap as both __builtin_foo and foo may exist.

Thanks,
Richard.


2007-03-12  Richard Guenther  <rguenther@suse.de>

	PR middle-end/31161
	* builtins.c (expand_builtin_cexpi): Bail out more friendly
	if we cannot expand a call to __builtin_cexpi.

Index: builtins.c
===================================================================
*** builtins.c	(revision 122838)
--- builtins.c	(working copy)
*************** expand_builtin_cexpi (tree exp, rtx targ
*** 2371,2384 ****
        expand_normal (build_call_nary (TREE_TYPE (TREE_TYPE (fn)),
  				      call, 3, arg, top1, top2));
      }
!   else
      {
        tree call, fn = NULL_TREE, narg;
        tree ctype = build_complex_type (type);
  
-       /* We can expand via the C99 cexp function.  */
-       gcc_assert (TARGET_C99_FUNCTIONS);
- 
        if (DECL_FUNCTION_CODE (fndecl) == BUILT_IN_CEXPIF)
  	fn = built_in_decls[BUILT_IN_CEXPF];
        else if (DECL_FUNCTION_CODE (fndecl) == BUILT_IN_CEXPI)
--- 2371,2382 ----
        expand_normal (build_call_nary (TREE_TYPE (TREE_TYPE (fn)),
  				      call, 3, arg, top1, top2));
      }
!   else if (TARGET_C99_FUNCTIONS)
      {
+       /* We can expand via the C99 cexp function.  */
        tree call, fn = NULL_TREE, narg;
        tree ctype = build_complex_type (type);
  
        if (DECL_FUNCTION_CODE (fndecl) == BUILT_IN_CEXPIF)
  	fn = built_in_decls[BUILT_IN_CEXPF];
        else if (DECL_FUNCTION_CODE (fndecl) == BUILT_IN_CEXPI)
*************** expand_builtin_cexpi (tree exp, rtx targ
*** 2395,2400 ****
--- 2393,2403 ----
        return expand_expr (build_call_nary (ctype, call, 1, arg), 
  			  target, VOIDmode, 0);
      }
+   else
+     {
+       sorry ("no way to expand a call to %<cexpi%>");
+       return gen_reg_rtx (TYPE_MODE (TREE_TYPE (exp)));
+     }
  
    /* Now build the proper return type.  */
    return expand_expr (build2 (COMPLEX_EXPR, build_complex_type (type),



More information about the Gcc-patches mailing list