Thanks for the suggestion.

Updated llvm_unreachable.

The static_cast not only check the switch cases all covered, also make sure 2 
enums not out of sync.



Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows

From: David Blaikie<mailto:[email protected]>
Sent: Monday, October 17, 2022 5:42 PM
To: Xiang Li<mailto:[email protected]>; Xiang 
Li<mailto:[email protected]>
Cc: [email protected]<mailto:[email protected]>
Subject: Re: [clang] 0674f2e - [NFC] Fix warning on no return after switch.

Also the static_assert is probably not needed - Clang builds with
-Wswitch-enum, which will warn if a switch over an enum doesn't cover
all the enumerators. We have lots of other switches over enums that
depend on this warning to detect code that needs to be updated when an
enum is modified.

On Mon, Oct 17, 2022 at 5:40 PM David Blaikie <[email protected]> wrote:
>
> If the switch is exhaustive (covers all the enumerators in an
> enumeration), we usually use an llvm_unreachable at the end, rather
> than a return. Could you change this to an llvm_unreachable?
>
> On Mon, Oct 17, 2022 at 3:52 PM Xiang Li via cfe-commits
> <[email protected]> wrote:
> >
> >
> > Author: Xiang Li
> > Date: 2022-10-17T15:52:23-07:00
> > New Revision: 0674f2ec96422131abde0c042fbf2c11267db210
> >
> > URL: 
> > https://github.com/llvm/llvm-project/commit/0674f2ec96422131abde0c042fbf2c11267db210
> > DIFF: 
> > https://github.com/llvm/llvm-project/commit/0674f2ec96422131abde0c042fbf2c11267db210.diff
> >
> > LOG: [NFC] Fix warning on no return after switch.
> >
> > Added:
> >
> >
> > Modified:
> >     clang/lib/CodeGen/CGHLSLRuntime.cpp
> >
> > Removed:
> >
> >
> >
> > ################################################################################
> > diff  --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp 
> > b/clang/lib/CodeGen/CGHLSLRuntime.cpp
> > index 7a80dedb8133..6f32136b49de 100644
> > --- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
> > +++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
> > @@ -270,6 +270,7 @@ 
> > castResourceShapeToResourceKind(HLSLResourceAttr::ResourceKind RK) {
> >        static_cast<uint32_t>(
> >            HLSLResourceAttr::ResourceKind::FeedbackTexture2DArray) ==
> >        (static_cast<uint32_t>(llvm::hlsl::ResourceKind::NumEntries) - 2));
> > +  return llvm::hlsl::ResourceKind::Invalid;
> >  }
> >
> >  void CGHLSLRuntime::annotateHLSLResource(const VarDecl *D, GlobalVariable 
> > *GV) {
> >
> >
> >
> > _______________________________________________
> > cfe-commits mailing list
> > [email protected]
> > https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to