[clang] 0674f2e - [NFC] Fix warning on no return after switch.
David Blaikie via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 17 18:10:26 PDT 2022
On Mon, Oct 17, 2022 at 5:52 PM stan li <python3kgae at outlook.com> wrote:
>
> 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.
Ah, OK - thanks for explaining!
>
>
>
>
>
>
>
> Sent from Mail for Windows
>
>
>
> From: David Blaikie
> Sent: Monday, October 17, 2022 5:42 PM
> To: Xiang Li; Xiang Li
> Cc: cfe-commits at lists.llvm.org
> 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 <dblaikie at gmail.com> 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
> > <cfe-commits at lists.llvm.org> 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
> > > cfe-commits at lists.llvm.org
> > > https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
>
More information about the cfe-commits
mailing list