File tree 3 files changed +37
-1
lines changed
regression/cbmc/human-readable-error-on-wrong-main-signature
3 files changed +37
-1
lines changed Original file line number Diff line number Diff line change
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 number Diff line number Diff line change
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
Original file line number Diff line number Diff line change 18
18
#include < linking/static_lifetime_init.h>
19
19
20
20
#include " c_nondet_symbol_factory.h"
21
+ #include " expr2c.h"
21
22
22
23
exprt::operandst build_function_environment (
23
24
const code_typet::parameterst ¶meters,
@@ -473,7 +474,19 @@ bool generate_ansi_c_start_function(
473
474
}
474
475
}
475
476
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
+ }
477
490
}
478
491
else
479
492
{
You can’t perform that action at this time.
0 commit comments