[clang] Match against all plugins when parsing microsoft attributes (PR #86426)

via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 8 06:24:30 PDT 2024


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff 5d7fd6a04a6748936dece9d90481b2ba4ec97e53 6ba913fb0d3efdb17ae481ccad63ccde2170d4e2 -- clang/examples/MicrosoftAttributes/MicrosoftAttributes.cpp clang/test/Frontend/ms-attributes.cpp clang/lib/Parse/ParseDeclCXX.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/clang/examples/MicrosoftAttributes/MicrosoftAttributes.cpp b/clang/examples/MicrosoftAttributes/MicrosoftAttributes.cpp
index 571d6f8624..dd252f7d5b 100644
--- a/clang/examples/MicrosoftAttributes/MicrosoftAttributes.cpp
+++ b/clang/examples/MicrosoftAttributes/MicrosoftAttributes.cpp
@@ -25,34 +25,35 @@ using namespace clang;
 namespace {
 
 struct ExampleAttrInfo : public ParsedAttrInfo {
-    ExampleAttrInfo() {
-        // Can take up to 1 optional argument.
-        OptArgs = 1;
-
-        // Only Microsoft-style [ms_example] supported.
-        // e.g.:
-        // [ms_example] class C {};
-        // [ms_example] void f() {}
-        static constexpr Spelling S[] = {
-            {ParsedAttr::AS_Microsoft, "ms_example"}
-        };
-        Spellings = S;
-    }
-
-    bool diagAppertainsToDecl(Sema &S, const ParsedAttr &Attr, const Decl *D) const override {
-        // This attribute can be applied to any declaration.
-        if (!isa<CXXRecordDecl>(D)) {
-            S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type_str)
-                << Attr << Attr.isRegularKeywordAttribute() << "classes";
-        }
-        return true;
-    }
-
-    AttrHandling handleDeclAttribute(Sema &S, Decl *D, const ParsedAttr &Attr) const override {
-        // Add an annotation to the declaration.
-        D->addAttr(AnnotateAttr::Create(S.Context, "ms_example", nullptr, 0, Attr.getRange()));
-        return AttributeApplied;
+  ExampleAttrInfo() {
+    // Can take up to 1 optional argument.
+    OptArgs = 1;
+
+    // Only Microsoft-style [ms_example] supported.
+    // e.g.:
+    // [ms_example] class C {};
+    // [ms_example] void f() {}
+    static constexpr Spelling S[] = {{ParsedAttr::AS_Microsoft, "ms_example"}};
+    Spellings = S;
+  }
+
+  bool diagAppertainsToDecl(Sema &S, const ParsedAttr &Attr,
+                            const Decl *D) const override {
+    // This attribute can be applied to any declaration.
+    if (!isa<CXXRecordDecl>(D)) {
+      S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type_str)
+          << Attr << Attr.isRegularKeywordAttribute() << "classes";
     }
+    return true;
+  }
+
+  AttrHandling handleDeclAttribute(Sema &S, Decl *D,
+                                   const ParsedAttr &Attr) const override {
+    // Add an annotation to the declaration.
+    D->addAttr(AnnotateAttr::Create(S.Context, "ms_example", nullptr, 0,
+                                    Attr.getRange()));
+    return AttributeApplied;
+  }
 };
 
 } // namespace
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index 619f7f88bf..b323f053c4 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -5064,8 +5064,8 @@ void Parser::ParseMicrosoftAttributes(ParsedAttributes &Attrs) {
 
         // For HLSL we want to handle all attributes, but for MSVC compat, we
         // silently ignore unknown Microsoft attributes.
-        int Attr = hasAttribute(AttributeCommonInfo::Syntax::AS_Microsoft, nullptr,
-                                II, getTargetInfo(), getLangOpts());
+        int Attr = hasAttribute(AttributeCommonInfo::Syntax::AS_Microsoft,
+                                nullptr, II, getTargetInfo(), getLangOpts());
         if (getLangOpts().HLSL || Attr != 0) {
           bool AttrParsed = false;
           if (Tok.is(tok::l_paren)) {

``````````

</details>


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


More information about the cfe-commits mailing list