Skip to content

Commit a3a8a41

Browse files
authored
Merge branch 'llvm:main' into otherwise-clause
2 parents 5efa687 + cca0f81 commit a3a8a41

File tree

149 files changed

+5925
-1722
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

149 files changed

+5925
-1722
lines changed

clang-tools-extra/clang-query/Query.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ bool MatchQuery::run(llvm::raw_ostream &OS, QuerySession &QS) const {
114114
Profiler.emplace();
115115

116116
for (auto &AST : QS.ASTs) {
117-
ast_matchers::MatchFinderOptions FinderOptions;
117+
ast_matchers::MatchFinder::MatchFinderOptions FinderOptions;
118118
std::optional<llvm::StringMap<llvm::TimeRecord>> Records;
119119
if (QS.EnableProfile) {
120120
Records.emplace();

clang-tools-extra/clang-tidy/ClangTidy.cpp

+1-5
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ ClangTidyASTConsumerFactory::createASTConsumer(
420420
std::vector<std::unique_ptr<ClangTidyCheck>> Checks =
421421
CheckFactories->createChecksForLanguage(&Context);
422422

423-
ast_matchers::MatchFinderOptions FinderOptions;
423+
ast_matchers::MatchFinder::MatchFinderOptions FinderOptions;
424424

425425
std::unique_ptr<ClangTidyProfiling> Profiling;
426426
if (Context.getEnableProfiling()) {
@@ -429,10 +429,6 @@ ClangTidyASTConsumerFactory::createASTConsumer(
429429
FinderOptions.CheckProfiling.emplace(Profiling->Records);
430430
}
431431

432-
// Avoid processing system headers, unless the user explicitly requests it
433-
if (!Context.getOptions().SystemHeaders.value_or(false))
434-
FinderOptions.SkipSystemHeaders = true;
435-
436432
std::unique_ptr<ast_matchers::MatchFinder> Finder(
437433
new ast_matchers::MatchFinder(std::move(FinderOptions)));
438434

clang-tools-extra/clang-tidy/cert/DontModifyStdNamespaceCheck.cpp

+5-27
Original file line numberDiff line numberDiff line change
@@ -35,41 +35,19 @@ AST_POLYMORPHIC_MATCHER_P(
3535
Builder) != Args.end();
3636
}
3737

38-
bool isStdOrPosixImpl(const DeclContext *Ctx) {
39-
if (!Ctx->isNamespace())
40-
return false;
41-
42-
const auto *ND = cast<NamespaceDecl>(Ctx);
43-
if (ND->isInline()) {
44-
return isStdOrPosixImpl(ND->getParent());
45-
}
46-
47-
if (!ND->getParent()->getRedeclContext()->isTranslationUnit())
48-
return false;
49-
50-
const IdentifierInfo *II = ND->getIdentifier();
51-
return II && (II->isStr("std") || II->isStr("posix"));
52-
}
53-
54-
AST_MATCHER(Decl, isInStdOrPosixNS) {
55-
for (const auto *Ctx = Node.getDeclContext(); Ctx; Ctx = Ctx->getParent()) {
56-
if (isStdOrPosixImpl(Ctx))
57-
return true;
58-
}
59-
return false;
60-
}
61-
6238
} // namespace
6339

6440
namespace clang::tidy::cert {
6541

6642
void DontModifyStdNamespaceCheck::registerMatchers(MatchFinder *Finder) {
6743
auto HasStdParent =
6844
hasDeclContext(namespaceDecl(hasAnyName("std", "posix"),
69-
unless(hasDeclContext(namespaceDecl())))
45+
unless(hasParent(namespaceDecl())))
7046
.bind("nmspc"));
71-
auto UserDefinedType = qualType(hasUnqualifiedDesugaredType(
72-
tagType(unless(hasDeclaration(tagDecl(isInStdOrPosixNS()))))));
47+
auto UserDefinedType = qualType(
48+
hasUnqualifiedDesugaredType(tagType(unless(hasDeclaration(tagDecl(
49+
hasAncestor(namespaceDecl(hasAnyName("std", "posix"),
50+
unless(hasParent(namespaceDecl()))))))))));
7351
auto HasNoProgramDefinedTemplateArgument = unless(
7452
hasAnyTemplateArgumentIncludingPack(refersToType(UserDefinedType)));
7553
auto InsideStdClassOrClassTemplateSpecialization = hasDeclContext(

clang-tools-extra/clangd/HeaderSourceSwitch.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ std::optional<Path> getCorrespondingHeaderOrSource(
2222
PathRef OriginalFile, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS) {
2323
llvm::StringRef SourceExtensions[] = {".cpp", ".c", ".cc", ".cxx",
2424
".c++", ".m", ".mm"};
25-
llvm::StringRef HeaderExtensions[] = {".h", ".hh", ".hpp", ".hxx", ".inc"};
25+
llvm::StringRef HeaderExtensions[] = {".h", ".hh", ".hpp", ".hxx",
26+
".inc", ".cppm", ".ccm", ".cxxm",
27+
".c++m", ".ixx"};
2628

2729
llvm::StringRef PathExt = llvm::sys::path::extension(OriginalFile);
2830

clang-tools-extra/clangd/unittests/HeaderSourceSwitchTests.cpp

+38
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,44 @@ TEST(HeaderSourceSwitchTest, FileHeuristic) {
7676
EXPECT_FALSE(PathResult.has_value());
7777
}
7878

79+
TEST(HeaderSourceSwitchTest, ModuleInterfaces) {
80+
MockFS FS;
81+
82+
auto FooCC = testPath("foo.cc");
83+
auto FooCPPM = testPath("foo.cppm");
84+
FS.Files[FooCC];
85+
FS.Files[FooCPPM];
86+
std::optional<Path> PathResult =
87+
getCorrespondingHeaderOrSource(FooCC, FS.view(std::nullopt));
88+
EXPECT_TRUE(PathResult.has_value());
89+
ASSERT_EQ(*PathResult, FooCPPM);
90+
91+
auto Foo2CPP = testPath("foo2.cpp");
92+
auto Foo2CCM = testPath("foo2.ccm");
93+
FS.Files[Foo2CPP];
94+
FS.Files[Foo2CCM];
95+
PathResult = getCorrespondingHeaderOrSource(Foo2CPP, FS.view(std::nullopt));
96+
EXPECT_TRUE(PathResult.has_value());
97+
ASSERT_EQ(*PathResult, Foo2CCM);
98+
99+
auto Foo3CXX = testPath("foo3.cxx");
100+
auto Foo3CXXM = testPath("foo3.cxxm");
101+
FS.Files[Foo3CXX];
102+
FS.Files[Foo3CXXM];
103+
PathResult = getCorrespondingHeaderOrSource(Foo3CXX, FS.view(std::nullopt));
104+
EXPECT_TRUE(PathResult.has_value());
105+
ASSERT_EQ(*PathResult, Foo3CXXM);
106+
107+
auto Foo4CPLUSPLUS = testPath("foo4.c++");
108+
auto Foo4CPLUSPLUSM = testPath("foo4.c++m");
109+
FS.Files[Foo4CPLUSPLUS];
110+
FS.Files[Foo4CPLUSPLUSM];
111+
PathResult =
112+
getCorrespondingHeaderOrSource(Foo4CPLUSPLUS, FS.view(std::nullopt));
113+
EXPECT_TRUE(PathResult.has_value());
114+
ASSERT_EQ(*PathResult, Foo4CPLUSPLUSM);
115+
}
116+
79117
MATCHER_P(declNamed, Name, "") {
80118
if (const NamedDecl *ND = dyn_cast<NamedDecl>(arg))
81119
if (ND->getQualifiedNameAsString() == Name)

clang-tools-extra/docs/ReleaseNotes.rst

-6
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,6 @@ Improvements to clang-query
9191
Improvements to clang-tidy
9292
--------------------------
9393

94-
- :program:`clang-tidy` no longer processes declarations from system headers
95-
by default, greatly improving performance. This behavior is disabled if the
96-
`SystemHeaders` option is enabled.
97-
Note: this may lead to false negatives; downstream users may need to adjust
98-
their checks to preserve existing behavior.
99-
10094
- Improved :program:`clang-tidy-diff.py` script. Add the `-warnings-as-errors`
10195
argument to treat warnings as errors.
10296

clang-tools-extra/test/clang-doc/DR-131697.cpp

+5-7
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@ int main() {
1313
}
1414

1515
//--- compile_commands.json
16-
[
17-
{
18-
"directory": "foo",
19-
"file":"main.cpp",
20-
"command":"clang main.cpp -c"
21-
}
22-
]
16+
[{
17+
"directory" : "foo",
18+
"file" : "main.cpp",
19+
"command" : "clang main.cpp -c"
20+
}]
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
#include "Calculator.h"
22

33
int Calculator::add(int a, int b) {
4-
return a + b;
4+
return a + b;
55
}
66

77
int Calculator::subtract(int a, int b) {
8-
return a - b;
8+
return a - b;
99
}
1010

1111
int Calculator::multiply(int a, int b) {
12-
return a * b;
12+
return a * b;
1313
}
1414

1515
double Calculator::divide(int a, int b) {
16-
return static_cast<double>(a) / b;
16+
return static_cast<double>(a) / b;
1717
}

clang-tools-extra/test/clang-doc/Inputs/basic-project/src/Circle.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
Circle::Circle(double radius) : radius_(radius) {}
44

55
double Circle::area() const {
6-
return 3.141 * radius_ * radius_;
6+
return 3.141 * radius_ * radius_;
77
}
88

99
double Circle::perimeter() const {
10-
return 3.141 * radius_;
10+
return 3.141 * radius_;
1111
}
12-
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#include "Rectangle.h"
22

33
Rectangle::Rectangle(double width, double height)
4-
: width_(width), height_(height) {}
4+
: width_(width), height_(height) {}
55

66
double Rectangle::area() const {
7-
return width_ * height_;
7+
return width_ * height_;
88
}
99

1010
double Rectangle::perimeter() const {
11-
return 2 * (width_ + height_);
11+
return 2 * (width_ + height_);
1212
}

clang-tools-extra/test/clang-doc/enum.cpp

+31-37
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,15 @@
1414
// RUN: FileCheck %s < %t/Vehicles/index.md --check-prefix=MD-VEHICLES-LINE
1515
// RUN: FileCheck %s < %t/Vehicles/index.md --check-prefix=MD-VEHICLES
1616

17-
1817
/**
1918
* @brief For specifying RGB colors
2019
*/
2120
enum Color {
22-
// MD-INDEX-LINE: *Defined at {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}enum.cpp#[[@LINE-1]]*
23-
// HTML-INDEX-LINE: <p>Defined at line [[@LINE-2]] of file {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}enum.cpp</p>
24-
Red, ///< Comment 1
21+
// MD-INDEX-LINE: *Defined at {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}enum.cpp#[[@LINE-1]]*
22+
// HTML-INDEX-LINE: <p>Defined at line [[@LINE-2]] of file {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}enum.cpp</p>
23+
Red, ///< Comment 1
2524
Green, ///< Comment 2
26-
Blue ///< Comment 3
25+
Blue ///< Comment 3
2726
};
2827

2928
// MD-INDEX: ## Enums
@@ -49,8 +48,8 @@ enum Color {
4948
* @brief Shape Types
5049
*/
5150
enum class Shapes {
52-
// MD-INDEX-LINE: *Defined at {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}enum.cpp#[[@LINE-1]]*
53-
// HTML-INDEX-LINE: <p>Defined at line [[@LINE-2]] of file {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}enum.cpp</p>
51+
// MD-INDEX-LINE: *Defined at {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}enum.cpp#[[@LINE-1]]*
52+
// HTML-INDEX-LINE: <p>Defined at line [[@LINE-2]] of file {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}enum.cpp</p>
5453

5554
/// Comment 1
5655
Circle,
@@ -77,22 +76,20 @@ enum class Shapes {
7776
// HTML-INDEX: <td>2</td>
7877
// HTML-INDEX: <p> Comment 3</p>
7978

80-
81-
8279
class Animals {
83-
// MD-ANIMAL-LINE: *Defined at {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}enum.cpp#[[@LINE-1]]*
84-
// HTML-ANIMAL-LINE: <p>Defined at line [[@LINE-2]] of file {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}enum.cpp</p>
80+
// MD-ANIMAL-LINE: *Defined at {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}enum.cpp#[[@LINE-1]]*
81+
// HTML-ANIMAL-LINE: <p>Defined at line [[@LINE-2]] of file {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}enum.cpp</p>
8582
public:
86-
/**
87-
* @brief specify what animal the class is
88-
*/
89-
enum AnimalType {
90-
// MD-ANIMAL-LINE: *Defined at {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}enum.cpp#[[@LINE-1]]*
91-
// HTML-ANIMAL-LINE: <p>Defined at line [[@LINE-2]] of file {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}enum.cpp</p>
92-
Dog, ///< Man's best friend
93-
Cat, ///< Man's other best friend
94-
Iguana ///< A lizard
95-
};
83+
/**
84+
* @brief specify what animal the class is
85+
*/
86+
enum AnimalType {
87+
// MD-ANIMAL-LINE: *Defined at {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}enum.cpp#[[@LINE-1]]*
88+
// HTML-ANIMAL-LINE: <p>Defined at line [[@LINE-2]] of file {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}enum.cpp</p>
89+
Dog, ///< Man's best friend
90+
Cat, ///< Man's other best friend
91+
Iguana ///< A lizard
92+
};
9693
};
9794

9895
// HTML-ANIMAL: <h1>class Animals</h1>
@@ -108,7 +105,6 @@ class Animals {
108105
// HTML-ANIMAL: <td>2</td>
109106
// HTML-ANIMAL: <p> A lizard</p>
110107

111-
112108
// MD-ANIMAL: # class Animals
113109
// MD-ANIMAL: ## Enums
114110
// MD-ANIMAL: | enum AnimalType |
@@ -118,21 +114,20 @@ class Animals {
118114
// MD-ANIMAL: | Iguana |
119115
// MD-ANIMAL: **brief** specify what animal the class is
120116

121-
122117
namespace Vehicles {
123-
/**
124-
* @brief specify type of car
125-
*/
126-
enum Car {
127-
// MD-VEHICLES-LINE: *Defined at {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}enum.cpp#[[@LINE-1]]*
128-
// HTML-VEHICLES-LINE: <p>Defined at line [[@LINE-2]] of file {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}enum.cpp</p>
129-
130-
Sedan, ///< Comment 1
131-
SUV, ///< Comment 2
132-
Pickup, ///< Comment 3
133-
Hatchback ///< Comment 4
134-
};
135-
}
118+
/**
119+
* @brief specify type of car
120+
*/
121+
enum Car {
122+
// MD-VEHICLES-LINE: *Defined at {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}enum.cpp#[[@LINE-1]]*
123+
// HTML-VEHICLES-LINE: <p>Defined at line [[@LINE-2]] of file {{.*}}clang-tools-extra{{[\/]}}test{{[\/]}}clang-doc{{[\/]}}enum.cpp</p>
124+
125+
Sedan, ///< Comment 1
126+
SUV, ///< Comment 2
127+
Pickup, ///< Comment 3
128+
Hatchback ///< Comment 4
129+
};
130+
} // namespace Vehicles
136131

137132
// MD-VEHICLES: # namespace Vehicles
138133
// MD-VEHICLES: ## Enums
@@ -159,7 +154,6 @@ namespace Vehicles {
159154
// HTML-VEHICLES: <td>3</td>
160155
// HTML-VEHICLES: <p> Comment 4</p>
161156

162-
163157
enum ColorUserSpecified {
164158
RedUserSpecified = 'A',
165159
GreenUserSpecified = 2,

0 commit comments

Comments
 (0)