Skip to content

cgen generates the same struct twice when importing a distinct object #1417

Closed
@starsiderfox

Description

@starsiderfox

Specification

When using importc and nodecl for an object that is just a distinct of another object, the compiler erroneously writes the same struct twice. When I edit the .c file to remove the duplicate, it works properly.

Example

Compile with --passL:-latomic

type int128* = object
        hi*{.align:16.}, lo*: uint64
type cint128 {.importc: "__int128",nodecl.} = distinct int128

let x = int128(hi: 123'u64, lo: 321'u64)
let y = cast[cint128](x)
echo cast[int128](y)

Actual Output

/home/user/.cache/nimskull/dupli_d/@mdupli.nim.c:42:8: error: redefinition of 'struct _G6int128_M5dupli'
   42 | struct _G6int128_M5dupli {
      |        ^~~~~~~~~~~~~~~~~
/home/user/.cache/nimskull/dupli_d/@mdupli.nim.c:38:8: note: originally defined here
   38 | struct _G6int128_M5dupli {
      |        ^~~~~~~~~~~~~~~~~

execution of an external program 'gcc -c  -w -fmax-errors=3   -I/home/user/nimskull/lib -I/tmp -o /home/user/.cache/nimskull/dupli_d/@mdupli.nim.c.o /home/user/.cache/nimskull/dupli_d/@mdupli.nim.c' failed with exit code '1'

Expected Output

(hi: 123, lo: 321)

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingcompiler/backendRelated to backend system of the compiler

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions