================
@@ -551,24 +541,21 @@ getHLSLResourceAttrFromEitherDecl(VarDecl *VD,
 
     // the resource attr could be on the record decl itself or on one of
     // its fields (the resource handle, most commonly)
-    const auto *Attr = TheRecordDecl->getAttr<HLSLResourceAttr>();
+    const auto *Attr = TheRecordDecl->getAttr<T>();
     if (!Attr) {
       for (auto *FD : TheRecordDecl->fields()) {
-        Attr = FD->getAttr<HLSLResourceAttr>();
+        Attr = FD->getAttr<T>();
         if (Attr)
           break;
       }
     }
     return Attr;
-  } else if (CBufferOrTBuffer) {
-    const auto *Attr = CBufferOrTBuffer->getAttr<HLSLResourceAttr>();
-    return Attr;
   }
-  llvm_unreachable("one of the two conditions should be true.");
+  llvm_unreachable("VD should not be null");
   return nullptr;
 }
 
-void traverseType(QualType TheQualTy, RegisterBindingFlags &Flags) {
+static void setFlagsFromType(QualType TheQualTy, RegisterBindingFlags &Flags) {
----------------
damyanp wrote:

For someone calling the function - even the highest-level call - they need to 
know that it is up to them to initialize the Flags parameter.  That's because 
this function only updates the Flags, it doesn't set them.  

If you want to come up with something that'll help people fall into a pit of 
success you could consider something like:

```c++
static void updateFlagsFromType(QualType TheQualTy, RegisterBindingFlags& Ty) { 
... }

RegisterBindingFlags getRegisterBindingFlagsFromType(QualType TheQualTy) {
  RegisterBindingFlags Flags{};
  updateFlagsFromType(TheQualTy, Flags);
  return Flags;
}
```

But as it is now, calling something that modifies a parameter without 
overwriting all of it "set" is misleading.

https://github.com/llvm/llvm-project/pull/97103
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to