Skip to content

Commit 48045c8

Browse files
[clang] Make 'fileScopeAsmDecl' matcher public
1 parent d50476b commit 48045c8

File tree

6 files changed

+27
-8
lines changed

6 files changed

+27
-8
lines changed

clang-tools-extra/clang-tidy/hicpp/NoAssemblerCheck.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,10 @@ using namespace clang::ast_matchers;
1313

1414
namespace clang::tidy::hicpp {
1515

16-
namespace {
17-
AST_MATCHER(VarDecl, isAsm) { return Node.hasAttr<clang::AsmLabelAttr>(); }
18-
const ast_matchers::internal::VariadicDynCastAllOfMatcher<Decl,
19-
FileScopeAsmDecl>
20-
fileScopeAsmDecl; // NOLINT(readability-identifier-*) preserve clang style
21-
} // namespace
22-
2316
void NoAssemblerCheck::registerMatchers(MatchFinder *Finder) {
2417
Finder->addMatcher(asmStmt().bind("asm-stmt"), this);
2518
Finder->addMatcher(fileScopeAsmDecl().bind("asm-file-scope"), this);
26-
Finder->addMatcher(varDecl(isAsm()).bind("asm-var"), this);
19+
Finder->addMatcher(varDecl(hasAttr(attr::AsmLabel)).bind("asm-var"), this);
2720
}
2821

2922
void NoAssemblerCheck::check(const MatchFinder::MatchResult &Result) {

clang/docs/LibASTMatchersReference.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,15 @@ <h2 id="decl-matchers">Node Matchers</h2>
825825
</pre></td></tr>
826826

827827

828+
<tr><td>Matcher&lt;<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>&gt;</td><td class="name" onclick="toggle('fileScopeAsmDecl0')"><a name="fileScopeAsmDecl0Anchor">fileScopeAsmDecl</a></td><td>Matcher&lt;<a href="https://clang.llvm.org/doxygen/classclang_1_1FileScopeAsmDecl.html">FileScopeAsmDecl</a>&gt;...</td></tr>
829+
<tr><td colspan="4" class="doc" id="fileScopeAsmDecl0"><pre>Matches top level asm declarations.
830+
831+
__asm__("nop");
832+
fileScopeAsmDecl()
833+
matches '__asm__("nop")'
834+
</pre></td></tr>
835+
836+
828837
<tr><td>Matcher&lt;<a href="https://clang.llvm.org/doxygen/classclang_1_1Decl.html">Decl</a>&gt;</td><td class="name" onclick="toggle('friendDecl0')"><a name="friendDecl0Anchor">friendDecl</a></td><td>Matcher&lt;<a href="https://clang.llvm.org/doxygen/classclang_1_1FriendDecl.html">FriendDecl</a>&gt;...</td></tr>
829838
<tr><td colspan="4" class="doc" id="friendDecl0"><pre>Matches friend declarations.
830839

clang/include/clang/ASTMatchers/ASTMatchers.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2478,6 +2478,16 @@ extern const internal::VariadicDynCastAllOfMatcher<Stmt, NullStmt> nullStmt;
24782478
/// matches '__asm("mov al, 2")'
24792479
extern const internal::VariadicDynCastAllOfMatcher<Stmt, AsmStmt> asmStmt;
24802480

2481+
/// Matches top level asm declarations.
2482+
///
2483+
/// \code
2484+
/// __asm__("nop");
2485+
/// \endcode
2486+
/// fileScopeAsmDecl()
2487+
/// matches '__asm__("nop")'
2488+
extern const internal::VariadicDynCastAllOfMatcher<Decl, FileScopeAsmDecl>
2489+
fileScopeAsmDecl;
2490+
24812491
/// Matches bool literals.
24822492
///
24832493
/// Example matches true

clang/lib/ASTMatchers/ASTMatchersInternal.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,8 @@ const internal::VariadicDynCastAllOfMatcher<Stmt, CXXTryStmt> cxxTryStmt;
954954
const internal::VariadicDynCastAllOfMatcher<Stmt, CXXThrowExpr> cxxThrowExpr;
955955
const internal::VariadicDynCastAllOfMatcher<Stmt, NullStmt> nullStmt;
956956
const internal::VariadicDynCastAllOfMatcher<Stmt, AsmStmt> asmStmt;
957+
const internal::VariadicDynCastAllOfMatcher<Decl, FileScopeAsmDecl>
958+
fileScopeAsmDecl;
957959
const internal::VariadicDynCastAllOfMatcher<Stmt, CXXBoolLiteralExpr>
958960
cxxBoolLiteral;
959961
const internal::VariadicDynCastAllOfMatcher<Stmt, StringLiteral> stringLiteral;

clang/lib/ASTMatchers/Dynamic/Registry.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ RegistryMaps::RegistryMaps() {
246246
REGISTER_MATCHER(expr);
247247
REGISTER_MATCHER(exprWithCleanups);
248248
REGISTER_MATCHER(fieldDecl);
249+
REGISTER_MATCHER(fileScopeAsmDecl);
249250
REGISTER_MATCHER(fixedPointLiteral);
250251
REGISTER_MATCHER(floatLiteral);
251252
REGISTER_MATCHER(forCallable);

clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,6 +1179,10 @@ TEST_P(ASTMatchersTest, PredefinedExpr) {
11791179
has(stringLiteral()))));
11801180
}
11811181

1182+
TEST_P(ASTMatchersTest, FileScopeAsmDecl) {
1183+
EXPECT_TRUE(matches("__asm__(\"nop\");", fileScopeAsmDecl()));
1184+
}
1185+
11821186
TEST_P(ASTMatchersTest, AsmStatement) {
11831187
EXPECT_TRUE(matches("void foo() { __asm(\"mov al, 2\"); }", asmStmt()));
11841188
}

0 commit comments

Comments
 (0)