From c6ce30730b070b7f403ca12925f471632b56e2b2 Mon Sep 17 00:00:00 2001 From: Evan Haas Date: Tue, 19 Mar 2024 17:15:08 -0700 Subject: [PATCH] Attribute: apply malloc attribute --- src/aro/Attribute.zig | 8 +++++++- test/cases/ignored attributes.c | 5 +++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 test/cases/ignored attributes.c diff --git a/src/aro/Attribute.zig b/src/aro/Attribute.zig index 909fc1c3..af5159c9 100644 --- a/src/aro/Attribute.zig +++ b/src/aro/Attribute.zig @@ -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, @@ -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, diff --git a/test/cases/ignored attributes.c b/test/cases/ignored attributes.c new file mode 100644 index 00000000..63102d81 --- /dev/null +++ b/test/cases/ignored attributes.c @@ -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]" \ +