Closed
Description
Consider:
https://gcc.godbolt.org/z/esvPqdfn9
#define NOMERGE [[clang::nomerge]]
bool condition();
void mergeChecks() {
if (condition())
NOMERGE __builtin_trap();
if (condition())
NOMERGE __builtin_trap();
if (condition())
NOMERGE __builtin_trap();
}
LLVM folds all these traps together:
_Z11mergeChecksv: # @_Z11mergeChecksv
push rax
call _Z9conditionv
test al, al
jne .LBB0_4
call _Z9conditionv
test al, al
jne .LBB0_4
call _Z9conditionv
test al, al
jne .LBB0_4
pop rax
ret
.LBB0_4: # %if.then
ud2
Ideally, the nomerge attribute should prevent this. Currently the attribute only really works with call expressions.