Skip to content

Commit 6f96674

Browse files
committed
C entry point generator: no unconditional conversion to pointer type
Do not try to create a pointer_typet when the type might not actually be a pointer type. This was triggerable by syntactically well-formed C input and should instead be handled by a user-facing error message. Fixes: #6975
1 parent 8b5d37a commit 6f96674

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

regression/ansi-c/main1/main.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
int main(char *argv, int arc)
2+
{
3+
return 0;
4+
}

regression/ansi-c/main1/test.desc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CORE test-c++-front-end
2+
main.c
3+
4+
'main' with signature 'signed int \(char \*argv, signed int arc\)' found
5+
^EXIT=(64|1)$
6+
^SIGNAL=0$
7+
--
8+
Invariant check failed
9+
--
10+
This test is to ensure that non-standard C entry points are handled gracefully
11+
and with a message to the user.

src/ansi-c/ansi_c_entry_point.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,16 @@ bool generate_ansi_c_start_function(
248248
{
249249
// ok
250250
}
251-
else if(parameters.size()==2 || parameters.size()==3)
251+
// The C standard (and any related architecture descriptions) enforces an
252+
// order of parameters. The user, however, may supply arbitrary
253+
// (syntactically valid) C code, even one that does not respect the calling
254+
// conventions set out in the C standard. If the user does supply such code,
255+
// then we can only tell them that they got it wrong, which is what we do
256+
// via the error message in the else branch of this code.
257+
else if(
258+
parameters.size() >= 2 && parameters[1].type().id() == ID_pointer &&
259+
(parameters.size() == 2 ||
260+
(parameters.size() == 3 && parameters[2].type().id() == ID_pointer)))
252261
{
253262
namespacet ns(symbol_table);
254263

0 commit comments

Comments
 (0)