[Bug fortran/92065] [8/9/10/11 Regression] internal compiler error: in expand_expr_real_1

jakub at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon Dec 21 10:09:02 GMT 2020


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92065

--- Comment #19 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Seems each function has properly its own this PARM_DECL, but the fun2 body
refers to the fun1 this PARM_DECL, which is invalid when fun2 is not nested in
fun1.

This wrong this PARM_DECL reference is added during:
#1  0x0000000001909a57 in build1 (code=INDIRECT_REF, type=<record_type
0x7fffea216498 __class_buggy_Foo_t>, node=<parm_decl 0x7fffea203700 this>)
    at ../../gcc/tree.c:4786
#2  0x0000000000ebcf48 in build1_loc (loc=91200, code=INDIRECT_REF,
type=<record_type 0x7fffea216498 __class_buggy_Foo_t>, 
    arg1=<parm_decl 0x7fffea203700 this>) at ../../gcc/tree.h:4382
#3  0x0000000000f01746 in build_fold_indirect_ref_loc (loc=91200, t=<parm_decl
0x7fffea203700 this>) at ../../gcc/fold-const.c:15930
#4  0x0000000000b6c166 in gfc_maybe_dereference_var (sym=0x38228a0,
var=<parm_decl 0x7fffea203700 this>, descriptor_only_p=false, 
    is_classarray=false) at ../../gcc/fortran/trans-expr.c:2787
#5  0x0000000000b6c97f in gfc_conv_variable (se=0x7fffffffd100, expr=0x37c0400)
at ../../gcc/fortran/trans-expr.c:2945
#6  0x0000000000b80aa3 in gfc_conv_expr (se=0x7fffffffd100, expr=0x37c0400) at
../../gcc/fortran/trans-expr.c:8864
#7  0x0000000000b80ba6 in gfc_conv_expr_val (se=0x7fffffffd100, expr=0x37c0400)
at ../../gcc/fortran/trans-expr.c:8909
#8  0x0000000000b80c55 in gfc_conv_expr_type (se=0x7fffffffd100,
expr=0x37c0400, type=<integer_type 0x7fffea056738 integer(kind=8)>)
    at ../../gcc/fortran/trans-expr.c:8923
#9  0x0000000000b2dceb in gfc_trans_dummy_array_bias (sym=0x3822be0,
tmpdesc=<var_decl 0x7ffff7fcae10 a.0>, block=0x7fffffffd430)
    at ../../gcc/fortran/trans-array.c:6753
#10 0x0000000000b57286 in gfc_trans_deferred_vars (proc_sym=0x3821ac0,
block=0x7fffffffd430) at ../../gcc/fortran/trans-decl.c:4829
#11 0x0000000000b5e212 in gfc_generate_function_code (ns=0x3825570) at
../../gcc/fortran/trans-decl.c:6984
#12 0x0000000000b19f9e in gfc_generate_module_code (ns=0x381c790) at
../../gcc/fortran/trans.c:2319
The proc_sym in the gfc_trans_deferred_vars above is fun2.

Already in gfc_trans_deferred_vars'
6638      as = IS_CLASS_ARRAY (sym) ? CLASS_DATA (sym)->as : sym->as;

the CLASS_DATA (sym)->as
contains:
(gdb) p debug_tree (as->upper[0]->symtree->n.sym->backend_decl)
 <parm_decl 0x7fffea203700 this
    type <reference_type 0x7fffea216690
        type <record_type 0x7fffea216498 __class_buggy_Foo_t type_4 TI
            size <integer_cst 0x7fffea041c00 constant 128>
            unit-size <integer_cst 0x7fffea041c18 constant 16>
            align:64 warn_if_not_align:0 symtab:0 alias-set -1 canonical-type
0x7fffea216498 fields <field_decl 0x7fffea215da8 _data> context <namespace_decl
0x7fffea2151c8 buggy>
            reference_to_this <reference_type 0x7fffea2165e8> chain <type_decl
0x7fffea215ed8 D.3955>>
        unsigned restrict DI
        size <integer_cst 0x7fffea041bb8 constant 64>
        unit-size <integer_cst 0x7fffea041bd0 constant 8>
        align:64 warn_if_not_align:0 symtab:0 alias-set -1 canonical-type
0x7fffea216690>
    readonly unsigned DI passed-by-reference pr92605.f90:17:17 size
<integer_cst 0x7fffea041bb8 64> unit-size <integer_cst 0x7fffea041bd0 8>
    align:64 warn_if_not_align:0 context <function_decl 0x7fffea214700 fun1>
arg-type <reference_type 0x7fffea216690> chain <parm_decl 0x7fffea203780 a>>
i.e. the fun1's this PARM_DECL, even when this is during processing of fun2.

I don't know the class code in the fortran FE at all, but as has been said, one
can't just use PARM_DECLs of some other function except for nested functions,
so perhaps one need to use some magic sym that will translate to the this
parameter of the current method, or just detect uses of this symbol from other
method of the same class and replace it with the right one, whatever.


More information about the Gcc-bugs mailing list