diff --git a/lib/Target/AMDGPU/MCTargetDesc/AMDGPUAsmBackend.cpp b/lib/Target/AMDGPU/MCTargetDesc/AMDGPUAsmBackend.cpp index c7c4cf0969d..933c167f013 100644 --- a/lib/Target/AMDGPU/MCTargetDesc/AMDGPUAsmBackend.cpp +++ b/lib/Target/AMDGPU/MCTargetDesc/AMDGPUAsmBackend.cpp @@ -96,8 +96,12 @@ void AMDGPUAsmBackend::applyFixup(const MCFixup &Fixup, char *Data, switch ((unsigned)Fixup.getKind()) { case AMDGPU::fixup_si_sopp_br: { + int64_t BrImm = (Value - 4) / 4; + if (!isInt<16>(BrImm)) + report_fatal_error("branch size exceeds simm16"); + uint16_t *Dst = (uint16_t*)(Data + Fixup.getOffset()); - *Dst = (Value - 4) / 4; + *Dst = BrImm; break; }