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

Codegen error on const: ...extra brace group... #10815

Closed
zevv opened this issue Mar 9, 2019 · 6 comments
Closed

Codegen error on const: ...extra brace group... #10815

zevv opened this issue Mar 9, 2019 · 6 comments

Comments

@zevv
Copy link
Contributor

zevv commented Mar 9, 2019

The following snippet causes illegal C code with nim c

type

  Opcode = enum
    iChar, iSet

  Inst = object
    case code: Opcode
      of iChar:
        c: char
      of iSet:
        cs: set[char]

  Patt* = seq[Inst]


proc `$`*(p: Patt): string =
  discard

proc P*(): Patt =
  result.add Inst(code: iSet)


const a = P()
echo a

Result:

Error: execution of an external compiler program 'gcc -c  -w  -I/home/ico/external/Nim/lib -I/tmp -o /home/ico/.cache/nim/bug_d/bug.c.o /home/ico/.cache/nim/bug_d/bug.c' failed with exit code: 1

/home/ico/.cache/nim/bug_d/bug.c:83:112: error: extra brace group at end of initializer
 } TM_rmH9bpP9b3ZIjFP4QhigizlA_2 = {{1, 1 | NIM_STRLIT_FLAG}, {{((tyEnum_Opcode_mDyAPYE0BEyHnksFSG9bR0w) 1), 0, {
                                                                                                                ^
/home/ico/.cache/nim/bug_d/bug.c:83:112: note: (near initialization for ‘TM_rmH9bpP9b3ZIjFP4QhigizlA_2.data[0]’)

Versions:

$ nim -v
Nim Compiler Version 0.19.9 [Linux: amd64]
Compiled at 2019-03-09
Copyright (c) 2006-2019 by Andreas Rumpf

git hash: b9f8528db675927aacc6443ae3a363711bb41945
active boot switches: -d:release
$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/8/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 8.3.0-2' --with-bugurl=file:///usr/share/doc/gcc-8/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-8 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 8.3.0 (Debian 8.3.0-2) 
@deech
Copy link
Contributor

deech commented Mar 9, 2019

Possibly related. #9622

@zevv
Copy link
Contributor Author

zevv commented Mar 25, 2019

And another example, might or might not be related:

type CharSet {.union.} = object 
  cs: set[char]
  vs: array[4, uint64]

const a = Charset(cs: {'a'..'z'})
echo a.repr

timotheecour added a commit to timotheecour/Nim that referenced this issue Oct 23, 2020
timotheecour added a commit to timotheecour/Nim that referenced this issue Oct 24, 2020
@timotheecour
Copy link
Member

based on #15696 this is architecture specific

@timotheecour
Copy link
Member

@ringabout
Copy link
Member

type CharSet {.union.} = object 
  cs: set[char]
  vs: array[4, uint64]

const a = Charset(cs: {'a'..'z'})
echo a.repr

is a different issue. {.union.} pragma is actually ignored on NimVM => #13481

@ringabout
Copy link
Member

The first case has been already added to test cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants