[llvm-dev] [RFC] A nofree (and nosynch) function attribute: Mixing dereferenceable and delete

Sanjoy Das via llvm-dev llvm-dev at lists.llvm.org
Wed Jul 11 16:41:41 PDT 2018


On Wed, Jul 11, 2018 at 4:13 PM Hal Finkel <hfinkel at anl.gov> wrote:
> Interestingly, I'm not sure. I trust that Richard can answer this
> question. :-)
>
> So, if we had:
>
> int y = ...;
> ...
> f(y);
>
> then I think that Clang's use of dereferenceable is almost certainly
> okay (because the standard explicitly says, 9.2.3.2p5, "A reference
> shall be initialized to refer to a valid object or
> function."). Because the reference must have been valid when f(y) began
> executing, unless it synchronizes somehow with the other thread, any
> asynchronous deletion of y must be a race.
>
> On the other hand, if we have:
>
> int &y = ...;
> ...
> f(y);
>
> do we know that, when f(y) begins executing, the reference points to a
> valid object? My reading of 9.3.3p2, which says, "Argument passing
> (7.6.1.2) and
> function value return (8.6.3) are initializations.", combined with the
> statement above, implies that, perhaps surprisingly, the same holds
> here. When the argument to f is initialized, it must refer to a valid
> object (even if the initializer is another reference).

Ok, I didn't know this.  If this is true then nosynch + nofree seems
sufficient to me.  And I realized my example is needlessly complex; if
arg passing isn't initialization then this is a problem too:

int&y = *ptr;
free(ptr);
f(y)

-- Sanjoy


More information about the llvm-dev mailing list