[llvm-branch-commits] [llvm] improve warning (PR #75762)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Sun Dec 17 19:05:28 PST 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-x86

Author: Fangrui Song (MaskRay)

<details>
<summary>Changes</summary>



---
Full diff: https://github.com/llvm/llvm-project/pull/75762.diff


2 Files Affected:

- (modified) llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp (+6-4) 
- (modified) llvm/test/MC/X86/displacement-overflow.s (+6-4) 


``````````diff
diff --git a/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp b/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
index ef622e08606cbf..1d40ce35c1b416 100644
--- a/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
+++ b/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
@@ -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)));
       }
     }
   }
diff --git a/llvm/test/MC/X86/displacement-overflow.s b/llvm/test/MC/X86/displacement-overflow.s
index 626003a29109ea..2882147af48280 100644
--- a/llvm/test/MC/X86/displacement-overflow.s
+++ b/llvm/test/MC/X86/displacement-overflow.s
@@ -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
@@ -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

``````````

</details>


https://github.com/llvm/llvm-project/pull/75762


More information about the llvm-branch-commits mailing list