Skip to content

Commit 2f80891

Browse files
Merge branch 'main' into cir-undef-codegen
2 parents 63f5d26 + dbf4525 commit 2f80891

File tree

180 files changed

+27372
-29121
lines changed

Some content is hidden

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

180 files changed

+27372
-29121
lines changed

clang-tools-extra/clang-tidy/readability/DuplicateIncludeCheck.cpp

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "DuplicateIncludeCheck.h"
10+
#include "../utils/OptionsUtils.h"
1011
#include "clang/Frontend/CompilerInstance.h"
1112
#include "clang/Lex/Preprocessor.h"
1213
#include "llvm/ADT/STLExtras.h"
1314
#include "llvm/ADT/SmallVector.h"
15+
#include "llvm/Support/Regex.h"
1416
#include <memory>
1517

1618
namespace clang::tidy::readability {
@@ -33,11 +35,8 @@ using FileList = SmallVector<StringRef>;
3335
class DuplicateIncludeCallbacks : public PPCallbacks {
3436
public:
3537
DuplicateIncludeCallbacks(DuplicateIncludeCheck &Check,
36-
const SourceManager &SM)
37-
: Check(Check), SM(SM) {
38-
// The main file doesn't participate in the FileChanged notification.
39-
Files.emplace_back();
40-
}
38+
const SourceManager &SM,
39+
llvm::ArrayRef<StringRef> IgnoredList);
4140

4241
void FileChanged(SourceLocation Loc, FileChangeReason Reason,
4342
SrcMgr::CharacteristicKind FileType,
@@ -62,10 +61,31 @@ class DuplicateIncludeCallbacks : public PPCallbacks {
6261
SmallVector<FileList> Files;
6362
DuplicateIncludeCheck &Check;
6463
const SourceManager &SM;
64+
SmallVector<llvm::Regex> AllowedRegexes;
6565
};
6666

6767
} // namespace
6868

69+
DuplicateIncludeCheck::DuplicateIncludeCheck(StringRef Name,
70+
ClangTidyContext *Context)
71+
: ClangTidyCheck(Name, Context),
72+
IgnoredFilesList(utils::options::parseStringList(
73+
Options.get("IgnoredFilesList", ""))) {}
74+
75+
DuplicateIncludeCallbacks::DuplicateIncludeCallbacks(
76+
DuplicateIncludeCheck &Check, const SourceManager &SM,
77+
llvm::ArrayRef<StringRef> IgnoredList)
78+
: Check(Check), SM(SM) {
79+
// The main file doesn't participate in the FileChanged notification.
80+
Files.emplace_back();
81+
82+
AllowedRegexes.reserve(IgnoredList.size());
83+
for (const StringRef &It : IgnoredList) {
84+
if (!It.empty())
85+
AllowedRegexes.emplace_back(It);
86+
}
87+
}
88+
6989
void DuplicateIncludeCallbacks::FileChanged(SourceLocation Loc,
7090
FileChangeReason Reason,
7191
SrcMgr::CharacteristicKind FileType,
@@ -78,14 +98,18 @@ void DuplicateIncludeCallbacks::FileChanged(SourceLocation Loc,
7898

7999
void DuplicateIncludeCallbacks::InclusionDirective(
80100
SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName,
81-
bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File,
101+
bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef /*File*/,
82102
StringRef SearchPath, StringRef RelativePath, const Module *SuggestedModule,
83103
bool ModuleImported, SrcMgr::CharacteristicKind FileType) {
84104
// Skip includes behind macros
85105
if (FilenameRange.getBegin().isMacroID() ||
86106
FilenameRange.getEnd().isMacroID())
87107
return;
88108
if (llvm::is_contained(Files.back(), FileName)) {
109+
if (llvm::any_of(AllowedRegexes, [&FileName](const llvm::Regex &R) {
110+
return R.match(FileName);
111+
}))
112+
return;
89113
// We want to delete the entire line, so make sure that [Start,End] covers
90114
// everything.
91115
const SourceLocation Start =
@@ -111,7 +135,13 @@ void DuplicateIncludeCallbacks::MacroUndefined(const Token &MacroNameTok,
111135

112136
void DuplicateIncludeCheck::registerPPCallbacks(
113137
const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) {
114-
PP->addPPCallbacks(std::make_unique<DuplicateIncludeCallbacks>(*this, SM));
138+
PP->addPPCallbacks(
139+
std::make_unique<DuplicateIncludeCallbacks>(*this, SM, IgnoredFilesList));
140+
}
141+
142+
void DuplicateIncludeCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
143+
Options.store(Opts, "IgnoredFilesList",
144+
utils::options::serializeStringList(IgnoredFilesList));
115145
}
116146

117147
} // namespace clang::tidy::readability

clang-tools-extra/clang-tidy/readability/DuplicateIncludeCheck.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,16 @@ namespace clang::tidy::readability {
1919
/// directives between them are analyzed.
2020
class DuplicateIncludeCheck : public ClangTidyCheck {
2121
public:
22-
DuplicateIncludeCheck(StringRef Name, ClangTidyContext *Context)
23-
: ClangTidyCheck(Name, Context) {}
22+
DuplicateIncludeCheck(StringRef Name, ClangTidyContext *Context);
2423

2524
void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
2625
Preprocessor *ModuleExpanderPP) override;
26+
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
27+
28+
private:
29+
// Semicolon-separated list of regexes or file names to ignore from duplicate
30+
// warnings.
31+
const std::vector<StringRef> IgnoredFilesList;
2732
};
2833

2934
} // namespace clang::tidy::readability

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,11 @@ Changes in existing checks
527527
ignoring default constructors with user provided arguments and adding
528528
detection in container's method except ``empty``.
529529

530+
- Improved :doc:`readability-duplicate-include
531+
<clang-tidy/checks/readability/duplicate-include>` check by adding
532+
the ``IgnoredFilesList`` option (semicolon-separated list of regexes or
533+
filenames) to allow intentional duplicates.
534+
530535
- Improved :doc:`readability-identifier-naming
531536
<clang-tidy/checks/readability/identifier-naming>` check by ignoring
532537
declarations and macros in system headers. The documentation is also improved

clang-tools-extra/docs/clang-tidy/checks/readability/duplicate-include.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,12 @@ Because of the intervening macro definitions, this code remains unchanged:
3333
#define NDEBUG
3434
#include "assertion.h"
3535
// ...code with assertions disabled
36+
37+
Options
38+
-------
39+
40+
.. option:: IgnoredFilesList
41+
42+
A semicolon-separated list of regular expressions or filenames that are
43+
allowed to be included multiple times without diagnostics. Matching is
44+
performed against the textual include name. Default is an empty string.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// Intentionally unguarded begin-pack header used in tests
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// Intentionally unguarded end-pack header used in tests
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// RUN: %check_clang_tidy %s readability-duplicate-include %t -- \
2+
// RUN: -config="{CheckOptions: {readability-duplicate-include.IgnoredFilesList: 'pack_.*\\.h'}}" \
3+
// RUN: -header-filter='' -- -I %S/Inputs/duplicate-include
4+
5+
int g;
6+
#include "duplicate-include.h"
7+
int h;
8+
#include "duplicate-include.h"
9+
int i;
10+
// CHECK-MESSAGES: :[[@LINE-2]]:1: warning: duplicate include [readability-duplicate-include]
11+
// CHECK-FIXES: int g;
12+
// CHECK-FIXES-NEXT: #include "duplicate-include.h"
13+
// CHECK-FIXES-NEXT: int h;
14+
// CHECK-FIXES-NEXT: int i;
15+
16+
#include "pack_begin.h"
17+
struct A { int x; };
18+
#include "pack_end.h"
19+
20+
#include "pack_begin.h"
21+
struct B { int x; };
22+
#include "pack_end.h"
23+
24+
// No warning here.

clang/include/clang/AST/StmtOpenACC.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -829,8 +829,13 @@ class OpenACCAtomicConstruct final
829829
// Listed as 'expr' in the standard, this is typically a generic expression
830830
// as a component.
831831
const Expr *RefExpr;
832+
// If this is an 'update', records whether this is a post-fix
833+
// increment/decrement. In the case where we have a single-line variant of
834+
// 'capture' we have to form the IR differently if this is the case to make
835+
// sure the old value is 'read' in the 2nd step.
836+
bool IsPostfixIncDec = false;
832837
static SingleStmtInfo Empty() {
833-
return {nullptr, nullptr, nullptr, nullptr};
838+
return {nullptr, nullptr, nullptr, nullptr, false};
834839
}
835840

836841
static SingleStmtInfo createRead(const Expr *WholeExpr, const Expr *V,
@@ -841,8 +846,9 @@ class OpenACCAtomicConstruct final
841846
const Expr *RefExpr) {
842847
return {WholeExpr, /*V=*/nullptr, X, RefExpr};
843848
}
844-
static SingleStmtInfo createUpdate(const Expr *WholeExpr, const Expr *X) {
845-
return {WholeExpr, /*V=*/nullptr, X, /*RefExpr=*/nullptr};
849+
static SingleStmtInfo createUpdate(const Expr *WholeExpr, const Expr *X,
850+
bool PostfixIncDec) {
851+
return {WholeExpr, /*V=*/nullptr, X, /*RefExpr=*/nullptr, PostfixIncDec};
846852
}
847853
};
848854

clang/include/clang/Basic/Builtins.td

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4949,25 +4949,25 @@ def HLSLResourceGetPointer : LangBuiltin<"HLSL_LANG"> {
49494949
def HLSLResourceUninitializedHandle : LangBuiltin<"HLSL_LANG"> {
49504950
let Spellings = ["__builtin_hlsl_resource_uninitializedhandle"];
49514951
let Attributes = [NoThrow];
4952-
let Prototype = "void(...)";
4952+
let Prototype = "__hlsl_resource_t(__hlsl_resource_t)";
49534953
}
49544954

49554955
def HLSLResourceHandleFromBinding : LangBuiltin<"HLSL_LANG"> {
49564956
let Spellings = ["__builtin_hlsl_resource_handlefrombinding"];
49574957
let Attributes = [NoThrow];
4958-
let Prototype = "void(...)";
4958+
let Prototype = "__hlsl_resource_t(__hlsl_resource_t, uint32_t, uint32_t, int32_t, uint32_t, char const*)";
49594959
}
49604960

49614961
def HLSLResourceHandleFromImplicitBinding : LangBuiltin<"HLSL_LANG"> {
49624962
let Spellings = ["__builtin_hlsl_resource_handlefromimplicitbinding"];
49634963
let Attributes = [NoThrow];
4964-
let Prototype = "void(...)";
4964+
let Prototype = "__hlsl_resource_t(__hlsl_resource_t, uint32_t, uint32_t, int32_t, uint32_t, char const*)";
49654965
}
49664966

49674967
def HLSLResourceCounterHandleFromImplicitBinding : LangBuiltin<"HLSL_LANG"> {
49684968
let Spellings = ["__builtin_hlsl_resource_counterhandlefromimplicitbinding"];
4969-
let Attributes = [NoThrow, CustomTypeChecking];
4970-
let Prototype = "void(...)";
4969+
let Attributes = [NoThrow];
4970+
let Prototype = "__hlsl_resource_t(__hlsl_resource_t, uint32_t, uint32_t)";
49714971
}
49724972

49734973
def HLSLResourceNonUniformIndex : LangBuiltin<"HLSL_LANG"> {
@@ -4979,13 +4979,13 @@ def HLSLResourceNonUniformIndex : LangBuiltin<"HLSL_LANG"> {
49794979
def HLSLResourceGetDimensionsX : LangBuiltin<"HLSL_LANG"> {
49804980
let Spellings = ["__builtin_hlsl_resource_getdimensions_x"];
49814981
let Attributes = [NoThrow];
4982-
let Prototype = "void(...)";
4982+
let Prototype = "void(__hlsl_resource_t, uint32_t&)";
49834983
}
49844984

49854985
def HLSLResourceGetStride : LangBuiltin<"HLSL_LANG"> {
49864986
let Spellings = ["__builtin_hlsl_resource_getstride"];
49874987
let Attributes = [NoThrow];
4988-
let Prototype = "void(...)";
4988+
let Prototype = "void(__hlsl_resource_t, uint32_t&)";
49894989
}
49904990

49914991
def HLSLAll : LangBuiltin<"HLSL_LANG"> {
@@ -5213,7 +5213,7 @@ def HLSLRadians : LangBuiltin<"HLSL_LANG"> {
52135213
def HLSLBufferUpdateCounter : LangBuiltin<"HLSL_LANG"> {
52145214
let Spellings = ["__builtin_hlsl_buffer_update_counter"];
52155215
let Attributes = [NoThrow];
5216-
let Prototype = "uint32_t(...)";
5216+
let Prototype = "uint32_t(__hlsl_resource_t, int)";
52175217
}
52185218

52195219
def HLSLSplitDouble: LangBuiltin<"HLSL_LANG"> {

clang/include/clang/Basic/TargetID.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ getConflictTargetIDCombination(const std::set<llvm::StringRef> &TargetIDs);
5656
/// Check whether the provided target ID is compatible with the requested
5757
/// target ID.
5858
bool isCompatibleTargetID(llvm::StringRef Provided, llvm::StringRef Requested);
59+
60+
/// Sanitize a target ID string for use in a file name.
61+
/// Replaces invalid characters (like ':') with safe characters (like '@').
62+
/// Currently only replaces ':' with '@' on Windows.
63+
std::string sanitizeTargetIDInFileName(llvm::StringRef TargetID);
5964
} // namespace clang
6065

6166
#endif

0 commit comments

Comments
 (0)