Skip to content

Commit

Permalink
Parser: check for invalid types in typedefs
Browse files Browse the repository at this point in the history
Do not try to combine invalid types into typedefs or render error messages
with invalid types.

Closes #645
  • Loading branch information
ehaas committed Mar 15, 2024
1 parent dfbd7c7 commit c24a2ff
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/aro/SymbolStack.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
1 change: 1 addition & 0 deletions src/aro/Type.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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 c24a2ff

Please sign in to comment.