Skip to content

improve warning #75762

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3079,12 +3079,14 @@ bool X86AsmParser::ParseMemOperand(unsigned SegReg, const MCExpr *Disp,
" is not within [-2147483648, 2147483647]");
} else if (!Is16) {
if (!isUInt<32>(Imm < 0 ? -uint64_t(Imm) : uint64_t(Imm))) {
Warning(BaseLoc,
"displacement " + Twine(Imm) + " shortened to signed 32-bit");
Warning(BaseLoc, "displacement " + Twine(Imm) +
" shortened to 32-bit signed " +
Twine(static_cast<int32_t>(Imm)));
}
} else if (!isUInt<16>(Imm < 0 ? -uint64_t(Imm) : uint64_t(Imm))) {
Warning(BaseLoc,
"displacement " + Twine(Imm) + " shortened to signed 16-bit");
Warning(BaseLoc, "displacement " + Twine(Imm) +
" shortened to 16-bit signed " +
Twine(static_cast<int16_t>(Imm)));
}
}
}
Expand Down
10 changes: 6 additions & 4 deletions llvm/test/MC/X86/displacement-overflow.s
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ leaq -0x80000001(%rip), %rax
movl 0xffffffff(%eax), %eax
leal -0xffffffff(%eax), %eax

# CHECK: [[#@LINE+1]]:19: warning: displacement 4294967296 shortened to signed 32-bit
# CHECK: [[#@LINE+1]]:19: warning: displacement 4294967296 shortened to 32-bit signed 0
movl 0xffffffff+1(%eax), %eax

# CHECK: [[#@LINE+1]]:20: warning: displacement -4294967296 shortened to signed 32-bit
# CHECK: [[#@LINE+1]]:20: warning: displacement -4294967296 shortened to 32-bit signed 0
leal -0xffffffff-1(%eax), %eax
# CHECK: [[#@LINE+1]]:20: warning: displacement -4294967297 shortened to 32-bit signed -1
leal -0xffffffff-2(%eax), %eax

{disp8} leal 0x100(%ebx), %eax
{disp8} leal -0x100(%ebx), %eax
Expand All @@ -29,8 +31,8 @@ leal -0xffffffff-1(%eax), %eax
movw $0, 0xffff(%bp)
movw $0, -0xffff(%si)

# 32: [[#@LINE+1]]:19: warning: displacement 65536 shortened to signed 16-bit
# 32: [[#@LINE+1]]:19: warning: displacement 65536 shortened to 16-bit signed 0
movw $0, 0xffff+1(%bp)
# 32: [[#@LINE+1]]:20: warning: displacement -65536 shortened to signed 16-bit
# 32: [[#@LINE+1]]:20: warning: displacement -65536 shortened to 16-bit signed 0
movw $0, -0xffff-1(%si)
.endif
You are viewing a condensed version of this merge commit. You can view the full changes here.