Skip to content

Commit

Permalink
Parser: do not define typedefs with invalid types
Browse files Browse the repository at this point in the history
Closes #645
  • Loading branch information
ehaas committed Mar 12, 2024
1 parent 15e8192 commit 61f3c85
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/aro/Parser.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
{
Expand Down
1 change: 1 addition & 0 deletions src/aro/SymbolStack.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
5 changes: 5 additions & 0 deletions test/cases/redefine invalid typedef.c
Original file line number Diff line number Diff line change
@@ -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 *'" \

0 comments on commit 61f3c85

Please sign in to comment.