[clang] 0674f2e - [NFC] Fix warning on no return after switch.

stan li via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 17 17:52:22 PDT 2022


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:dblaikie at gmail.com>
Sent: Monday, October 17, 2022 5:42 PM
To: Xiang Li<mailto:python3kgae at outlook.com>; Xiang Li<mailto:llvmlistbot at llvm.org>
Cc: cfe-commits at lists.llvm.org<mailto: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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221018/83db7b91/attachment.html>


More information about the cfe-commits mailing list