llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

<details>
<summary>Changes</summary>

There's a problem with this attribute where the declaration in a header file 
doesn't have the attribute, but the definition in the source file has. As a 
result, the attribute doesn't take effect when just the header file is included.

This is a WIP patch to address this problem and emit a warning for it. I'm not 
sure if this is the best place to do it. As discussed with @<!-- 
-->AaronBallman on Discord, it can't be done in `Sema::MergeFunctionDecl()`, 
because this is a late parsed attribute and they aren't available yet when we 
merge the decl.

---
Full diff: https://github.com/llvm/llvm-project/pull/67520.diff


1 Files Affected:

- (modified) clang/lib/Parse/Parser.cpp (+12) 


``````````diff
diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp
index dda1dbaa0c21aa9..befdb43ca4c00ee 100644
--- a/clang/lib/Parse/Parser.cpp
+++ b/clang/lib/Parse/Parser.cpp
@@ -1484,6 +1484,18 @@ Decl *Parser::ParseFunctionDefinition(ParsingDeclarator 
&D,
   if (LateParsedAttrs)
     ParseLexedAttributeList(*LateParsedAttrs, Res, false, true);
 
+  if (Res) {
+    for (const auto *FD : Res->redecls()) {
+      if (FD == Res)
+        continue;
+      if (Res->hasAttr<RequiresCapabilityAttr>() &&
+          !FD->hasAttr<RequiresCapabilityAttr>()) {
+        // Definition has attribute, but the declaration doesn't.
+        llvm::errs() << "AHA!\n";
+      }
+    }
+  }
+
   return ParseFunctionStatementBody(Res, BodyScope);
 }
 

``````````

</details>


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

Reply via email to