-
Notifications
You must be signed in to change notification settings - Fork 265
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5416 from hannes-steffenhagen-diffblue/fix/human-…
…readable-error-on-wrong-main-signature Add human readable error message for invalid main signatures
- Loading branch information
Showing
3 changed files
with
37 additions
and
1 deletion.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
regression/cbmc/human-readable-error-on-wrong-main-signature/main.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#include <assert.h> | ||
#include <stddef.h> | ||
|
||
struct foo | ||
{ | ||
int x; | ||
int y; | ||
}; | ||
|
||
int main(struct foo *p) | ||
{ | ||
} |
11 changes: 11 additions & 0 deletions
11
regression/cbmc/human-readable-error-on-wrong-main-signature/test.desc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
CORE | ||
main.c | ||
|
||
'main' with signature .* found | ||
^EXIT=6$ | ||
^SIGNAL=0$ | ||
-- | ||
Invariant check failed | ||
-- | ||
This is just to check that CBMC doesn’t crash when we see a ‘main’ function | ||
with an unexpected signature, see https://github.com/diffblue/cbmc/issues/5415 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ Author: Daniel Kroening, [email protected] | |
#include <linking/static_lifetime_init.h> | ||
|
||
#include "c_nondet_symbol_factory.h" | ||
#include "expr2c.h" | ||
|
||
exprt::operandst build_function_environment( | ||
const code_typet::parameterst ¶meters, | ||
|
@@ -473,7 +474,19 @@ bool generate_ansi_c_start_function( | |
} | ||
} | ||
else | ||
UNREACHABLE; | ||
{ | ||
const namespacet ns{symbol_table}; | ||
const std::string main_signature = type2c(symbol.type, ns); | ||
throw invalid_source_file_exceptiont{ | ||
"'main' with signature '" + main_signature + | ||
"' found," | ||
" but expecting one of:\n" | ||
" int main(void)\n" | ||
" int main(int argc, char *argv[])\n" | ||
" int main(int argc, char *argv[], char *envp[])\n" | ||
"If this is a non-standard main entry point please provide a custom\n" | ||
"entry function and point to it via cbmc --function instead"}; | ||
} | ||
} | ||
else | ||
{ | ||
|