nim-lang / Nim

Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Its design focuses on efficiency, expressiveness, and elegance (in that order of priority).
https://nim-lang.org
Other
16.56k stars 1.47k forks source link

Unclear compiler errors with --os:any on AVR targets #16574

Open FedericoCeratto opened 3 years ago

FedericoCeratto commented 3 years ago

Compilation fails for AVR targets with unclear error messages.

Test with:

for gc in arc orc regions none;do  for os in any standalone;do for malloc in '' '-d:useMalloc';do echo "\n\nnim --gc:$gc --os:$os $malloc c demo.nim"; nim --gc:$gc --os:$os $malloc c demo.nim; done; done; done

And nim.cfg:

--cpu:avr
-d:danger
# Used by --os:any
avr.any.gcc.exe = "avr-gcc"
avr.any.gcc.linkerexe = "avr-gcc"
avr.any.gcc.path = "/usr/bin"
# Used by --os:standalone
avr.standalone.gcc.exe = "avr-gcc"
avr.standalone.gcc.linkerexe = "avr-gcc"
avr.standalone.gcc.path = "/usr/bin"
define = "StandaloneHeapSize=8191"
gcc.options.linker = ""
lineTrace = "off"
passC = "-DF_CPU=16000000UL"
passC = "-Os"
passC = "-flto"
passC = "-mmcu=attiny85"
passL = "-flto"
passL = "-mmcu=attiny85"
passL = "-nostdlib"
stackTrace = "off"

All uses of --os:any generate:

/home/fede/.cache/nim/demo_r/stdlib_system.nim.c: In function ‘signalHandler’:
/home/fede/.cache/nim/demo_r/stdlib_system.nim.c:1823:17: error: ‘SIGINT’ undeclared (first use in this function)
   if (!(sign == SIGINT)) goto LA3_;
                 ^
/home/fede/.cache/nim/demo_r/stdlib_system.nim.c:1823:17: note: each undeclared identifier is reported only once for each function it appears in
/home/fede/.cache/nim/demo_r/stdlib_system.nim.c:1829:17: error: ‘SIGSEGV’ undeclared (first use in this function)
   if (!(sign == SIGSEGV)) goto LA6_;
                 ^
/home/fede/.cache/nim/demo_r/stdlib_system.nim.c:1835:17: error: ‘SIGABRT’ undeclared (first use in this function)
   if (!(sign == SIGABRT)) goto LA9_;

Also, nim --gc:none --os:any -d:useMalloc c demo.nim triggers #15617 /usr/lib/nim/system/mmdisp.nim(96, 77) Error: undeclared identifier: 'newObj'

awr1 commented 3 years ago

Try -d:noSignalHandler

FedericoCeratto commented 3 years ago

Thanks @awr1 . I wonder if --os:any should automatically set noSignalHandler or it's a matter of printing a better error message

awr1 commented 3 years ago

I think --os:standalone sets it, perhaps it should be extended to --os:any; either that or the difference between any and standalone should be made more clear, if any (in which case some deprecation is probably in order).

Worth mentioning that the docs do not seem to reference --os:standalone.

timotheecour commented 3 years ago

@FedericoCeratto please change title to something more descriptive / searchable