summary refs log tree commit diff stats
diff options
context:
space:
mode:
authoralaviss <leorize+oss@disroot.org>2020-10-03 17:39:56 -0500
committerGitHub <noreply@github.com>2020-10-04 00:39:56 +0200
commitfc973b2c0cf4fb550556ef05968e952ca174956f (patch)
treea15f14f033dd443d8f8e35719baf624f9a026457
parent2288188fe9a9d854a167dd270eb8d72d19676865 (diff)
downloadNim-fc973b2c0cf4fb550556ef05968e952ca174956f.tar.gz
renderer: use the biggest integer type for masking literals (#15482)
On 32-bit system the mask would have a size of 32-bit, which is smaller
than the BiggestInt (usually 64-bit) it was masked against.

For some reason this only affect 32-bit Windows but not 32-bit Linux.
Might just be a difference in how gcc handle out of bound shifts for
Windows and Linux.
-rw-r--r--compiler/renderer.nim2
-rw-r--r--tests/macros/tmacros_issues.nim2
2 files changed, 3 insertions, 1 deletions
diff --git a/compiler/renderer.nim b/compiler/renderer.nim
index 9c7609f9a..88b9adf27 100644
--- a/compiler/renderer.nim
+++ b/compiler/renderer.nim
@@ -336,7 +336,7 @@ proc litAux(g: TSrcGen; n: PNode, x: BiggestInt, size: int): string =
 
   if nfBase2 in n.flags: result = "0b" & toBin(x, size * 8)
   elif nfBase8 in n.flags:
-    var y = if size < sizeof(BiggestInt): x and ((1 shl (size*8)) - 1)
+    var y = if size < sizeof(BiggestInt): x and ((1.BiggestInt shl (size*8)) - 1)
             else: x
     result = "0o" & toOct(y, size * 3)
   elif nfBase16 in n.flags: result = "0x" & toHex(x, size * 2)
diff --git a/tests/macros/tmacros_issues.nim b/tests/macros/tmacros_issues.nim
index 3d992a27f..19c706a82 100644
--- a/tests/macros/tmacros_issues.nim
+++ b/tests/macros/tmacros_issues.nim
@@ -29,6 +29,7 @@ array[0 .. 100, int]
 10
 test
 0o377'i8
+0o000000000755'i32
 1
 2
 3
@@ -257,6 +258,7 @@ macro toRendererBug(n): untyped =
   result = newLit repr(n)
 
 echo toRendererBug(0o377'i8)
+echo toRendererBug(0o755'i32)
 
 # bug #12129
 macro foobar() =