Skip to content

Follow target ABI sign-/zero-extension rules for enum types #36321

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

Merged
merged 2 commits into from
Sep 9, 2016

Conversation

uweigand
Copy link
Contributor

@uweigand uweigand commented Sep 7, 2016

While attempting to port Rust to s390x, I ran into an ABI violation
(that caused rust_eh_personality to be miscompiled, breaking unwinding).
The problem is that this function returns an enum type, which is
supposed to be sign-extended according to the s390x ABI. However,
common code would ignore target sign-/zero-extension rules for any
types that do not satisfy is_integral(), which includes enums.

For the general case of Rust enum types, which map to structure types
with a discriminant, that seems correct. However, in the special case
of simple enums that map directly to C enum types (i.e. LLVM integers),
this is incorrect; we must follow the target extension rules for those.

Signed-off-by: Ulrich Weigand [email protected]

While attempting to port Rust to s390x, I ran into an ABI violation
(that caused rust_eh_personality to be miscompiled, breaking unwinding).
The problem is that this function returns an enum type, which is
supposed to be sign-extended according to the s390x ABI.  However,
common code would ignore target sign-/zero-extension rules for any
types that do not satisfy is_integral(), which includes enums.

For the general case of Rust enum types, which map to structure types
with a discriminant, that seems correct.  However, in the special case
of simple enums that map directly to C enum types (i.e. LLVM integers),
this is incorrect; we must follow the target extension rules for those.

Signed-off-by: Ulrich Weigand <[email protected]>
@japaric
Copy link
Member

japaric commented Sep 7, 2016

@rust-highfive didn't assign a reviewer. Could we get someone familiar with the backend (@eddyb? 😄) to review this PR?

cc @alexcrichton

if let ty::TyEnum(..) = ty.sty {
if arg.ty.kind() == llvm::Integer {
let repr = adt::represent_type(ccx, ty);
arg.signedness = Some(adt::is_discr_signed(&repr));
Copy link
Member

Choose a reason for hiding this comment

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

This should pattern-match on ccx.layout_of(ty) (see librustc/ty/layout.rs) instead of checking the LLVM type and then asking adt (which is being phased out by #36151) for more information.

@eddyb
Copy link
Member

eddyb commented Sep 7, 2016

r? @eddyb

@eddyb
Copy link
Member

eddyb commented Sep 7, 2016

@bors r+ Thanks!

@bors
Copy link
Collaborator

bors commented Sep 7, 2016

📌 Commit ce3cecf has been approved by eddyb

@bors
Copy link
Collaborator

bors commented Sep 8, 2016

⌛ Testing commit ce3cecf with merge 9d76bed...

@bors
Copy link
Collaborator

bors commented Sep 8, 2016

💔 Test failed - auto-win-gnu-32-opt-rustbuild

@sanxiyn
Copy link
Member

sanxiyn commented Sep 9, 2016

@bors retry

@bors
Copy link
Collaborator

bors commented Sep 9, 2016

⌛ Testing commit ce3cecf with merge 1df6445...

bors added a commit that referenced this pull request Sep 9, 2016
Follow target ABI sign-/zero-extension rules for enum types

While attempting to port Rust to s390x, I ran into an ABI violation
(that caused rust_eh_personality to be miscompiled, breaking unwinding).
The problem is that this function returns an enum type, which is
supposed to be sign-extended according to the s390x ABI.  However,
common code would ignore target sign-/zero-extension rules for any
types that do not satisfy is_integral(), which includes enums.

For the general case of Rust enum types, which map to structure types
with a discriminant, that seems correct.  However, in the special case
of simple enums that map directly to C enum types (i.e. LLVM integers),
this is incorrect; we must follow the target extension rules for those.

Signed-off-by: Ulrich Weigand <[email protected]>
@bors bors merged commit ce3cecf into rust-lang:master Sep 9, 2016
@uweigand uweigand deleted the enum-abi branch September 11, 2016 23:38
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.

5 participants