← Back to context

Comment by bregma

12 days ago

It's not UB, it's documented behaviour of a vendor extension.

It's not UB because it's defined as outside the scope of the language standard. The vendor (in this case, GCC) does document how to use its inline assembly extension in quite a lot of detail, including how to use clobber lists to prevent exactly the kind of thing these failures demonstrate.

GCC says that register extensions are not supported with basic asm. What happens if you do it anyway is not documented. Ergo UB.

  • 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.

      2 replies →