-
Notifications
You must be signed in to change notification settings - Fork 14.5k
Match against all plugins when parsing microsoft attributes #86426
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
apache-hb
wants to merge
8
commits into
llvm:main
Choose a base branch
from
apache-hb:ms-plugin-spelling
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
245a215
Match against all plugins when parsing microsoft attributes
apache-hb 4e47899
Apply formatting
apache-hb 8adb5bc
use hasAttribute instead of ParsedAttrInfo::get
apache-hb b3f297e
Update ReleaseNotes.rst
apache-hb 1b4823b
add test for custom microsoft attributes
apache-hb 82ef047
fix failing test
apache-hb 6ba913f
Update clang/docs/ReleaseNotes.rst
apache-hb fb6755e
Apply clang format
apache-hb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
add_llvm_library(MicrosoftAttributes MODULE MicrosoftAttributes.cpp PLUGIN_TOOL clang) | ||
|
||
if(WIN32 OR CYGWIN) | ||
target_link_libraries(MicrosoftAttributes PRIVATE | ||
clangAST | ||
clangBasic | ||
clangFrontend | ||
clangLex | ||
LLVMSupport | ||
) | ||
endif() |
61 changes: 61 additions & 0 deletions
61
clang/examples/MicrosoftAttributes/MicrosoftAttributes.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
//===- Attribute.cpp ------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Example clang plugin which adds an an annotation to class declarations | ||
// with a microsoft style '[example]' attribute. | ||
// | ||
// This plugin is used by clang/test/Frontend/ms-attributes tests. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "clang/AST/ASTContext.h" | ||
#include "clang/AST/Attr.h" | ||
#include "clang/Sema/ParsedAttr.h" | ||
#include "clang/Sema/Sema.h" | ||
#include "clang/Sema/SemaDiagnostic.h" | ||
#include "llvm/IR/Attributes.h" | ||
|
||
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; | ||
} | ||
}; | ||
|
||
} // namespace | ||
|
||
static ParsedAttrInfoRegistry::Add<ExampleAttrInfo> Y("microsoft-example", ""); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// RUN: %clang -fplugin=%llvmshlibdir/MicrosoftAttributes%pluginext -fsyntax-only -fms-extensions -E %s | FileCheck %s | ||
// REQUIRES: plugins, examples | ||
// expected-no-diagnostics | ||
[ms_example] | ||
class C {}; | ||
// CHECK: AnnotateAttr{{.*}} "ms_example" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.