Skip to content
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

SIGSEGV during the compile #5519

Closed
vegansk opened this issue Mar 13, 2017 · 5 comments

Comments

Projects
None yet
3 participants
@vegansk
Copy link
Contributor

commented Mar 13, 2017

import os, algorithm

iterator filesIt(path: string): auto {.closure.} =
  var files = newSeq[string]()
  var dirs = newSeq[string]()
  for k, p in os.walkDir(path):
    let (_, n, e) = p.splitFile
    if e != "":
      continue
    case k
    of pcFile, pcLinkToFile:
      files.add(n)
    else:
      dirs.add(n)
  files.sort(system.cmp)
  dirs.sort(system.cmp)
  for f in files:
    yield f

  for d in dirs:
    files = newSeq[string]()
    for k, p in os.walkDir(path / d):
      let (_, n, e) = p.splitFile
      if e != "":
        continue
      case k
      of pcFile, pcLinkToFile:
        files.add(n)
      else:
        discard
    files.sort(system.cmp)
    let prefix = path.splitPath[1]
    for f in files:
      yield prefix / f

./koch temp c outputs:

Traceback (most recent call last)
nim.nim(121)             nim
nim.nim(77)              handleCmdLine
main.nim(163)            mainCommand
main.nim(74)             commandCompileToC
modules.nim(240)         compileProject
modules.nim(180)         compileModule
passes.nim(215)          processModule
passes.nim(135)          processTopLevelStmt
sem.nim(519)             myProcess
sem.nim(491)             semStmtAndGenerateGenerics
semstmts.nim(1645)       semStmt
semexprs.nim(824)        semExprNoType
semexprs.nim(2369)       semExpr
semstmts.nim(1417)       semIterator
semstmts.nim(1373)       semProcAux
transf.nim(966)          transformBody
transf.nim(908)          processTransf
transf.nim(893)          transform
transf.nim(111)          transformSons
transf.nim(893)          transform
transf.nim(111)          transformSons
transf.nim(804)          transform
transf.nim(596)          transformFor
transf.nim(893)          transform
transf.nim(111)          transformSons
transf.nim(893)          transform
transf.nim(111)          transformSons
transf.nim(893)          transform
transf.nim(111)          transformSons
transf.nim(893)          transform
transf.nim(111)          transformSons
transf.nim(893)          transform
transf.nim(111)          transformSons
transf.nim(893)          transform
transf.nim(111)          transformSons
transf.nim(893)          transform
transf.nim(111)          transformSons
transf.nim(893)          transform
transf.nim(111)          transformSons
transf.nim(893)          transform
transf.nim(111)          transformSons
transf.nim(811)          transform
transf.nim(246)          transformBlock
transf.nim(111)          transformSons
transf.nim(809)          transform
transf.nim(270)          transformWhile
transf.nim(111)          transformSons
transf.nim(811)          transform
transf.nim(246)          transformBlock
transf.nim(111)          transformSons
transf.nim(893)          transform
transf.nim(111)          transformSons
transf.nim(893)          transform
transf.nim(111)          transformSons
transf.nim(893)          transform
transf.nim(111)          transformSons
transf.nim(893)          transform
transf.nim(111)          transformSons
transf.nim(893)          transform
transf.nim(111)          transformSons
transf.nim(893)          transform
transf.nim(111)          transformSons
transf.nim(893)          transform
transf.nim(111)          transformSons
transf.nim(869)          transform
transf.nim(354)          transformYield
transf.nim(325)          introduceNewLocalVars
transf.nim(325)          introduceNewLocalVars
transf.nim(313)          introduceNewLocalVars
transf.nim(193)          transformVarSection
system.nim(2626)         sysFatal
Error: unhandled exception: sym is not accessible [FieldError]
FAILURE
@vegansk

This comment has been minimized.

Copy link
Contributor Author

commented Mar 13, 2017

And if I use workaround:

import os, algorithm

iterator filesItImpl(path: string): auto =
  var files = newSeq[string]()
  var dirs = newSeq[string]()
  for k, p in os.walkDir(path):
    let (_, n, e) = p.splitFile
    if e != "":
      continue
    case k
    of pcFile, pcLinkToFile:
      files.add(n)
    else:
      dirs.add(n)
  files.sort(system.cmp)
  dirs.sort(system.cmp)
  for f in files:
    yield f

  for d in dirs:
    files = newSeq[string]()
    for k, p in os.walkDir(path / d):
      let (_, n, e) = p.splitFile
      if e != "":
        continue
      case k
      of pcFile, pcLinkToFile:
        files.add(n)
      else:
        discard
    files.sort(system.cmp)
    let prefix = path.splitPath[1]
    for f in files:
      yield prefix / f

iterator filesIt(path: string): string {.closure.} =
  for f in filesItImpl(path):
    yield f

for f in filesIt("/tmp"):
  echo f

the error is:

Error: execution of an external compiler program 'gcc -c  -w  -I/home/vega/work/oss/Nim/lib -o /home/vega/work/oss/nim-projects/nimtests/issues/5519/nimcache/nimtests_iter.o /home/vega/work/oss/nim-projects/nimtests/issues/5519/nimcache/nimtests_iter.c' failed with exit code: 1

/home/vega/work/oss/nim-projects/nimtests/issues/5519/nimcache/nimtests_iter.c: In function ‘filesIt_6l9agPy2DsgQ5q1mYZAL1sw’:
/home/vega/work/oss/nim-projects/nimtests/issues/5519/nimcache/nimtests_iter.c:1242:9: error: duplicate label ‘STATE1’
         STATE1: ;
         ^
/home/vega/work/oss/nim-projects/nimtests/issues/5519/nimcache/nimtests_iter.c:926:6: note: previous definition of ‘STATE1’ was here
      STATE1: ;
      ^
@vegansk

This comment has been minimized.

Copy link
Contributor Author

commented Mar 15, 2017

@Araq, in gitter you said:

<Araq> checkout compiler/lowerings.nim proc addField and addUniqueField
<Araq> actually, only addUniqueField
<Araq> make for the skField s.flags.incl sfAnon
<Araq> and in the codegen patch mangleField (ccgtypes.nim) if the field as sfAnon, add its line number

I checked it, addUniqueField doesn't called for that example, only addField.

@Araq

This comment has been minimized.

Copy link
Member

commented Mar 15, 2017

Ok, well then check how addField can produce duplicate fields.

@vegansk

This comment has been minimized.

Copy link
Contributor Author

commented Mar 15, 2017

addField doesn't duplicate fields. But the codegen does. Below is the c representation and the dump of the resulting type.

struct  Env_iterdotnim4__avKrFwqUFh25chQBRno0tg  {
NI colonstate3_;
TY_sM4lkSb7zS6F7OVMvW9cffQ* files1570434;
TY_sM4lkSb7zS6F7OVMvW9cffQ* dirs1570725;
PathComponent_9c1SIU9cO1wHcl09b703A9cDrg k1570736;
NimStringDesc* p1570746;
NimStringDesc* _1570757;
NimStringDesc* n1570767;
NimStringDesc* e1570777;
NimStringDesc* f15860217;
NimStringDesc* d15861120;
PathComponent_9c1SIU9cO1wHcl09b703A9cDrg k15864022;
NimStringDesc* p15864122;
NimStringDesc* _15864223;
NimStringDesc* n15864323;
NimStringDesc* e15864423;
NimStringDesc* prefix15868032;
NimStringDesc* f15868933;
PathComponent_9c1SIU9cO1wHcl09b703A9cDrg k147402954;
NimStringDesc* v147403954;
TY_HhwRVSXQRFCCEUo2zMKJVg* colontmp1480023542_;
NI i1480053544;
NI L1480073545;
DIR* d147601974;
struct dirent* x147614978;
NimStringDesc* y147627980;
struct stat s147628982;
PathComponent_9c1SIU9cO1wHcl09b703A9cDrg k147629985;
TY_sM4lkSb7zS6F7OVMvW9cffQ* colontmp1587293542_;
NI i1584683544;
NI L1584773545;
NimStringDesc* colontmp158737930_;
PathComponent_9c1SIU9cO1wHcl09b703A9cDrg k147402954;
NimStringDesc* v147403954;
TY_HhwRVSXQRFCCEUo2zMKJVg* colontmp1480023542_;
NI i1480053544;
NI L1480073545;
DIR* d147601974;
struct dirent* x147614978;
NimStringDesc* y147627980;
struct stat s147628982;
PathComponent_9c1SIU9cO1wHcl09b703A9cDrg k147629985;
TY_sM4lkSb7zS6F7OVMvW9cffQ* colontmp1587543542_;
NI i1584683544;
NI L1584773545;
TY_sM4lkSb7zS6F7OVMvW9cffQ* colontmp1587593542_;
NI i1584683544;
NI L1584773545;
};
tyObject Env_iter.nim_4(null, node: {
    "kind": "nkRecList",
    "info": ["iter.nim", 4, 6],
    "flags": {},
    "sons": [
      {
        "kind": "nkSym",
        "info": ["iter.nim", 3, 9],
        "flags": {},
        "sym": :state_158693,
        "typ": tyRange(tyInt int)
      },
      {
        "kind": "nkSym",
        "info": ["iter.nim", 4, 6],
        "flags": {},
        "sym": files157043_158696,
        "typ": tySequence(tyString string)
      },
      {
        "kind": "nkSym",
        "info": ["iter.nim", 5, 6],
        "flags": {},
        "sym": dirs157072_158697,
        "typ": tySequence(tyString string)
      },
      {
        "kind": "nkSym",
        "info": ["iter.nim", 6, 6],
        "flags": {},
        "sym": k157073_158698,
        "typ": tyEnum PathComponent, node: {
    "kind": "nkEnumTy",
    "info": ["lib/pure/os.nim", 904, 19],
    "flags": {},
    "sons": [
      {
        "kind": "nkSym",
        "info": ["lib/pure/os.nim", 905, 4]
      },
      {
        "kind": "nkSym",
        "info": ["lib/pure/os.nim", 906, 4]
      },
      {
        "kind": "nkSym",
        "info": ["lib/pure/os.nim", 907, 4]
      },
      {
        "kind": "nkSym",
        "info": ["lib/pure/os.nim", 908, 4]
      }
    ]
  }(null)
      },
      {
        "kind": "nkSym",
        "info": ["iter.nim", 6, 9],
        "flags": {},
        "sym": p157074_158699,
        "typ": tyString string
      },
      {
        "kind": "nkSym",
        "info": ["iter.nim", 7, 9],
        "flags": {},
        "sym": _157075_158700,
        "typ": tyString string
      },
      {
        "kind": "nkSym",
        "info": ["iter.nim", 7, 12],
        "flags": {},
        "sym": n157076_158701,
        "typ": tyString string
      },
      {
        "kind": "nkSym",
        "info": ["iter.nim", 7, 15],
        "flags": {},
        "sym": e157077_158702,
        "typ": tyString string
      },
      {
        "kind": "nkSym",
        "info": ["iter.nim", 17, 6],
        "flags": {},
        "sym": f158602_158703,
        "typ": tyString string
      },
      {
        "kind": "nkSym",
        "info": ["iter.nim", 20, 6],
        "flags": {},
        "sym": d158611_158704,
        "typ": tyString string
      },
      {
        "kind": "nkSym",
        "info": ["iter.nim", 22, 8],
        "flags": {},
        "sym": k158640_158705,
        "typ": tyEnum PathComponent, node: {
    "kind": "nkEnumTy",
    "info": ["lib/pure/os.nim", 904, 19],
    "flags": {},
    "sons": [
      {
        "kind": "nkSym",
        "info": ["lib/pure/os.nim", 905, 4]
      },
      {
        "kind": "nkSym",
        "info": ["lib/pure/os.nim", 906, 4]
      },
      {
        "kind": "nkSym",
        "info": ["lib/pure/os.nim", 907, 4]
      },
      {
        "kind": "nkSym",
        "info": ["lib/pure/os.nim", 908, 4]
      }
    ]
  }(null)
      },
      {
        "kind": "nkSym",
        "info": ["iter.nim", 22, 11],
        "flags": {},
        "sym": p158641_158706,
        "typ": tyString string
      },
      {
        "kind": "nkSym",
        "info": ["iter.nim", 23, 11],
        "flags": {},
        "sym": _158642_158707,
        "typ": tyString string
      },
      {
        "kind": "nkSym",
        "info": ["iter.nim", 23, 14],
        "flags": {},
        "sym": n158643_158708,
        "typ": tyString string
      },
      {
        "kind": "nkSym",
        "info": ["iter.nim", 23, 17],
        "flags": {},
        "sym": e158644_158709,
        "typ": tyString string
      },
      {
        "kind": "nkSym",
        "info": ["iter.nim", 32, 8],
        "flags": {},
        "sym": prefix158680_158710,
        "typ": tyString string
      }
    ]
  })

vegansk added a commit to vegansk/Nim that referenced this issue Mar 15, 2017

@Araq Araq added the Crash label Mar 23, 2017

@dom96

This comment has been minimized.

Copy link
Member

commented Aug 11, 2017

I still get a SIGSEGV.

@Araq Araq closed this in 68c6d70 Oct 18, 2018

narimiran added a commit to narimiran/Nim that referenced this issue Oct 31, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.