From: Aldy Hernandez Date: Wed, 21 Oct 2020 06:47:03 +0000 (+0200) Subject: Fix discrepancy in Walloca test on 32-bit systems. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=1768f534c192362e8747ad199daccabed43fa0bb;p=gcc.git Fix discrepancy in Walloca test on 32-bit systems. 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; [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; [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. gcc/testsuite/ChangeLog: * gcc.dg/Walloca-1.c: Adjust for 32-bits. --- 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" } */