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

Fix several ICEs related to malformed #[repr(...)] attributes #87013

Merged
merged 1 commit into from
Jul 10, 2021

Conversation

FabianWolff
Copy link
Contributor

This PR fixes #83921. #83921 actually contains two related but distinct issues (one of them incorrectly reported as a duplicate in #83921 (comment)):

In the first, a call to delay_span_bug leads to an ICE when compiling with -Zunpretty=everybody_loops (and some other pretty-printing modes), because the corresponding error is emitted in a later pass, which does not run when only pretty-printing is requested.

The second issue is about parsing #[repr(...)] attributes. Currently, all of the following cause an ICE when applied to a struct/enum:

#[repr(packed())]
#[repr(align)]
#[repr(align(2, 4))]
#[repr(align())]
#[repr(i8())]
#[repr(u32(42))]
#[repr(i64 = 2)]

I have fixed this by expanding the well-formedness checks in find_repr_attrs().

@rust-highfive
Copy link
Collaborator

r? @estebank

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 9, 2021
Comment on lines +874 to +886
let mut err = struct_span_err!(
diagnostic,
item.span(),
E0589,
"invalid `repr(align)` attribute: `align` needs an argument"
);
err.span_suggestion(
item.span(),
"supply an argument here",
"align(...)".to_string(),
Applicability::HasPlaceholders,
);
err.emit();
Copy link
Contributor

Choose a reason for hiding this comment

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

Because you have no conditional changes on the diagnostic, you can rely on chaining instead:

Suggested change
let mut err = struct_span_err!(
diagnostic,
item.span(),
E0589,
"invalid `repr(align)` attribute: `align` needs an argument"
);
err.span_suggestion(
item.span(),
"supply an argument here",
"align(...)".to_string(),
Applicability::HasPlaceholders,
);
err.emit();
struct_span_err!(
diagnostic,
item.span(),
E0589,
"invalid `repr(align)` attribute: `align` needs an argument"
).span_suggestion(
item.span(),
"supply an argument here",
"align(...)".to_string(),
Applicability::HasPlaceholders,
).emit();

(Might need to run ./x.py fmt to fix the formatting here)

@estebank
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Jul 10, 2021

📌 Commit a7bfd35 has been approved by estebank

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 10, 2021
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 10, 2021
Rollup of 5 pull requests

Successful merges:

 - rust-lang#87006 (Revert the revert of renaming traits::VTable to ImplSource)
 - rust-lang#87011 (avoid reentrant lock acquire when ThreadIds run out)
 - rust-lang#87013 (Fix several ICEs related to malformed `#[repr(...)]` attributes)
 - rust-lang#87020 (remove const_raw_ptr_to_usize_cast feature)
 - rust-lang#87028 (Fix type: `'satic` -> `'static`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 945458d into rust-lang:master Jul 10, 2021
@rustbot rustbot added this to the 1.55.0 milestone Jul 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ICE: "unrecognized representation hint" with -Z unpretty=everybody_loops
5 participants