https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78201
Bug ID: 78201 Summary: [7 Regression] ICE in tree_to_shwi, at tree.h:4037 (seen both on ARM32 an AArch64) Product: gcc Version: 7.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: yroux at gcc dot gnu.org Target Milestone: --- Created attachment 39959 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=39959&action=edit Reduced testcase Hi, the attached reduced testcase fails with ICE on trunk since r239561. It was observed on ARM and AArch64 targets, but might affect targets with section-anchors enabled. $ aarch64-linux-gnu-g++ -O2 reduced.C reduced.C: In function 'void f()': reduced.C:7:8: internal compiler error: in tree_to_shwi, at tree.c:7313 char a[e] = ""; ^ 0x1007a32 tree_to_shwi(tree_node const*) .../gcc.git~master/gcc/tree.c:7313 0x105bffa default_use_anchors_for_symbol_p(rtx_def const*) .../gcc.git~master/gcc/varasm.c:6810 ... The issue is that tree_to_shwi is called without checking its parameter fits in a signed HOST_WIDE_INT first. I've validated the following fix, which does the checking and avoid using section anchors if it fails, on ARM and AArch64 targets, and will submit it on the list. diff --git a/gcc/varasm.c b/gcc/varasm.c index 6a7ffc2..231ac05 100644 --- a/gcc/varasm.c +++ b/gcc/varasm.c @@ -6807,8 +6807,9 @@ default_use_anchors_for_symbol_p (const_rtx symbol) anchor range to reduce the amount of instructions require to refer to the entire declaration. */ if (decl && DECL_SIZE (decl) - && tree_to_shwi (DECL_SIZE (decl)) - >= (targetm.max_anchor_offset * BITS_PER_UNIT)) + && (!tree_fits_shwi_p (DECL_SIZE (decl)) + || tree_to_shwi (DECL_SIZE (decl)) + >= (targetm.max_anchor_offset * BITS_PER_UNIT))) return false;