-
-
Notifications
You must be signed in to change notification settings - Fork 14.6k
c-variadic: error when we can't guarantee that the backend does the right thing #152935
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
Open
folkertdev
wants to merge
1
commit into
rust-lang:main
Choose a base branch
from
folkertdev:c-variadic-disallow
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this "clang does it so it's probably fine" or "people familiar with the target have confirmed it's fine"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is "clang does this so we're matching the de-facto standard C compiler that rust code would interact with". We could pull that implementation into
rustcas well if you prefer. I've traced how this implementation is picked here https://github.com/rust-lang/rust/pull/150831/changes#r2673777819.The mips case right above will be handled by #152576.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy to leave that choice to you.^^ It is very strange to me that clang mostly does not use the LLVM impl here, given that they are part of the same project, so this is all a bit confusing.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pinging some target maintainers:
@jonathanpallant @Patryk27 @glaubitz @ricky26
apparently
msp430-none-elfdoes not have a target maintainer. For m68k I can't get programs to link (some incorrect relocation issue, might be an LLVM problem).Can you confirm that this test (with your target) works?
this likely needs some sort of config in
bootstrap.toml, I have some variations onIf we don't get any response here, it's probably safer to exclude these targets from stabilization for now, because looking at it again, I think this implementation is also a fallback in clang/llvm so there is a good chance that it's actually untested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will check tomorrow!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's a known bug, see: llvm/llvm-project#181481
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that that test is not applicable to AVR (it's a non-std target), but in general the AVR backend for LLVM implements variadics:
https://github.com/llvm/llvm-project/blob/8701cfc0008c4756f04f9839fd4afbb3f112bdad/llvm/lib/Target/AVR/AVRCallingConv.td#L28
... and we strive to be compatible with avr-gcc, so I'd expect things to just-work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're hesitant with accepting targets because the LLVM
va_argimplementation is known to miscompile programs on many platforms. In large part that is because a correct implementation would require layout information that LLVM just won't have. Hence, for many targets the actual logic is implemented inclangand we replicate that logic inrustc.I just tried this locally, compilation still fails but it gets far enough along to emit these errors:
I suppose this really should work, and we're currently implicitly assuming that
c_intisi32.What types implement
VaArgSafeis based on section 7.16.1 of the C23 specOur reading is that, on most targets, it is UB to read an
i16because it is incompatible with what was passed (even if ani16was passed, it has been promoted toc_int(we implicitly assume this isi32) through the default argument promotions).I'll make a separate PR to fix that and hopefully we can figure out some approach to testing
avr-nonethere too.