Handle null cfun [PR102243].

Resolves:
PR middle-end/102243 - ICE on placement new at global scope

gcc/ChangeLog:
	PR middle-end/102243
	* tree-ssa-strlen.c (get_range): Handle null cfun.

gcc/testsuite/ChangeLog:
	PR middle-end/102243
	* g++.dg/warn/Wplacement-new-size-10.C: New test.
This commit is contained in:
Martin Sebor 2021-09-19 17:16:26 -06:00
parent 32731fa5b0
commit c3895ef466
2 changed files with 23 additions and 4 deletions

View file

@ -0,0 +1,13 @@
/* PR middle-end/102243 - ICE on placement new at global scope
{ dg-do compile }
{ dg-options "-Wall" } */
void *operator new (__SIZE_TYPE__, void *);
char a[2][sizeof (int)];
int *p = new (a[1]) int;
void *operator new[] (__SIZE_TYPE__, void *p) { return p; }
int *q = new (a[1]) int[1];

View file

@ -199,16 +199,22 @@ static bool handle_assign (gimple_stmt_iterator *, tree, bool *,
/* Sets MINMAX to either the constant value or the range VAL is in
and returns either the constant value or VAL on success or null
when the range couldn't be determined. Uses RVALS when nonnull
to determine the range, otherwise uses CFUN or global range info,
whichever is nonnull. */
when the range couldn't be determined. Uses RVALS or CFUN for
range info, whichever is nonnull. */
tree
get_range (tree val, gimple *stmt, wide_int minmax[2],
range_query *rvals /* = NULL */)
{
if (!rvals)
rvals = get_range_query (cfun);
{
if (!cfun)
/* When called from front ends for global initializers CFUN
may be null. */
return NULL_TREE;
rvals = get_range_query (cfun);
}
value_range vr;
if (!rvals->range_of_expr (vr, val, stmt))