[OptTable] Fix typo VALUE => VALUES (NFCI) (#121523)
[llvm-project.git] / clang / unittests / Tooling / RecursiveASTVisitorTests / Attr.cpp
blob7693e77236b0c4c726dcb8d8a178d216b457f408
1 //===- unittest/Tooling/RecursiveASTVisitorTests/Attr.cpp -----------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "CRTPTestVisitor.h"
11 using namespace clang;
13 namespace {
15 // Check to ensure that attributes and expressions within them are being
16 // visited.
17 class AttrVisitor : public CRTPExpectedLocationVisitor<AttrVisitor> {
18 public:
19 bool VisitMemberExpr(MemberExpr *ME) {
20 Match(ME->getMemberDecl()->getNameAsString(), ME->getBeginLoc());
21 return true;
23 bool VisitAttr(Attr *A) {
24 Match("Attr", A->getLocation());
25 return true;
27 bool VisitGuardedByAttr(GuardedByAttr *A) {
28 Match("guarded_by", A->getLocation());
29 return true;
33 TEST(RecursiveASTVisitor, AttributesAreVisited) {
34 AttrVisitor Visitor;
35 Visitor.ExpectMatch("Attr", 4, 24);
36 Visitor.ExpectMatch("guarded_by", 4, 24);
37 Visitor.ExpectMatch("mu1", 4, 35);
38 Visitor.ExpectMatch("Attr", 5, 29);
39 Visitor.ExpectMatch("mu1", 5, 54);
40 Visitor.ExpectMatch("mu2", 5, 59);
41 EXPECT_TRUE(Visitor.runOver(
42 "class Foo {\n"
43 " int mu1;\n"
44 " int mu2;\n"
45 " int a __attribute__((guarded_by(mu1)));\n"
46 " void bar() __attribute__((exclusive_locks_required(mu1, mu2)));\n"
47 "};\n"));
50 } // end anonymous namespace