From 61f3c8567806705452ec572e586577c828fdc8e9 Mon Sep 17 00:00:00 2001 From: Evan Haas Date: Tue, 12 Mar 2024 07:15:12 -0700 Subject: [PATCH] Parser: do not define typedefs with invalid types Closes #645 --- src/aro/Parser.zig | 6 ++++-- src/aro/SymbolStack.zig | 1 + test/cases/redefine invalid typedef.c | 5 +++++ 3 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 test/cases/redefine invalid typedef.c diff --git a/src/aro/Parser.zig b/src/aro/Parser.zig index c20a273c..0836ca86 100644 --- a/src/aro/Parser.zig +++ b/src/aro/Parser.zig @@ -1152,8 +1152,10 @@ fn decl(p: *Parser) Error!bool { const interned_name = try StrInt.intern(p.comp, p.tokSlice(init_d.d.name)); if (decl_spec.storage_class == .typedef) { - try p.syms.defineTypedef(p, interned_name, init_d.d.ty, init_d.d.name, node); - p.typedefDefined(interned_name, init_d.d.ty); + if (!init_d.d.ty.is(.invalid)) { + try p.syms.defineTypedef(p, interned_name, init_d.d.ty, init_d.d.name, node); + p.typedefDefined(interned_name, init_d.d.ty); + } } else if (init_d.initializer.node != .none or (p.func.ty != null and decl_spec.storage_class != .@"extern")) { diff --git a/src/aro/SymbolStack.zig b/src/aro/SymbolStack.zig index dba72234..a8e06407 100644 --- a/src/aro/SymbolStack.zig +++ b/src/aro/SymbolStack.zig @@ -175,6 +175,7 @@ pub fn defineTypedef( tok: TokenIndex, node: NodeIndex, ) !void { + assert(!ty.is(.invalid)); if (s.get(name, .vars)) |prev| { switch (prev.kind) { .typedef => { 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 *'" \ +