librz/type: fix forward type for enums (#6539)

Co-authored-by: Anton Kochkov <anton.kochkov@gmail.com>
This commit is contained in:
NOT XVilka 2026-06-20 17:32:06 +08:00 committed by GitHub
parent 2e8d857e63
commit 06217cd05e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 1 deletions

View file

@ -210,7 +210,7 @@ int parse_sole_type_name(CParserState *state, TSNode node, const char *text, Par
free(real_type);
return 0;
}
// Before resorting to create a new forward type, check if there is some union or struct with the same name already.
// Before resorting to create a new forward type, check if there is some union, struct or enum with the same name already.
// This will e.g. catch cases like referring to `struct MyStruct` by just `MyStruct`.
if ((*tpair = c_parser_get_structure_type(state, real_type))) {
parser_debug(state, "Fetched type as struct: \"%s\"\n", real_type);
@ -222,6 +222,11 @@ int parse_sole_type_name(CParserState *state, TSNode node, const char *text, Par
free(real_type);
return 0;
}
if ((*tpair = c_parser_get_enum_type(state, real_type))) {
parser_debug(state, "Fetched type as enum: \"%s\"\n", real_type);
free(real_type);
return 0;
}
// If not - we form both RzType and RzBaseType to store in the Types database
// as a forward-looking definition
*tpair = c_parser_new_primitive_type(state, real_type, is_const);

View file

@ -2381,6 +2381,19 @@ fcn.00014d50
EOF
RUN
NAME=tx on enum type
FILE=bins/elf/ioli/crackme0x00
CMDS=<<EOF
td "enum myenum { A=0, B=1 };"
af @ main
afs int main(enum myenum e) @ main
tx myenum
EOF
EXPECT=<<EOF
main
EOF
RUN
NAME=aht aligned
FILE==
BROKEN=1