Is it "legal" to have a gcc inline asm statement without the actual instruction?
For example, is the asm statement "legal"? Will it introduce undefined behaviour?
int main(){ int *p = something; asm("":"=m"(p)); return 0; } int main(){ int *p = 0; asm("":"=m"(p)); return 0; } Compiles without any errors, but it is unnecessary:
main: .LFB0: .cfi_startproc pushq %rbp .cfi_def_cfa_offset 16 .cfi_offset 6, -16 movq %rsp, %rbp .cfi_def_cfa_register 6 movq $0, -8(%rbp) movl $0, %eax popq %rbp .cfi_def_cfa 7, 8 ret GCC completely ignores that empty asm statement.
In that specific example, the compiler can see that none of the outputs of the asm (ie p) are ever used. Since the asm is not volatile (and has at least 1 output), the compiler is free to completely discard the statement during optimization.
It may also be worth mentioning that on i386, all extended asm statements (ie ones with parameters) always implicitly clobber fpsr (floating point flags) and eflags (think: cc clobber). If the statement isn't completely discarded (for example if it is volatile), this might have an effect. If it does, it will at worst be a tiny loss of efficiency, not incorrect results.
So to sum up:
p could be undefined since you are saying that you are overwriting the contents, but you aren't actually putting anything in it.
"# no code here today!").return *pon gcc-{other than 4.8} -O3).