Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

[linux-port] Add missing case statements - #222

Merged
ehsannas merged 1 commit into
google:linuxfrom
pow2clk:pow2clk-addcase
Jun 7, 2018
Merged

ehsannas merged 1 commit into
google:linuxfrom
pow2clk:pow2clk-addcase

Conversation

@pow2clk

@pow2clk pow2clk commented May 27, 2018

Copy link
Copy Markdown

When switching over an enum value, the ideal is to include a case
for every possibly value. Where possible, that's what this change
does to silence warnings and also to provide space to properly
handle every possible input and throw a warning should a new one
be added. In some cases, it's not practical to list every input.
In these cases, putting a default that doesn't change the behavior,
but let's the compiler know that the behavior is intended.
Fixes 133 clang and 8108(!) gcc warnings.

Contributes to #206

@AppVeyorBot

Copy link
Copy Markdown

Comment thread lib/HLSL/DxilDebugInstrumentation.cpp Outdated

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is a change in behavior. Is it the right behavior? I don't know...

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

These are processor specific types. Unless dxil runs on PPC or x86 (it doesn't does it?) it shouldn't be hit. Even if it does, I doubt it'd use these optimizations.

Comment thread lib/HLSL/DxilShaderAccessTracking.cpp Outdated

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Changes behavior .... It does look like a reasonable change though.

Comment thread tools/clang/lib/AST/ASTContext.cpp Outdated

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Complex LitFloat is not supported

Comment thread tools/clang/lib/AST/ASTContextHLSL.cpp Outdated

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

haha.. Nice

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

do we need these 3 case statements now that we have added the default below?

Comment thread tools/clang/lib/Sema/SemaOverload.cpp Outdated

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

change in behavior: These cases used to hit llvm_unreachable, but now hit false. Is this the correct behavior?

Comment thread tools/clang/lib/Sema/DeclSpec.cpp Outdated

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

change in behavior: These cases used to hit llvm_unreachable, but now hit false. Is this the correct behavior?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

these types can't be function declarations. So returning false seems correct.

Comment thread tools/clang/lib/CodeGen/CGDebugInfo.cpp Outdated

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Not sure about this one... they should probably actually implement these cases? >.<

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This function is for generating DWARF data for debugging purposes. I don't think any HLSL debuggers use that format. Do they?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I guess not.

@pow2clk

pow2clk commented May 28, 2018

Copy link
Copy Markdown
Author

These are the tricky ones. Every bug I ran into developing this was due to this kind of changed behavior. I'll look at these more closely and maybe split them up further to better drill down which can safely be resolved with a default: break;, which should be errors, and which should have actual implementations.

@pow2clk
pow2clk force-pushed the pow2clk-addcase branch 2 times, most recently from 9466403 to e5b8bec Compare June 6, 2018 19:31
@pow2clk

pow2clk commented Jun 6, 2018

Copy link
Copy Markdown
Author

I've audited all the case and default statements I added. I've added comments explaining the default statements. I removed any that were less certain so they can be addressed in a later change with more scrutiny.

Comment thread tools/clang/lib/Sema/SemaHLSL.cpp Outdated

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This conditional and switch is a duplicate of the previous. It depends on the same variables for the result and changes none of them. So the repetition accomplishes nothing.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

😲

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Good catch!

@AppVeyorBot

Copy link
Copy Markdown

@pow2clk pow2clk left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Now I've investigated the issues further, I can respond belatedly to your review comments.

Comment thread tools/clang/lib/Sema/DeclSpec.cpp Outdated

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

these types can't be function declarations. So returning false seems correct.

Comment thread tools/clang/lib/CodeGen/CGDebugInfo.cpp Outdated

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This function is for generating DWARF data for debugging purposes. I don't think any HLSL debuggers use that format. Do they?

@ehsannas ehsannas left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks a lot @pow2clk ! I know this must have taken a lot of time. Just one case seemed curious to me pointed out below.

Comment thread tools/clang/lib/CodeGen/CGDebugInfo.cpp Outdated

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I guess not.

Comment thread tools/clang/lib/Sema/SemaHLSL.cpp Outdated

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think in some cases (where the case matches, but the if condition inside the case isn't true), AssignOpt used to be executed, but now won't.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yeah. it looks like you're right. I'll move it back out and make it a break.

Comment thread tools/clang/lib/Sema/SemaHLSL.cpp Outdated

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

😲

When switching over an enum value, the ideal is to include a case
for every possibly value. Where possible, that's what this change
does to silence warnings and also to provide space to properly
handle every possible input and throw a warning should a new one
be added. In some cases, it's not practical to list every input.
In these cases, putting a default that doesn't change the behavior,
but let's the compiler know that the behavior is intended.
Fixes 133 clang and 8108(!) gcc warnings.

Contributes to google#206
@pow2clk
pow2clk force-pushed the pow2clk-addcase branch from e5b8bec to d4c6ba1 Compare June 7, 2018 17:34
@AppVeyorBot

Copy link
Copy Markdown

@ehsannas

ehsannas commented Jun 7, 2018

Copy link
Copy Markdown

Bots passing.

@ehsannas
ehsannas merged commit 0786b7f into google:linux Jun 7, 2018
@pow2clk
pow2clk deleted the pow2clk-addcase branch June 7, 2018 20:20
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants