================
@@ -209,6 +202,13 @@ inline bool isValidParameterType(uint32_t V) {
   return false;
 }
 
+inline bool isValidRangeType(uint32_t V) {
+  static_assert(llvm::to_underlying(dxil::ResourceClass::Sampler) == 3,
+                "dxil::ResourceClass numeric values must match the Root "
+                "Signature values associated to each class.");
+  return V <= llvm::to_underlying(dxil::ResourceClass::Sampler);
----------------
bogner wrote:

I don't think this assert really captures what you want it to here - if we were 
to add another value to `ResourceClass` after `Sampler` this would still be 
fine but the `<=` check wouldn't be correct any more. Similarly, if we 
reordered `SRV` and `UAV` for some reason this wouldn't detect it.

A better way to do this would probably be to add a `LastEntry` to 
`ResourceClass` that aliases `Sampler`, that is:
```c++
enum class ResourceClass : uint8_t {
  SRV = 0,
  UAV,
  CBuffer,
  Sampler,
  LastEntry = Sampler,
};
```

Then we can just check `V <= 
llvm::to_underlying(dxil::ResourceClass::LastEntry)` here and we don't need an 
assert to sanity check the enum. Note that `-Wcovered-switch` will be fine with 
this, since the value is indeed covered by the "Sampler" case.

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

Reply via email to