[go: nahoru, domu]

Bug 93573 - [11/12/13/14/15 Regression] internal compiler error: in force_constant_size, at gimplify.c:733
Summary: [11/12/13/14/15 Regression] internal compiler error: in force_constant_size, ...
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 10.0
: P2 normal
Target Milestone: 11.5
Assignee: Not yet assigned to anyone
URL:
Keywords: error-recovery, ice-on-invalid-code
Depends on:
Blocks:
 
Reported: 2020-02-04 17:25 UTC by Yongheng Chen
Modified: 2024-04-26 10:37 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 7.3.0
Known to fail: 10.0, 8.3.0, 9.2.0
Last reconfirmed: 2020-02-13 00:00:00


Attachments
gcc10-pr93573.patch (719 bytes, patch)
2020-03-27 18:04 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Yongheng Chen 2020-02-04 17:25:04 UTC
POC:
---
int f1 ( char * p ) ( ) { int x ;
 x = 4 ;
 if ( ! x != 10 ) return 1 ;
 if ( ( sum ( 1 , 2 ) / 2 ) != 1 ) return 1 ;
 if ( - ( 2 * sum ( 3 , 4 ) + sum ( ( union foo { int i , X [ 2 ] [ - ( 100.000000 / 2 ) * 2 ] , k ;
 char * p ;
 float ( * f1 ( int a , int b ) ) ( int c , int b ) ;
 } ) p , 2 ) ) != 0 - 4 ) return 1 ;
 return 0 ;
 }
---

Gcc version:
---
Using built-in specs.
COLLECT_GCC=/mnt/raidhhd/gcc_instr_install/usr/local/bin/gcc
COLLECT_LTO_WRAPPER=/mnt/raidhhd/gcc_instr_install/usr/local/bin/../libexec/gcc/x86_64-pc-linux-gnu/10.0.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 10.0.1 20200127 (experimental) (GCC)
---

CMD:
---
gcc -o tmp poc.c
---
Comment 1 Yongheng Chen 2020-02-04 20:44:10 UTC
Stack dump:
---
tt.c:1:5: error: ‘f1’ declared as function returning a function
    1 | int f1 ( char * p  ) ( ) { int x ;
      |     ^~
tt.c: In function ‘f1’:
tt.c:4:9: warning: implicit declaration of function ‘sum’ [-Wimplicit-function-declaration]
    4 |  if ( ( sum ( 1 , 2  ) / 2  ) != 1  ) return 1 ;
      |         ^~~
tt.c:5:60: error: size of array ‘X’ has non-integer type
    5 |  if ( - ( 2 * sum ( 3 , 4  ) + sum ( ( union foo { int i , X [ 2  ] [ - ( 100.000000 / 2  ) * 2  ] , k ;
      |                                                            ^
tt.c:7:34: error: field ‘f1’ declared as a function
    7 |                        float ( * f1 ( int a , int b  )  ) ( int c , int b  ) ;
      |                                  ^~
tt.c:5:32: internal compiler error: in force_constant_size, at gimplify.c:733
    5 |  if ( - ( 2 * sum ( 3 , 4  ) + sum ( ( union foo { int i , X [ 2  ] [ - ( 100.000000 / 2  ) * 2  ] , k ;
      |                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    6 |                       char * p ;
      |                       ~~~~~~~~~~
    7 |                        float ( * f1 ( int a , int b  )  ) ( int c , int b  ) ;
      |                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    8 |                         }  ) p , 2  )  ) != 0 - 4  ) return 1 ;
      |                         ~~~~~~~~~~~~~
0x69d4dc force_constant_size
        ../../gcc/gimplify.c:733
0xb1b637 gimple_add_tmp_var(tree_node*)
        ../../gcc/gimplify.c:771
0xae9287 create_tmp_var(tree_node*, char const*)
        ../../gcc/gimple-expr.c:485
0xb2d5df create_tmp_from_val
        ../../gcc/gimplify.c:561
0xb2d5df lookup_tmp_var
        ../../gcc/gimplify.c:582
0xb2d5df internal_get_tmp_var
        ../../gcc/gimplify.c:635
0xb26ccf get_formal_tmp_var(tree_node*, gimple**)
        ../../gcc/gimplify.c:663
0xb26ccf gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*), int)
        ../../gcc/gimplify.c:14582
0xb287c6 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*), int)
        ../../gcc/gimplify.c:14030
0xb314b4 gimplify_expr
        ../../gcc/gimplify.c:14628
0xb33335 gimplify_call_expr
        ../../gcc/gimplify.c:3497
0xb28467 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*), int)
        ../../gcc/gimplify.c:13553
0xb27790 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*), int)
        ../../gcc/gimplify.c:14350
0xb27757 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*), int)
        ../../gcc/gimplify.c:14348
0xb3cdbb gimplify_cond_expr
        ../../gcc/gimplify.c:4177
0xb27ece gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*), int)
        ../../gcc/gimplify.c:13538
0xb2af96 gimplify_stmt(tree_node**, gimple**)
        ../../gcc/gimplify.c:6822
0xb2885b gimplify_statement_list
        ../../gcc/gimplify.c:1869
0xb2885b gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*), int)
        ../../gcc/gimplify.c:14025
0xb2af96 gimplify_stmt(tree_node**, gimple**)
        ../../gcc/gimplify.c:6822
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
---
Comment 2 Martin Sebor 2020-02-13 17:55:33 UTC
Confirmed.  Bisection points to r256748 (GCC 8):

commit 47c268c4b27782717fbccec5019e0cd97d005afb
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Tue Jan 16 16:18:24 2018 +0100

    re PR libgomp/83590 ([nvptx] openacc reduction C regressions)
    
            PR libgomp/83590
            * gimplify.c (gimplify_one_sizepos): For is_gimple_constant (expr)
            return early, inline manually is_gimple_sizepos.  Make sure if we
            call gimplify_expr we don't end up with a gimple constant.
            * tree.c (variably_modified_type_p): Don't return true for
            is_gimple_constant (_t).  Inline manually is_gimple_sizepos.
            * gimplify.h (is_gimple_sizepos): Remove.
    
    Co-Authored-By: Richard Biener <rguenther@suse.de>
    
    From-SVN: r256748
Comment 3 Jakub Jelinek 2020-03-27 16:40:04 UTC
Reduced testcase:
void bar ();

void
foo (char a)
{
  union C { int d[100.0]; char *e; };
  bar ((union C) &a);
}
Comment 4 Jakub Jelinek 2020-03-27 18:04:57 UTC
Created attachment 48135 [details]
gcc10-pr93573.patch

For the error-recovery ICE, we can just make sure that after errors the type isn't assumed to be VLA.

Unfortunately:
void bar ();

void
foo (char a, int b)
{
  union C { int d[b]; char *e; };
  bar ((union C) &a);
}

still ICEs.
Comment 5 GCC Commits 2020-03-28 09:31:13 UTC
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:c6a562de88c44a555e1688c212869b20b02151bc

commit r10-7438-gc6a562de88c44a555e1688c212869b20b02151bc
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Sat Mar 28 10:30:31 2020 +0100

    c: After issuing errors about array size, for error-recovery don't make the array VLA [PR93573]
    
    After we report various errors about array size, we set for error-recovery
    the size to be 1, but because size_int_const is false, it still means we
    pretend the array is a VLA, can emit a second diagnostics in that case etc.
    E.g.
    $ ./cc1.unpatched -quiet a.c
    a.c:1:5: error: size of array âfâ has non-integer type
        1 | int f[100.0];
          |     ^
    a.c:1:1: warning: variably modified âfâ at file scope
        1 | int f[100.0];
          | ^~~
    $ ./cc1 -quiet a.c
    a.c:1:5: error: size of array âfâ has non-integer type
        1 | int f[100.0];
          |     ^
    
    2020-03-28  Jakub Jelinek  <jakub@redhat.com>
    
            PR c/93573
            * c-decl.c (grokdeclarator): After issuing errors, set size_int_const
            to true after setting size to integer_one_node.
    
            * gcc.dg/pr93573-1.c: New test.
            * gcc.dg/pr93573-2.c: New test.
Comment 6 Jakub Jelinek 2020-03-28 09:35:32 UTC
Fixed the error-recovery bug on the trunk, but the ice on the #c4 testcase is still there (and the question is if it is valid or not).  If it is valid, probably the FE or gimplifier needs to turn that cast to VLA union into creation of a VLA temporary and assigning the cast operand into the right field of it.
Comment 7 jsm-csl@polyomino.org.uk 2020-03-30 23:22:48 UTC
Passing a variable-size struct or union by value to a non-nested function 
seems very questionable (the function couldn't be declared with a matching 
prototype), but perhaps that doesn't answer the question because the 
cast-to-union case might appear for a nested function as well.
Comment 8 Jakub Jelinek 2021-05-14 09:52:48 UTC
GCC 8 branch is being closed.
Comment 9 Richard Biener 2021-06-01 08:16:13 UTC
GCC 9.4 is being released, retargeting bugs to GCC 9.5.
Comment 10 Richard Biener 2022-05-27 09:42:01 UTC
GCC 9 branch is being closed
Comment 11 Jakub Jelinek 2022-06-28 10:39:36 UTC
GCC 10.4 is being released, retargeting bugs to GCC 10.5.
Comment 12 Richard Biener 2023-07-07 10:36:40 UTC
GCC 10 branch is being closed.
Comment 13 Andrew Pinski 2024-02-20 07:36:33 UTC
(In reply to Jakub Jelinek from comment #6)
> Fixed the error-recovery bug on the trunk, but the ice on the #c4 testcase
> is still there (and the question is if it is valid or not).  If it is valid,
> probably the FE or gimplifier needs to turn that cast to VLA union into
> creation of a VLA temporary and assigning the cast operand into the right
> field of it.

Hmm, is the testcase in comment #4 a regression though? It ICEs even in the same way in GCC 4.1.2 all the way to the trunk including GCC 7.3.0.
Comment 14 Jakub Jelinek 2024-02-20 07:43:45 UTC
(In reply to Andrew Pinski from comment #13)
> Hmm, is the testcase in comment #4 a regression though? It ICEs even in the
> same way in GCC 4.1.2 all the way to the trunk including GCC 7.3.0.

It is.  gcc 3.2, 3.3 and 3.4 at least compile that just fine,
while r0-63127-ga63c0d13291b93a42e927d0356b2d9854c654337 ICEs.