Skip to content

Make [[clang::nomerge]] work for trap intrinsics such as __debugbreak and __builtin_trap #53011

Closed
@rnk

Description

@rnk

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.

Metadata

Metadata

Assignees

Labels

clang:codegenIR generation bugs: mangling, exceptions, etc.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions