Bug 30147 - [4.3 Regression] ICE in fold_convert with -O2
Summary: [4.3 Regression] ICE in fold_convert with -O2
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: 4.2.0
Assignee: Richard Biener
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks: 29975
  Show dependency treegraph
 
Reported: 2006-12-11 15:31 UTC by Tobias Burnus
Modified: 2006-12-12 12:21 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2006-12-11 23:17:05


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2006-12-11 15:31:03 UTC
Today's gfortran crashes with "-c -O2" for the program below.
It works with today's 4.2.0 and with "-O".

I don't see right away whether this is a middle end or middle-end triggered front-end problem.

input_cp2k_motion2.f90: In function 'create_neb_section':
input_cp2k_motion2.f90:12: internal compiler error: in fold_convert, at fold-const.c:2150


MODULE input_cp2k_motion
  IMPLICIT NONE
  interface
    SUBROUTINE keyword_create(variants)
      CHARACTER(len=*), DIMENSION(:), &
      INTENT(in)                   :: variants
    end subroutine
  end interface
CONTAINS
  SUBROUTINE create_neb_section()
    CALL keyword_create(variants=(/"K"/))
  END SUBROUTINE create_neb_section
END MODULE input_cp2k_motion
Comment 1 Richard Biener 2006-12-11 16:19:11 UTC
#2  0x00000000007395cf in fold_read_from_constant_string (exp=0x2ab7c225bd00)
    at /space/rguenther/src/svn/trunk/gcc/fold-const.c:12854
12854           return fold_convert (TREE_TYPE (exp),
(gdb) call debug_generic_expr (exp) 
*(charD.21[1:1] *) "K"

#1  0x00000000006c380a in fold_convert (type=0x2ab7c224f000, 
    arg=0x2ab7c2260ae0) at /space/rguenther/src/svn/trunk/gcc/fold-const.c:2150
2150          gcc_unreachable ();
(gdb) call debug_generic_expr (type)
charD.21[1:1]
(gdb) call debug_generic_expr (arg) 
75

fold_convert does not know how to fold to char[1:1].
Comment 2 Richard Biener 2006-12-11 16:25:37 UTC
This fixes it:

Index: fold-const.c
===================================================================
*** fold-const.c        (revision 119733)
--- fold-const.c        (working copy)
*************** fold_unary_to_constant (enum tree_code c
*** 12726,12732 ****
  tree
  fold_read_from_constant_string (tree exp)
  {
!   if (TREE_CODE (exp) == INDIRECT_REF || TREE_CODE (exp) == ARRAY_REF)
      {
        tree exp1 = TREE_OPERAND (exp, 0);
        tree index;
--- 12817,12825 ----
  tree
  fold_read_from_constant_string (tree exp)
  {
!   if ((TREE_CODE (exp) == INDIRECT_REF
!        || TREE_CODE (exp) == ARRAY_REF)
!       && !AGGREGATE_TYPE_P (TREE_TYPE (exp)))
      {
        tree exp1 = TREE_OPERAND (exp, 0);
        tree index;
Comment 3 Richard Biener 2006-12-11 23:17:05 UTC
This is caused by

2006-05-09  Dirk Mueller  <dmueller@suse.de>
        Richard Guenther  <rguenther@suse.de>

        PR middle-end/27498
        * fold-const.c (fold_read_from_constant_string): Relax check
        for matching types to matching modes.

and the fix is probably correct.  Mine.  4.2 should be also affected really.
Comment 4 Andrew Pinski 2006-12-11 23:20:41 UTC
Instead of mode checking, what about checking the code of the type inaddition, though maybe checking the for INTEGERAL_TYPE_P before the check for the mode will also fix this issue?
Comment 5 Richard Biener 2006-12-12 12:21:22 UTC
Fixed.