Bug 70457 - ICE (segfault) in gimple_expand_builtin_pow on powerpc64le-linux-gnu
Summary: ICE (segfault) in gimple_expand_builtin_pow on powerpc64le-linux-gnu
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 6.0
: P3 normal
Target Milestone: 6.0
Assignee: Bill Schmidt
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2016-03-30 12:49 UTC by Matthias Klose
Modified: 2016-04-04 15:49 UTC (History)
3 users (show)

See Also:
Host:
Target: powerpc64le-linux-gnu, aarch64-none-elf
Build:
Known to work:
Known to fail: 4.8.5, 4.9.3, 5.3.1, 6.0
Last reconfirmed: 2016-03-30 00:00:00


Attachments
Patch that permits this to compile (782 bytes, patch)
2016-04-01 15:17 UTC, Bill Schmidt
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Matthias Klose 2016-03-30 12:49:49 UTC
fails in 4.8 up to 6, works with -O2

$ gcc -c -O3 math.i 
math.i: In function 'P_Pow':
math.i:26:8: internal compiler error: Segmentation fault
 Object P_Pow (Object x, Object y) { return General_Function (x, y, pow); }
        ^
0x102bde83 crash_signal
        ../../src/gcc/toplev.c:383
0x1031d914 gimple_expand_builtin_pow
        ../../src/gcc/tree-ssa-math-opts.c:1169
0x10a42827 execute
        ../../src/gcc/tree-ssa-math-opts.c:1517
Please submit a full bug report,
with preprocessed source if appropriate.

$ cat math.i 
extern double pow (double __x, double __y) __attribute__ ((__nothrow__ , __leaf__)); extern double __pow (double __x, double __y) __attribute__ ((__nothrow__ , __leaf__));

typedef int int64_t __attribute__ ((__mode__ (__DI__)));

typedef struct {
    int64_t data;
    int tag;
} Object;

extern Object Make_Flonum (double);
extern Object P_Pow (Object, Object);

Object General_Function (Object x, Object y, double (*fun)()) {
    double d, ret;

    d = 1.0;

    if (y.tag >> 1)
        ret = (*fun) (d);
    else
        ret = (*fun) (d, 0.0);

    return Make_Flonum (ret);
}

Object P_Pow (Object x, Object y) { return General_Function (x, y, pow); }
Comment 1 ktkachov 2016-03-30 13:06:57 UTC
Confirmed on aarch64 as well
Comment 2 ktkachov 2016-03-30 13:16:09 UTC
Using gdb, the gimple stmt causing the ICE is:
# .MEM_10 = VDEF <.MEM_1(D)>
ret_5 = pow (1.0e+0);
Comment 3 Bill Schmidt 2016-04-01 14:30:43 UTC
So we have an unreachable call to pow with the wrong number of arguments.  I suppose the expansion logic for builtin_pow should tolerate this situation and just do nothing with it.
Comment 4 Bill Schmidt 2016-04-01 14:32:24 UTC
(I should say, presumably unreachable.  This source code looks pretty dicey in the first place, but nonetheless we should probably tolerate it at this stage of optimization.)
Comment 5 Bill Schmidt 2016-04-01 15:17:59 UTC
Created attachment 38156 [details]
Patch that permits this to compile

The attached patch allows the compilation to succeed in spite of the incorrect number of arguments provided to pow ().

I suppose this is a reasonable approach, but it makes me a bit queasy to let obviously incorrect code go by undiagnosed.  Still, it's no different than providing the wrong number of arguments to some other function; we only notice here because we convert the function call to a built-in.

CCing Richard for his opinion.
Comment 6 Jakub Jelinek 2016-04-01 15:48:34 UTC
IMHO much better would be to call gimple_call_builtin_p (call, BUILT_IN_NORMAL)
(for non-internal functions) and only treat those as builtins if that function
returned true.  That checks both the number of arguments, roughly their types etc.
Comment 7 Jakub Jelinek 2016-04-01 15:50:46 UTC
Ah, but gimple_call_combined_fn already performs this.
So perhaps all you need is the tree-inline.c part?
Comment 8 Bill Schmidt 2016-04-01 16:04:43 UTC
The tree-inline part only shows up after fixing the part in tree-ssa-math-opts.c, where the initial failure occurs.  The DECL is already encoded as a BUILT_IN_POW by the time we get that far.
Comment 9 Jakub Jelinek 2016-04-01 16:07:37 UTC
I've missed the pass_optimize_widening_mul::execute in your patch, that is also another spot where you'd want to call it.  But the sincos hunks should be safe as is.
Comment 10 Bill Schmidt 2016-04-01 16:20:35 UTC
Ok, sounds good.  I have vacation this afternoon, but will revisit this over the weekend or Monday.
Comment 11 Bill Schmidt 2016-04-03 15:12:46 UTC
Jakub, thanks, I've verified that works and makes for a much better patch.  Will post shortly on gcc-patches.
Comment 12 Bill Schmidt 2016-04-04 15:42:50 UTC
Author: wschmidt
Date: Mon Apr  4 15:42:19 2016
New Revision: 234716

URL: https://gcc.gnu.org/viewcvs?rev=234716&root=gcc&view=rev
Log:
[gcc]

2016-04-04  Bill Schmidt  <wschmidt@linux.vnet.ibm.com>
	    Jakub Jelinek <jakub@redhat.com>

	PR middle-end/70457
	* tree-inline.c (estimate_num_insn): Use gimple_call_builtin_p
	to ensure a call statement is compatible with a built-in's
	prototype.
	* tree-ssa-math-opts.c (pass_optimize_windening_mul::execute):
	Likewise.

[gcc/testsuite]

2016-04-04  Bill Schmidt  <wschmidt@linux.vnet.ibm.com>
	    Jakub Jelinek <jakub@redhat.com>

	PR middle-end/70457
	* gcc.dg/torture/pr70457.c: New.


Added:
    trunk/gcc/testsuite/gcc.dg/torture/pr70457.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-inline.c
    trunk/gcc/tree-ssa-math-opts.c
Comment 13 Bill Schmidt 2016-04-04 15:46:30 UTC
Author: wschmidt
Date: Mon Apr  4 15:45:59 2016
New Revision: 234717

URL: https://gcc.gnu.org/viewcvs?rev=234717&root=gcc&view=rev
Log:
[gcc]

2016-04-04  Bill Schmidt  <wschmidt@linux.vnet.ibm.com>
	    Jakub Jelinek <jakub@redhat.com>

	PR middle-end/70457
	* tree-inline.c (estimate_num_insn): Use gimple_call_builtin_p
	to ensure a call statement is compatible with a built-in's
	prototype.
	* tree-ssa-math-opts.c (execute_cse_sincos_1): Likewise.
	(pass_cse_sincos::execute): Likewise.
	(pass_optimize_widening_mul::execute):	Likewise.

[gcc/testsuite]

2016-04-04  Bill Schmidt  <wschmidt@linux.vnet.ibm.com>
	    Jakub Jelinek <jakub@redhat.com>

	PR middle-end/70457
	* gcc.dg/torture/pr70457.c: New.


Added:
    branches/gcc-5-branch/gcc/testsuite/gcc.dg/torture/pr70457.c
Modified:
    branches/gcc-5-branch/gcc/ChangeLog
    branches/gcc-5-branch/gcc/testsuite/ChangeLog
    branches/gcc-5-branch/gcc/tree-inline.c
    branches/gcc-5-branch/gcc/tree-ssa-math-opts.c
Comment 14 Bill Schmidt 2016-04-04 15:48:25 UTC
Author: wschmidt
Date: Mon Apr  4 15:47:51 2016
New Revision: 234718

URL: https://gcc.gnu.org/viewcvs?rev=234718&root=gcc&view=rev
Log:
[gcc]

2016-04-04  Bill Schmidt  <wschmidt@linux.vnet.ibm.com>
	    Jakub Jelinek <jakub@redhat.com>

	PR middle-end/70457
	* tree-inline.c (estimate_num_insn): Use gimple_call_builtin_p
	to ensure a call statement is compatible with a built-in's
	prototype.
	* tree-ssa-math-opts.c (execute_cse_sincos_1): Likewise.
	(execute_cse_sincos): Likewise.
	(execute_optimize_widening_mul): Likewise.

[gcc/testsuite]

2016-04-04  Bill Schmidt  <wschmidt@linux.vnet.ibm.com>
	    Jakub Jelinek <jakub@redhat.com>

	PR middle-end/70457
	* gcc.dg/torture/pr70457.c: New.


Added:
    branches/gcc-4_9-branch/gcc/testsuite/gcc.dg/torture/pr70457.c
Modified:
    branches/gcc-4_9-branch/gcc/ChangeLog
    branches/gcc-4_9-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_9-branch/gcc/tree-inline.c
    branches/gcc-4_9-branch/gcc/tree-ssa-math-opts.c
Comment 15 Bill Schmidt 2016-04-04 15:49:23 UTC
Matthias, the code is now fixed everywhere upstream.  Do you need a merge into ibm/gcc-5-branch?
Comment 16 Bill Schmidt 2016-04-04 15:49:53 UTC
Fixed.