Message ID | nycvar.YFH.7.76.2003171539350.5137@zhemvz.fhfr.qr |
---|---|
State | New |
Headers | show |
Series | middle-end/94188 fix fold of addr expression generation | expand |
> On 17 Mar 2020, at 17:40, Richard Biener <rguenther@suse.de> wrote: > > > This adds a missing type conversion to build_fold_addr_expr and adjusts > fallout - build_fold_addr_expr was used as a convenience to build an > ADDR_EXPR but some callers do not expect the result to be simplified > to something else. > > Bootstrapped on x86_64-unknown-linux-gnu, testin in progress. > > This is the 3rd or 4th attempt and I hope to have catched all fallout > with this. I think it's inevitable we fix the mistake in > build_fold_addr_expr. > > Richard. > > 2020-03-17 Richard Biener <rguenther@suse.de> > > PR middle-end/94188 > * fold-const.c (build_fold_addr_expr): Convert address to > correct type. > * asan.c (maybe_create_ssa_name): Strip useless type conversions. > * gimple-fold.c (gimple_fold_stmt_to_constant_1): Use build1 > to build the ADDR_EXPR which we don't really want to simplify. > * tree-ssa-dom.c (record_equivalences_from_stmt): Likewise. > * tree-ssa-loop-im.c (gather_mem_refs_stmt): Likewise. > * tree-ssa-forwprop.c (forward_propagate_addr_expr_1): Likewise. > (simplify_builtin_call): Strip useless type conversions. > * tree-ssa-strlen.c (new_strinfo): Likewise. > > * gcc.dg/pr94188.c: New testcase. Hi Richard, This breaks Linux kernel build on 32-bit ARM: 00:01:29 ./include/linux/string.h:333:9: internal compiler error: in gen_movsi, at config/arm/arm.md:6291 00:01:29 make[2]: *** [sound/drivers/serial-u16550.o] Error 1 Would you please investigate? Let me know if you need any help reproducing the problem. Kernel’s build line is (assuming cross-compilation): make CC=/path/to/arm-linux-gnueabihf-gcc ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- HOSTCC=gcc allyesconfig Regards, -- Maxim Kuvyrkov https://www.linaro.org
On March 18, 2020 6:20:29 PM GMT+01:00, Maxim Kuvyrkov <maxim.kuvyrkov@linaro.org> wrote: > >> On 17 Mar 2020, at 17:40, Richard Biener <rguenther@suse.de> wrote: >> >> >> This adds a missing type conversion to build_fold_addr_expr and >adjusts >> fallout - build_fold_addr_expr was used as a convenience to build an >> ADDR_EXPR but some callers do not expect the result to be simplified >> to something else. >> >> Bootstrapped on x86_64-unknown-linux-gnu, testin in progress. >> >> This is the 3rd or 4th attempt and I hope to have catched all fallout > >> with this. I think it's inevitable we fix the mistake in >> build_fold_addr_expr. >> >> Richard. >> >> 2020-03-17 Richard Biener <rguenther@suse.de> >> >> PR middle-end/94188 >> * fold-const.c (build_fold_addr_expr): Convert address to >> correct type. >> * asan.c (maybe_create_ssa_name): Strip useless type conversions. >> * gimple-fold.c (gimple_fold_stmt_to_constant_1): Use build1 >> to build the ADDR_EXPR which we don't really want to simplify. >> * tree-ssa-dom.c (record_equivalences_from_stmt): Likewise. >> * tree-ssa-loop-im.c (gather_mem_refs_stmt): Likewise. >> * tree-ssa-forwprop.c (forward_propagate_addr_expr_1): Likewise. >> (simplify_builtin_call): Strip useless type conversions. >> * tree-ssa-strlen.c (new_strinfo): Likewise. >> >> * gcc.dg/pr94188.c: New testcase. > >Hi Richard, > >This breaks Linux kernel build on 32-bit ARM: > >00:01:29 ./include/linux/string.h:333:9: internal compiler error: in >gen_movsi, at config/arm/arm.md:6291 >00:01:29 make[2]: *** [sound/drivers/serial-u16550.o] Error 1 > >Would you please investigate? Let me know if you need any help >reproducing the problem. Please file a bug report with preprocessed source and instructions how to configure a cross to reproduce this. The change has caused more fallout than I expected... Thanks, Richard. >Kernel’s build line is (assuming cross-compilation): >make CC=/path/to/arm-linux-gnueabihf-gcc ARCH=arm >CROSS_COMPILE=arm-linux-gnueabihf- HOSTCC=gcc allyesconfig > >Regards, > >-- >Maxim Kuvyrkov >https://www.linaro.org
On Wed, 18 Mar 2020 at 20:30, Richard Biener <rguenther@suse.de> wrote: > > On March 18, 2020 6:20:29 PM GMT+01:00, Maxim Kuvyrkov <maxim.kuvyrkov@linaro.org> wrote: > > > >> On 17 Mar 2020, at 17:40, Richard Biener <rguenther@suse.de> wrote: > >> > >> > >> This adds a missing type conversion to build_fold_addr_expr and > >adjusts > >> fallout - build_fold_addr_expr was used as a convenience to build an > >> ADDR_EXPR but some callers do not expect the result to be simplified > >> to something else. > >> > >> Bootstrapped on x86_64-unknown-linux-gnu, testin in progress. > >> > >> This is the 3rd or 4th attempt and I hope to have catched all fallout > > > >> with this. I think it's inevitable we fix the mistake in > >> build_fold_addr_expr. > >> > >> Richard. > >> > >> 2020-03-17 Richard Biener <rguenther@suse.de> > >> > >> PR middle-end/94188 > >> * fold-const.c (build_fold_addr_expr): Convert address to > >> correct type. > >> * asan.c (maybe_create_ssa_name): Strip useless type conversions. > >> * gimple-fold.c (gimple_fold_stmt_to_constant_1): Use build1 > >> to build the ADDR_EXPR which we don't really want to simplify. > >> * tree-ssa-dom.c (record_equivalences_from_stmt): Likewise. > >> * tree-ssa-loop-im.c (gather_mem_refs_stmt): Likewise. > >> * tree-ssa-forwprop.c (forward_propagate_addr_expr_1): Likewise. > >> (simplify_builtin_call): Strip useless type conversions. > >> * tree-ssa-strlen.c (new_strinfo): Likewise. > >> > >> * gcc.dg/pr94188.c: New testcase. > > > >Hi Richard, > > > >This breaks Linux kernel build on 32-bit ARM: > > > >00:01:29 ./include/linux/string.h:333:9: internal compiler error: in > >gen_movsi, at config/arm/arm.md:6291 > >00:01:29 make[2]: *** [sound/drivers/serial-u16550.o] Error 1 > > > >Would you please investigate? Let me know if you need any help > >reproducing the problem. > > Please file a bug report with preprocessed source and instructions how to configure a cross to reproduce this. > > The change has caused more fallout than I expected... > I think this commit is also causing regressions in gfortran, that's probably easier to reproduce for you? gfortran.dg/char_expr_3.f90 -O1 (internal compiler error) gfortran.dg/char_expr_3.f90 -O2 (internal compiler error) gfortran.dg/char_expr_3.f90 -O3 -fomit-frame-pointer -funroll-loops -fpeel-loops -ftracer -finline-functions (internal compiler error) gfortran.dg/char_expr_3.f90 -O3 -g (internal compiler error) seen on cross arm-none-linux-gnueabi[hf] Christophe > Thanks, > Richard. > > >Kernel’s build line is (assuming cross-compilation): > >make CC=/path/to/arm-linux-gnueabihf-gcc ARCH=arm > >CROSS_COMPILE=arm-linux-gnueabihf- HOSTCC=gcc allyesconfig > > > >Regards, > > > >-- > >Maxim Kuvyrkov > >https://www.linaro.org >
On Thu, 19 Mar 2020, Christophe Lyon wrote: > On Wed, 18 Mar 2020 at 20:30, Richard Biener <rguenther@suse.de> wrote: > > > > On March 18, 2020 6:20:29 PM GMT+01:00, Maxim Kuvyrkov <maxim.kuvyrkov@linaro.org> wrote: > > > > > >> On 17 Mar 2020, at 17:40, Richard Biener <rguenther@suse.de> wrote: > > >> > > >> > > >> This adds a missing type conversion to build_fold_addr_expr and > > >adjusts > > >> fallout - build_fold_addr_expr was used as a convenience to build an > > >> ADDR_EXPR but some callers do not expect the result to be simplified > > >> to something else. > > >> > > >> Bootstrapped on x86_64-unknown-linux-gnu, testin in progress. > > >> > > >> This is the 3rd or 4th attempt and I hope to have catched all fallout > > > > > >> with this. I think it's inevitable we fix the mistake in > > >> build_fold_addr_expr. > > >> > > >> Richard. > > >> > > >> 2020-03-17 Richard Biener <rguenther@suse.de> > > >> > > >> PR middle-end/94188 > > >> * fold-const.c (build_fold_addr_expr): Convert address to > > >> correct type. > > >> * asan.c (maybe_create_ssa_name): Strip useless type conversions. > > >> * gimple-fold.c (gimple_fold_stmt_to_constant_1): Use build1 > > >> to build the ADDR_EXPR which we don't really want to simplify. > > >> * tree-ssa-dom.c (record_equivalences_from_stmt): Likewise. > > >> * tree-ssa-loop-im.c (gather_mem_refs_stmt): Likewise. > > >> * tree-ssa-forwprop.c (forward_propagate_addr_expr_1): Likewise. > > >> (simplify_builtin_call): Strip useless type conversions. > > >> * tree-ssa-strlen.c (new_strinfo): Likewise. > > >> > > >> * gcc.dg/pr94188.c: New testcase. > > > > > >Hi Richard, > > > > > >This breaks Linux kernel build on 32-bit ARM: > > > > > >00:01:29 ./include/linux/string.h:333:9: internal compiler error: in > > >gen_movsi, at config/arm/arm.md:6291 > > >00:01:29 make[2]: *** [sound/drivers/serial-u16550.o] Error 1 > > > > > >Would you please investigate? Let me know if you need any help > > >reproducing the problem. > > > > Please file a bug report with preprocessed source and instructions how to configure a cross to reproduce this. > > > > The change has caused more fallout than I expected... > > > > I think this commit is also causing regressions in gfortran, that's > probably easier to reproduce for you? > gfortran.dg/char_expr_3.f90 -O1 (internal compiler error) > gfortran.dg/char_expr_3.f90 -O2 (internal compiler error) > gfortran.dg/char_expr_3.f90 -O3 -fomit-frame-pointer > -funroll-loops -fpeel-loops -ftracer -finline-functions (internal > compiler error) > gfortran.dg/char_expr_3.f90 -O3 -g (internal compiler error) > > seen on cross arm-none-linux-gnueabi[hf] Can't reproduce those on master (which has seen two fixes already). Richard. > Christophe > > > Thanks, > > Richard. > > > > >Kernel’s build line is (assuming cross-compilation): > > >make CC=/path/to/arm-linux-gnueabihf-gcc ARCH=arm > > >CROSS_COMPILE=arm-linux-gnueabihf- HOSTCC=gcc allyesconfig > > > > > >Regards, > > > > > >-- > > >Maxim Kuvyrkov > > >https://www.linaro.org > > >
On Thu, 19 Mar 2020 at 13:34, Richard Biener <rguenther@suse.de> wrote: > > On Thu, 19 Mar 2020, Christophe Lyon wrote: > > > On Wed, 18 Mar 2020 at 20:30, Richard Biener <rguenther@suse.de> wrote: > > > > > > On March 18, 2020 6:20:29 PM GMT+01:00, Maxim Kuvyrkov <maxim.kuvyrkov@linaro.org> wrote: > > > > > > > >> On 17 Mar 2020, at 17:40, Richard Biener <rguenther@suse.de> wrote: > > > >> > > > >> > > > >> This adds a missing type conversion to build_fold_addr_expr and > > > >adjusts > > > >> fallout - build_fold_addr_expr was used as a convenience to build an > > > >> ADDR_EXPR but some callers do not expect the result to be simplified > > > >> to something else. > > > >> > > > >> Bootstrapped on x86_64-unknown-linux-gnu, testin in progress. > > > >> > > > >> This is the 3rd or 4th attempt and I hope to have catched all fallout > > > > > > > >> with this. I think it's inevitable we fix the mistake in > > > >> build_fold_addr_expr. > > > >> > > > >> Richard. > > > >> > > > >> 2020-03-17 Richard Biener <rguenther@suse.de> > > > >> > > > >> PR middle-end/94188 > > > >> * fold-const.c (build_fold_addr_expr): Convert address to > > > >> correct type. > > > >> * asan.c (maybe_create_ssa_name): Strip useless type conversions. > > > >> * gimple-fold.c (gimple_fold_stmt_to_constant_1): Use build1 > > > >> to build the ADDR_EXPR which we don't really want to simplify. > > > >> * tree-ssa-dom.c (record_equivalences_from_stmt): Likewise. > > > >> * tree-ssa-loop-im.c (gather_mem_refs_stmt): Likewise. > > > >> * tree-ssa-forwprop.c (forward_propagate_addr_expr_1): Likewise. > > > >> (simplify_builtin_call): Strip useless type conversions. > > > >> * tree-ssa-strlen.c (new_strinfo): Likewise. > > > >> > > > >> * gcc.dg/pr94188.c: New testcase. > > > > > > > >Hi Richard, > > > > > > > >This breaks Linux kernel build on 32-bit ARM: > > > > > > > >00:01:29 ./include/linux/string.h:333:9: internal compiler error: in > > > >gen_movsi, at config/arm/arm.md:6291 > > > >00:01:29 make[2]: *** [sound/drivers/serial-u16550.o] Error 1 > > > > > > > >Would you please investigate? Let me know if you need any help > > > >reproducing the problem. > > > > > > Please file a bug report with preprocessed source and instructions how to configure a cross to reproduce this. > > > > > > The change has caused more fallout than I expected... > > > > > > > I think this commit is also causing regressions in gfortran, that's > > probably easier to reproduce for you? > > gfortran.dg/char_expr_3.f90 -O1 (internal compiler error) > > gfortran.dg/char_expr_3.f90 -O2 (internal compiler error) > > gfortran.dg/char_expr_3.f90 -O3 -fomit-frame-pointer > > -funroll-loops -fpeel-loops -ftracer -finline-functions (internal > > compiler error) > > gfortran.dg/char_expr_3.f90 -O3 -g (internal compiler error) > > > > seen on cross arm-none-linux-gnueabi[hf] > > Can't reproduce those on master (which has seen two fixes already). > Ha, it's possible this has been fixed, then. Sorry my validations are bit delayed these days. Christophe > Richard. > > > Christophe > > > > > Thanks, > > > Richard. > > > > > > >Kernel’s build line is (assuming cross-compilation): > > > >make CC=/path/to/arm-linux-gnueabihf-gcc ARCH=arm > > > >CROSS_COMPILE=arm-linux-gnueabihf- HOSTCC=gcc allyesconfig > > > > > > > >Regards, > > > > > > > >-- > > > >Maxim Kuvyrkov > > > >https://www.linaro.org > > > > > > > -- > Richard Biener <rguenther@suse.de> > SUSE Software Solutions Germany GmbH, Maxfeldstrasse 5, 90409 Nuernberg, > Germany; GF: Felix Imendörffer; HRB 36809 (AG Nuernberg)
diff --git a/gcc/asan.c b/gcc/asan.c index 05f8b63139c..00d0e678a0e 100644 --- a/gcc/asan.c +++ b/gcc/asan.c @@ -62,6 +62,7 @@ along with GCC; see the file COPYING3. If not see #include "builtins.h" #include "fnmatch.h" #include "tree-inline.h" +#include "tree-ssa.h" /* AddressSanitizer finds out-of-bounds and use-after-free bugs with <2x slowdown on average. @@ -2061,10 +2062,10 @@ static tree maybe_create_ssa_name (location_t loc, tree base, gimple_stmt_iterator *iter, bool before_p) { + STRIP_USELESS_TYPE_CONVERSION (base); if (TREE_CODE (base) == SSA_NAME) return base; - gimple *g = gimple_build_assign (make_ssa_name (TREE_TYPE (base)), - TREE_CODE (base), base); + gimple *g = gimple_build_assign (make_ssa_name (TREE_TYPE (base)), base); gimple_set_location (g, loc); if (before_p) gsi_insert_before (iter, g, GSI_SAME_STMT); diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 71a1d3eb735..3ab1a9adcdf 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -8523,7 +8523,12 @@ build_fold_addr_expr_with_type_loc (location_t loc, tree t, tree ptrtype) } else if (TREE_CODE (t) == MEM_REF && integer_zerop (TREE_OPERAND (t, 1))) - return TREE_OPERAND (t, 0); + { + t = TREE_OPERAND (t, 0); + + if (TREE_TYPE (t) != ptrtype) + t = fold_convert_loc (loc, ptrtype, t); + } else if (TREE_CODE (t) == MEM_REF && TREE_CODE (TREE_OPERAND (t, 0)) == INTEGER_CST) return fold_binary (POINTER_PLUS_EXPR, ptrtype, diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c index 9e45cc55df4..3f17de974ed 100644 --- a/gcc/gimple-fold.c +++ b/gcc/gimple-fold.c @@ -6413,8 +6413,8 @@ gimple_fold_stmt_to_constant_1 (gimple *stmt, tree (*valueize) (tree), && TREE_CODE (op1) == INTEGER_CST) { tree off = fold_convert (ptr_type_node, op1); - return build_fold_addr_expr_loc - (loc, + return build1_loc + (loc, ADDR_EXPR, TREE_TYPE (op0), fold_build2 (MEM_REF, TREE_TYPE (TREE_TYPE (op0)), unshare_expr (op0), off)); diff --git a/gcc/testsuite/gcc.dg/pr94188.c b/gcc/testsuite/gcc.dg/pr94188.c new file mode 100644 index 00000000000..7a73c1bc071 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr94188.c @@ -0,0 +1,10 @@ +/* { dg-do compile } */ + +struct dm_tree_link { + int list; + int node; +}; +void fn1(void *p) +{ + 0 ? ((struct dm_tree_link *)((char *)p - (char *)&((struct dm_tree_link *)0)->list))->node : 0; +} diff --git a/gcc/tree-ssa-dom.c b/gcc/tree-ssa-dom.c index eea494c8a96..7742d75d2f5 100644 --- a/gcc/tree-ssa-dom.c +++ b/gcc/tree-ssa-dom.c @@ -1725,11 +1725,10 @@ record_equivalences_from_stmt (gimple *stmt, int may_optimize_p, tree op0 = gimple_assign_rhs1 (stmt); tree op1 = gimple_assign_rhs2 (stmt); tree new_rhs - = build_fold_addr_expr (fold_build2 (MEM_REF, - TREE_TYPE (TREE_TYPE (op0)), - unshare_expr (op0), - fold_convert (ptr_type_node, - op1))); + = build1 (ADDR_EXPR, TREE_TYPE (op0), + fold_build2 (MEM_REF, TREE_TYPE (TREE_TYPE (op0)), + unshare_expr (op0), fold_convert (ptr_type_node, + op1))); if (dump_file && (dump_flags & TDF_DETAILS)) { fprintf (dump_file, "==== ASGN "); diff --git a/gcc/tree-ssa-forwprop.c b/gcc/tree-ssa-forwprop.c index f65216d23e9..61b4eec271b 100644 --- a/gcc/tree-ssa-forwprop.c +++ b/gcc/tree-ssa-forwprop.c @@ -50,6 +50,7 @@ along with GCC; see the file COPYING3. If not see #include "vec-perm-indices.h" #include "internal-fn.h" #include "cgraph.h" +#include "tree-ssa.h" /* This pass propagates the RHS of assignment statements into use sites of the LHS of the assignment. It's basically a specialized @@ -732,16 +733,15 @@ forward_propagate_addr_expr_1 (tree name, tree def_rhs, if (TREE_CODE (new_def_rhs) == MEM_REF && !is_gimple_mem_ref_addr (TREE_OPERAND (new_def_rhs, 0))) return false; - new_def_rhs = build_fold_addr_expr_with_type (new_def_rhs, - TREE_TYPE (rhs)); + new_def_rhs = build1 (ADDR_EXPR, TREE_TYPE (rhs), new_def_rhs); /* Recurse. If we could propagate into all uses of lhs do not bother to replace into the current use but just pretend we did. */ - if (TREE_CODE (new_def_rhs) == ADDR_EXPR - && forward_propagate_addr_expr (lhs, new_def_rhs, single_use_p)) + if (forward_propagate_addr_expr (lhs, new_def_rhs, single_use_p)) return true; - if (useless_type_conversion_p (TREE_TYPE (lhs), TREE_TYPE (new_def_rhs))) + if (useless_type_conversion_p (TREE_TYPE (lhs), + TREE_TYPE (new_def_rhs))) gimple_assign_set_rhs_with_ops (use_stmt_gsi, TREE_CODE (new_def_rhs), new_def_rhs); else if (is_gimple_min_invariant (new_def_rhs)) @@ -1319,6 +1319,7 @@ simplify_builtin_call (gimple_stmt_iterator *gsi_p, tree callee2) || !tree_fits_shwi_p (src1)) break; ptr1 = build_fold_addr_expr (ptr1); + STRIP_USELESS_TYPE_CONVERSION (ptr1); callee1 = NULL_TREE; len1 = size_one_node; lhs1 = NULL_TREE; diff --git a/gcc/tree-ssa-loop-im.c b/gcc/tree-ssa-loop-im.c index 3e64ae71944..273a58038bd 100644 --- a/gcc/tree-ssa-loop-im.c +++ b/gcc/tree-ssa-loop-im.c @@ -1527,7 +1527,8 @@ gather_mem_refs_stmt (class loop *loop, gimple *stmt) tree ref_alias_type = reference_alias_ptr_type (*mem); unsigned int ref_align = get_object_alignment (*mem); tree ref_type = TREE_TYPE (*mem); - tree tmp = build_fold_addr_expr (unshare_expr (mem_base)); + tree tmp = build1 (ADDR_EXPR, ptr_type_node, + unshare_expr (mem_base)); if (TYPE_ALIGN (ref_type) != ref_align) ref_type = build_aligned_type (ref_type, ref_align); (*slot)->mem.ref diff --git a/gcc/tree-ssa-strlen.c b/gcc/tree-ssa-strlen.c index 0d70f3cc95d..6a5bae900d8 100644 --- a/gcc/tree-ssa-strlen.c +++ b/gcc/tree-ssa-strlen.c @@ -57,9 +57,9 @@ along with GCC; see the file COPYING3. If not see #include "cfgloop.h" #include "tree-ssa-loop.h" #include "tree-scalar-evolution.h" - #include "vr-values.h" #include "gimple-ssa-evrp-analyze.h" +#include "tree-ssa.h" /* A vector indexed by SSA_NAME_VERSION. 0 means unknown, positive value is an index into strinfo vector, negative value stands for @@ -679,6 +679,7 @@ new_strinfo (tree ptr, int idx, tree nonzero_chars, bool full_string_p) { strinfo *si = strinfo_pool.allocate (); si->nonzero_chars = nonzero_chars; + STRIP_USELESS_TYPE_CONVERSION (ptr); si->ptr = ptr; si->stmt = NULL; si->alloc = NULL;