Bug 22589 - [3.4 regression] ICE casting to long long
Summary: [3.4 regression] ICE casting to long long
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 3.4.3
: P2 normal
Target Milestone: 3.4.5
Assignee: rsandifo@gcc.gnu.org
URL:
Keywords: ice-on-valid-code, monitored
Depends on:
Blocks:
 
Reported: 2005-07-21 13:45 UTC by lex.augusteijn
Modified: 2005-07-28 08:10 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 3.3.6 4.0.0
Known to fail: 3.4.0 3.4.4
Last reconfirmed: 2005-07-27 17:31:33


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description lex.augusteijn 2005-07-21 13:45:42 UTC
Seg fault of gcc on the following program:

void bar (void)
{
  char *foo;

  (long long)((int)foo+0) < 0 ;
}

command use: gcc -c file.c
Comment 1 Volker Reichelt 2005-07-21 16:36:13 UTC
Confirmed.
Appeared with gcc 3.4.0. Only  affects 3.4 branch.
Comment 2 rsandifo@gcc.gnu.org 2005-07-27 17:31:28 UTC
This seems to be caused by:

2004-02-15  Roger Sayle  <roger@eyesopen.com>

	Backport from mainline:

	2004-02-07  Roger Sayle  <roger@eyesopen.com>
	PR middle-end/13696
	* fold-const.c (fold_convert): New function to provide type
	conversion to the middle-end without using convert.
	(negate_expr, associate_trees, size_diffop, omit_one_operand,
	operand_equal_for_comparison_p, pedantic_omit_one_operand,
	invert_truthvalue, optimize_bit_field_compare, range_binop,
	decode_field_reference, make_range, build_range_check, unextend,
	fold_truthop, extract_muldiv_1, fold_mathfn_compare,
	fold_binary_op_with_conditional_arg, fold_inf_compare,
	fold_single_bit_test, fold, multiple_of_p): Replace all calls to
	convert with calls to fold_convert.

convert() uses CONVERT_EXPR rather than NOP_EXPR for pointer-to-integer
conversions, but after the patch above, the original <CONVERT_EXPR int foo>
will be "folded" to <NOP_EXPR int foo>.

On 3.4, get_narrower(<NOP_EXPR int foo>) returns "foo", which has
a pointer type, and causes the segfault in shorten_compare().
This was fixed (worked around?) on mainline by:

2004-07-08  Alexandre Oliva  <aoliva@redhat.com>

	Introduce H8SX support.
	....
	2004-06-16  Alexandre Oliva  <aoliva@redhat.com>
	* tree.c (get_narrower): Don't narrow integral types into
	non-integral types.

and backporting that patch seems to fix the testcase.

I'm not a tree expert, and I can't find any discussion of Alex's patch:

    http://gcc.gnu.org/ml/gcc-patches/2004-06/msg01644.html

so I'm not sure if CONVERT_EXPR really is required here.  But given
that this bug is specific to a release branch, and that the branch
is deep into "maintenance only" mode, I think that backporting
Alex's patch is the best fix here.  I'm regression testing it now.

Richard
Comment 3 CVS Commits 2005-07-28 08:01:16 UTC
Subject: Bug 22589

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	rsandifo@gcc.gnu.org	2005-07-28 08:00:58

Modified files:
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gcc.c-torture/compile: pr22589-1.c 

Log message:
	PR c/22589
	* gcc.c-torture/compile/pr22589.c: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.5835&r2=1.5836
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.c-torture/compile/pr22589-1.c.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 4 CVS Commits 2005-07-28 08:03:46 UTC
Subject: Bug 22589

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-4_0-branch
Changes by:	rsandifo@gcc.gnu.org	2005-07-28 08:03:28

Modified files:
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gcc.c-torture/compile: pr22589-1.c 

Log message:
	PR c/22589
	* gcc.c-torture/compile/pr22589.c: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.5084.2.303&r2=1.5084.2.304
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.c-torture/compile/pr22589-1.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.1.2.1

Comment 5 CVS Commits 2005-07-28 08:09:07 UTC
Subject: Bug 22589

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_4-branch
Changes by:	rsandifo@gcc.gnu.org	2005-07-28 08:08:26

Modified files:
	gcc            : ChangeLog tree.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gcc.c-torture/compile: pr22589-1.c 

Log message:
	PR c/22589
	Backport from mainline:
	
	2004-06-16  Alexandre Oliva  <aoliva@redhat.com>
	* tree.c (get_narrower): Don't narrow integral types into
	non-integral types.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=2.2326.2.885&r2=2.2326.2.886
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/tree.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.342.2.5&r2=1.342.2.6
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.3389.2.409&r2=1.3389.2.410
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.c-torture/compile/pr22589-1.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.4.1

Comment 6 rsandifo@gcc.gnu.org 2005-07-28 08:10:25 UTC
Patch applied to 3.4.  I also applied the testcase to mainline and 4.0
(where it passes already).