Skip to content

Commit d988a28

Browse files
authored
Merge branch 'main' into llvmdll-lib-ADT
2 parents 6786976 + 2f1ef1d commit d988a28

File tree

301 files changed

+22984
-4248
lines changed

Some content is hidden

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

301 files changed

+22984
-4248
lines changed

clang-tools-extra/clang-tidy/modernize/UseDesignatedInitializersCheck.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,9 @@ void UseDesignatedInitializersCheck::registerMatchers(MatchFinder *Finder) {
121121
hasAnyBase(hasType(cxxRecordDecl(has(fieldDecl()))));
122122
Finder->addMatcher(
123123
initListExpr(
124-
hasType(cxxRecordDecl(RestrictToPODTypes ? isPOD() : isAggregate(),
125-
unless(HasBaseWithFields))
124+
hasType(cxxRecordDecl(
125+
RestrictToPODTypes ? isPOD() : isAggregate(),
126+
unless(anyOf(HasBaseWithFields, hasName("::std::array"))))
126127
.bind("type")),
127128
IgnoreSingleElementAggregates ? hasMoreThanOneElement() : anything(),
128129
unless(isFullyDesignated()))

clang-tools-extra/clangd/Preamble.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,10 @@ buildPreamble(PathRef FileName, CompilerInvocation CI,
711711
Result->Marks = CapturedInfo.takeMarks();
712712
Result->StatCache = StatCache;
713713
Result->MainIsIncludeGuarded = CapturedInfo.isMainFileIncludeGuarded();
714-
Result->TargetOpts = CI.TargetOpts;
714+
// Move the options instead of copying them. The invocation doesn't need
715+
// them anymore.
716+
Result->TargetOpts =
717+
std::make_unique<TargetOptions>(std::move(CI.getTargetOpts()));
715718
if (PreambleCallback) {
716719
trace::Span Tracer("Running PreambleCallback");
717720
auto Ctx = CapturedInfo.takeLife();
@@ -932,7 +935,7 @@ void PreamblePatch::apply(CompilerInvocation &CI) const {
932935
// ParsedASTTest.PreambleWithDifferentTarget.
933936
// Make sure this is a deep copy, as the same Baseline might be used
934937
// concurrently.
935-
*CI.TargetOpts = *Baseline->TargetOpts;
938+
CI.getTargetOpts() = *Baseline->TargetOpts;
936939

937940
// No need to map an empty file.
938941
if (PatchContents.empty())

clang-tools-extra/clangd/Preamble.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ struct PreambleData {
103103
// Target options used when building the preamble. Changes in target can cause
104104
// crashes when deserializing preamble, this enables consumers to use the
105105
// same target (without reparsing CompileCommand).
106-
std::shared_ptr<TargetOptions> TargetOpts = nullptr;
106+
std::unique_ptr<TargetOptions> TargetOpts = nullptr;
107107
PrecompiledPreamble Preamble;
108108
std::vector<Diag> Diags;
109109
// Processes like code completions and go-to-definitions will need #include

clang-tools-extra/clangd/SystemIncludeExtractor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ bool isValidTarget(llvm::StringRef Triple) {
256256
DiagnosticsEngine Diags(new DiagnosticIDs, new DiagnosticOptions,
257257
new IgnoringDiagConsumer);
258258
llvm::IntrusiveRefCntPtr<TargetInfo> Target =
259-
TargetInfo::CreateTargetInfo(Diags, TargetOpts);
259+
TargetInfo::CreateTargetInfo(Diags, *TargetOpts);
260260
return bool(Target);
261261
}
262262

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,10 @@ Changes in existing checks
182182
``constexpr`` and ``static``` values on member initialization and by detecting
183183
explicit casting of built-in types within member list initialization.
184184

185+
- Improved :doc:`modernize-use-designated-initializers
186+
<clang-tidy/checks/modernize/use-designated-initializers>` check by avoiding
187+
diagnosing designated initializers for ``std::array`` initializations.
188+
185189
- Improved :doc:`modernize-use-ranges
186190
<clang-tidy/checks/modernize/use-ranges>` check by updating suppress
187191
warnings logic for ``nullptr`` in ``std::find``.

clang-tools-extra/docs/clang-tidy/checks/modernize/use-designated-initializers.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ Options
5454

5555
The value `false` specifies that even initializers for aggregate types with
5656
only a single element should be checked. The default value is `true`.
57+
``std::array`` initializations are always excluded, as the type is a
58+
standard library abstraction and not intended to be initialized with
59+
designated initializers.
5760

5861
.. option:: RestrictToPODTypes
5962

clang-tools-extra/modularize/ModularizeUtilities.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ ModularizeUtilities::ModularizeUtilities(std::vector<std::string> &InputPaths,
5353
Diagnostics(
5454
new DiagnosticsEngine(DiagIDs, DiagnosticOpts.get(), &DC, false)),
5555
TargetOpts(new ModuleMapTargetOptions()),
56-
Target(TargetInfo::CreateTargetInfo(*Diagnostics, TargetOpts)),
56+
Target(TargetInfo::CreateTargetInfo(*Diagnostics, *TargetOpts)),
5757
FileMgr(new FileManager(FileSystemOpts)),
5858
SourceMgr(new SourceManager(*Diagnostics, *FileMgr, false)), HSOpts(),
5959
HeaderInfo(new HeaderSearch(HSOpts, *SourceMgr, *Diagnostics, *LangOpts,

clang-tools-extra/test/clang-tidy/checkers/modernize/use-designated-initializers.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,3 +209,18 @@ struct S15{
209209
S15(S14& d):d{d}{}
210210
S14& d;
211211
};
212+
213+
//Issue #133715
214+
namespace std {
215+
template<typename T, unsigned int N>
216+
struct array {
217+
T __elems[N];
218+
};
219+
template<typename T, typename... U>
220+
array(T, U...) -> array<T, 1 + sizeof...(U)>;
221+
}
222+
223+
std::array a{1,2,3};
224+
std::array<int,2> b{10, 11};
225+
using array = std::array<int, 2>;
226+
array c{10, 11};

clang/include/clang/AST/OperationKinds.def

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,7 @@ CAST_OPERATION(ArrayToPointerDecay)
119119
CAST_OPERATION(FunctionToPointerDecay)
120120

121121
/// CK_NullToPointer - Null pointer constant to pointer, ObjC
122-
/// pointer, or block pointer. The result of this conversion can
123-
/// still be a null pointer constant if it has type std::nullptr_t.
122+
/// pointer, block pointer, or std::nullptr_t.
124123
/// (void*) 0
125124
/// void (^block)() = 0;
126125
CAST_OPERATION(NullToPointer)

clang/include/clang/Basic/DiagnosticFrontendKinds.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,10 @@ def err_modules_embed_file_not_found :
260260
DefaultFatal;
261261
def err_module_header_file_not_found :
262262
Error<"module header file '%0' not found">, DefaultFatal;
263+
def err_frontend_action_unsupported_input_format
264+
: Error<"%0 does not support input file format of file '%1': "
265+
"'%select{Source|ModuleMap|Precompiled|Unknown}2'">,
266+
DefaultFatal;
263267

264268
def err_test_module_file_extension_version : Error<
265269
"test module file extension '%0' has different version (%1.%2) than expected "

clang/include/clang/Basic/HeaderInclude.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,14 @@ enum HeaderIncludeFormatKind { HIFMT_None, HIFMT_Textual, HIFMT_JSON };
2323

2424
/// Whether header information is filtered or not. If HIFIL_Only_Direct_System
2525
/// is used, only information on system headers directly included from
26-
/// non-system headers is emitted.
27-
enum HeaderIncludeFilteringKind { HIFIL_None, HIFIL_Only_Direct_System };
26+
/// non-system files is emitted. The HIFIL_Direct_Per_File filtering shows the
27+
/// direct imports and includes for each non-system source and header file
28+
/// separately.
29+
enum HeaderIncludeFilteringKind {
30+
HIFIL_None,
31+
HIFIL_Only_Direct_System,
32+
HIFIL_Direct_Per_File
33+
};
2834

2935
inline HeaderIncludeFormatKind
3036
stringToHeaderIncludeFormatKind(const char *Str) {
@@ -40,6 +46,7 @@ inline bool stringToHeaderIncludeFiltering(const char *Str,
4046
llvm::StringSwitch<std::pair<bool, HeaderIncludeFilteringKind>>(Str)
4147
.Case("none", {true, HIFIL_None})
4248
.Case("only-direct-system", {true, HIFIL_Only_Direct_System})
49+
.Case("direct-per-file", {true, HIFIL_Direct_Per_File})
4350
.Default({false, HIFIL_None});
4451
Kind = P.second;
4552
return P.first;
@@ -64,6 +71,8 @@ headerIncludeFilteringKindToString(HeaderIncludeFilteringKind K) {
6471
return "none";
6572
case HIFIL_Only_Direct_System:
6673
return "only-direct-system";
74+
case HIFIL_Direct_Per_File:
75+
return "direct-per-file";
6776
}
6877
llvm_unreachable("Unknown HeaderIncludeFilteringKind enum");
6978
}

clang/include/clang/Basic/TargetInfo.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ enum OpenCLTypeKind : uint8_t {
224224
///
225225
class TargetInfo : public TransferrableTargetInfo,
226226
public RefCountedBase<TargetInfo> {
227-
std::shared_ptr<TargetOptions> TargetOpts;
227+
TargetOptions *TargetOpts;
228228
llvm::Triple Triple;
229229
protected:
230230
// Target values set by the ctor of the actual target implementation. Default
@@ -310,10 +310,9 @@ class TargetInfo : public TransferrableTargetInfo,
310310
///
311311
/// \param Opts - The options to use to initialize the target. The target may
312312
/// modify the options to canonicalize the target feature information to match
313-
/// what the backend expects.
314-
static TargetInfo *
315-
CreateTargetInfo(DiagnosticsEngine &Diags,
316-
const std::shared_ptr<TargetOptions> &Opts);
313+
/// what the backend expects. These must outlive the returned TargetInfo.
314+
static TargetInfo *CreateTargetInfo(DiagnosticsEngine &Diags,
315+
TargetOptions &Opts);
317316

318317
virtual ~TargetInfo();
319318

clang/include/clang/CIR/Dialect/IR/CIRTypes.td

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,18 +292,18 @@ def CIR_ArrayType : CIR_Type<"Array", "array",
292292
`CIR.array` represents C/C++ constant arrays.
293293
}];
294294

295-
let parameters = (ins "mlir::Type":$eltType, "uint64_t":$size);
295+
let parameters = (ins "mlir::Type":$elementType, "uint64_t":$size);
296296

297297
let builders = [
298298
TypeBuilderWithInferredContext<(ins
299-
"mlir::Type":$eltType, "uint64_t":$size
299+
"mlir::Type":$elementType, "uint64_t":$size
300300
), [{
301-
return $_get(eltType.getContext(), eltType, size);
301+
return $_get(elementType.getContext(), elementType, size);
302302
}]>,
303303
];
304304

305305
let assemblyFormat = [{
306-
`<` $eltType `x` $size `>`
306+
`<` $elementType `x` $size `>`
307307
}];
308308
}
309309

clang/include/clang/Driver/Options.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7793,7 +7793,8 @@ def header_include_format_EQ : Joined<["-"], "header-include-format=">,
77937793
MarshallingInfoEnum<DependencyOutputOpts<"HeaderIncludeFormat">, "HIFMT_Textual">;
77947794
def header_include_filtering_EQ : Joined<["-"], "header-include-filtering=">,
77957795
HelpText<"set the flag that enables filtering header information">,
7796-
Values<"none,only-direct-system">, NormalizedValues<["HIFIL_None", "HIFIL_Only_Direct_System"]>,
7796+
Values<"none,only-direct-system,direct-per-file">,
7797+
NormalizedValues<["HIFIL_None", "HIFIL_Only_Direct_System", "HIFIL_Direct_Per_File"]>,
77977798
MarshallingInfoEnum<DependencyOutputOpts<"HeaderIncludeFiltering">, "HIFIL_None">;
77987799
def show_includes : Flag<["--"], "show-includes">,
77997800
HelpText<"Print cl.exe style /showIncludes to stdout">;

clang/include/clang/Frontend/ASTUnit.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ class ASTUnit {
143143
/// Parse available.
144144
std::shared_ptr<CompilerInvocation> CCInvocation;
145145

146+
/// Optional owned invocation, just used to keep the invocation alive for the
147+
/// members initialized in transferASTDataFromCompilerInstance.
148+
std::shared_ptr<CompilerInvocation> ModifiedInvocation;
149+
146150
/// Fake module loader: the AST unit doesn't need to load any modules.
147151
TrivialModuleLoader ModuleLoader;
148152

clang/include/clang/Frontend/CompilerInstance.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ class CompilerInstance : public ModuleLoader {
8888
/// The target being compiled for.
8989
IntrusiveRefCntPtr<TargetInfo> Target;
9090

91+
/// Options for the auxiliary target.
92+
std::unique_ptr<TargetOptions> AuxTargetOpts;
93+
9194
/// Auxiliary Target info.
9295
IntrusiveRefCntPtr<TargetInfo> AuxTarget;
9396

clang/include/clang/Frontend/CompilerInvocation.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class CompilerInvocationBase {
8989
std::shared_ptr<PreprocessorOptions> PPOpts;
9090

9191
/// Options controlling the static analyzer.
92-
AnalyzerOptionsRef AnalyzerOpts;
92+
std::shared_ptr<AnalyzerOptions> AnalyzerOpts;
9393

9494
std::shared_ptr<MigratorOptions> MigratorOpts;
9595

@@ -268,7 +268,6 @@ class CompilerInvocation : public CompilerInvocationBase {
268268
/// Base class internals.
269269
/// @{
270270
using CompilerInvocationBase::LangOpts;
271-
using CompilerInvocationBase::TargetOpts;
272271
std::shared_ptr<LangOptions> getLangOptsPtr() { return LangOpts; }
273272
/// @}
274273

clang/include/clang/Frontend/FrontendActions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ class GenerateModuleFromModuleMapAction : public GenerateModuleAction {
156156
/// files) for C++20 Named Modules.
157157
class GenerateModuleInterfaceAction : public GenerateModuleAction {
158158
protected:
159+
bool PrepareToExecuteAction(CompilerInstance &CI) override;
159160
bool BeginSourceFileAction(CompilerInstance &CI) override;
160161

161162
std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,

clang/include/clang/Sema/SemaOpenACC.h

Lines changed: 64 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -125,38 +125,78 @@ class SemaOpenACC : public SemaBase {
125125
/// 'loop' clause enforcement, where this is 'blocked' by a compute construct.
126126
llvm::SmallVector<OpenACCReductionClause *> ActiveReductionClauses;
127127

128-
// Type to check the info about the 'for stmt'.
129-
struct ForStmtBeginChecker {
128+
// Type to check the 'for' (or range-for) statement for compatibility with the
129+
// 'loop' directive.
130+
class ForStmtBeginChecker {
130131
SemaOpenACC &SemaRef;
131132
SourceLocation ForLoc;
132-
bool IsRangeFor = false;
133-
std::optional<const CXXForRangeStmt *> RangeFor = nullptr;
134-
const Stmt *Init = nullptr;
135-
bool InitChanged = false;
136-
std::optional<const Stmt *> Cond = nullptr;
137-
std::optional<const Stmt *> Inc = nullptr;
133+
bool IsInstantiation = false;
134+
135+
struct RangeForInfo {
136+
const CXXForRangeStmt *Uninstantiated = nullptr;
137+
const CXXForRangeStmt *CurrentVersion = nullptr;
138+
// GCC 7.x requires this constructor, else the construction of variant
139+
// doesn't work correctly.
140+
RangeForInfo() : Uninstantiated{nullptr}, CurrentVersion{nullptr} {}
141+
RangeForInfo(const CXXForRangeStmt *Uninst, const CXXForRangeStmt *Cur)
142+
: Uninstantiated{Uninst}, CurrentVersion{Cur} {}
143+
};
144+
145+
struct ForInfo {
146+
const Stmt *Init = nullptr;
147+
const Stmt *Condition = nullptr;
148+
const Stmt *Increment = nullptr;
149+
};
150+
151+
struct CheckForInfo {
152+
ForInfo Uninst;
153+
ForInfo Current;
154+
};
155+
156+
std::variant<RangeForInfo, CheckForInfo> Info;
138157
// Prevent us from checking 2x, which can happen with collapse & tile.
139158
bool AlreadyChecked = false;
140159

141-
ForStmtBeginChecker(SemaOpenACC &SemaRef, SourceLocation ForLoc,
142-
std::optional<const CXXForRangeStmt *> S)
143-
: SemaRef(SemaRef), ForLoc(ForLoc), IsRangeFor(true), RangeFor(S) {}
160+
void checkRangeFor();
161+
162+
bool checkForInit(const Stmt *InitStmt, const ValueDecl *&InitVar,
163+
bool Diag);
164+
bool checkForCond(const Stmt *CondStmt, const ValueDecl *InitVar,
165+
bool Diag);
166+
bool checkForInc(const Stmt *IncStmt, const ValueDecl *InitVar, bool Diag);
144167

168+
void checkFor();
169+
170+
// void checkRangeFor(); ?? ERICH
171+
// const ValueDecl *checkInit();
172+
// void checkCond(const ValueDecl *Init);
173+
// void checkInc(const ValueDecl *Init);
174+
public:
175+
// Checking for non-instantiation version of a Range-for.
145176
ForStmtBeginChecker(SemaOpenACC &SemaRef, SourceLocation ForLoc,
146-
const Stmt *I, bool InitChanged,
147-
std::optional<const Stmt *> C,
148-
std::optional<const Stmt *> Inc)
149-
: SemaRef(SemaRef), ForLoc(ForLoc), IsRangeFor(false), Init(I),
150-
InitChanged(InitChanged), Cond(C), Inc(Inc) {}
151-
// Do the checking for the For/Range-For. Currently this implements the 'not
152-
// seq' restrictions only, and should be called either if we know we are a
153-
// top-level 'for' (the one associated via associated-stmt), or extended via
154-
// 'collapse'.
155-
void check();
177+
const CXXForRangeStmt *RangeFor)
178+
: SemaRef(SemaRef), ForLoc(ForLoc), IsInstantiation(false),
179+
Info(RangeForInfo{nullptr, RangeFor}) {}
180+
// Checking for an instantiation of the range-for.
181+
ForStmtBeginChecker(SemaOpenACC &SemaRef, SourceLocation ForLoc,
182+
const CXXForRangeStmt *OldRangeFor,
183+
const CXXForRangeStmt *RangeFor)
184+
: SemaRef(SemaRef), ForLoc(ForLoc), IsInstantiation(true),
185+
Info(RangeForInfo{OldRangeFor, RangeFor}) {}
186+
// Checking for a non-instantiation version of a traditional for.
187+
ForStmtBeginChecker(SemaOpenACC &SemaRef, SourceLocation ForLoc,
188+
const Stmt *Init, const Stmt *Cond, const Stmt *Inc)
189+
: SemaRef(SemaRef), ForLoc(ForLoc), IsInstantiation(false),
190+
Info(CheckForInfo{{}, {Init, Cond, Inc}}) {}
191+
// Checking for an instantiation version of a traditional for.
192+
ForStmtBeginChecker(SemaOpenACC &SemaRef, SourceLocation ForLoc,
193+
const Stmt *OldInit, const Stmt *OldCond,
194+
const Stmt *OldInc, const Stmt *Init, const Stmt *Cond,
195+
const Stmt *Inc)
196+
: SemaRef(SemaRef), ForLoc(ForLoc), IsInstantiation(true),
197+
Info(CheckForInfo{{OldInit, OldCond, OldInc}, {Init, Cond, Inc}}) {}
156198

157-
const ValueDecl *checkInit();
158-
void checkCond();
159-
void checkInc(const ValueDecl *Init);
199+
void check();
160200
};
161201

162202
/// Helper function for checking the 'for' and 'range for' stmts.

clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ class PositiveAnalyzerOption {
176176
/// and should be eventually converted into -analyzer-config flags. New analyzer
177177
/// options should not be implemented as frontend flags. Frontend flags still
178178
/// make sense for things that do not affect the actual analysis.
179-
class AnalyzerOptions : public RefCountedBase<AnalyzerOptions> {
179+
class AnalyzerOptions {
180180
public:
181181
using ConfigTable = llvm::StringMap<std::string>;
182182

@@ -416,8 +416,6 @@ class AnalyzerOptions : public RefCountedBase<AnalyzerOptions> {
416416
}
417417
};
418418

419-
using AnalyzerOptionsRef = IntrusiveRefCntPtr<AnalyzerOptions>;
420-
421419
//===----------------------------------------------------------------------===//
422420
// We'll use AnalyzerOptions in the frontend, but we can't link the frontend
423421
// with clangStaticAnalyzerCore, because clangStaticAnalyzerCore depends on

0 commit comments

Comments
 (0)