Skip to content

Commit 354b2c1

Browse files
authored
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
2 parents 695a360 + 3b9b155 commit 354b2c1

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include <assert.h>
2+
#include <stddef.h>
3+
4+
struct foo
5+
{
6+
int x;
7+
int y;
8+
};
9+
10+
int main(struct foo *p)
11+
{
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CORE
2+
main.c
3+
4+
'main' with signature .* found
5+
^EXIT=6$
6+
^SIGNAL=0$
7+
--
8+
Invariant check failed
9+
--
10+
This is just to check that CBMC doesn’t crash when we see a ‘main’ function
11+
with an unexpected signature, see https://github.com/diffblue/cbmc/issues/5415

src/ansi-c/ansi_c_entry_point.cpp

+14-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Author: Daniel Kroening, [email protected]
1818
#include <linking/static_lifetime_init.h>
1919

2020
#include "c_nondet_symbol_factory.h"
21+
#include "expr2c.h"
2122

2223
exprt::operandst build_function_environment(
2324
const code_typet::parameterst &parameters,
@@ -473,7 +474,19 @@ bool generate_ansi_c_start_function(
473474
}
474475
}
475476
else
476-
UNREACHABLE;
477+
{
478+
const namespacet ns{symbol_table};
479+
const std::string main_signature = type2c(symbol.type, ns);
480+
throw invalid_source_file_exceptiont{
481+
"'main' with signature '" + main_signature +
482+
"' found,"
483+
" but expecting one of:\n"
484+
" int main(void)\n"
485+
" int main(int argc, char *argv[])\n"
486+
" int main(int argc, char *argv[], char *envp[])\n"
487+
"If this is a non-standard main entry point please provide a custom\n"
488+
"entry function and point to it via cbmc --function instead"};
489+
}
477490
}
478491
else
479492
{

0 commit comments

Comments
 (0)