← Back to context

Comment by bregma

14 days ago

GCC says that register extensions are not supported with basic inline asm. If you do it anyway it doesn't work it's not undefined behaviour, it's behaving as documented. Once you've ventured into vendorland you're outside the realm of undefined behaviour to start with, but following the vendor's documentation on how to use the vendor's extension is the minimum requirement for meeting your expectations that the feature will work.

> it's behaving as documented.

what do you think the documented behaviour is? None is documented, so it is undefined. The only defined behaviour is with extended asm.

Remember in C and C++ everything is UB unless defined in the standard or by an implementation.

If it was documented as giving an hard error, you would be right. But it is not.

  • I don't think this is exactly correct. Undefined behavior means a very specific thing - that the program could do literally anything. But I think that's not quite the situation in this case. Rather, I would suspect that these specified-register variables are only guaranteed to be effective with extended asm constraints.

    For basic asm I would assume then that the register contents cannot be relied on to contain the value of the variable, but as long as you don't rely on it, then you are in the clear.

    Then again it's hard to be sure about these matters with C.

    • > For basic asm I would assume then that the register contents cannot be relied on to contain the value of the variable, but as long as you don't rely on it, then you are in the clear.

      That's the crux. The example invokes 'syscall', which obviously relies on specific register content, from basic asm.