This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


On Wed, 14 Mar 2007, Andrew Pinski wrote:

> On 3/14/07, Richard Guenther <rguenther@suse.de> wrote:
> >
> > 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.
> 
> Why not just emit a call to __builtin_cexpi instead like how the
> __sync_* functions do?

I've ended up with the following, falling back to cexp and its variants.
This should result in the best possible user-experience if the user
calls __builtin_cepxi.

I built a cross compiler to ppc-darwin and checked that the calls are
emitted correctly.  A bootstrap on x86_64 is still running, will apply
it after that finishes successfully.

Richard.

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

	PR middle-end/31161
	* builtins.c (expand_builtin_cexpi): As a fallback if we
	don't have builtins for sincos or cexp create a function
	declaration for cexp and expand to a call to that.

Index: builtins.c
===================================================================
*** builtins.c	(revision 122953)
--- builtins.c	(working copy)
*************** expand_builtin_cexpi (tree exp, rtx targ
*** 2376,2384 ****
        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)
--- 2376,2381 ----
*************** expand_builtin_cexpi (tree exp, rtx targ
*** 2387,2392 ****
--- 2384,2409 ----
  	fn = built_in_decls[BUILT_IN_CEXPL];
        else
  	gcc_unreachable ();
+ 
+       /* If we don't have a decl for cexp create one.  This is the
+ 	 friendliest fallback if the user calls __builtin_cexpi
+ 	 without full target C99 function support.  */
+       if (fn == NULL_TREE)
+ 	{
+ 	  tree fntype;
+ 	  const char *name = NULL;
+ 
+ 	  if (DECL_FUNCTION_CODE (fndecl) == BUILT_IN_CEXPIF)
+ 	    name = "cexpf";
+ 	  else if (DECL_FUNCTION_CODE (fndecl) == BUILT_IN_CEXPI)
+ 	    name = "cexp";
+ 	  else if (DECL_FUNCTION_CODE (fndecl) == BUILT_IN_CEXPIL)
+ 	    name = "cexpl";
+ 
+ 	  fntype = build_function_type_list (ctype, ctype, NULL_TREE);
+ 	  fn = build_fn_decl (name, fntype);
+ 	}
+ 
        narg = fold_build2 (COMPLEX_EXPR, ctype,
  			  build_real (type, dconst0), arg);
  


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]