From 7dc7de834989d85cb1dbaf7b5a0917ba07319cfb Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <thomas@codesourcery.com>
Date: Sat, 9 Sep 2023 16:49:16 +0200
Subject: [PATCH] Fix false positive for -Walloc-size-larger-than, part II
[PR79132]
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
In a GCC bootstrap, I was running into:
In file included from [...]/gcc/system.h:729,
from [...]/gcc/tree-ssa-reassoc.cc:22:
[...]/gcc/tree-ssa-reassoc.cc: In function ‘void rewrite_expr_tree_parallel(gassign*, int, bool, const vec<operand_entry*>&)’:
[...]/gcc/../include/libiberty.h:733:36: error: argument to ‘alloca’ is too large [-Werror=alloca-larger-than=]
733 | # define alloca(x) __builtin_alloca(x)
| ~~~~~~~~~~~~~~~~^~~
[...]/gcc/../include/libiberty.h:365:40: note: in expansion of macro ‘alloca’
365 | #define XALLOCAVEC(T, N) ((T *) alloca (sizeof (T) * (N)))
| ^~~~~~
[...]/gcc/tree-ssa-reassoc.cc:5518:20: note: in expansion of macro ‘XALLOCAVEC’
5518 | gimple **stmts = XALLOCAVEC (gimple *, stmt_num);
| ^~~~~~~~~~
[...]/gcc/../include/libiberty.h:733:36: note: limit is 9223372036854775807 bytes, but argument is 18446744073709551608
733 | # define alloca(x) __builtin_alloca(x)
| ~~~~~~~~~~~~~~~~^~~
[...]/gcc/../include/libiberty.h:365:40: note: in expansion of macro ‘alloca’
365 | #define XALLOCAVEC(T, N) ((T *) alloca (sizeof (T) * (N)))
| ^~~~~~
[...]/gcc/tree-ssa-reassoc.cc:5518:20: note: in expansion of macro ‘XALLOCAVEC’
5518 | gimple **stmts = XALLOCAVEC (gimple *, stmt_num);
| ^~~~~~~~~~
'18446744073709551608' means '-8', which is 'sizeof (gimple *) * (-1)'.
That's the very issue that PR79132
"False positive for -Walloc-size-larger-than= with -fsanitize=address aka. bootstrap-asan breakage"
commit ad8040243acd2a909b61b5690f7dac9ae362c945 (Subversion r244857)
"Fix false positive for -Walloc-size-larger-than (PR bootstrap/79132)"
meant to address -- the detail being that '-fsanitize=address' nowadays
doesn't seem necessary anymore to trigger this, and why I was running
into this at all, is 'configure'ing with '--enable-checking=no', which
per 'gcc/system.h' means:
#define gcc_assert(EXPR) ((void)(0 && (EXPR)))
..., and thus the 'gcc_assert (op_num > 0);' is a no-op, eh...
PR bootstrap/79132
gcc/
* tree-ssa-reassoc.cc (rewrite_expr_tree_parallel): Reformulate
'gcc_assert' into 'gcc_unreachable'.
---
gcc/tree-ssa-reassoc.cc | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
@@ -5513,7 +5513,8 @@ rewrite_expr_tree_parallel (gassign *stmt, int width, bool has_fma,
enum tree_code opcode = gimple_assign_rhs_code (stmt);
int op_num = ops.length ();
int op_normal_num = op_num;
- gcc_assert (op_num > 0);
+ if (op_num < 1)
+ gcc_unreachable ();
int stmt_num = op_num - 1;
gimple **stmts = XALLOCAVEC (gimple *, stmt_num);
int i = 0, j = 0;
--
2.34.1