Hi, Kees,

Sorry for the late reply (I have been busy with other work recently).

Currently, I am working on the issue of flexible length array as the last field 
of the structure.

In order to fix it correctly, I have the following question:


> On Feb 26, 2021, at 3:42 PM, Kees Cook <keesc...@chromium.org> wrote:
> 
> On Thu, Feb 25, 2021 at 05:56:38PM -0600, Qing Zhao wrote:
>> Just noticed that you didn’t add -fauto-var-init-approach=D to the command 
>> line.
> 
> Ah-ha! I didn't realize that was needed; thanks. However, now some of the 
> sources crash in a different way. Here's the reproducer:
> 
> $ cat poc.i
> struct a {
>  int b;
>  int array[];
> };
> void c() {
>  struct a d;
> }
> 

For such variable length array as the last field of the structure, static 
initialization is not allowed, 
User needs to explicitly allocate memory and initialize the allocated array 
manually in the source code. 

So, if the compiler has to initialize this structure when requested by 
-ftrivial-auto-var-init,  I think that 
only the fields before the last fields need to be initialized, Is this the 
correct behavior you expected?

Thanks.

Qing


> $ gcc -ftrivial-auto-var-init=pattern -fauto-var-init-approach=D -c /dev/null 
> poc.i
> during RTL pass: expand
> poc.i: In function ‘c’:
> poc.i:6:12: internal compiler error: in build_pattern_cst, at tree.c:2652
>    6 |   struct a d;
>      |            ^
> 0x75b572 build_pattern_cst(tree_node*)
>        ../../../gcc/gcc/tree.c:2652
> 0x10db116 build_pattern_cst(tree_node*)
>        ../../../gcc/gcc/tree.c:2612
> 0xb8a230 expand_DEFERRED_INIT
>        ../../../gcc/gcc/internal-fn.c:2980
> 0x970e17 expand_call_stmt
>        ../../../gcc/gcc/cfgexpand.c:2749
> 0x970e17 expand_gimple_stmt_1
>        ../../../gcc/gcc/cfgexpand.c:3844
> 0x970e17 expand_gimple_stmt
>        ../../../gcc/gcc/cfgexpand.c:4008
> 0x9766b3 expand_gimple_basic_block
>        ../../../gcc/gcc/cfgexpand.c:6045
> 0x9780d6 execute
>        ../../../gcc/gcc/cfgexpand.c:6729
> 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.
> 
> I assume it's not handling the flex-array happily?
> 
> -- 
> Kees Cook

Reply via email to