Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parser: do not define typedefs with invalid types #647

Merged
merged 1 commit into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
ehaas marked this conversation as resolved.
Show resolved Hide resolved
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 *'" \

Loading