diff mbox series

Fix discrepancy in Walloca test on 32-bit systems.

Message ID 20201021071304.49756-1-aldyh@redhat.com
State New
Headers show
Series Fix discrepancy in Walloca test on 32-bit systems. | expand

Commit Message

Aldy Hernandez Oct. 21, 2020, 7:13 a.m. UTC
There is a discrepancy in the way we report -Walloca-larger-than=
errors on 32-bit versus 64-bit architectures, due to the nature of
ranges derived from a cast operation.

For the Walloca-1 tests on 64-bits we get:

  int num.0_1;
  long unsigned int _2;

  <bb 2> [local count: 1073741824]:
  num.0_1 = num;
  _2 = (long unsigned int) num.0_1;
  s_8 = __builtin_alloca (_2);

Because of the cast of a 32-bit quantity into a 64-bit quantity in _2,
ranger calculates its range as:

	long unsigned int [0, 2147483647][18446744071562067968, +INF]

Thus excluding the numbers that can't exist in _2.

This causes the Walloca pass to report that the argument to alloca may be
too large.

However, for -m32 on x86, the gimple is:

  int num.0_1;
  unsigned int num.1_2;

  <bb 2> [local count: 1073741824]:
  num.0_1 = num;
  num.1_2 = (unsigned int) num.0_1;
  s_8 = __builtin_alloca (num.1_2);

Since num.0_1 and num.1_2 are of the same size, we cannot determine
any useful range, so we return VARYING.  In the Walloca pass, VARYING
basically means "unbounded" (no known bounds for the alloca call argument).
So on 32-bits, the error message issued is slightly different:

	warning: unbounded use of ‘alloca’

versus on 64-bits, where due to the cast, it is:

	warning: argument to ‘alloca’ may be too large

In reality both versions of the IL show an unbounded call, but in one
version (64-bits) we can exclude some values so we assume the range
was provided, but it was out of bounds.

I've mentioned various times that all these diagnostics passes
(alloca, restrict, printf, etc), could benefit from less specific error
messages since what we have can potentially confuse the user.  However,
no consensus has been reached on how to report these things.

In the meantime, this patch adjusts the testcase to accept both variants.

Pushed.

gcc/testsuite/ChangeLog:

	* gcc.dg/Walloca-1.c: Adjust for 32-bits.
---
 gcc/testsuite/gcc.dg/Walloca-1.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/gcc/testsuite/gcc.dg/Walloca-1.c b/gcc/testsuite/gcc.dg/Walloca-1.c
index ed1fa929398..37ee1912187 100644
--- a/gcc/testsuite/gcc.dg/Walloca-1.c
+++ b/gcc/testsuite/gcc.dg/Walloca-1.c
@@ -24,7 +24,7 @@  void foo1 (size_t len, size_t len2, size_t len3)
   char *s = alloca (123);
   useit (s);			// OK, constant argument to alloca
 
-  s = alloca (num);		// { dg-warning "may be too large" }
+  s = alloca (num);		// { dg-warning "\(may be too large|unbounded use\)" }
   useit (s);
 
   s = alloca (30000);		/* { dg-warning "is too large" } */