Skip to content

Commit ff50e60

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merged main:d5cad0550626 into amd-gfx:1b9a5a807978
Local branch amd-gfx 1b9a5a8 Merged main:247cc265e74e into amd-gfx:8b39e87bc826 Remote branch main d5cad05 [lldb] Remve old CODE_OWNERS.txt
2 parents 1b9a5a8 + d5cad05 commit ff50e60

Some content is hidden

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

44 files changed

+2591
-463
lines changed

clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ IncludeCleanerCheck::IncludeCleanerCheck(StringRef Name,
5555
ClangTidyContext *Context)
5656
: ClangTidyCheck(Name, Context),
5757
IgnoreHeaders(utils::options::parseStringList(
58-
Options.getLocalOrGlobal("IgnoreHeaders", ""))) {
58+
Options.getLocalOrGlobal("IgnoreHeaders", ""))),
59+
DeduplicateFindings(
60+
Options.getLocalOrGlobal("DeduplicateFindings", true)) {
5961
for (const auto &Header : IgnoreHeaders) {
6062
if (!llvm::Regex{Header}.isValid())
6163
configurationDiag("Invalid ignore headers regex '%0'") << Header;
@@ -69,6 +71,7 @@ IncludeCleanerCheck::IncludeCleanerCheck(StringRef Name,
6971
void IncludeCleanerCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
7072
Options.store(Opts, "IgnoreHeaders",
7173
utils::options::serializeStringList(IgnoreHeaders));
74+
Options.store(Opts, "DeduplicateFindings", DeduplicateFindings);
7275
}
7376

7477
bool IncludeCleanerCheck::isLanguageVersionSupported(
@@ -114,12 +117,26 @@ void IncludeCleanerCheck::check(const MatchFinder::MatchResult &Result) {
114117
// FIXME: Filter out implicit template specializations.
115118
MainFileDecls.push_back(D);
116119
}
120+
llvm::DenseSet<include_cleaner::Symbol> SeenSymbols;
117121
// FIXME: Find a way to have less code duplication between include-cleaner
118122
// analysis implementation and the below code.
119123
walkUsed(MainFileDecls, RecordedPreprocessor.MacroReferences, &RecordedPI,
120124
*SM,
121125
[&](const include_cleaner::SymbolReference &Ref,
122126
llvm::ArrayRef<include_cleaner::Header> Providers) {
127+
// Process each symbol once to reduce noise in the findings.
128+
// Tidy checks are used in two different workflows:
129+
// - Ones that show all the findings for a given file. For such
130+
// workflows there is not much point in showing all the occurences,
131+
// as one is enough to indicate the issue.
132+
// - Ones that show only the findings on changed pieces. For such
133+
// workflows it's useful to show findings on every reference of a
134+
// symbol as otherwise tools might give incosistent results
135+
// depending on the parts of the file being edited. But it should
136+
// still help surface findings for "new violations" (i.e.
137+
// dependency did not exist in the code at all before).
138+
if (DeduplicateFindings && !SeenSymbols.insert(Ref.Target).second)
139+
return;
123140
bool Satisfied = false;
124141
for (const include_cleaner::Header &H : Providers) {
125142
if (H.kind() == include_cleaner::Header::Physical &&

clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ class IncludeCleanerCheck : public ClangTidyCheck {
4444
include_cleaner::PragmaIncludes RecordedPI;
4545
HeaderSearch *HS;
4646
std::vector<StringRef> IgnoreHeaders;
47+
// Whether emit only one finding per usage of a symbol.
48+
const bool DeduplicateFindings;
4749
llvm::SmallVector<llvm::Regex> IgnoreHeadersRegex;
4850
bool shouldIgnore(const include_cleaner::Header &H);
4951
};

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,10 @@ Changes in existing checks
180180
<clang-tidy/checks/llvm/namespace-comment>` check to provide fixes for
181181
``inline`` namespaces in the same format as :program:`clang-format`.
182182

183+
- Improved :doc:`misc-include-cleaner
184+
<clang-tidy/checks/misc/include-cleaner>` check by adding option
185+
`DeduplicateFindings` to output one finding per symbol occurence.
186+
183187
- Improved :doc:`modernize-loop-convert
184188
<clang-tidy/checks/modernize/loop-convert>` to support for-loops with
185189
iterators initialized by free functions like ``begin``, ``end``, or ``size``.

clang-tools-extra/docs/clang-tidy/checks/misc/include-cleaner.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,8 @@ Options
3333
files that match this regex as a suffix. E.g., `foo/.*` disables
3434
insertion/removal for all headers under the directory `foo`. By default, no
3535
headers will be ignored.
36+
37+
.. option:: DeduplicateFindings
38+
39+
A boolean that controls whether the check should deduplicate findings for the
40+
same symbol. Defaults to `true`.

clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#include "llvm/Support/FormatVariadic.h"
1616
#include "llvm/Support/Path.h"
1717
#include "llvm/Support/Regex.h"
18+
#include "llvm/Testing/Annotations/Annotations.h"
19+
#include "gmock/gmock.h"
1820
#include "gtest/gtest.h"
1921
#include <initializer_list>
2022

@@ -108,6 +110,50 @@ int BazResult = baz();
108110
)"}}));
109111
}
110112

113+
TEST(IncludeCleanerCheckTest, DedupsMissingIncludes) {
114+
llvm::Annotations Code(R"(
115+
#include "baz.h" // IWYU pragma: keep
116+
117+
int BarResult1 = $diag1^bar();
118+
int BarResult2 = $diag2^bar();)");
119+
120+
{
121+
std::vector<ClangTidyError> Errors;
122+
runCheckOnCode<IncludeCleanerCheck>(Code.code(), &Errors, "file.cpp",
123+
std::nullopt, ClangTidyOptions(),
124+
{{"baz.h", R"(#pragma once
125+
#include "bar.h"
126+
)"},
127+
{"bar.h", R"(#pragma once
128+
int bar();
129+
)"}});
130+
ASSERT_THAT(Errors.size(), testing::Eq(1U));
131+
EXPECT_EQ(Errors.front().Message.Message,
132+
"no header providing \"bar\" is directly included");
133+
EXPECT_EQ(Errors.front().Message.FileOffset, Code.point("diag1"));
134+
}
135+
{
136+
std::vector<ClangTidyError> Errors;
137+
ClangTidyOptions Opts;
138+
Opts.CheckOptions.insert({"DeduplicateFindings", "false"});
139+
runCheckOnCode<IncludeCleanerCheck>(Code.code(), &Errors, "file.cpp",
140+
std::nullopt, Opts,
141+
{{"baz.h", R"(#pragma once
142+
#include "bar.h"
143+
)"},
144+
{"bar.h", R"(#pragma once
145+
int bar();
146+
)"}});
147+
ASSERT_THAT(Errors.size(), testing::Eq(2U));
148+
EXPECT_EQ(Errors.front().Message.Message,
149+
"no header providing \"bar\" is directly included");
150+
EXPECT_EQ(Errors.front().Message.FileOffset, Code.point("diag1"));
151+
EXPECT_EQ(Errors.back().Message.Message,
152+
"no header providing \"bar\" is directly included");
153+
EXPECT_EQ(Errors.back().Message.FileOffset, Code.point("diag2"));
154+
}
155+
}
156+
111157
TEST(IncludeCleanerCheckTest, SuppressMissingIncludes) {
112158
const char *PreCode = R"(
113159
#include "bar.h"

clang/include/clang/AST/StmtOpenMP.h

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,15 @@ class OMPExecutableDirective : public Stmt {
281281
return Data->getClauses();
282282
}
283283

284+
/// Was this directive mapped from an another directive?
285+
/// e.g. 1) omp loop bind(parallel) is mapped to OMPD_for
286+
/// 2) omp loop bind(teams) is mapped to OMPD_distribute
287+
/// 3) omp loop bind(thread) is mapped to OMPD_simd
288+
/// It was necessary to note it down in the Directive because of
289+
/// clang::TreeTransform::TransformOMPExecutableDirective() pass in
290+
/// the frontend.
291+
OpenMPDirectiveKind PrevMappedDirective = llvm::omp::OMPD_unknown;
292+
284293
protected:
285294
/// Data, associated with the directive.
286295
OMPChildren *Data = nullptr;
@@ -345,6 +354,10 @@ class OMPExecutableDirective : public Stmt {
345354
return Inst;
346355
}
347356

357+
void setMappedDirective(OpenMPDirectiveKind MappedDirective) {
358+
PrevMappedDirective = MappedDirective;
359+
}
360+
348361
public:
349362
/// Iterates over expressions/statements used in the construct.
350363
class used_clauses_child_iterator
@@ -598,6 +611,8 @@ class OMPExecutableDirective : public Stmt {
598611
"Expected directive with the associated statement.");
599612
return Data->getRawStmt();
600613
}
614+
615+
OpenMPDirectiveKind getMappedDirective() const { return PrevMappedDirective; }
601616
};
602617

603618
/// This represents '#pragma omp parallel' directive.
@@ -1604,7 +1619,8 @@ class OMPSimdDirective : public OMPLoopDirective {
16041619
SourceLocation EndLoc, unsigned CollapsedNum,
16051620
ArrayRef<OMPClause *> Clauses,
16061621
Stmt *AssociatedStmt,
1607-
const HelperExprs &Exprs);
1622+
const HelperExprs &Exprs,
1623+
OpenMPDirectiveKind ParamPrevMappedDirective);
16081624

16091625
/// Creates an empty directive with the place
16101626
/// for \a NumClauses clauses.
@@ -1682,7 +1698,8 @@ class OMPForDirective : public OMPLoopDirective {
16821698
SourceLocation EndLoc, unsigned CollapsedNum,
16831699
ArrayRef<OMPClause *> Clauses,
16841700
Stmt *AssociatedStmt, const HelperExprs &Exprs,
1685-
Expr *TaskRedRef, bool HasCancel);
1701+
Expr *TaskRedRef, bool HasCancel,
1702+
OpenMPDirectiveKind ParamPrevMappedDirective);
16861703

16871704
/// Creates an empty directive with the place
16881705
/// for \a NumClauses clauses.
@@ -4406,7 +4423,8 @@ class OMPDistributeDirective : public OMPLoopDirective {
44064423
static OMPDistributeDirective *
44074424
Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
44084425
unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses,
4409-
Stmt *AssociatedStmt, const HelperExprs &Exprs);
4426+
Stmt *AssociatedStmt, const HelperExprs &Exprs,
4427+
OpenMPDirectiveKind ParamPrevMappedDirective);
44104428

44114429
/// Creates an empty directive with the place
44124430
/// for \a NumClauses clauses.

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9875,6 +9875,11 @@ def err_break_not_in_loop_or_switch : Error<
98759875
def warn_loop_ctrl_binds_to_inner : Warning<
98769876
"'%0' is bound to current loop, GCC binds it to the enclosing loop">,
98779877
InGroup<GccCompat>;
9878+
def err_omp_bind_required_on_loop : Error<
9879+
"expected 'bind' clause for 'loop' construct without an enclosing OpenMP "
9880+
"construct">;
9881+
def err_omp_loop_reduction_clause : Error<
9882+
"'reduction' clause not allowed with '#pragma omp loop bind(teams)'">;
98789883
def warn_break_binds_to_switch : Warning<
98799884
"'break' is bound to loop, GCC binds it to switch">,
98809885
InGroup<GccCompat>;

clang/include/clang/Sema/Sema.h

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11185,6 +11185,23 @@ class Sema final {
1118511185
/// All `omp assumes` we encountered so far.
1118611186
SmallVector<AssumptionAttr *, 4> OMPAssumeGlobal;
1118711187

11188+
/// OMPD_loop is mapped to OMPD_for, OMPD_distribute or OMPD_simd depending
11189+
/// on the parameter of the bind clause. In the methods for the
11190+
/// mapped directives, check the parameters of the lastprivate clause.
11191+
bool checkLastPrivateForMappedDirectives(ArrayRef<OMPClause *> Clauses);
11192+
/// Depending on the bind clause of OMPD_loop map the directive to new
11193+
/// directives.
11194+
/// 1) loop bind(parallel) --> OMPD_for
11195+
/// 2) loop bind(teams) --> OMPD_distribute
11196+
/// 3) loop bind(thread) --> OMPD_simd
11197+
/// This is being handled in Sema instead of Codegen because of the need for
11198+
/// rigorous semantic checking in the new mapped directives.
11199+
bool mapLoopConstruct(llvm::SmallVector<OMPClause *> &ClausesWithoutBind,
11200+
ArrayRef<OMPClause *> Clauses,
11201+
OpenMPBindClauseKind BindKind,
11202+
OpenMPDirectiveKind &Kind,
11203+
OpenMPDirectiveKind &PrevMappedDirective);
11204+
1118811205
public:
1118911206
/// The declarator \p D defines a function in the scope \p S which is nested
1119011207
/// in an `omp begin/end declare variant` scope. In this method we create a
@@ -11480,7 +11497,8 @@ class Sema final {
1148011497
StmtResult ActOnOpenMPExecutableDirective(
1148111498
OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName,
1148211499
OpenMPDirectiveKind CancelRegion, ArrayRef<OMPClause *> Clauses,
11483-
Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc);
11500+
Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc,
11501+
OpenMPDirectiveKind PrevMappedDirective = llvm::omp::OMPD_unknown);
1148411502
/// Called on well-formed '\#pragma omp parallel' after parsing
1148511503
/// of the associated statement.
1148611504
StmtResult ActOnOpenMPParallelDirective(ArrayRef<OMPClause *> Clauses,

clang/lib/AST/StmtOpenMP.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -297,11 +297,10 @@ OMPParallelDirective *OMPParallelDirective::CreateEmpty(const ASTContext &C,
297297
/*NumChildren=*/1);
298298
}
299299

300-
OMPSimdDirective *
301-
OMPSimdDirective::Create(const ASTContext &C, SourceLocation StartLoc,
302-
SourceLocation EndLoc, unsigned CollapsedNum,
303-
ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt,
304-
const HelperExprs &Exprs) {
300+
OMPSimdDirective *OMPSimdDirective::Create(
301+
const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
302+
unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt,
303+
const HelperExprs &Exprs, OpenMPDirectiveKind ParamPrevMappedDirective) {
305304
auto *Dir = createDirective<OMPSimdDirective>(
306305
C, Clauses, AssociatedStmt, numLoopChildren(CollapsedNum, OMPD_simd),
307306
StartLoc, EndLoc, CollapsedNum);
@@ -321,6 +320,7 @@ OMPSimdDirective::Create(const ASTContext &C, SourceLocation StartLoc,
321320
Dir->setDependentInits(Exprs.DependentInits);
322321
Dir->setFinalsConditions(Exprs.FinalsConditions);
323322
Dir->setPreInits(Exprs.PreInits);
323+
Dir->setMappedDirective(ParamPrevMappedDirective);
324324
return Dir;
325325
}
326326

@@ -336,7 +336,8 @@ OMPSimdDirective *OMPSimdDirective::CreateEmpty(const ASTContext &C,
336336
OMPForDirective *OMPForDirective::Create(
337337
const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
338338
unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt,
339-
const HelperExprs &Exprs, Expr *TaskRedRef, bool HasCancel) {
339+
const HelperExprs &Exprs, Expr *TaskRedRef, bool HasCancel,
340+
OpenMPDirectiveKind ParamPrevMappedDirective) {
340341
auto *Dir = createDirective<OMPForDirective>(
341342
C, Clauses, AssociatedStmt, numLoopChildren(CollapsedNum, OMPD_for) + 1,
342343
StartLoc, EndLoc, CollapsedNum);
@@ -366,6 +367,7 @@ OMPForDirective *OMPForDirective::Create(
366367
Dir->setPreInits(Exprs.PreInits);
367368
Dir->setTaskReductionRefExpr(TaskRedRef);
368369
Dir->setHasCancel(HasCancel);
370+
Dir->setMappedDirective(ParamPrevMappedDirective);
369371
return Dir;
370372
}
371373

@@ -1515,7 +1517,7 @@ OMPParallelMaskedTaskLoopSimdDirective::CreateEmpty(const ASTContext &C,
15151517
OMPDistributeDirective *OMPDistributeDirective::Create(
15161518
const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
15171519
unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt,
1518-
const HelperExprs &Exprs) {
1520+
const HelperExprs &Exprs, OpenMPDirectiveKind ParamPrevMappedDirective) {
15191521
auto *Dir = createDirective<OMPDistributeDirective>(
15201522
C, Clauses, AssociatedStmt,
15211523
numLoopChildren(CollapsedNum, OMPD_distribute), StartLoc, EndLoc,
@@ -1544,6 +1546,7 @@ OMPDistributeDirective *OMPDistributeDirective::Create(
15441546
Dir->setDependentInits(Exprs.DependentInits);
15451547
Dir->setFinalsConditions(Exprs.FinalsConditions);
15461548
Dir->setPreInits(Exprs.PreInits);
1549+
Dir->setMappedDirective(ParamPrevMappedDirective);
15471550
return Dir;
15481551
}
15491552

0 commit comments

Comments
 (0)