Compiling an empty program leads to a core dump in 12:wlur
Compiling an empty program leads to a core dump in 12:wlur
In the most recent commit on the develop branch (c21cf938), SaC dumps the core when trying to compile an empty program in the with-loop unrolling step.
This bug is not yet present in the 1.3.3-MijasCosta-705-g41ed2
release.
I'd attach a minimum working example but if you're in the build folder it's literally just touch test-empty.sac && ./sac2c_d test-empty.sac
added bug label
- Michiel Verloop @MVerloop changed title from Compiling an empty program leads to an uncaught crash in 12:wlur to Compiling an empty program leads to a core dump in 12:wlur
changed title from Compiling an empty program leads to an uncaught crash in 12:wlur to Compiling an empty program leads to a core dump in 12:wlur
changed the description
- Owner
I'm surprised it even makes it that far... shouldn't the scanparser complain that there's nothing to parse @tema?
- Owner
Ha, it gets more interesting, with sac2c
sac2c 1.3.3-MijasCosta-703-g13fbfb
, I get the following output:** 22: Creating binary code ... **** De-allocating syntax tree representation ... **** Handling dependencies ... **** Invoking C compiler ... Preprocessing C source "a.out.c" Compiling C source "a.out.i" /home/hans/git/sac/sac2c/build-dev/a.out.c: In function ‘main’: /home/hans/git/sac/sac2c/build-dev/a.out.c:350:3: warning: implicit declaration of function ‘SACf__MAIN__main’ [-Wimplicit-function-declaration] 350 | SAC_INVOKE_MAIN_FUN( SACf__MAIN__main, SAC_ND_ARG_out( (SAC_res, (SCL, (NHD, (NUQ, (INT, (GLO, (NON, (NOT, (NDI, (INT, )))))))))), int)); | ^~~~~~~~~~~~~~~~ Linking "a.out" /usr/bin/ld: /tmp/SAC_hAPnGO/a.out.o: in function `main': /home/hans/git/sac/sac2c/build-dev/a.out.c:350: undefined reference to `SACf__MAIN__main' collect2: error: ld returned 1 exit status abort: System failed to execute shell command abort: /usr/bin/cc /tmp/SAC_hAPnGO/a.out.o -Wl,-allow-shlib-undefined -L/home/hans/git/sac/sac-project-example/build/lib/host/seq abort: -Wl,-rpath,/home/hans/git/sac/sac-project-example/build/lib/host/seq -L/home/hans/git/sac/JSON/build/lib/host/seq abort: -Wl,-rpath,/home/hans/git/sac/JSON/build/lib/host/seq -L/home/hans/git/apex/TestsForNow/UTWORKS/build/lib/host/seq abort: -Wl,-rpath,/home/hans/git/apex/TestsForNow/UTWORKS/build/lib/host/seq -L/home/hans/git/sac/sacpac/build/lib/host/seq abort: -Wl,-rpath,/home/hans/git/sac/sacpac/build/lib/host/seq -L/home/hans/git/sac/png/build/lib/host/seq -Wl,-rpath,/home/hans/git/sac/png/build/lib/host/seq abort: -L/home/hans/git/sac/sactools/build-sacdoc/lib/host/seq -Wl,-rpath,/home/hans/git/sac/sactools/build-sacdoc/lib/host/seq abort: -L/home/hans/git/sac/yaml/build/lib/host/seq -Wl,-rpath,/home/hans/git/sac/yaml/build/lib/host/seq abort: -L/home/hans/git/apex/Ancillary/benchmks/UnitTests/build/lib/host/seq -Wl,-rpath,/home/hans/git/apex/Ancillary/benchmks/UnitTests/build/lib/host/seq abort: -L/home/hans/git/sac/sdl/build/lib/host/seq -Wl,-rpath,/home/hans/git/sac/sdl/build/lib/host/seq -L/home/hans/git/sac/stdlib/build/lib/host/seq abort: -Wl,-rpath,/home/hans/git/sac/stdlib/build/lib/host/seq -L/home/hans/git/sac/sac-project-example/build/lib/host/seq abort: -Wl,-rpath,/home/hans/git/sac/sac-project-example/build/lib/host/seq -L/home/hans/git/sac/JSON/build/lib/host/seq abort: -Wl,-rpath,/home/hans/git/sac/JSON/build/lib/host/seq -L/home/hans/git/apex/TestsForNow/UTWORKS/build/lib/host/seq abort: -Wl,-rpath,/home/hans/git/apex/TestsForNow/UTWORKS/build/lib/host/seq -L/home/hans/git/sac/sacpac/build/lib/host/seq abort: -Wl,-rpath,/home/hans/git/sac/sacpac/build/lib/host/seq -L/home/hans/git/sac/png/build/lib/host/seq -Wl,-rpath,/home/hans/git/sac/png/build/lib/host/seq abort: -L/home/hans/git/sac/sactools/build-sacdoc/lib/host/seq -Wl,-rpath,/home/hans/git/sac/sactools/build-sacdoc/lib/host/seq abort: -L/home/hans/git/sac/yaml/build/lib/host/seq -Wl,-rpath,/home/hans/git/sac/yaml/build/lib/host/seq abort: -L/home/hans/git/apex/Ancillary/benchmks/UnitTests/build/lib/host/seq -Wl,-rpath,/home/hans/git/apex/Ancillary/benchmks/UnitTests/build/lib/host/seq abort: -L/home/hans/git/sac/sdl/build/lib/host/seq -Wl,-rpath,/home/hans/git/sac/sdl/build/lib/host/seq -L/home/hans/git/sac/stdlib/build/lib/host/seq abort: -Wl,-rpath,/home/hans/git/sac/stdlib/build/lib/host/seq -L/home/hans/git/sac/sac2c/build-dev/runtime_build/src/runtime_libraries-build/lib/host/seq abort: -Wl,-rpath,/home/hans/git/sac/sac2c/build-dev/runtime_build/src/runtime_libraries-build/lib/host/seq abort: -L/home/hans/git/sac/sac2c/build-dev/runtime_build/src/runtime_libraries-build/lib/prelude/host/seq abort: -Wl,-rpath,/home/hans/git/sac/sac2c/build-dev/runtime_build/src/runtime_libraries-build/lib/prelude/host/seq abort: -L/home/hans/git/sac/sac2c/build-prod/runtime_build/src/runtime_libraries-build/lib/prelude/host/seq abort: -Wl,-rpath,/home/hans/git/sac/sac2c/build-prod/runtime_build/src/runtime_libraries-build/lib/prelude/host/seq abort: -L/home/hans/git/sac/sac2c/build-dev/runtime_build/src/runtime_libraries-build/lib/host/seq abort: -Wl,-rpath,/home/hans/git/sac/sac2c/build-dev/runtime_build/src/runtime_libraries-build/lib/host/seq abort: -L/home/hans/git/sac/sac2c/build-dev/runtime_build/src/runtime_libraries-build/lib/prelude/host/seq abort: -Wl,-rpath,/home/hans/git/sac/sac2c/build-dev/runtime_build/src/runtime_libraries-build/lib/prelude/host/seq abort: -L/home/hans/git/sac/sac2c/build-prod/runtime_build/src/runtime_libraries-build/lib/prelude/host/seq abort: -Wl,-rpath,/home/hans/git/sac/sac2c/build-prod/runtime_build/src/runtime_libraries-build/lib/prelude/host/seq abort: -L/home/hans/git/sac/sac2c/build-dev/runtime_build/src/runtime_libraries-build/lib/host/seq abort: -Wl,-rpath,/home/hans/git/sac/sac2c/build-dev/runtime_build/src/runtime_libraries-build/lib/host/seq abort: -L/home/hans/git/sac/sac2c/build-dev/runtime_build/src/runtime_libraries-build/lib/prelude/host/seq abort: -Wl,-rpath,/home/hans/git/sac/sac2c/build-dev/runtime_build/src/runtime_libraries-build/lib/prelude/host/seq abort: -L/home/hans/git/sac/sac2c/build-prod/runtime_build/src/runtime_libraries-build/lib/prelude/host/seq abort: -Wl,-rpath,/home/hans/git/sac/sac2c/build-prod/runtime_build/src/runtime_libraries-build/lib/prelude/host/seq abort: -L/home/hans/git/sac/sac2c/build-dev/runtime_build/src/runtime_libraries-build/lib/host/seq abort: -Wl,-rpath,/home/hans/git/sac/sac2c/build-dev/runtime_build/src/runtime_libraries-build/lib/host/seq abort: -L/home/hans/git/sac/sac2c/build-dev/runtime_build/src/runtime_libraries-build/lib/prelude/host/seq abort: -Wl,-rpath,/home/hans/git/sac/sac2c/build-dev/runtime_build/src/runtime_libraries-build/lib/prelude/host/seq abort: -L/home/hans/git/sac/sac2c/build-prod/runtime_build/src/runtime_libraries-build/lib/prelude/host/seq abort: -Wl,-rpath,/home/hans/git/sac/sac2c/build-prod/runtime_build/src/runtime_libraries-build/lib/prelude/host/seq -L/usr/lib -Wl,-rpath,/usr/lib abort: -L/opt/cuda/lib64 -Wl,-rpath,/opt/cuda/lib64 -lsac_d -lsacphm_d -lm -lhwloc -lcudart -lcublas -lyaml -lcjson -o abort: /home/hans/git/sac/sac2c/build-dev/a.out abort: with exit code 1 compilation failed while Creating binary code. FAIL: 178
This makes more sense in my mind because it means that we never generated a main function because there is none.
Edited by Hans-Nikolai Viessmann - Owner
So what changed? Between 703 and 705 there's only the fix for #2276 (closed).
changed the description
- Owner
Ok, so on my system with
1.3.3-MijasCosta-705-g41ed2
I get the same error message as above. - Owner
@hans, an empty program seem to be correct from the perspective of parser. I am surprised that it breaks at
wlur
, this is weird. I would expect it to break when compiling C code, similarly to the break you get from feeding an empty program to CC:/tmp|=> echo "" | gcc -xc - /usr/lib/gcc/x86_64-pc-linux-gnu/11.2.1/../../../../x86_64-pc-linux-gnu/bin/ld: /usr/lib/gcc/x86_64-pc-linux-gnu/11.2.1/../../../../lib64/Scrt1.o: in function `_start': (.text+0x17): undefined reference to `main' collect2: error: ld returned 1 exit status
- Owner
well, strictly speaking, it is EXACTLY the C error we see here. We always build a main and wrap around our own main.....
Nevertheless, I would think we could easily equip the parser to keep track whether a function "main" has been seen. We surely also do know whether we are in a module or not.... so we could simply shortcut there and report a user-friendly messsage....
- Owner
@sbs, the title of the issue says that the compiler dies in
12:wlur
, which is far before the code generation.You are right, we can surely check for the lack of
main
. I am just wondering whether there is a good reason to allow for empty programs. I suppose C compilers can't tell whether they are compiling the "main module" or not. Therefore the linker has to fail if none of the object files contain_start
symbol. mentioned in merge request !172 (merged)
assigned to @hans
mentioned in commit 06911838
closed via merge request !172 (merged)
mentioned in commit d793beec
- You're only seeing other activity in the feed. To add a comment, switch to one of the following options.