================
@@ -4620,6 +4620,205 @@ bool SemaHLSL::transformInitList(const 
InitializedEntity &Entity,
   return true;
 }
 
+QualType SemaHLSL::CheckMatrixComponent(Sema &S, QualType baseType,
+                                        ExprValueKind &VK, SourceLocation 
OpLoc,
+                                        const IdentifierInfo *CompName,
+                                        SourceLocation CompLoc) {
+  const auto *MT = baseType->getAs<ConstantMatrixType>();
+  StringRef AccessorName = CompName->getName();
+  assert(MT &&
+         "CheckMatrixComponent is intended to be used on ConstantMatrixType");
+  assert(!AccessorName.empty() && "Matrix Accessor must have a name");
+
+  unsigned Rows = MT->getNumRows();
+  unsigned Cols = MT->getNumColumns();
+  bool IsZeroBasedAccessor = false;
+  unsigned ChunkLen = 0;
+  if (AccessorName.size() < 2) {
+    const char Expected[] = "length 4 for zero based: \'_mRC\' or length 3 for 
"
+                            "one-based: \'_RC\' accessor";
+    S.Diag(OpLoc, diag::err_builtin_matrix_invalid_member)
+        << CompName->getName() << StringRef(Expected, sizeof(Expected) - 1)
+        << SourceRange(CompLoc);
+    return QualType();
+  }
+  if (AccessorName[0] == '_' && AccessorName[1] == 'm') {
+    IsZeroBasedAccessor = true; // zero-based: 00..33
+    ChunkLen = 4;               // zero-based: "_mRC"
+  } else if (AccessorName[0] == '_')
+    // one-based: 11..44
+    ChunkLen = 3; // one-based: "_RC"
+  else {
+    const char Expected[] =
+        "zero based: \'_mRC\' or one-based: \'_RC\' accessor";
+    S.Diag(OpLoc, diag::err_builtin_matrix_invalid_member)
+        << CompName->getName() << StringRef(Expected, sizeof(Expected) - 1)
+        << SourceRange(CompLoc);
+    return QualType();
+  }
+
+  if (IsZeroBasedAccessor && AccessorName.size() < 4) {
+    const char Expected[] = "zero based: \'_mRC\' accessor";
+    S.Diag(OpLoc, diag::err_builtin_matrix_invalid_member)
+        << CompName->getName() << StringRef(Expected, sizeof(Expected) - 1)
+        << SourceRange(CompLoc);
+    return QualType();
+  }
+
+  if (AccessorName.size() < 3) {
+    const char Expected[] = "one-based: \'_RC\' accessor";
+    S.Diag(OpLoc, diag::err_builtin_matrix_invalid_member)
+        << CompName->getName() << StringRef(Expected, sizeof(Expected) - 1)
+        << SourceRange(CompLoc);
+    return QualType();
+  }
+
+  auto isDigit = [](char c) { return c >= '0' && c <= '9'; };
+  auto isZeroBasedIndex = [](int i) { return i >= 0 && i <= 3; };
+  auto isOneBasedIndex = [](int i) { return i >= 1 && i <= 4; };
----------------
hekota wrote:

```suggestion
  auto isZeroBasedIndex = [](unsigned i) { return i <= 3; };
  auto isOneBasedIndex = [](unsigned i) { return i >= 1 && i <= 4; };
```
These are only called with `unsigned`.

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

Reply via email to