Skip to content

Commit

Permalink
Fix delving into an invalid expr-ident union member
Browse files Browse the repository at this point in the history
  • Loading branch information
bobrippling committed Sep 23, 2024
1 parent 1aeb310 commit ce3d9d8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
26 changes: 21 additions & 5 deletions src/cc1/attribute.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,27 @@ attribute *expr_attr_present(expr *e, enum attribute_type t)
}

if(expr_kind(e, identifier)){
sym *s = e->bits.ident.bits.ident.sym;
if(s){
da = attribute_present(s->decl, t);
if(da)
return da;
switch(e->bits.ident.type){
case IDENT_NORM:
{
sym *s = e->bits.ident.bits.ident.sym;
if(s){
da = attribute_present(s->decl, t);
if(da)
return da;
}
break;
}
case IDENT_ENUM:
{
enum_member *enu = e->bits.ident.bits.enum_mem;
da = attr_present(enu->attr, t);
if(da)
return da;
if(enu->val != (expr *)-1 && (da = expr_attr_present(enu->val, t)))
return da;
break;
}
}
}

Expand Down
7 changes: 7 additions & 0 deletions test/cases/__attribute__/expr_enum.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// RUN: %ucc -fsyntax-only %s
enum bool { false, true };

int main() {
// ensure attr checking on enums doesn't crash
if(false);
}

0 comments on commit ce3d9d8

Please sign in to comment.