Correct way to express to the compiler "this does not get clobbered"?

David Brown david.brown@hesbynett.no
Fri Dec 4 08:27:31 GMT 2020


On 04/12/2020 00:00, Andrea Corallo wrote:
> David Brown <david.brown@hesbynett.no> writes:
> 
> Hi David,
> 
>> As "f()" runs, the value of "y->fun_ptr" changes with each step as you
>> get alternating "foo1", "foo2" outputs.  Thus it is clear (I hope) that
>> the compiler cannot assume that "y->fun_ptr" is not clobbered by the
>> function call.
> 
> Indeed that's clear.  The question is more if there's some way to express
> this to the compiler qualifying the variables in discussion without
> changing the structure of the code.  This because as I wrote may be not
> trivial to modify the code generator for optimal results.
> 
> I understand this is probably not possible and there's no magic
> attribute or qualifier to express this.
> 

In order to add a qualifier or attribute, you'd still need to change the 
code in some way.  Is it possible to make /some/ changes to the code 
generator, but not others?  (I appreciate that code generators can be 
difficult to change.)

On trick that sometimes works when you want to give the compiler more 
information is to use "if (!x) __builtin_unreachable();" as a way of 
saying "x is always true".  But I can't see any way that would help 
here, I'm afraid.



More information about the Gcc-help mailing list