Skip to content

Commit 52b198b

Browse files
committed
Merge from 'main' to 'sycl-web' (#4)
CONFLICT (content): Merge conflict in clang/lib/Sema/Sema.cpp
2 parents 9eeba35 + 11b47c1 commit 52b198b

File tree

266 files changed

+6277
-2766
lines changed

Some content is hidden

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

266 files changed

+6277
-2766
lines changed

clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ void UnnecessaryCopyInitialization::registerMatchers(MatchFinder *Finder) {
147147
return compoundStmt(
148148
forEachDescendant(
149149
declStmt(
150+
unless(has(decompositionDecl())),
150151
has(varDecl(hasLocalStorage(),
151152
hasType(qualType(
152153
hasCanonicalType(allOf(

clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %check_clang_tidy %s performance-unnecessary-copy-initialization %t
1+
// RUN: %check_clang_tidy -std=c++17 %s performance-unnecessary-copy-initialization %t
22

33
template <typename T>
44
struct Iterator {
@@ -637,3 +637,18 @@ void negativeReferenceIsInitializedOutsideOfBlock() {
637637
}
638638
};
639639
}
640+
641+
void negativeStructuredBinding() {
642+
// Structured bindings are not yet supported but can trigger false positives
643+
// since the DecompositionDecl itself is unused and the check doesn't traverse
644+
// VarDecls of the BindingDecls.
645+
struct Pair {
646+
ExpensiveToCopyType first;
647+
ExpensiveToCopyType second;
648+
};
649+
650+
Pair P;
651+
const auto [C, D] = P;
652+
C.constMethod();
653+
D.constMethod();
654+
}

clang/docs/OpenMPSupport.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ want to help with the implementation.
268268
+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
269269
| atomic extension | 'fail' clause on atomic construct | :none:`unclaimed` | |
270270
+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
271-
| base language | C++ attribute specifier syntax | :part:`worked on` | |
271+
| base language | C++ attribute specifier syntax | :good:`done` | D105648 |
272272
+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+
273273
| device extension | 'present' map type modifier | :good:`done` | D83061, D83062, D84422 |
274274
+------------------------------+--------------------------------------------------------------+--------------------------+-----------------------------------------------------------------------+

clang/include/clang/AST/ASTContext.h

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,7 @@ class ASTContext : public RefCountedBase<ASTContext> {
459459
friend class ASTWriter;
460460
template <class> friend class serialization::AbstractTypeReader;
461461
friend class CXXRecordDecl;
462+
friend class IncrementalParser;
462463

463464
/// A mapping to contain the template or declaration that
464465
/// a variable declaration describes or was instantiated from,
@@ -567,7 +568,7 @@ class ASTContext : public RefCountedBase<ASTContext> {
567568
ImportDecl *FirstLocalImport = nullptr;
568569
ImportDecl *LastLocalImport = nullptr;
569570

570-
TranslationUnitDecl *TUDecl;
571+
TranslationUnitDecl *TUDecl = nullptr;
571572
mutable ExternCContextDecl *ExternCContext = nullptr;
572573
mutable BuiltinTemplateDecl *MakeIntegerSeqDecl = nullptr;
573574
mutable BuiltinTemplateDecl *TypePackElementDecl = nullptr;
@@ -624,6 +625,7 @@ class ASTContext : public RefCountedBase<ASTContext> {
624625
IdentifierTable &Idents;
625626
SelectorTable &Selectors;
626627
Builtin::Context &BuiltinInfo;
628+
const TranslationUnitKind TUKind;
627629
mutable DeclarationNameTable DeclarationNames;
628630
IntrusiveRefCntPtr<ExternalASTSource> ExternalSource;
629631
ASTMutationListener *Listener = nullptr;
@@ -1022,7 +1024,18 @@ class ASTContext : public RefCountedBase<ASTContext> {
10221024
/// Get the initializations to perform when importing a module, if any.
10231025
ArrayRef<Decl*> getModuleInitializers(Module *M);
10241026

1025-
TranslationUnitDecl *getTranslationUnitDecl() const { return TUDecl; }
1027+
TranslationUnitDecl *getTranslationUnitDecl() const {
1028+
return TUDecl->getMostRecentDecl();
1029+
}
1030+
void addTranslationUnitDecl() {
1031+
assert(!TUDecl || TUKind == TU_Incremental);
1032+
TranslationUnitDecl *NewTUDecl = TranslationUnitDecl::Create(*this);
1033+
if (TraversalScope.empty() || TraversalScope.back() == TUDecl)
1034+
TraversalScope = {NewTUDecl};
1035+
if (TUDecl)
1036+
NewTUDecl->setPreviousDecl(TUDecl);
1037+
TUDecl = NewTUDecl;
1038+
}
10261039

10271040
ExternCContextDecl *getExternCContextDecl() const;
10281041
BuiltinTemplateDecl *getMakeIntegerSeqDecl() const;
@@ -1104,7 +1117,8 @@ class ASTContext : public RefCountedBase<ASTContext> {
11041117
llvm::DenseSet<const VarDecl *> CUDADeviceVarODRUsedByHost;
11051118

11061119
ASTContext(LangOptions &LOpts, SourceManager &SM, IdentifierTable &idents,
1107-
SelectorTable &sels, Builtin::Context &builtins);
1120+
SelectorTable &sels, Builtin::Context &builtins,
1121+
TranslationUnitKind TUKind);
11081122
ASTContext(const ASTContext &) = delete;
11091123
ASTContext &operator=(const ASTContext &) = delete;
11101124
~ASTContext();

clang/include/clang/AST/Decl.h

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,23 @@ class UnresolvedSetImpl;
7979
class VarTemplateDecl;
8080

8181
/// The top declaration context.
82-
class TranslationUnitDecl : public Decl, public DeclContext {
82+
class TranslationUnitDecl : public Decl,
83+
public DeclContext,
84+
public Redeclarable<TranslationUnitDecl> {
85+
using redeclarable_base = Redeclarable<TranslationUnitDecl>;
86+
87+
TranslationUnitDecl *getNextRedeclarationImpl() override {
88+
return getNextRedeclaration();
89+
}
90+
91+
TranslationUnitDecl *getPreviousDeclImpl() override {
92+
return getPreviousDecl();
93+
}
94+
95+
TranslationUnitDecl *getMostRecentDeclImpl() override {
96+
return getMostRecentDecl();
97+
}
98+
8399
ASTContext &Ctx;
84100

85101
/// The (most recently entered) anonymous namespace for this
@@ -91,6 +107,16 @@ class TranslationUnitDecl : public Decl, public DeclContext {
91107
virtual void anchor();
92108

93109
public:
110+
using redecl_range = redeclarable_base::redecl_range;
111+
using redecl_iterator = redeclarable_base::redecl_iterator;
112+
113+
using redeclarable_base::getMostRecentDecl;
114+
using redeclarable_base::getPreviousDecl;
115+
using redeclarable_base::isFirstDecl;
116+
using redeclarable_base::redecls;
117+
using redeclarable_base::redecls_begin;
118+
using redeclarable_base::redecls_end;
119+
94120
ASTContext &getASTContext() const { return Ctx; }
95121

96122
NamespaceDecl *getAnonymousNamespace() const { return AnonymousNamespace; }

clang/include/clang/AST/Redeclarable.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ class Redeclarable {
193193
public:
194194
friend class ASTDeclReader;
195195
friend class ASTDeclWriter;
196+
friend class IncrementalParser;
196197

197198
Redeclarable(const ASTContext &Ctx)
198199
: RedeclLink(LatestDeclLink(Ctx)),

clang/include/clang/Analysis/AnalysisDeclContext.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ class AnalysisDeclContext {
200200
/// \returns Whether the root namespace of \p D is the \c std C++ namespace.
201201
static bool isInStdNamespace(const Decl *D);
202202

203+
static std::string getFunctionName(const Decl *D);
204+
203205
private:
204206
std::unique_ptr<ManagedAnalysis> &getAnalysisImpl(const void *tag);
205207

clang/include/clang/Basic/AttrDocs.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5837,11 +5837,14 @@ provided it declares the right formal arguments.
58375837

58385838
In most respects, this is similar to the ``swiftcall`` attribute, except for
58395839
the following:
5840+
58405841
- A parameter may be marked ``swift_async_context``, ``swift_context``
58415842
or ``swift_indirect_result`` (with the same restrictions on parameter
58425843
ordering as ``swiftcall``) but the parameter attribute
58435844
``swift_error_result`` is not permitted.
5845+
58445846
- A ``swiftasynccall`` function must have return type ``void``.
5847+
58455848
- Within a ``swiftasynccall`` function, a call to a ``swiftasynccall``
58465849
function that is the immediate operand of a ``return`` statement is
58475850
guaranteed to be performed as a tail call. This syntax is allowed even

clang/include/clang/Basic/DiagnosticGroups.td

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1188,8 +1188,11 @@ def OpenMPClauses : DiagGroup<"openmp-clauses">;
11881188
def OpenMPLoopForm : DiagGroup<"openmp-loop-form">;
11891189
def OpenMPMapping : DiagGroup<"openmp-mapping">;
11901190
def OpenMPTarget : DiagGroup<"openmp-target", [OpenMPMapping]>;
1191+
def OpenMPPre51Compat : DiagGroup<"pre-openmp-51-compat">;
1192+
def OpenMP51Ext : DiagGroup<"openmp-51-extensions">;
11911193
def OpenMP : DiagGroup<"openmp", [
1192-
SourceUsesOpenMP, OpenMPClauses, OpenMPLoopForm, OpenMPTarget, OpenMPMapping
1194+
SourceUsesOpenMP, OpenMPClauses, OpenMPLoopForm, OpenMPTarget,
1195+
OpenMPMapping, OpenMP51Ext
11931196
]>;
11941197

11951198
// SYCL warnings

clang/include/clang/Basic/DiagnosticParseKinds.td

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,6 +1427,15 @@ def err_omp_expected_interop_type : Error<
14271427
def warn_omp_more_one_interop_type
14281428
: Warning<"interop type '%0' cannot be specified more than once">,
14291429
InGroup<OpenMPClauses>;
1430+
def err_expected_sequence_or_directive : Error<
1431+
"expected an OpenMP 'directive' or 'sequence' attribute argument">;
1432+
def ext_omp_attributes : ExtWarn<
1433+
"specifying OpenMP directives with [[]] is an OpenMP 5.1 extension">,
1434+
InGroup<OpenMP51Ext>;
1435+
def warn_omp51_compat_attributes : Warning<
1436+
"specifying OpenMP directives with [[]] is incompatible with OpenMP "
1437+
"standards before OpenMP 5.1">,
1438+
InGroup<OpenMPPre51Compat>, DefaultIgnore;
14301439

14311440
// Pragma loop support.
14321441
def err_pragma_loop_missing_argument : Error<

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,11 @@ def err_typecheck_converted_constant_expression_indirect : Error<
8282
"bind reference to a temporary">;
8383
def err_expr_not_cce : Error<
8484
"%select{case value|enumerator value|non-type template argument|"
85-
"array size|constexpr if condition|explicit specifier argument}0 "
85+
"array size|explicit specifier argument}0 "
8686
"is not a constant expression">;
8787
def ext_cce_narrowing : ExtWarn<
8888
"%select{case value|enumerator value|non-type template argument|"
89-
"array size|constexpr if condition|explicit specifier argument}0 "
89+
"array size|explicit specifier argument}0 "
9090
"%select{cannot be narrowed from type %2 to %3|"
9191
"evaluates to %2, which cannot be narrowed to type %3}1">,
9292
InGroup<CXX11Narrowing>, DefaultError, SFINAEFailure;
@@ -1520,6 +1520,8 @@ def err_messaging_class_with_direct_method : Error<
15201520
// C++ declarations
15211521
def err_static_assert_expression_is_not_constant : Error<
15221522
"static_assert expression is not an integral constant expression">;
1523+
def err_constexpr_if_condition_expression_is_not_constant : Error<
1524+
"constexpr if condition is not a constant expression">;
15231525
def err_static_assert_failed : Error<"static_assert failed%select{ %1|}0">;
15241526
def err_static_assert_requirement_failed : Error<
15251527
"static_assert failed due to requirement '%0'%select{ %2|}1">;

clang/include/clang/Basic/LangOptions.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,11 @@ enum TranslationUnitKind {
715715
TU_Prefix,
716716

717717
/// The translation unit is a module.
718-
TU_Module
718+
TU_Module,
719+
720+
/// The translation unit is a is a complete translation unit that we might
721+
/// incrementally extend later.
722+
TU_Incremental
719723
};
720724

721725
} // namespace clang

clang/include/clang/Basic/TokenKinds.def

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -873,6 +873,13 @@ PRAGMA_ANNOTATION(pragma_ms_pragma)
873873
PRAGMA_ANNOTATION(pragma_opencl_extension)
874874

875875
// Annotations for OpenMP pragma directives - #pragma omp ...
876+
// The parser produces this annotation token when it parses an [[omp::*]]
877+
// attribute. The tokens from the attribute argument list are replayed to the
878+
// token stream with this leading token (and a trailing pragma_openmp_end) so
879+
// that the parser can reuse the OpenMP parsing logic but still be able to
880+
// distinguish between a real pragma and a converted pragma. It is not marked
881+
// as a PRAGMA_ANNOTATION because it doesn't get generated from a #pragma.
882+
ANNOTATION(attr_openmp)
876883
// The lexer produces these so that they only take effect when the parser
877884
// handles #pragma omp ... directives.
878885
PRAGMA_ANNOTATION(pragma_openmp)

clang/include/clang/Interpreter/Interpreter.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#ifndef LLVM_CLANG_INTERPRETER_INTERPRETER_H
1515
#define LLVM_CLANG_INTERPRETER_INTERPRETER_H
1616

17-
#include "clang/Interpreter/Transaction.h"
17+
#include "clang/Interpreter/PartialTranslationUnit.h"
1818

1919
#include "llvm/Support/Error.h"
2020

@@ -55,14 +55,14 @@ class Interpreter {
5555
static llvm::Expected<std::unique_ptr<Interpreter>>
5656
create(std::unique_ptr<CompilerInstance> CI);
5757
const CompilerInstance *getCompilerInstance() const;
58-
llvm::Expected<Transaction &> Parse(llvm::StringRef Code);
59-
llvm::Error Execute(Transaction &T);
58+
llvm::Expected<PartialTranslationUnit &> Parse(llvm::StringRef Code);
59+
llvm::Error Execute(PartialTranslationUnit &T);
6060
llvm::Error ParseAndExecute(llvm::StringRef Code) {
61-
auto ErrOrTransaction = Parse(Code);
62-
if (auto Err = ErrOrTransaction.takeError())
63-
return Err;
64-
if (ErrOrTransaction->TheModule)
65-
return Execute(*ErrOrTransaction);
61+
auto PTU = Parse(Code);
62+
if (!PTU)
63+
return PTU.takeError();
64+
if (PTU->TheModule)
65+
return Execute(*PTU);
6666
return llvm::Error::success();
6767
}
6868
};

clang/include/clang/Interpreter/Transaction.h renamed to clang/include/clang/Interpreter/PartialTranslationUnit.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,27 @@
1111
//
1212
//===----------------------------------------------------------------------===//
1313

14-
#ifndef LLVM_CLANG_INTERPRETER_TRANSACTION_H
15-
#define LLVM_CLANG_INTERPRETER_TRANSACTION_H
14+
#ifndef LLVM_CLANG_INTERPRETER_PARTIALTRANSLATIONUNIT_H
15+
#define LLVM_CLANG_INTERPRETER_PARTIALTRANSLATIONUNIT_H
1616

1717
#include <memory>
18-
#include <vector>
1918

2019
namespace llvm {
2120
class Module;
2221
}
2322

2423
namespace clang {
2524

26-
class DeclGroupRef;
25+
class TranslationUnitDecl;
2726

2827
/// The class keeps track of various objects created as part of processing
2928
/// incremental inputs.
30-
struct Transaction {
31-
/// The decls created for the input.
32-
std::vector<clang::DeclGroupRef> Decls;
29+
struct PartialTranslationUnit {
30+
TranslationUnitDecl *TUPart = nullptr;
3331

3432
/// The llvm IR produced for the input.
3533
std::unique_ptr<llvm::Module> TheModule;
3634
};
3735
} // namespace clang
3836

39-
#endif // LLVM_CLANG_INTERPRETER_TRANSACTION_H
37+
#endif // LLVM_CLANG_INTERPRETER_PARTIALTRANSLATIONUNIT_H

clang/include/clang/Lex/Preprocessor.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,11 @@ class Preprocessor {
264264
/// avoid tearing the Lexer and etc. down).
265265
bool IncrementalProcessing = false;
266266

267+
public:
267268
/// The kind of translation unit we are processing.
268-
TranslationUnitKind TUKind;
269+
const TranslationUnitKind TUKind;
269270

271+
private:
270272
/// The code-completion handler.
271273
CodeCompletionHandler *CodeComplete = nullptr;
272274

clang/include/clang/Parse/Parser.h

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2773,6 +2773,16 @@ class Parser : public CodeCompletionHandler {
27732773
IdentifierInfo *ScopeName, SourceLocation ScopeLoc,
27742774
ParsedAttr::Syntax Syntax);
27752775

2776+
void ReplayOpenMPAttributeTokens(CachedTokens &OpenMPTokens) {
2777+
// If parsing the attributes found an OpenMP directive, emit those tokens
2778+
// to the parse stream now.
2779+
if (!OpenMPTokens.empty()) {
2780+
PP.EnterToken(Tok, /*IsReinject*/ true);
2781+
PP.EnterTokenStream(OpenMPTokens, /*DisableMacroExpansion*/ true,
2782+
/*IsReinject*/ true);
2783+
ConsumeAnyToken(/*ConsumeCodeCompletionTok*/ true);
2784+
}
2785+
}
27762786
void MaybeParseCXX11Attributes(Declarator &D) {
27772787
if (standardAttributesAllowed() && isCXX11AttributeSpecifier()) {
27782788
ParsedAttributesWithRange attrs(AttrFactory);
@@ -2802,8 +2812,18 @@ class Parser : public CodeCompletionHandler {
28022812
return false;
28032813
}
28042814

2805-
void ParseCXX11AttributeSpecifier(ParsedAttributes &attrs,
2806-
SourceLocation *EndLoc = nullptr);
2815+
void ParseOpenMPAttributeArgs(IdentifierInfo *AttrName,
2816+
CachedTokens &OpenMPTokens);
2817+
2818+
void ParseCXX11AttributeSpecifierInternal(ParsedAttributes &Attrs,
2819+
CachedTokens &OpenMPTokens,
2820+
SourceLocation *EndLoc = nullptr);
2821+
void ParseCXX11AttributeSpecifier(ParsedAttributes &Attrs,
2822+
SourceLocation *EndLoc = nullptr) {
2823+
CachedTokens OpenMPTokens;
2824+
ParseCXX11AttributeSpecifierInternal(Attrs, OpenMPTokens, EndLoc);
2825+
ReplayOpenMPAttributeTokens(OpenMPTokens);
2826+
}
28072827
void ParseCXX11Attributes(ParsedAttributesWithRange &attrs,
28082828
SourceLocation *EndLoc = nullptr);
28092829
/// Parses a C++11 (or C2x)-style attribute argument list. Returns true
@@ -2812,7 +2832,8 @@ class Parser : public CodeCompletionHandler {
28122832
SourceLocation AttrNameLoc,
28132833
ParsedAttributes &Attrs, SourceLocation *EndLoc,
28142834
IdentifierInfo *ScopeName,
2815-
SourceLocation ScopeLoc);
2835+
SourceLocation ScopeLoc,
2836+
CachedTokens &OpenMPTokens);
28162837

28172838
IdentifierInfo *TryParseCXX11AttributeIdentifier(SourceLocation &Loc);
28182839

clang/include/clang/Sema/Sema.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1545,7 +1545,7 @@ class Sema final {
15451545
/// initializers for tentative definitions in C) once parsing has
15461546
/// completed. Modules and precompiled headers perform different kinds of
15471547
/// checks.
1548-
TranslationUnitKind TUKind;
1548+
const TranslationUnitKind TUKind;
15491549

15501550
llvm::BumpPtrAllocator BumpAlloc;
15511551

@@ -3742,7 +3742,6 @@ class Sema final {
37423742
CCEK_Enumerator, ///< Enumerator value with fixed underlying type.
37433743
CCEK_TemplateArg, ///< Value of a non-type template parameter.
37443744
CCEK_ArrayBound, ///< Array bound in array declarator or new-expression.
3745-
CCEK_ConstexprIf, ///< Condition in a constexpr if statement.
37463745
CCEK_ExplicitBool ///< Condition in an explicit(bool) specifier.
37473746
};
37483747
ExprResult CheckConvertedConstantExpression(Expr *From, QualType T,

0 commit comments

Comments
 (0)