From c24a2fff9152bb0f324495786bae8ed1852f71ae Mon Sep 17 00:00:00 2001 From: Evan Haas Date: Tue, 12 Mar 2024 07:15:12 -0700 Subject: [PATCH] Parser: check for invalid types in typedefs Do not try to combine invalid types into typedefs or render error messages with invalid types. Closes #645 --- src/aro/SymbolStack.zig | 8 +++++--- src/aro/Type.zig | 1 + test/cases/redefine invalid typedef.c | 5 +++++ 3 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 test/cases/redefine invalid typedef.c diff --git a/src/aro/SymbolStack.zig b/src/aro/SymbolStack.zig index dba72234..8f0541f1 100644 --- a/src/aro/SymbolStack.zig +++ b/src/aro/SymbolStack.zig @@ -178,9 +178,11 @@ pub fn defineTypedef( if (s.get(name, .vars)) |prev| { switch (prev.kind) { .typedef => { - if (!ty.eql(prev.ty, p.comp, true)) { - try p.errStr(.redefinition_of_typedef, tok, try p.typePairStrExtra(ty, " vs ", prev.ty)); - if (prev.tok != 0) try p.errTok(.previous_definition, prev.tok); + if (!prev.ty.is(.invalid)) { + if (!ty.eql(prev.ty, p.comp, true)) { + try p.errStr(.redefinition_of_typedef, tok, try p.typePairStrExtra(ty, " vs ", prev.ty)); + if (prev.tok != 0) try p.errTok(.previous_definition, prev.tok); + } } }, .enumeration, .decl, .def, .constexpr => { diff --git a/src/aro/Type.zig b/src/aro/Type.zig index fb617d07..31e800d2 100644 --- a/src/aro/Type.zig +++ b/src/aro/Type.zig @@ -1899,6 +1899,7 @@ pub const Builder = struct { /// Try to combine type from typedef, returns true if successful. pub fn combineTypedef(b: *Builder, p: *Parser, typedef_ty: Type, name_tok: TokenIndex) bool { + if (typedef_ty.is(.invalid)) return false; b.error_on_invalid = true; defer b.error_on_invalid = false; diff --git a/test/cases/redefine invalid typedef.c b/test/cases/redefine invalid typedef.c new file mode 100644 index 00000000..e4138760 --- /dev/null +++ b/test/cases/redefine invalid typedef.c @@ -0,0 +1,5 @@ +typedef float *invalid1 __attribute__((vector_size(8))); +typedef float invalid1; + +#define EXPECTED_ERRORS "redefine invalid typedef.c:1:40: error: invalid vector element type 'float *'" \ +