You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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*: uint64type cint128 {.importc: "__int128",nodecl.} =distinct int128
let x =int128(hi: 123'u64, lo: 321'u64)
let y =cast[cint128](x)
echocast[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)
The text was updated successfully, but these errors were encountered:
## Summary
Marking a `distinct T` type as imported resulted in multiple C
definitions for `T`, if `T` is a non-numeric, non-pointer type. This is
now fixed.
Fixes#1417.
## Details
When translating imported types, `mirtypes` always created a new type
symbol for the imported type's underlying type. For `tyAlias` and
`tyDistinct` types (or any other type kind in the `Skip` set), this
resulted in a duplicate of the underlying type symbol being created.
Since MIR types are identified by ID, both look separate to `cgen`, and
thus a C definition is emitted for each.
`handleImportedTypes` now goes through the caching mechanism for the
underlying type if its not the type marked with `.importc`, fixing the
issue.
Specification
When using
importc
andnodecl
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
Actual Output
Expected Output
The text was updated successfully, but these errors were encountered: