Skip to content

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

Merged
bors merged 2 commits into
rust-lang:masterfrom
uweigand:enum-abi
Sep 9, 2016
Merged

Follow target ABI sign-/zero-extension rules for enum types#36321
bors merged 2 commits into
rust-lang:masterfrom
uweigand:enum-abi

Conversation

@uweigand

@uweigand uweigand commented Sep 7, 2016

Copy link
Copy Markdown
Contributor

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 ulrich.weigand@de.ibm.com

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 <ulrich.weigand@de.ibm.com>
@japaric

japaric commented Sep 7, 2016

Copy link
Copy Markdown
Contributor

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

cc @alexcrichton

Comment thread src/librustc_trans/abi.rs Outdated
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
Copy Markdown
Contributor

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

eddyb commented Sep 7, 2016

Copy link
Copy Markdown
Contributor

r? @eddyb

@eddyb

eddyb commented Sep 7, 2016

Copy link
Copy Markdown
Contributor

@bors r+ Thanks!

@bors

bors commented Sep 7, 2016

Copy link
Copy Markdown
Collaborator

📌 Commit ce3cecf has been approved by eddyb

@bors

bors commented Sep 8, 2016

Copy link
Copy Markdown
Collaborator

⌛ Testing commit ce3cecf with merge 9d76bed...

@bors

bors commented Sep 8, 2016

Copy link
Copy Markdown
Collaborator

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

@sanxiyn

sanxiyn commented Sep 9, 2016

Copy link
Copy Markdown
Contributor

@bors retry

@bors

bors commented Sep 9, 2016

Copy link
Copy Markdown
Collaborator

⌛ 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 <ulrich.weigand@de.ibm.com>
@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