Details
- Reviewers
• tstellarAMD arsenm
Diff Detail
Event Timeline
Where are you seeing this warning? It's switching over all values of the enum so I see the warning for that if I add the default
lib/Target/AMDGPU/AMDGPUInstrInfo.cpp | ||
---|---|---|
147–149 | Fall through comment doesn't make sense after unreachable |
I am getting this warning when building without default:
/home/kzhuravl/Lightning/llvm/lib/Target/AMDGPU/AMDGPUInstrInfo.cpp: In function â?~SIEncodingFamily subtargetEncodingFamily(const llvm::AMDGPUSubtarget&)â?T: /home/kzhuravl/Lightning/llvm/lib/Target/AMDGPU/AMDGPUInstrInfo.cpp:160:1: warning: control reaches end of non-void function [-Wreturn-type] } ^
I am not getting a warning with default, which makes sense to me.
Underlying type of an unscoped enum is some integral type (int, unsigned int, etc... implementation-defined). So, I do not think, that switching over all defined enum values is enough:
- What happens if, for some reason, ST.getGeneration() returns an undefined enum value (for example, some garbage)? - undefined behavior.
- What happens if we add a new enum value, and forget to add it to a switch statement? - undefined behavior.
Someone can argue that above 2 cases can never happen, hence it is a warning, not a compilation error. But I'd rather know that unreachable will be executed if something goes wrong.
Please, correct me if I am wrong.
I am not sure why you experience the reverse behavior. Do you have any other modified files? Can you paste the warning you are getting?
It's undefined to be out of bounds value. Clang warns when there is a default when all enum values are covered. It won't warn on the non void here because it won't reach there. I think you have to move the unreachable after the switch and remove default
Fall through comment doesn't make sense after unreachable