* [PATCH] Handle a_2= &b properly in range calculations.
@ 2020-10-22 0:19 Andrew MacLeod
0 siblings, 0 replies; only message in thread
From: Andrew MacLeod @ 2020-10-22 0:19 UTC (permalink / raw)
To: gcc-patches
[-- Attachment #1: Type: text/plain, Size: 124 bytes --]
Pick up the correct type for the RHS of a_2 = &b.
bootstrapped on x86_64-pc-linux-gnu, no regressions, pushed.
Andrew
[-- Attachment #2: pr97520.patch --]
[-- Type: text/x-patch, Size: 2491 bytes --]
commit 966fdb2e12c0347aa3f9efaf5f4e1cd8237fa024
Author: Andrew MacLeod <amacleod@redhat.com>
Date: Wed Oct 21 20:11:16 2020 -0400
Handle a_2= &b properly in range calculations.
when processing assignments, we were using the type of b instead of type
of &b when computing a range. This was usually filtered out by FRE.
turning it off exposed it.
gcc/
PR tree-optimization/97520
* gimple-range.cc (range_of_non_trivial_assignment): Handle x = &a
by returning a non-zero range.
gcc/testsuite/
* gcc.dg/pr97520.c: New.
diff --git a/gcc/gimple-range.cc b/gcc/gimple-range.cc
index c5520e0700b..267ebad757f 100644
--- a/gcc/gimple-range.cc
+++ b/gcc/gimple-range.cc
@@ -446,17 +446,31 @@ gimple_ranger::range_of_non_trivial_assignment (irange &r, gimple *stmt)
return false;
tree base = gimple_range_base_of_assignment (stmt);
- if (base && TREE_CODE (base) == MEM_REF
- && TREE_CODE (TREE_OPERAND (base, 0)) == SSA_NAME)
+ if (base)
{
- int_range_max range1;
- tree ssa = TREE_OPERAND (base, 0);
- if (range_of_expr (range1, ssa, stmt))
+ if (TREE_CODE (base) == MEM_REF)
{
- tree type = TREE_TYPE (ssa);
- range_operator *op = range_op_handler (POINTER_PLUS_EXPR, type);
- int_range<2> offset (TREE_OPERAND (base, 1), TREE_OPERAND (base, 1));
- op->fold_range (r, type, range1, offset);
+ if (TREE_CODE (TREE_OPERAND (base, 0)) == SSA_NAME)
+ {
+ int_range_max range1;
+ tree ssa = TREE_OPERAND (base, 0);
+ if (range_of_expr (range1, ssa, stmt))
+ {
+ tree type = TREE_TYPE (ssa);
+ range_operator *op = range_op_handler (POINTER_PLUS_EXPR,
+ type);
+ int_range<2> offset (TREE_OPERAND (base, 1),
+ TREE_OPERAND (base, 1));
+ op->fold_range (r, type, range1, offset);
+ return true;
+ }
+ }
+ return false;
+ }
+ if (gimple_assign_rhs_code (stmt) == ADDR_EXPR)
+ {
+ // Handle "= &a" and return non-zero.
+ r = range_nonzero (TREE_TYPE (gimple_assign_rhs1 (stmt)));
return true;
}
}
diff --git a/gcc/testsuite/gcc.dg/pr97520.c b/gcc/testsuite/gcc.dg/pr97520.c
new file mode 100644
index 00000000000..9f665959138
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr97520.c
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fno-tree-fre" } */
+
+char a;
+void b() {
+ char *c[5];
+ char *d = &a;
+ &d;
+ *(c[4] = d);
+}
+int main() { return 0; }
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-10-22 0:19 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-22 0:19 [PATCH] Handle a_2= &b properly in range calculations Andrew MacLeod
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).