[clang] Implement resource binding type prefix mismatch errors (PR #87578)

Farzon Lotfi via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 15 10:35:13 PDT 2024


================
@@ -7367,8 +7367,72 @@ static void handleHLSLResourceBindingAttr(Sema &S, Decl *D,
     return;
   }
 
-  // FIXME: check reg type match decl. Issue
-  // https://github.com/llvm/llvm-project/issues/57886.
+  VarDecl *VD = dyn_cast<VarDecl>(D);
+  HLSLBufferDecl *BD = dyn_cast<HLSLBufferDecl>(D);
+
+  if (VD || BD) {
----------------
farzonl wrote:

just a small note to piggy back on Justin's There are Three changes I would like 1) spell out your variable names, VD,BD, RC don't really mean much when I'm reading the code and I find myself regularly looking what each of these are.

Secon if you end up splitting behavior maybe move the dyn_casts into the if statement like you do with TDecl on line 7386.

Third, try and reduce some of the conditional nesting you have.
for example if you did
```cpp
if(!VD) 
   return;
const Type *Ty = VD->getType()->getPointeeOrArrayElementType();
if (!Ty)
  return;
```
you would not need to do: 
```cpp
if(VD) {
  if(!TY)
    return;
```

Less layers of nesting improve readability. 

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


More information about the cfe-commits mailing list