Skip to content

Commit 7cb9a4e

Browse files
Merge branch 'develop-c99-testsMainType'. Close #468.
**Description** `copilot-c99`'s tests fail on non-Intel architectures. The issue is that the return code of the programs being generated (and executed) during tests are not zero, which the test interprets as a failure. More specifically, the return type of the `main` function included in the generated C code is `void`, but should be `int`. By making it `int` and returning `0`, the testing system will not interpret the test as a failure. **Type** - Bug: test fails to run. **Additional context** None. **Requester** - Scott Talbert (Debian Developer & Debian Haskell Group) **Method to check presence of bug** Running `copilot-c99`' tests can lead to failures depending on the architecture and compiler used, producing errors such as: ``` Copilot.Compile.C99: Compile specification: [OK, passed 1 tests] Compile specification in custom dir: [OK, passed 1 tests] Run specification: [Failed] *** Failed! Exception: 'callProcess: ./main (exit 64): failed' (after 1 test): ``` This error manifests on non-Intel architectures, making it very hard to reproduce. For what is worth, searching for void main in the search tree now brings up no results, while searching for int main brings up several results: ``` $ grep -nIHre 'void main' $ grep -nIHre 'int main' copilot-c99/tests/Test/Copilot/Compile/C99.hs:160: , "int main () {" copilot-c99/tests/Test/Copilot/Compile/C99.hs:696: , "int main () {" ``` That, however, is a fairly weak check, since splitting the type and the function name would make the search pattern not succeed (which is common for example with other coding standards like GNU's). **Expected result** The above test should run without errors. **Solution implemented** Modify the tests for `copilot-c99` so that the `main` has type `int`. Changing its type is enough to make it return `0` when reaching the end of the function. **Further notes** The decision of what value to return upon program termination is dependent on the C standard, the compiler and architecture. ISO C Standard (ISO/IEC 9899:1999) states in section "5.1.2.2.3 Program termination": > If the return type of the main function is a type compatible with int > [...] reaching the } that terminates the main function returns a value > of 0. If the return type is not compatible with int, the termination > status returned to the host environment is unspecified.
2 parents cfc565b + 1da7ac4 commit 7cb9a4e

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

copilot-c99/CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2023-12-14
2+
* Change return type of main generated for tests. (#468)
3+
14
2023-11-07
25
* Version bump (3.17). (#466)
36
* Replace uses of deprecated functions. (#457)

copilot-c99/tests/Test/Copilot/Compile/C99.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ testRun = ioProperty $ do
157157
, "void nop () {"
158158
, "}"
159159
, ""
160-
, "void main () {"
160+
, "int main () {"
161161
, " step();"
162162
, "}"
163163
]

0 commit comments

Comments
 (0)