Skip to content

Improper code generation for cross-compilation using arm-none-eabi-gcc #23817

@maleyva1

Description

@maleyva1

Description

Nim generates improper code for cross-compilation. The followingnim.cfg used:

cpu:arm
mm:arc
os:standalone
define:useMalloc
define:noSignalHandler
stackTrace:off
threads:off
lineTrace:off
assertions:off
checks:on
d:nimAllocPagesViaMalloc
d:nimPage512

arm.standalone.gcc.path = "/usr/bin/"
arm.standalone.gcc.exe = "arm-none-eabi-gcc"
arm.standalone.gcc.linkerexe = "arm-none-eabi-gcc"

Example that highlights this behavior:

proc main() =
  var t = 0
  inc(t)

when isMainModule:
  main()

Nim Version

Nim Compiler Version 2.0.8 [Linux: amd64]
Compiled at 2024-07-03
Copyright (c) 2006-2023 by Andreas Rumpf

git hash: 5935c3b
active boot switches: -d:release

Current Output

In file included from /home/mark/.cache/nim/test_d/@mtest.nim.c:7:
/home/mark/.cache/nim/test_d/@mtest.nim.c: In function 'main__test_u1':
/home/mark/.cache/nim/test_d/@mtest.nim.c:32:35: error: passing argument 3 of '__builtin_sadd_overflow' from incompatible pointer type [-Wincompatible-pointer-types]
   32 |         if (nimAddInt(t, ((NI)1), &TM__ipcYmBC9bj9a1BW35ABoB1Kw_2)) { raiseOverflow(); goto BeforeRet_;
      |                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                   |
      |                                   NI * {aka long int *}
/home/mark/.choosenim/toolchains/nim-2.0.8/lib/nimbase.h:576:64: note: in definition of macro 'nimAddInt'
  576 |     #define nimAddInt(a, b, res) __builtin_sadd_overflow(a, b, res)
      |                                                                ^~~
/home/mark/.cache/nim/test_d/@mtest.nim.c:32:35: note: expected 'int *' but argument is of type 'NI *' {aka 'long int *'}
   32 |         if (nimAddInt(t, ((NI)1), &TM__ipcYmBC9bj9a1BW35ABoB1Kw_2)) { raiseOverflow(); goto BeforeRet_;
      |                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/mark/.choosenim/toolchains/nim-2.0.8/lib/nimbase.h:576:64: note: in definition of macro 'nimAddInt'
  576 |     #define nimAddInt(a, b, res) __builtin_sadd_overflow(a, b, res)
      |                                                                ^~~
Error: execution of an external compiler program '/usr/bin/arm-none-eabi-gcc -c  -w -fmax-errors=3   -I/home/mark/.choosenim/toolchains/nim-2.0.8/lib -I/home/mark/Documents/Programming/nim/embedded -o /home/mark/.cache/nim/test_d/@mtest.nim.c.o /home/mark/.cache/nim/test_d/@mtest.nim.c' failed with exit code: 1

Expected Output

Valid generated code for cross-compiling with arm-none-eabi-gcc.

Possible Solution

No response

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions