Commit 7cb9a4e
committed
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 files changed
+4
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
1 | 4 | | |
2 | 5 | | |
3 | 6 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
157 | 157 | | |
158 | 158 | | |
159 | 159 | | |
160 | | - | |
| 160 | + | |
161 | 161 | | |
162 | 162 | | |
163 | 163 | | |
| |||
0 commit comments