Skip to content

make memcmp return a value of c_int_width instead of i32 #90791

New issue

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

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

Already on GitHub? # to your account

Merged
merged 1 commit into from
Apr 3, 2022

Conversation

drmorr0
Copy link
Contributor

@drmorr0 drmorr0 commented Nov 11, 2021

This is an attempt to fix #32610 and #78022, namely, that memcmp always returns an i32 regardless of the platform. I'm running into some issues and was hoping I could get some help.

Here's what I've been attempting so far:

  1. Build the stage0 compiler with all the changes expect for the changes in library/core/src/slice/cmp.rs and compiler/rustc_codegen_llvm/src/context.rs; this is because target_c_int_width isn't passed through and recognized as a valid config option yet. I'm building with ./x.py build --stage 0 library/core library/proc_macro compiler/rustc
  2. Next I add in the #[cfg(c_int_width = ...)] params to cmp.rs and context.rs and build the stage 1 compiler by running ./x.py build --keep-stage 0 --stage 1 library/core library/proc_macro compiler/rustc. This step now runs successfully.
  3. Lastly, I try to build the test program for AVR mentioned in Array comparisons don't work on AVR #78022 with RUSTFLAGS="--emit llvm-ir" cargo build --release, and look at the resulting llvm IR, which still shows:
...
%11 = call addrspace(1) i32 @memcmp(i8* nonnull %5, i8* nonnull %10, i16 5) #7, !dbg !1191                                                                                                                                                                                                                                %.not = icmp eq i32 %11, 0, !dbg !1191
...
; Function Attrs: nounwind optsize                                                                                                                                                                                                                                                                                          declare i32 @memcmp(i8*, i8*, i16) local_unnamed_addr addrspace(1) #4

Any ideas what I'm missing here? Alternately, if this is totally the wrong approach I'm open to other suggestions.

cc @Rahix

@rust-highfive
Copy link
Contributor

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @joshtriplett (or someone else) soon.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 11, 2021
@rust-log-analyzer

This comment has been minimized.

@drmorr0 drmorr0 force-pushed the drmorr-memcmp-cint-cfg branch from 1434ae4 to 3e0a0b6 Compare November 12, 2021 07:20
@rust-log-analyzer

This comment has been minimized.

@drmorr0
Copy link
Contributor Author

drmorr0 commented Nov 12, 2021

Ok, thanks to your pointers I got this actually working and confirmed that this works for the test program.

I think I need to do this in two parts to pass CI? The first part will make the compiler handle different c_int_widths, and then I can uncomment the #[cfg(...)] bits in core.

Also, I'm unsure what to do for the "default" case for the match statement... currently this outputs the following if you use a bad value for target-c-int-width:

error: internal compiler error: compiler/rustc_codegen_llvm/src/context.rs:784:18: Unsupported target_c_int_width = 17
thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1147:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md
note: rustc 1.58.0-dev running on x86_64-unknown-linux-gnu
note: compiler flags: -Z unstable-options -C opt-level=s -C panic=abort -C linker-plugin-lto -C codegen-units=1 -C debuginfo=2 --crate-type lib
note: some of the compiler flags provided by cargo are hidden

Lastly, are there any tests I should write, or any other things I can do to help get this through?

@drmorr0 drmorr0 force-pushed the drmorr-memcmp-cint-cfg branch from 3e0a0b6 to abb4d28 Compare November 12, 2021 07:29
@rust-log-analyzer

This comment has been minimized.

@drmorr0 drmorr0 force-pushed the drmorr-memcmp-cint-cfg branch from abb4d28 to 4ba643a Compare November 12, 2021 07:36
@cuviper
Copy link
Member

cuviper commented Nov 12, 2021

I think I need to do this in two parts to pass CI? The first part will make the compiler handle different c_int_widths, and then I can uncomment the #[cfg(...)] bits in core.

You can use cfg(bootstrap) to work with the stage0 compiler that doesn't have your changes yet.
e.g. combined: #[cfg(any(bootstrap, c_int_width = "32"))]

@drmorr0 drmorr0 force-pushed the drmorr-memcmp-cint-cfg branch from 4ba643a to b3c287b Compare November 13, 2021 16:42
@drmorr0 drmorr0 changed the title [WIP] make memcmp return a value of c_int_width instead of i32 make memcmp return a value of c_int_width instead of i32 Nov 13, 2021
@drmorr0
Copy link
Contributor Author

drmorr0 commented Nov 13, 2021

You can use cfg(bootstrap) to work with the stage0 compiler that doesn't have your changes yet.
e.g. combined: #[cfg(any(bootstrap, c_int_width = "32"))]

Fixed, thanks!

@apiraino apiraino added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Nov 18, 2021
@JohnCSimon JohnCSimon added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 5, 2021
@drmorr0
Copy link
Contributor Author

drmorr0 commented Dec 27, 2021

@joshtriplett Hi, just checking if there's anything else I need to do on this to get it merged in?

@bors

This comment was marked as resolved.

@joshtriplett
Copy link
Member

r? @rust-lang/compiler

@petrochenkov
Copy link
Contributor

The codegen changes look reasonable to me, although I'm not an expert in that area.

@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 22, 2022
@mrk-its
Copy link

mrk-its commented Jan 22, 2022

I'm testing these changes in my rust fork for mos arch (8bit 6502 CPU) and everything works fine. https://github.com/mrk-its/rust/tree/mos_target

Copy link
Member

@nagisa nagisa left a comment

Choose a reason for hiding this comment

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

I'm going to request that Vadim's review comments are addressed. I don't believe this PR should land as is.

@JohnCSimon JohnCSimon added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 12, 2022
@Dylan-DPC
Copy link
Member

@drmorr0 any updates on this?

@drmorr0
Copy link
Contributor Author

drmorr0 commented Mar 1, 2022

@Dylan-DPC I have not had a chance to revisit this yet, I'm hoping to get to it soon-ish, though.

@drmorr0 drmorr0 force-pushed the drmorr-memcmp-cint-cfg branch from b3c287b to 6c811ce Compare April 2, 2022 21:31
@rust-log-analyzer

This comment has been minimized.

@drmorr0 drmorr0 force-pushed the drmorr-memcmp-cint-cfg branch 2 times, most recently from d22ded4 to 4de3090 Compare April 2, 2022 22:26
@rust-log-analyzer

This comment has been minimized.

@drmorr0 drmorr0 force-pushed the drmorr-memcmp-cint-cfg branch from 4de3090 to 9692b53 Compare April 2, 2022 22:34
@rust-log-analyzer

This comment has been minimized.

@drmorr0 drmorr0 force-pushed the drmorr-memcmp-cint-cfg branch from 9692b53 to b33bf18 Compare April 2, 2022 22:38
@rust-log-analyzer

This comment has been minimized.

@drmorr0 drmorr0 force-pushed the drmorr-memcmp-cint-cfg branch from b33bf18 to 1aa9676 Compare April 2, 2022 22:46
@drmorr0 drmorr0 force-pushed the drmorr-memcmp-cint-cfg branch from 1aa9676 to aa67016 Compare April 3, 2022 00:21
@drmorr0
Copy link
Contributor Author

drmorr0 commented Apr 3, 2022

Ok I think this is ready; I'm trying to get my test environment back up so that I can confirm it's generating the right thing but some other stuff has broken in the interim.

@petrochenkov
Copy link
Contributor

Thanks!
@bors r+

@bors
Copy link
Collaborator

bors commented Apr 3, 2022

📌 Commit aa67016 has been approved by petrochenkov

@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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 3, 2022
@bors
Copy link
Collaborator

bors commented Apr 3, 2022

⌛ Testing commit aa67016 with merge 15a242a...

@bors
Copy link
Collaborator

bors commented Apr 3, 2022

☀️ Test successful - checks-actions
Approved by: petrochenkov
Pushing 15a242a to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Apr 3, 2022
@bors bors merged commit 15a242a into rust-lang:master Apr 3, 2022
@rustbot rustbot added this to the 1.61.0 milestone Apr 3, 2022
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (15a242a): comparison url.

Summary: This benchmark run did not return any relevant results.

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

@rustbot label: -perf-regression

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

core dependency on c_int in memcmp