Segher Boessenkool <seg...@kernel.crashing.org> writes: > On Fri, Mar 13, 2020 at 01:31:19PM +0000, Richard Sandiford wrote: >> This might not be what you mean, but for: >> >> int >> f1 (void) >> { >> int x = 1; >> asm volatile ("": "=m" (x)); >> return x; >> } >> >> struct s { int i[5]; }; >> struct s >> f2 (void) >> { >> struct s x = { 1, 2, 3, 4, 5 }; >> asm volatile ("": "=m" (x)); >> return x; >> } >> >> we do delete "x = 1" for f1. I think that's the expected behaviour. >> We don't yet delete the initialisation in f2, but I think in principle >> we could. > > Right. And this is incorrect if the asm may throw.
Well... > >> So the kind of contract I was advocating was: >> >> - the compiler can't make any assumptions about what the asm does >> or doesn't do to output operands when an exception is raised >> >> - the source code can't make any assumption about the values bound >> to output operands when an exception is raised ...with this interpretation, the deletions above would be correct even if the asm throws. > And the easiest (and only feasible?) way to do this is for the compiler > to automatically make an input for every output as well, imo. Modifying the asm like that feels a bit dangerous, And the other problem still exists: he compiler might assume that the output isn't modified unless the asm completes normally. Thanks, Richard