================
@@ -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
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to