[clang] Implement resource binding type prefix mismatch diagnostic infrastructure (PR #97103)

Damyan Pepper via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 9 16:59:40 PDT 2024


================
@@ -635,46 +626,52 @@ RegisterBindingFlags HLSLFillRegisterBindingFlags(Sema &S, Decl *D) {
       } else
         r.Other = true;
     }
-  } else {
-    llvm_unreachable("unknown decl type");
   }
   return r;
 }
 
+int getRegisterTypeIndex(StringRef Slot) {
+  switch (Slot[0]) {
+  case 't':
+    return 0;
+  case 'u':
+    return 1;
+  case 'b':
+    return 2;
+  case 's':
+    return 3;
+  case 'c':
+    return 4;
+  case 'i':
+    return 5;
+  default:
+    llvm_unreachable("invalid register type");
+  }
+}
+
 static void ValidateMultipleRegisterAnnotations(Sema &S, Decl *D,
                                                 StringRef &Slot) {
-  // make sure that there are no register annotations applied to the decl
-  // with the same register type but different numbers
-  std::unordered_map<char, std::set<char>>
-      s; // store unique register type + numbers
-  std::set<char> starting_set = {Slot[1]};
-  s.insert(std::make_pair(Slot[0], starting_set));
+  // make sure that there are no tworegister annotations
+  // applied to the decl with the same register type
+  bool registerTypesDetectedCount[6];
+  for (int i = 0; i < 6; i++)
+    registerTypesDetectedCount[i] = false;
+  registerTypesDetectedCount[getRegisterTypeIndex(Slot)] = true;
+
   for (auto it = D->attr_begin(); it != D->attr_end(); ++it) {
     if (HLSLResourceBindingAttr *attr =
             dyn_cast<HLSLResourceBindingAttr>(*it)) {
       std::string otherSlot(attr->getSlot().data());
----------------
damyanp wrote:

Do we really need to construct a `std::string` here?

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


More information about the cfe-commits mailing list