[PATCH v2] generate EH info for volatile asm statements (PR93981)

J.W. Jagersma jwjagersma@gmail.com
Tue Mar 10 01:12:10 GMT 2020


On 2020-03-10 01:25, Segher Boessenkool wrote:
> On Mon, Mar 09, 2020 at 07:42:20PM +0100, J.W. Jagersma wrote:
>> On 2020-03-09 19:01, Segher Boessenkool wrote:
>>> On Mon, Mar 09, 2020 at 01:54:53PM +0100, Richard Biener wrote:
>>>>         int foo = 0
>>>>         try
>>>>           {
>>>>             asm volatile ("..." : "=r" (foo));
>>>>           }
>>>>         catch (...whatever...)
>>>>           {
>>>>             foo should be still zero, but SSA doesn't have the correct use here
>>>>           }
>>>>
>>>> that means the compiler really assumes the asm will populate the outputs
>>>> even when it throws.
>>>
>>> How is memory any different here?  In both cases you do not know if it
>>> is the old value or some new value in foo, after it threw an exception.
>>
>> If foo were a memory operand, the compiler makes no assumptions about
>> its value.  When you reference it in the catch block it is always read
>> back from memory.  Only register operands are clobbered and retain
>> their previous value.  If you compile such an example with -O3, you'll
>> see that the initial "int foo = 0;" is eliminated from the normal code
>> path.  It is only set to 0 in the catch block.
> 
> My question is *why* that is, and/or what in our code makes that so :-)
> 
> 
> Segher

The code I added in tree-eh.c does that.  Register outputs are assigned
to a temporary variable, which is discarded when the asm throws.  As I
said it's not possible to do this for memory operands too.  So, if this
behavior should be consistent for both types of operands, then you'd
have to assume that register outputs are valid after throwing.


More information about the Gcc-patches mailing list