This is an archive of the discontinued LLVM Phabricator instance.

[AMDGPU] Fix warning
AbandonedPublic

Authored by kzhuravl on Jun 24 2016, 2:24 PM.

Details

Diff Detail

Event Timeline

kzhuravl updated this revision to Diff 61839.Jun 24 2016, 2:24 PM
kzhuravl retitled this revision from to [AMDGPU] Fix warning.
kzhuravl updated this object.
kzhuravl added reviewers: tstellarAMD, arsenm.
kzhuravl added a subscriber: llvm-commits.
arsenm edited edge metadata.Jun 24 2016, 2:28 PM

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

kzhuravl updated this revision to Diff 61884.Jun 24 2016, 9:16 PM
kzhuravl edited edge metadata.

Address review comments

arsenm accepted this revision.Jun 27 2016, 1:17 PM
arsenm edited edge metadata.

LGTM

This revision is now accepted and ready to land.Jun 27 2016, 1:17 PM