32 bit fixes (#10608)

This commit is contained in:
Arne Döring
2019-02-12 22:00:31 +01:00
committed by Andreas Rumpf
parent 304b1dd34b
commit 28394153ab
26 changed files with 165 additions and 135 deletions

View File

@@ -3,6 +3,9 @@
# Exit if anything fails
set -e
which nim > /dev/null || (echo "nim not in PATH"; exit 1)
which gdb > /dev/null || (echo "gdb not in PATH"; exit 1)
# Find out where the pretty printer Python module is
NIM_SYSROOT=$(dirname $(dirname $(readlink -e $(which nim))))
GDB_PYTHON_MODULE_PATH="$NIM_SYSROOT/tools/nim-gdb.py"

View File

@@ -27,7 +27,6 @@ build_nim_csources(){
[ -f $nim_csources ] || echo_run build_nim_csources
# Note: if fails, may need to `cd csources && git pull`
# see D20190115T162028
echo_run bin/nim c --skipUserCfg --skipParentCfg koch
echo_run ./koch boot -d:release

View File

@@ -271,6 +271,10 @@ type
# language; for interfacing with Objective C
sfDiscardable, # returned value may be discarded implicitly
sfOverriden, # proc is overriden
sfCallSideLineinfo# A flag for template symbols to tell the
# compiler it should use line information from
# the calling side of the macro, not from the
# implementation.
sfGenSym # symbol is 'gensym'ed; do not add to symbol table
TSymFlags* = set[TSymFlag]
@@ -1265,7 +1269,10 @@ proc `$`*(x: TLockLevel): string =
else: result = $int16(x)
proc `$`*(s: PSym): string =
result = s.name.s & "@" & $s.id
if s != nil:
result = s.name.s & "@" & $s.id
else:
result = "<nil>"
proc newType*(kind: TTypeKind, owner: PSym): PType =
new(result)

View File

@@ -1997,6 +1997,11 @@ proc genMagicExpr(p: BProc, e: PNode, d: var TLoc, op: TMagic) =
of mSizeOf:
let t = e.sons[1].typ.skipTypes({tyTypeDesc})
putIntoDest(p, d, e, "((NI)sizeof($1))" % [getTypeDesc(p.module, t)])
of mAlignOf:
let t = e.sons[1].typ.skipTypes({tyTypeDesc})
if not p.module.compileToCpp:
p.module.includeHeader("<stdalign.h>")
putIntoDest(p, d, e, "((NI)alignof($1))" % [getTypeDesc(p.module, t)])
of mChr: genSomeCast(p, e, d)
of mOrd: genOrd(p, e, d)
of mLengthArray, mHigh, mLengthStr, mLengthSeq, mLengthOpenArray:

View File

@@ -186,9 +186,9 @@ proc evalTemplate*(n: PNode, tmpl, genSymOwner: PSym;
renderTree(result, {renderNoComments}))
else:
result = copyNode(body)
#ctx.instLines = body.kind notin {nkStmtList, nkStmtListExpr,
# nkBlockStmt, nkBlockExpr}
#if ctx.instLines: result.info = n.info
ctx.instLines = sfCallSideLineinfo in tmpl.flags
if ctx.instLines:
result.info = n.info
for i in countup(0, safeLen(body) - 1):
evalTemplateAux(body.sons[i], args, ctx, result)
result.flags.incl nfFromTemplate
@@ -196,4 +196,3 @@ proc evalTemplate*(n: PNode, tmpl, genSymOwner: PSym;
#if ctx.debugActive:
# echo "instantion of ", renderTree(result, {renderIds})
dec(conf.evalTemplateCounter)

View File

@@ -803,12 +803,15 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int,
of wSize:
if sym.typ == nil: invalidPragma(c, it)
var size = expectIntLit(c, it)
if not isPowerOfTwo(size) or size <= 0 or size > 8:
localError(c.config, it.info, "size may only be 1, 2, 4 or 8")
else:
case size
of 1, 2, 4, 8:
sym.typ.size = size
# TODO, this is not correct
sym.typ.align = int16(size)
if size == 8 and c.config.target.targetCPU == cpuI386:
sym.typ.align = 4
else:
sym.typ.align = int16(size)
else:
localError(c.config, it.info, "size may only be 1, 2, 4 or 8")
of wNodecl:
noVal(c, it)
incl(sym.loc.flags, lfNoDecl)

View File

@@ -353,9 +353,17 @@ proc magicsAfterOverloadResolution(c: PContext, n: PNode,
localError(c.config, n.info, "cannot evaluate 'sizeof' because its type is not defined completely, type: " & n[1].typ.typeToString)
result = n
of mAlignOf:
result = newIntNode(nkIntLit, getAlign(c.config, n[1].typ))
result.info = n.info
result.typ = n.typ
# this is 100% analog to mSizeOf, could be made more dry.
let align = getAlign(c.config, n[1].typ)
if align == szUnknownSize:
result = n
elif align >= 0:
result = newIntNode(nkIntLit, align)
result.info = n.info
result.typ = n.typ
else:
localError(c.config, n.info, "cannot evaluate 'alignof' because its type is not defined completely, type: " & n[1].typ.typeToString)
result = n
of mOffsetOf:
var dotExpr: PNode

View File

@@ -558,6 +558,10 @@ proc semTemplateDef(c: PContext, n: PNode): PNode =
incl(s.flags, sfGlobal)
else:
s = semIdentVis(c, skTemplate, n.sons[0], {})
if s.owner != nil and s.owner.name.s == "system" and s.name.s in ["!=", ">=", ">", "incl", "excl", "in", "notin", "isnot"]:
incl(s.flags, sfCallSideLineinfo)
styleCheckDef(c.config, s)
onDef(n[0].info, s)
# check parameter list:

View File

@@ -495,7 +495,7 @@ proc suggestSym*(conf: ConfigRef; info: TLineInfo; s: PSym; usageSym: var PSym;
proc extractPragma(s: PSym): PNode =
if s.kind in routineKinds:
result = s.ast[pragmasPos]
elif s.kind in {skType, skVar, skLet}:
elif s.kind in {skType, skVar, skLet} and s.ast[0].kind == nkPragmaExpr:
# s.ast = nkTypedef / nkPragmaExpr / [nkSym, nkPragma]
result = s.ast[0][1]
doAssert result == nil or result.kind == nkPragma

View File

@@ -299,9 +299,8 @@ proc boot(args: string) =
var extraOption = ""
if i == 0:
extraOption.add " --skipUserCfg --skipParentCfg"
# Note(D20190115T162028:here): the configs are skipped for bootstrap
# The configs are skipped for bootstrap
# (1st iteration) to prevent newer flags from breaking bootstrap phase.
# fixes #10030.
let ret = execCmdEx(nimStart & " --version")
doAssert ret.exitCode == 0
let version = ret.output.splitLines[0]

View File

@@ -1185,7 +1185,7 @@ when isMainModule:
doAssert floorMod(-8.5, 3.0) ==~ 0.5
block: # log
doAssert log(4.0, 3.0) == ln(4.0) / ln(3.0)
doAssert log(4.0, 3.0) ==~ ln(4.0) / ln(3.0)
doAssert log2(8.0'f64) == 3.0'f64
doAssert log2(4.0'f64) == 2.0'f64
doAssert log2(2.0'f64) == 1.0'f64

View File

@@ -206,6 +206,9 @@ proc parseSpec*(filename: string): TSpec =
if isTravis: result.err = reDisabled
of "appveyor":
if isAppVeyor: result.err = reDisabled
of "32bit":
if sizeof(int) == 4:
result.err = reDisabled
else:
result.parseErrors.addLine "cannot interpret as a bool: ", e.value
of "cmd":

View File

@@ -65,14 +65,14 @@ expression: f(y)
'''
errormsg: "type mismatch: got <MatchingType>"
line: 138
disabled: 32bit
"""
# disabled on 32 bit, because the order of suggested alternatives ``r`` differs
# proc r[T](a: SomeNumber; b: T; c: auto)
# proc r(i: string): int
# proc r(o: RegularConcept): int

View File

@@ -1,6 +1,8 @@
# bug #3799
discard """
output: '''
import strutils
const output = splitLines("""
00000000000000000000000000000000000000000
00000000000001111111111111110000000000000
00000000001111111111111111111110000000000
@@ -28,11 +30,7 @@ output: '''
00000000111111111111111111111111100000000
00000000000111111111111111111100000000000
00000000000000111111111111100000000000000
'''
"""
import macros
""")
const nmax = 500
@@ -63,19 +61,25 @@ proc julia*[T](z0, c: Complex[T], er2: T, nmax: int): int =
template dendriteFractal*[T](z0: Complex[T], er2: T, nmax: int): int =
julia(z0, (T(0.0), T(1.0)), er2, nmax)
iterator stepIt[T](start, step: T, iterations: int): T =
iterator stepIt[T](start, step: T, iterations: int): (int, T) =
for i in 0 .. iterations:
yield start + T(i) * step
yield (i, start + T(i) * step)
var errors = 0
let c = (0.36237, 0.32)
for y in stepIt(2.0, -0.0375 * 4, 107 div 4):
for j, y in stepIt(2.0, -0.0375 * 4, 107 div 4):
var row = ""
for x in stepIt(-2.0, 0.025 * 4, 160 div 4):
for i, x in stepIt(-2.0, 0.025 * 4, 160 div 4):
#let n = julia((x, y), c, 4.0, nmax) ### this works
let n = dendriteFractal((x, y), 4.0, nmax)
if n < nmax:
row.add($(n mod 10))
else:
row.add(' ')
echo row
let c = char(int('0') + n mod 10)
let e = output[j][i] # expected
if c != e:
errors += 1
row.add(c)
# Printing aparently makes the test fail when joined.
# echo row
doAssert errors < 10, "total errors: " & $errors

View File

@@ -1,7 +1,7 @@
discard """
tfile: "tenummix.nim"
tline: 11
errormsg: "type mismatch"
file: "tenummix.nim"
line: 11
"""
type

View File

@@ -16,9 +16,12 @@ proc rsplit(s: string; sep: string; maxsplit: int = -1): seq[string]
expression: rsplit("abc:def", {':'}, maxsplits = 1)
'''
disabled: 32bit
"""
# bug #8043
# disabled on 32 bit systems because the order of suggested proc alternatives is different.
import strutils
"abc:def".rsplit({':'}, maxsplits = 1)

View File

@@ -3,8 +3,10 @@ discard """
[0, 0]'''
target: "c"
joinable: false
disabled: 32bit
"""
# this test wasn't written for 32 bit
# don't join because the code is too messy.
# Nim RTree and R*Tree implementation

View File

@@ -246,6 +246,9 @@ proc main() =
r: PRadixNode = nil
for x in items(numbers):
echo testOrIncl(r, x)
for x in elements(r): echo(x)
for x in elements(r):
# ByteAddress being defined as a signed integer cases trouble
# exactly here
echo(cast[uint](x))
main()

View File

@@ -279,6 +279,11 @@ testinstance:
InheritanceC {.objectconfig.} = object of InheritanceB
c: char
# from issue 4763
GenericObject[T] = object
a: int32
b: T
#Float128Test = object
# a: byte
# b: float128
@@ -298,6 +303,7 @@ testinstance:
var f : PaddingAfterBranch
var g : RecursiveStuff
var ro : RootObj
var go : GenericObject[int64]
var
e1: Enum1
@@ -311,7 +317,7 @@ testinstance:
testAlign(SimpleAlignment)
testSizeAlignOf(t,a,b,c,d,e,f,g,ro, e1, e2, e4, e8, eoa, eob)
testSizeAlignOf(t,a,b,c,d,e,f,g,ro,go, e1, e2, e4, e8, eoa, eob)
when not defined(cpp):
type
@@ -414,6 +420,28 @@ type
doAssert sizeof(MixedBitsize) == 12
##########################################
# bug #9794
##########################################
type
imported_double {.importc: "double".} = object
Pod = object
v* : imported_double
seed*: int32
Pod2 = tuple[v: imported_double, seed: int32]
proc foobar() =
testAlign(Pod)
testSize(Pod)
testAlign(Pod2)
testSize(Pod2)
doAssert sizeof(Pod) == sizeof(Pod2)
doAssert alignof(Pod) == alignof(Pod2)
foobar()
if failed:
quit("FAIL")
else:

View File

@@ -1,10 +1,7 @@
discard """
output: '''TBar2
TFoo
16
12
16
12'''
'''
"""
## XXX this output needs to be adapated for VCC which produces different results.
@@ -67,29 +64,6 @@ var aa = makeWindow()
thisCausesError(dd, aa)
# bug #4763
type
testObject_1 = object
size: int32
value: int64
testObject_2 {.packed.} = object
size: int32
value: int64
testObject_3[T] = object
size: int32
value: T
testObject_4 {.packed.} [T] = object
size: int32
value: T
echo sizeof(testObject_1)
echo sizeof(testObject_2)
echo sizeof(testObject_3[int64])
echo sizeof(testObject_4[int64])
# bug #5892
type
Foo6 = distinct array[4, float32]

View File

@@ -48,10 +48,10 @@ when defined(case_testfile): # compiled test file for child process
else:
import os, osproc, strutils, posix
const nim = getCurrentCompilerExe()
block execShellCmdTest:
## first, compile child program
const nim = getCurrentCompilerExe()
const sourcePath = currentSourcePath()
let output = buildDir / "D20190111T024543".addFileExt(ExeExt)
let cmd = "$# c -o:$# -d:release -d:case_testfile $#" % [nim, output,
@@ -71,14 +71,10 @@ else:
runTest("exitnow_139", 139)
runTest("c_exit2_139", 139)
runTest("quit_139", 139)
runTest("exit_array", 1)
when defined(posix): # on windows, -1073741571
runTest("exit_recursion", SIGSEGV.int + 128) # bug #10273: was returning 0
assertEquals exitStatusLikeShell(SIGSEGV), SIGSEGV + 128.cint
block execProcessTest:
let dir = parentDir(currentSourcePath())
let (outp, err) = execCmdEx("nim c " & quoteShell(dir / "osproctest.nim"))
let (outp, err) = execCmdEx(nim & " c " & quoteShell(dir / "osproctest.nim"))
doAssert err == 0
let exePath = dir / addFileExt("osproctest", ExeExt)
let outStr1 = execProcess(exePath, workingDir = dir, args = ["foo",

View File

@@ -2,6 +2,7 @@ discard """
disabled: "travis"
disabled: "appveyor"
joinable: false
disabled: 32bit
"""
# CI integration servers are out of memory for this test

View File

@@ -5,40 +5,42 @@ joinable: false
# appveyor is "out of memory"
const
nmax = 2*1024*1024*1024
when sizeof(int) >= 8:
# no point to test this on system with smaller address space
const
nmax = 2*1024*1024*1024
proc test(n: int) =
var a = alloc0(9999)
var t = cast[ptr UncheckedArray[int8]](alloc(n))
var b = alloc0(9999)
t[0] = 1
t[1] = 2
t[n-2] = 3
t[n-1] = 4
dealloc(a)
dealloc(t)
dealloc(b)
proc test(n: int) =
var a = alloc0(9999)
var t = cast[ptr UncheckedArray[int8]](alloc(n))
var b = alloc0(9999)
t[0] = 1
t[1] = 2
t[n-2] = 3
t[n-1] = 4
dealloc(a)
dealloc(t)
dealloc(b)
# allocator adds 48 bytes to BigChunk
# BigChunk allocator edges at 2^n * (1 - s) for s = [1..32]/64
proc test2(n: int) =
let d = n div 256 # cover edges and more
for i in countdown(128,1):
for j in [-4096, -64, -49, -48, -47, -32, 0, 4096]:
let b = n + j - i*d
if b>0 and b<=nmax:
test(b)
#echo b, ": ", getTotalMem(), " ", getOccupiedMem(), " ", getFreeMem()
# allocator adds 48 bytes to BigChunk
# BigChunk allocator edges at 2^n * (1 - s) for s = [1..32]/64
proc test2(n: int) =
let d = n div 256 # cover edges and more
for i in countdown(128,1):
for j in [-4096, -64, -49, -48, -47, -32, 0, 4096]:
let b = n + j - i*d
if b>0 and b<=nmax:
test(b)
#echo b, ": ", getTotalMem(), " ", getOccupiedMem(), " ", getFreeMem()
proc test3 =
var n = 1
while n <= nmax:
test2(n)
n *= 2
n = nmax
while n >= 1:
test2(n)
n = n div 2
proc test3 =
var n = 1
while n <= nmax:
test2(n)
n *= 2
n = nmax
while n >= 1:
test2(n)
n = n div 2
test3()
test3()

View File

@@ -1,6 +1,5 @@
discard """
output: '''abc
16 == 16'''
output: '''abc'''
"""
type
@@ -14,20 +13,3 @@ a.x = "abc"
doAssert TA.sizeof == string.sizeof
echo a.x
##########################################
# bug #9794
##########################################
type
imported_double {.importc: "double".} = object
Pod = object
v* : imported_double
seed*: int32
Pod2 = tuple[v: imported_double, seed: int32]
proc test() =
echo sizeof(Pod), " == ",sizeof(Pod2)
test()

View File

@@ -40,6 +40,11 @@ static:
let a2 = arcsin 0.3
doAssert a1 == a2
block bitxor:
let x = -1'i32
let y = 1'i32
doAssert (x xor y) == -2
block:
# Check against bugs like #9176
doAssert getCurrentCompilerExe() == forceConst(getCurrentCompilerExe())

View File

@@ -13,14 +13,14 @@ proc get_values(): (seq[int8], seq[int16], seq[int32]) =
result[0] = @[]; result[1] = @[]; result[2] = @[]
for offset in RANGE:
let i8 = -(1 shl 9) + offset
let i16 = -(1 shl 17) + offset
let i32 = -(1 shl 33) + offset
let i8 = -(1'i64 shl 9) + offset
let i16 = -(1'i64 shl 17) + offset
let i32 = -(1'i64 shl 33) + offset
# higher bits are masked. these should be exactly equal to offset.
result[0].add i8.toU8
result[1].add i16.toU16
result[2].add i32.toU32
result[0].add cast[int8 ](uint8 cast[uint64](i8 ))
result[1].add cast[int16](uint16 cast[uint64](i16))
result[2].add cast[int32](uint32 cast[uint64](i32))
# these values this computed by VM