On Fri, 2021-03-12 at 14:52 +0100, Jakub Jelinek via Gcc-patches wrote: > On Tue, Mar 09, 2021 at 03:07:38PM -0700, Martin Sebor via Gcc- > patches wrote: > > The gimple_call_alloc_size() function is documented to "return null > > when STMT is not a call to a valid allocation function" but the > > code > > assumes STMT is a call statement, causing the function to ICE when > > it isn't. > > > > The attached patch changes the function to fulfill its contract and > > return null also when STMT isn't a call. The fix seems obvious to > > me but I'll wait some time before committing it in case it's not > > to someone else. > > I think the name of the function suggests that it should be called on > calls, > not random stmts. Currently the function has 3 callers, two of them > already verify is_gimple_call before calling it and only one doesn't, > and the stmt will never be NULL. > So I'd say it would be better to remove the if (!stmt) return > NULL_TREE; > from the start of the function and add is_gimple_call (stmt) && > in tree-ssa-strlen.c.
Maybe even make it convert it to taking a "const gcall *", so those if (is_gimple_call (stmt)) { ... if (gimple_call_alloc_size (stmt, ...)) { } } become: if (const gcall *call = dyn_cast <const gcall *> (stmt)) { ... if (gimple_call_alloc_size (call, ...)) { } } so that the compiler can enforce this requirement via the type system? Hope this is constructive Dave