Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue a warning on packed record member access #800

Merged
merged 6 commits into from
Nov 12, 2024

Conversation

wrongnull
Copy link
Contributor

Closes #788

src/aro/Parser.zig Outdated Show resolved Hide resolved
@@ -21,6 +21,10 @@ pub const Message = struct {

pub const Extra = union {
str: []const u8,
record_member: struct {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This makes the Extra union 32 bytes instead of 16 (on a 64-bit system). We should use something like what is done in errDeprecated or valueChangedStr - write the string to p.strings, dupe it, and then just use the .str Extra field

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -7226,8 +7241,7 @@ fn unExpr(p: *Parser) Error!Result {
const lhs_ty = p.nodes.items(.ty)[@intFromEnum(data.member.lhs)];
if (lhs_ty.hasAttribute(.@"packed")) {
const record = lhs_ty.getRecord().?;
const mapper = p.comp.string_interner.getSlowTypeMapper();
const extra = Diagnostics.Message.Extra{ .record_member = .{ .record = mapper.lookup(record.name), .member = mapper.lookup(record.fields[data.member.index].name) } };
const extra = Diagnostics.Message.Extra{ .str = try p.packedMemberAccessStr(record.name, record.fields[data.member.index].name) };
try p.errExtra(.packed_member_address, orig_tok_i, extra);
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can use the errStr function here with the string

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Vexu Vexu merged commit 7a40472 into Vexu:master Nov 12, 2024
3 checks passed
@Vexu
Copy link
Owner

Vexu commented Nov 12, 2024

Thanks!

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.

Add diagnostic for taking address of packed record member
3 participants