Skip to content

Rewrite attributes#1048

Open
Vexu wants to merge 20 commits into
masterfrom
attribute-rewrite
Open

Rewrite attributes#1048
Vexu wants to merge 20 commits into
masterfrom
attribute-rewrite

Conversation

@Vexu

@Vexu Vexu commented Jun 14, 2026

Copy link
Copy Markdown
Owner

Will close #944
Will close #367

@Vexu Vexu force-pushed the attribute-rewrite branch from 9d1fd35 to 7c576d4 Compare June 15, 2026 16:48
@Vexu Vexu marked this pull request as ready for review June 18, 2026 11:07
@Vexu

Vexu commented Jun 18, 2026

Copy link
Copy Markdown
Owner Author

For anyone interested in taking a look this is now mostly ready with 21 integration tests failing with TODO: implement 'X' attribute and 204 failing record layout tests (likely caused by maybe 3 bugs).

@ehaas

ehaas commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

I'm away from my main computer until the weekend but thank you for taking this on, the old attribute implementation had a bit too much comptime :)

@dotcarmen dotcarmen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still haven't reviewed Wip, Parser, and TypeStore. lgtm so far, a lot better than the old way :) i'll try rebasing my blocks PR when i have time in the next few days

syntax
_BitInt change size.c:1:17: warning: implicit conversion from 'double' to 'signed _BitInt(10)' changes value from 1.2 to 1 [-Wfloat-conversion]
_BitInt change size.c:2:35: warning: implicit conversion from 'double' to '_Complex unsigned _BitInt(10)' changes value from 1.2 to 1 [-Wfloat-conversion]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you intend to remove this test? seems helpful and like it shouldn't be removed

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made _Complex _BitInt an error as it is in gcc and clang.

Comment thread src/aro/Attribute.zig
maybe_unused,
nodiscard,
noreturn,
_Noreturn, // Deprecated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mind moving this comment and others below to be doc-comments?

Suggested change
_Noreturn, // Deprecated
/// Deprecated in c23
_Noreturn,

Comment thread src/aro/Attribute.zig
Comment on lines +561 to +565
inline for (.{ "gnu", "clang", "aro" }) |vendor_name| {
if (std.meta.stringToEnum(@FieldType(Namespaced, vendor_name), name)) |tag| {
return @unionInit(Namespaced, vendor_name, tag);
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO this should match the compiler being emulated

Suggested change
inline for (.{ "gnu", "clang", "aro" }) |vendor_name| {
if (std.meta.stringToEnum(@FieldType(Namespaced, vendor_name), name)) |tag| {
return @unionInit(Namespaced, vendor_name, tag);
}
}
switch (comp.langopts.emulate) {
.msvc => {}, // TODO
inline .clang, .gcc => |vendor| if (std.meta.stringToEnum(@FieldType(Namespaced, vendor_name), name)) |tag| {
return @unionInit(Namespaced, vendor_name, tag);
},
.no => if (std.meta.stringToEnum(Namespaced.Aro, name)) |tag| {
return @unionInit(Namespaced, "aro", tag);
},
}

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we were to go that route then we should also check which specific attributes each compiler supports but seeing as attributes are an extension and unknown ones are ignored I don't really want to do that.

Comment thread src/aro/Attribute/Map.zig
Comment thread src/aro/Attribute/Map.zig
Comment thread src/aro/Attribute/Map.zig
if (max_requested == null or max_requested.? < requested) {
max_requested = requested;
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems most attributes will be using the last attribute present (by using getAttribute). is this implementation the same behavior of clang/gcc/msvc, or can this be simplified/removed to follow the conforming behavior?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The biggest specified alignment is used so this logic needs to exist either when applying attributes or when fetching them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect attribute application for nested pointers Attributes before declarations applied incorrectly.

3 participants