[clang] Fix build break in SemaHLSL.cpp on MSVC 2022: warning C4715: 'getResourceClass': not all control paths return a value (PR #112767)

Daniel Paoliello via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 18 09:30:16 PDT 2024


================
@@ -102,6 +102,7 @@ static ResourceClass getResourceClass(RegisterType RT) {
     return ResourceClass::Sampler;
   case RegisterType::C:
   case RegisterType::I:
+  default:
     llvm_unreachable("unexpected RegisterType value");
   }
----------------
dpaoliello wrote:

> It sounds like line 107 will be impossible to hit.

Not impossible: someone can always cast an arbitrary value into the enum type, which is what MSVC is trying to guard against.

As a compromise we could keep the unreachable at the bottom, and then deliberately fall through to that in the unhandled cases:
```cpp
  case RegisterType::C:
  case RegisterType::I:
    // Deliberately falling through to the unreachable below.
    break;
  }
  llvm_unreachable("unexpected RegisterType value");
}
```

https://github.com/llvm/llvm-project/pull/112767


More information about the cfe-commits mailing list