Inline asm bug?

Consider this program:

--- asm.c ---
int G;

int foo(char *p) {
   int rv;
   G = 0;
   asm ("" : "=r"(rv)
           : "r"(p)
           : "memory");
   return rv + G;
}

unpredictable fashion, add `memory' to the list of clobbered
registers. This causes GCC to not keep memory values cached in
registers across the assembler instruction and not optimize stores or
loads to that memory. You also should add the volatile keyword if the
memory affected is not listed in the inputs or outputs of the asm, as
the `memory' clobber does not count as a side-effect of the asm. "

-Eli

Yes, I've read this. It's not a very precise description. If I need to make the asm "volatile", then why would I need to put "memory" in the clobber list? Shouldn't "asm volatile" be sufficient by itself? If so, then what's the point of having the clobber "memory" in the first place?

-Krzysztof

It's kind of weird... inline asm hooks into the compiler at a low
level, so think of it this way: alias analysis queries the "memory"
clobber, but dead code elimination ignores the clobber list. You're
right, this makes absolutely no sense from the user's perspective.

-Eli

Ok, this sheds some light on it.

Given that the "memory" clobber in the original example had no effect, I am assuming that this is indeed a bug. Am I correct? The problem there is that the load from G has been lost during translation to MI, so I'm assuming that this is something that the clobber should have prevented.

I have a local patch for it that I can submit here for review.

-Krzysztof

Yes, I believe so.

-Eli

Created bug 14859 for this issue:
http://llvm.org/bugs/show_bug.cgi?id=14859

-Krzysztof