[clang] [SemaHLSL] Verify assignment of local resources (PR #176793)

Deric C. via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 19 11:16:52 PST 2026


================
@@ -4412,14 +4440,37 @@ bool SemaHLSL::CheckResourceBinOp(BinaryOperatorKind Opc, Expr *LHSExpr,
   while (auto *ASE = dyn_cast<ArraySubscriptExpr>(E))
     E = ASE->getBase()->IgnoreParenImpCasts();
 
+  auto RHSBinding = GetGlobalBinding(RHSExpr);
+  if (!RHSBinding) {
+    SemaRef.Diag(Loc, diag::err_hlsl_assigning_local_resource_is_not_unique)
+        << RHSExpr;
+    return false;
+  }
+
   // Report error if LHS is a non-static resource declared at a global scope.
   if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E->IgnoreParens())) {
     if (VarDecl *VD = dyn_cast<VarDecl>(DRE->getDecl())) {
-      if (VD->hasGlobalStorage() && VD->getStorageClass() != SC_Static) {
-        // assignment to global resource is not allowed
-        SemaRef.Diag(Loc, diag::err_hlsl_assign_to_global_resource) << VD;
-        SemaRef.Diag(VD->getLocation(), diag::note_var_declared_here) << VD;
-        return false;
+      if (VD->getStorageClass() != SC_Static) {
+        if (VD->hasGlobalStorage()) {
+          // assignment to global resource is not allowed
+          SemaRef.Diag(Loc, diag::err_hlsl_assign_to_global_resource) << VD;
+          SemaRef.Diag(VD->getLocation(), diag::note_var_declared_here) << VD;
+          return false;
+        }
+
+        // Ensure assignment to a non-static local resource does not conflict
+        // with previous assignments to global resources
+        const DeclBindingInfo *LHSBinding = LocalResourceBindings[VD];
+        if (!LHSBinding) {
+          // occurs when local resource was instantiated without an expression
----------------
Icohedron wrote:

nit
```suggestion
          // LHSBinding is a nullptr when the local resource is instantiated without an expression.
```

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


More information about the cfe-commits mailing list