Fix builtin_mathfn_code ICE on internal fns (PR c++/84444)

Message ID 20180219191115.GS5867@tucnak
State New
Headers show
Series
  • Fix builtin_mathfn_code ICE on internal fns (PR c++/84444)
Related show

Commit Message

Jakub Jelinek Feb. 19, 2018, 7:11 p.m.
Hi!

Many years ago Jason has added call to get_callee_fndecl, which does the
right thing for internal functions as well as handles ADDR_EXPR and also
casts and constant function pointers with a usable DECL_INITIAL, so while
to fix this PR I could have added || CALL_EXPR_FN (t)) == NULL_TREE before
the || TREE_CODE (CALL_EXPR_FN (t)) != ADDR_EXPR check, IMHO it is just
better to remove it, get_callee_fndecl will DTRT.

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

2018-02-19  Jakub Jelinek  <jakub@redhat.com>

	PR c++/84444
	* builtins.c (builtin_mathfn_code): Don't check if CALL_EXPR_FN (t)
	is ADDR_EXPR.

	* g++.dg/cpp1z/launder8.C: New test.


	Jakub

Patch

--- gcc/builtins.c.jj	2018-01-18 21:11:57.272207030 +0100
+++ gcc/builtins.c	2018-02-19 14:05:58.887842922 +0100
@@ -7836,8 +7836,7 @@  builtin_mathfn_code (const_tree t)
   const_tree argtype, parmtype;
   const_call_expr_arg_iterator iter;
 
-  if (TREE_CODE (t) != CALL_EXPR
-      || TREE_CODE (CALL_EXPR_FN (t)) != ADDR_EXPR)
+  if (TREE_CODE (t) != CALL_EXPR)
     return END_BUILTINS;
 
   fndecl = get_callee_fndecl (t);
--- gcc/testsuite/g++.dg/cpp1z/launder8.C.jj	2018-02-19 14:13:07.120887805 +0100
+++ gcc/testsuite/g++.dg/cpp1z/launder8.C	2018-02-19 14:12:43.369885316 +0100
@@ -0,0 +1,11 @@ 
+// PR c++/84444
+// { dg-do compile }
+// { dg-options "-O2" }
+
+struct A {};
+
+__UINTPTR_TYPE__
+foo (A *p)
+{
+  return (__UINTPTR_TYPE__) __builtin_launder (p);
+}