Fix compiletest's --target-arch handling.#307
Merged
LegNeato merged 1 commit intoRust-GPU:mainfrom Nov 19, 2025
Merged
Conversation
compiletests lets you specify one or more target architectures. E.g. on
CI we run this:
```
cargo run -p compiletests --release --no-default-features -- \
--target-arch compute_61,compute_70,compute_90
```
While trying out various different target architectures, including
invalid ones, I get strange results.
First, if the target arch has fewer than 8 chars (e.g. `--target-arch
blah`), then nvvm panics:
```
thread 'rustc' panicked at crates/nvvm/src/lib.rs:246:38: byte
index 8 is out of bounds of `blah`
```
Second, if the target arch has 8 or more chars but is invalid, it is
just ignored. This means invalid flags like `--target-arch compute_999`
run, but just use the default target architecture.
This commit fixes the problems.
- Fix the slicing into the `-arch=` option to avoid the bounds panic.
- In `CodegenArgs::parse`, check for the `Err` case and panic instead of
swallowing it. A panic isn't ideal, but it's much better than silently
accepting and ignoring invalid input.
- Use a `String` instead of `&'static str` for the `Err` case, so the
error message is more informative, i.e. it includes the bad flag
value.
Also, the commit improves the `NvvmOption::from_str` test.
- Move inputs next to expected outputs, which makes it easier to
read and update.
- Add the missing compute capabilities.
- Add some checks for invalid inputs.
LegNeato
approved these changes
Nov 19, 2025
Contributor
LegNeato
left a comment
There was a problem hiding this comment.
Thanks for catching these
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
compiletests lets you specify one or more target architectures. E.g. on CI we run this:
While trying out various different target architectures, including invalid ones, I get strange results.
First, if the target arch has fewer than 8 chars (e.g.
--target-arch blah), then nvvm panics:Second, if the target arch has 8 or more chars but is invalid, it is just ignored. This means invalid flags like
--target-arch compute_999run, but just use the default target architecture.This commit fixes the problems.
-arch=option to avoid the bounds panic.CodegenArgs::parse, check for theErrcase and panic instead of swallowing it. A panic isn't ideal, but it's much better than silently accepting and ignoring invalid input.Stringinstead of&'static strfor theErrcase, so the error message is more informative, i.e. it includes the bad flag value.Also, the commit improves the
NvvmOption::from_strtest.