-
Notifications
You must be signed in to change notification settings - Fork 22
Don't use switch fallthrough #423
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
llvm-beanz
wants to merge
3
commits into
llvm:main
Choose a base branch
from
llvm-beanz:cbieneman/dont-use-switch-fallthrough
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 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,17 +6,16 @@ RWStructuredBuffer<uint> Out : register(u1); | |
void main(uint3 threadID : SV_DispatchThreadID) { | ||
bool B1 = false; | ||
|
||
switch (value[threadID.x]) { | ||
case 0: // threads 0 and 1; result is number of active lanes (2) | ||
Out[threadID.x + 4] = WaveActiveCountBits(true); // threads 0 and 1 | ||
case 2: | ||
B1 = true; // set b1 to true for thread 3 | ||
break; | ||
default: | ||
Out[threadID.x + 4] = WaveActiveCountBits(false); // thread 2; expect 0 | ||
break; | ||
} | ||
// should be 3 because B1 set to true for threads 0,1, and 3. | ||
if (value[threadID.x] == 0) // thread 0 and 1. | ||
Out[threadID.x + 4] = WaveActiveCountBits(true); | ||
// thread 0-3 set b1 to true. | ||
if (value[threadID.x] == 0 || value[threadID.x] == 1) | ||
|
||
B1 = true; | ||
else // thread 4 | ||
Out[threadID.x + 4] = WaveActiveCountBits(false); | ||
|
||
// Out[threadID.x + 4] on thread 3 is never written to and should remain 0. | ||
// All threads count 3 because B1 set to true for threads 0,1, and 3. | ||
uint Count = WaveActiveCountBits(B1); | ||
Out[threadID.x] = Count; | ||
} | ||
|
@@ -35,11 +34,11 @@ Buffers: | |
- Name: Out | ||
Format: UInt32 | ||
Stride: 4 | ||
ZeroInitSize: 28 | ||
ZeroInitSize: 32 | ||
- Name: ExpectedOut | ||
Format: UInt32 | ||
Stride: 4 | ||
Data: [3, 3, 3, 3, 2, 2, 0] | ||
Data: [3, 3, 3, 3, 2, 2, 0, 0] | ||
Results: | ||
- Result: Test | ||
Rule: BufferExact | ||
|
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.
While this matches the behavior of the replaced switch, the comment seemed to imply that thread
1
was meant to also go through this branch. The later comment also seems to assume this ("result for all threads is true because B1 is true for threads 0-2"). However thread numbers are translated through the LUTvalue
, which is[0, 0, 1, 2]
.Even accounting for this looked up value, the removed and remaining comments don't seem to align with the test's design and expected behavior. The test seems to be written in a way to make it a bit confusing on purpose.
I don't understand the intention behind these odd details of the test. Was this a mistake in the code or in the comments?
It would be nice to have an explanatory comment for the test design.
The second test has a similar issue.