From eada851cc9fb2822989d3ef81bb5b4b08dcc81a7 Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Tue, 29 Sep 2015 13:02:42 +0000 Subject: [PATCH] re PR tree-optimization/67741 (Invalid built-in usage should not cause segmentation fault in compiler) 2015-09-29 Richard Biener PR tree-optimization/67741 * tree-ssa-math-opts.c (pass_cse_sincos::execute): Only recognize builtin calls with correct signature. * gcc.dg/torture/pr67741.c: New testcase. From-SVN: r228243 --- gcc/ChangeLog | 6 ++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/torture/pr67741.c | 13 +++++++++++++ gcc/tree-ssa-math-opts.c | 7 +++---- 4 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/torture/pr67741.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 12de2e10ae7..8fc37ce5951 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2015-09-29 Richard Biener + + PR tree-optimization/67741 + * tree-ssa-math-opts.c (pass_cse_sincos::execute): Only recognize + builtin calls with correct signature. + 2015-09-29 Ilya Enkovich PR target/65105 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 09a72d9c929..6582172b572 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2015-09-29 Richard Biener + + PR tree-optimization/67741 + * gcc.dg/torture/pr67741.c: New testcase. + 2015-09-29 Uros Bizjak * gcc.dg/tg-tests.h (foo_1) [UNSAFE]: Also check if f and ld are diff --git a/gcc/testsuite/gcc.dg/torture/pr67741.c b/gcc/testsuite/gcc.dg/torture/pr67741.c new file mode 100644 index 00000000000..1ffc7078469 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr67741.c @@ -0,0 +1,13 @@ +/* { dg-do compile } */ + +struct singlecomplex { float real, imag ; } ; +struct doublecomplex { double real, imag ; } ; +struct extendedcomplex { long double real, imag ; } ; +extern double cabs(); +float cabsf(fc) + struct singlecomplex fc; /* { dg-warning "doesn't match" } */ +{ + struct doublecomplex dc ; + dc.real=fc.real; dc.imag=fc.imag; + return (float) cabs(dc); +} diff --git a/gcc/tree-ssa-math-opts.c b/gcc/tree-ssa-math-opts.c index 42708ee6ad1..97477391e0f 100644 --- a/gcc/tree-ssa-math-opts.c +++ b/gcc/tree-ssa-math-opts.c @@ -1738,15 +1738,14 @@ pass_cse_sincos::execute (function *fun) of a basic block. */ cleanup_eh = false; - if (is_gimple_call (stmt) - && gimple_call_lhs (stmt) - && (fndecl = gimple_call_fndecl (stmt)) - && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL) + if (gimple_call_builtin_p (stmt, BUILT_IN_NORMAL) + && gimple_call_lhs (stmt)) { tree arg, arg0, arg1, result; HOST_WIDE_INT n; location_t loc; + fndecl = gimple_call_fndecl (stmt); switch (DECL_FUNCTION_CODE (fndecl)) { CASE_FLT_FN (BUILT_IN_COS): -- 2.30.2