[PATCH] D135595: [HLSL] Add utility to convert environment to stage

Chris Bieneman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 10 08:53:20 PDT 2022


beanz created this revision.
beanz added reviewers: aaron.ballman, MaskRay, klimek, python3kgae, pow2clk.
Herald added subscribers: Anastasia, StephenFan.
Herald added a project: All.
beanz requested review of this revision.
Herald added a project: clang.

We had a bunch of places in the code where we were translating triple
environment enum cases to shader stage enum cases. The order of these
enums needs to be kept in sync for the translation to be simple, but we
were not properly handling out-of-bounds cases.

In normal compilation out-of-bounds cases shouldn't be possible because
the driver errors if you don't have a valid shader environment set, but
in clang tooling that error doesn't get treated as fatal and parsing
continues. This can result in crashes in clang tooling for out-of-range
shader stages.

To address this, this patch adds a constexpr method to handle the
conversion which handles out-of-range values by converting them to
`Invalid`.

Since this new method is a constexpr, the tests for this are a group of
static_asserts in the implementation file that verifies the correct
conversion for each valid enum case and validates that other cases are
converted to `Invalid`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135595

Files:
  clang/include/clang/Basic/HLSLRuntime.h
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D135595.466519.patch
Type: text/x-patch
Size: 6895 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221010/5cd0a81b/attachment-0001.bin>


More information about the cfe-commits mailing list