https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/67520
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. >From 080796647c91bfd76f4cbb5a26b08bdb65104330 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbae...@redhat.com> Date: Wed, 27 Sep 2023 09:11:21 +0200 Subject: [PATCH] [clang] WIP: Warn on mismatched RequiresCapability attributes --- clang/lib/Parse/Parser.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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); } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits