Skip to content

Commit

Permalink
Attribute: apply malloc attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
ehaas authored and Vexu committed Mar 22, 2024
1 parent 9cfb6dc commit c6ce307
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/aro/Attribute.zig
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,13 @@ pub fn applyFunctionAttributes(p: *Parser, ty: Type, attr_buf_start: usize) !Typ
else => try p.errStr(.callconv_not_supported, tok, p.tok_ids[tok].lexeme().?),
},
},
.malloc => {
if (base_ty.returnType().isPtr()) {
try p.attr_application_buf.append(p.gpa, attr);
} else {
try ignoredAttrErr(p, tok, attr.tag, "functions that do not return pointers");
}
},
.access,
.alloc_align,
.alloc_size,
Expand All @@ -908,7 +915,6 @@ pub fn applyFunctionAttributes(p: *Parser, ty: Type, attr_buf_start: usize) !Typ
.ifunc,
.interrupt,
.interrupt_handler,
.malloc,
.no_address_safety_analysis,
.no_icf,
.no_instrument_function,
Expand Down
5 changes: 5 additions & 0 deletions test/cases/ignored attributes.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
__attribute__((malloc)) int foo(void);
__attribute__((malloc)) int *bar(void);

#define EXPECTED_ERRORS "ignored attributes.c:1:16: warning: attribute 'malloc' ignored on functions that do not return pointers [-Wignored-attributes]" \

0 comments on commit c6ce307

Please sign in to comment.