mirror of
https://github.com/mirror/tinycc.git
synced 2025-01-27 06:10:06 +08:00
Handle corner case for abstract decls
sometimes abstract decls in parameter lists left the returned name uninitialized potentially leading to segfaults, like in int f(int ()) { return 0; } Deal with this.
This commit is contained in:
parent
ef0397cf3d
commit
4b46e0ec63
4
tccgen.c
4
tccgen.c
@ -4591,12 +4591,14 @@ static CType *type_decl(CType *type, AttributeDef *ad, int *v, int td)
|
|||||||
parse_attribute(ad);
|
parse_attribute(ad);
|
||||||
post = type_decl(type, ad, v, td);
|
post = type_decl(type, ad, v, td);
|
||||||
skip(')');
|
skip(')');
|
||||||
}
|
} else
|
||||||
|
goto abstract;
|
||||||
} else if (tok >= TOK_IDENT && (td & TYPE_DIRECT)) {
|
} else if (tok >= TOK_IDENT && (td & TYPE_DIRECT)) {
|
||||||
/* type identifier */
|
/* type identifier */
|
||||||
*v = tok;
|
*v = tok;
|
||||||
next();
|
next();
|
||||||
} else {
|
} else {
|
||||||
|
abstract:
|
||||||
if (!(td & TYPE_ABSTRACT))
|
if (!(td & TYPE_ABSTRACT))
|
||||||
expect("identifier");
|
expect("identifier");
|
||||||
*v = 0;
|
*v = 0;
|
||||||
|
@ -130,4 +130,15 @@ static enum myenum { L = -1 } L;
|
|||||||
void foo(void) {
|
void foo(void) {
|
||||||
static enum myenum { L = -1 } L;
|
static enum myenum { L = -1 } L;
|
||||||
}
|
}
|
||||||
|
#elif defined test_abstract_decls
|
||||||
|
int bar(const char *()); // abstract declarator here is okay
|
||||||
|
int bar (const char *(*g)()) // should match this 'g' argument
|
||||||
|
{
|
||||||
|
g();
|
||||||
|
return 42;
|
||||||
|
}
|
||||||
|
int foo(int ()) // abstract decl is wrong in definitions
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -59,3 +59,6 @@
|
|||||||
|
|
||||||
[test_duplicate_def_2]
|
[test_duplicate_def_2]
|
||||||
60_errors_and_warnings.c:131: error: redeclaration of 'L'
|
60_errors_and_warnings.c:131: error: redeclaration of 'L'
|
||||||
|
|
||||||
|
[test_abstract_decls]
|
||||||
|
60_errors_and_warnings.c:141: error: identifier expected
|
||||||
|
Loading…
Reference in New Issue
Block a user