[clang] [HLSL] Add testing for space parameter on global constants (PR #106782)

Damyan Pepper via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 30 19:52:20 PDT 2024


================
@@ -795,6 +796,9 @@ static void DiagnoseHLSLRegisterAttribute(Sema &S, SourceLocation &ArgLoc,
         S.Diag(ArgLoc, diag::warn_hlsl_deprecated_register_type_b);
       else if (regType != RegisterType::C)
         S.Diag(ArgLoc, diag::err_hlsl_binding_type_mismatch) << regTypeNum;
+      // Space argument cannot be specified for global constants
+      if (AL.getNumArgs() == 2)
+        S.Diag(ArgLoc, diag::err_hlsl_space_on_global_constant);
----------------
damyanp wrote:

Rather than checking for this diagnostic in two places, if you add this just before the call to `ValidateMultipleRegisterAnnotations` then the tests still pass:

```c++
  // Space argument cannot be specified for global constants
  if ((Flags.DefaultGlobals || Flags.UDT) && AL.getNumArgs() == 2) {
    S.Diag(ArgLoc, diag::err_hlsl_space_on_global_constant);
    return;
  }
```

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


More information about the cfe-commits mailing list