[PATCH] unshare expressions in attribute arguments

Martin Sebor msebor@gmail.com
Fri Nov 20 21:54:34 GMT 2020


On 11/20/20 2:41 PM, Jakub Jelinek wrote:
> On Fri, Nov 20, 2020 at 02:30:43PM -0700, Martin Sebor wrote:
>> VLA parameter bounds can involve any other expressions, including
>> function calls.  It's those rather than other parameters that also
>> trigger the problem (at least in the test cases I've seen).
>>
>> When/how would the unsharing cause the expression to be evaluated
>> multiple times?  And if/when it did, would simply wrapping the whole
>> expression in a SAVE_EXPR be the right way to avoid it or would it
>> need to be more involved than that?
> 
> Well, unshare_expr just doesn't unshare SAVE_EXPRs, it only ensures that
> the trees inside of them aren't shared with something else (aka unshares the
> subtrees the first time it sees the SAVE_EXPR), but doesn't unshare the
> SAVE_EXPR node itself and doesn't walk children the second and following
> time.
> So, the question is whether you are creating the attributes before the
> SAVE_EXPRs are added to the bounds or after it, and whether when evaluating
> the (unshared) expressions in there you always place it after something
> initialized those SAVE_EXPRs first.
> The SAVE_EXPRs are essential, so that the functions aren't called multiple
> times.

At the point the attribute is created there is no SAVE_EXPR.  So for
something like:

  int f (void);
  void g (int a[f () + 1]) { }

the bound is a PLUS_EXPR (CALL_EXPR (f), 1).

I don't do anything with the expression except put them on the chain
of arguments to the two attributes and print them in warnings.

Martin


More information about the Gcc-patches mailing list