From 5ac2a26666406c3bb591176e5790de83b0a2557b Mon Sep 17 00:00:00 2001 From: Michael Matz Date: Sun, 7 Apr 2019 03:15:05 +0200 Subject: [PATCH] Don't endlessly recurse on invalid nested typedefs see testcase. --- tccgen.c | 3 ++- tests/tests2/60_errors_and_warnings.c | 6 ++++++ tests/tests2/60_errors_and_warnings.expect | 3 +++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/tccgen.c b/tccgen.c index 6c341e0..39f9a28 100644 --- a/tccgen.c +++ b/tccgen.c @@ -2782,7 +2782,7 @@ ST_FUNC int type_size(CType *type, int *a) *a = PTR_SIZE; return PTR_SIZE; } - } else if (IS_ENUM(type->t) && type->ref->c == -1) { + } else if (IS_ENUM(type->t) && type->ref->c < 0) { return -1; /* incomplete enum */ } else if (bt == VT_LDOUBLE) { *a = LDOUBLE_ALIGN; @@ -3934,6 +3934,7 @@ do_decl: next(); if (s->c != -1) tcc_error("struct/union/enum already defined"); + s->c = -2; /* cannot be empty */ /* non empty enums are not allowed */ ps = &s->next; diff --git a/tests/tests2/60_errors_and_warnings.c b/tests/tests2/60_errors_and_warnings.c index 556278c..44f7f67 100644 --- a/tests/tests2/60_errors_and_warnings.c +++ b/tests/tests2/60_errors_and_warnings.c @@ -160,4 +160,10 @@ void foo(void) { i = 42.2; } } +#elif defined test_nested_types +union u { + union u { + int i; + } m; +}; #endif diff --git a/tests/tests2/60_errors_and_warnings.expect b/tests/tests2/60_errors_and_warnings.expect index 25b5c66..3b34fef 100644 --- a/tests/tests2/60_errors_and_warnings.expect +++ b/tests/tests2/60_errors_and_warnings.expect @@ -74,3 +74,6 @@ [test_conflicting_types] 60_errors_and_warnings.c:159: error: conflicting types for 'i' + +[test_nested_types] +60_errors_and_warnings.c:166: error: struct/union/enum already defined