Skip to content

Commit e03bbe3

Browse files
committed
Merge from 'main' to 'sycl-web' (intel#39)
CONFLICT (content): Merge conflict in clang/tools/CMakeLists.txt
2 parents ac12836 + 44a4000 commit e03bbe3

File tree

149 files changed

+3917
-893
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

+3917
-893
lines changed

clang/include/clang/AST/DeclTemplate.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,7 @@ class TemplateParameterList final
160160

161161
/// Determine whether this template parameter list contains an
162162
/// unexpanded parameter pack.
163-
bool containsUnexpandedParameterPack() const {
164-
return ContainsUnexpandedParameterPack;
165-
}
163+
bool containsUnexpandedParameterPack() const;
166164

167165
/// Determine whether this template parameter list contains a parameter pack.
168166
bool hasParameterPack() const {

clang/include/clang/AST/EvaluatedExprVisitor.h

+18-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ class EvaluatedExprVisitorBase : public StmtVisitorBase<Ptr, ImplClass, void> {
3232
const ASTContext &Context;
3333

3434
public:
35+
// Return whether this visitor should recurse into discarded statements for a
36+
// 'constexpr-if'.
37+
bool shouldVisitDiscardedStmt() const { return true; }
3538
#define PTR(CLASS) typename Ptr<CLASS>::type
3639

3740
explicit EvaluatedExprVisitorBase(const ASTContext &Context) : Context(Context) { }
@@ -83,7 +86,7 @@ class EvaluatedExprVisitorBase : public StmtVisitorBase<Ptr, ImplClass, void> {
8386

8487
void VisitCallExpr(PTR(CallExpr) CE) {
8588
if (!CE->isUnevaluatedBuiltinCall(Context))
86-
return static_cast<ImplClass*>(this)->VisitExpr(CE);
89+
return getDerived().VisitExpr(CE);
8790
}
8891

8992
void VisitLambdaExpr(PTR(LambdaExpr) LE) {
@@ -103,6 +106,20 @@ class EvaluatedExprVisitorBase : public StmtVisitorBase<Ptr, ImplClass, void> {
103106
this->Visit(SubStmt);
104107
}
105108

109+
void VisitIfStmt(PTR(IfStmt) If) {
110+
if (!getDerived().shouldVisitDiscardedStmt()) {
111+
if (auto SubStmt = If->getNondiscardedCase(Context)) {
112+
if (*SubStmt)
113+
this->Visit(*SubStmt);
114+
return;
115+
}
116+
}
117+
118+
getDerived().VisitStmt(If);
119+
}
120+
121+
ImplClass &getDerived() { return *static_cast<ImplClass *>(this); }
122+
106123
#undef PTR
107124
};
108125

clang/include/clang/AST/RecursiveASTVisitor.h

+20-5
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,8 @@ template <typename Derived> class RecursiveASTVisitor {
481481
template <typename T>
482482
bool TraverseDeclTemplateParameterLists(T *D);
483483

484+
bool TraverseTemplateTypeParamDeclConstraints(const TemplateTypeParmDecl *D);
485+
484486
bool TraverseTemplateArgumentLocsHelper(const TemplateArgumentLoc *TAL,
485487
unsigned Count);
486488
bool TraverseArrayTypeLocHelper(ArrayTypeLoc TL);
@@ -658,8 +660,14 @@ bool RecursiveASTVisitor<Derived>::TraverseDecl(Decl *D) {
658660

659661
// As a syntax visitor, by default we want to ignore declarations for
660662
// implicit declarations (ones not typed explicitly by the user).
661-
if (!getDerived().shouldVisitImplicitCode() && D->isImplicit())
663+
if (!getDerived().shouldVisitImplicitCode() && D->isImplicit()) {
664+
// For an implicit template type parameter, its type constraints are not
665+
// implicit and are not represented anywhere else. We still need to visit
666+
// them.
667+
if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(D))
668+
return TraverseTemplateTypeParamDeclConstraints(TTPD);
662669
return true;
670+
}
663671

664672
switch (D->getKind()) {
665673
#define ABSTRACT_DECL(DECL)
@@ -1779,10 +1787,9 @@ DEF_TRAVERSE_DECL(BuiltinTemplateDecl, {
17791787
TRY_TO(TraverseTemplateParameterListHelper(D->getTemplateParameters()));
17801788
})
17811789

1782-
DEF_TRAVERSE_DECL(TemplateTypeParmDecl, {
1783-
// D is the "T" in something like "template<typename T> class vector;"
1784-
if (D->getTypeForDecl())
1785-
TRY_TO(TraverseType(QualType(D->getTypeForDecl(), 0)));
1790+
template <typename Derived>
1791+
bool RecursiveASTVisitor<Derived>::TraverseTemplateTypeParamDeclConstraints(
1792+
const TemplateTypeParmDecl *D) {
17861793
if (const auto *TC = D->getTypeConstraint()) {
17871794
if (Expr *IDC = TC->getImmediatelyDeclaredConstraint()) {
17881795
TRY_TO(TraverseStmt(IDC));
@@ -1794,6 +1801,14 @@ DEF_TRAVERSE_DECL(TemplateTypeParmDecl, {
17941801
TRY_TO(TraverseConceptReference(*TC));
17951802
}
17961803
}
1804+
return true;
1805+
}
1806+
1807+
DEF_TRAVERSE_DECL(TemplateTypeParmDecl, {
1808+
// D is the "T" in something like "template<typename T> class vector;"
1809+
if (D->getTypeForDecl())
1810+
TRY_TO(TraverseType(QualType(D->getTypeForDecl(), 0)));
1811+
TRY_TO(TraverseTemplateTypeParamDeclConstraints(D));
17971812
if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited())
17981813
TRY_TO(TraverseTypeLoc(D->getDefaultArgumentInfo()->getTypeLoc()));
17991814
})

clang/include/clang/AST/Stmt.h

+1
Original file line numberDiff line numberDiff line change
@@ -2080,6 +2080,7 @@ class IfStmt final
20802080
/// If this is an 'if constexpr', determine which substatement will be taken.
20812081
/// Otherwise, or if the condition is value-dependent, returns None.
20822082
Optional<const Stmt*> getNondiscardedCase(const ASTContext &Ctx) const;
2083+
Optional<Stmt *> getNondiscardedCase(const ASTContext &Ctx);
20832084

20842085
bool isObjCAvailabilityCheck() const;
20852086

clang/include/clang/Basic/CodeGenOptions.h

-17
Original file line numberDiff line numberDiff line change
@@ -75,23 +75,6 @@ class CodeGenOptions : public CodeGenOptionsBase {
7575
LocalExecTLSModel
7676
};
7777

78-
/// Clang versions with different platform ABI conformance.
79-
enum class ClangABI {
80-
/// Attempt to be ABI-compatible with code generated by Clang 3.8.x
81-
/// (SVN r257626). This causes <1 x long long> to be passed in an
82-
/// integer register instead of an SSE register on x64_64.
83-
Ver3_8,
84-
85-
/// Attempt to be ABI-compatible with code generated by Clang 4.0.x
86-
/// (SVN r291814). This causes move operations to be ignored when
87-
/// determining whether a class type can be passed or returned directly.
88-
Ver4,
89-
90-
/// Conform to the underlying platform's C and C++ ABIs as closely
91-
/// as we can.
92-
Latest
93-
};
94-
9578
enum StructReturnConventionKind {
9679
SRCK_Default, // No special option was passed.
9780
SRCK_OnStack, // Small structs on the stack (-fpcc-struct-return).

clang/include/clang/Basic/LangOptions.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,18 @@ class LangOptions : public LangOptionsBase {
173173
Ver9,
174174

175175
/// Attempt to be ABI-compatible with code generated by Clang 11.0.x
176-
/// (git 2e10b7a39b93). This causes clang to pass unions with a 256-bit
176+
/// (git 2e10b7a39b93). This causes clang to pass unions with a 256-bit
177177
/// vector member on the stack instead of using registers, to not properly
178178
/// mangle substitutions for template names in some cases, and to mangle
179179
/// declaration template arguments without a cast to the parameter type
180180
/// even when that can lead to mangling collisions.
181181
Ver11,
182182

183+
/// Attempt to be ABI-compatible with code generated by Clang 12.0.x
184+
/// (git 8e464dd76bef). This causes clang to mangle lambdas within
185+
/// global-scope inline variables incorrectly.
186+
Ver12,
187+
183188
/// Conform to the underlying platform's C and C++ ABIs as closely
184189
/// as we can.
185190
Latest

clang/include/clang/CodeGen/CodeGenAction.h

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ namespace llvm {
1919

2020
namespace clang {
2121
class BackendConsumer;
22+
class CodeGenerator;
2223

2324
class CodeGenAction : public ASTFrontendAction {
2425
private:
@@ -77,6 +78,8 @@ class CodeGenAction : public ASTFrontendAction {
7778
/// Take the LLVM context used by this action.
7879
llvm::LLVMContext *takeLLVMContext();
7980

81+
CodeGenerator *getCodeGenerator() const;
82+
8083
BackendConsumer *BEConsumer;
8184
};
8285

clang/include/clang/Frontend/FrontendAction.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ class FrontendAction {
234234

235235
/// Perform any per-file post processing, deallocate per-file
236236
/// objects, and run statistics and output file cleanup code.
237-
void EndSourceFile();
237+
virtual void EndSourceFile();
238238

239239
/// @}
240240
};
@@ -302,15 +302,16 @@ class PreprocessorFrontendAction : public FrontendAction {
302302
/// some existing action's behavior. It implements every virtual method in
303303
/// the FrontendAction interface by forwarding to the wrapped action.
304304
class WrapperFrontendAction : public FrontendAction {
305+
protected:
305306
std::unique_ptr<FrontendAction> WrappedAction;
306307

307-
protected:
308308
bool PrepareToExecuteAction(CompilerInstance &CI) override;
309309
std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
310310
StringRef InFile) override;
311311
bool BeginInvocation(CompilerInstance &CI) override;
312312
bool BeginSourceFileAction(CompilerInstance &CI) override;
313313
void ExecuteAction() override;
314+
void EndSourceFile() override;
314315
void EndSourceFileAction() override;
315316
bool shouldEraseOutputFiles() override;
316317

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
//===--- Interpreter.h - Incremental Compilation and Execution---*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// This file defines the component which performs incremental code
10+
// compilation and execution.
11+
//
12+
//===----------------------------------------------------------------------===//
13+
14+
#ifndef LLVM_CLANG_INTERPRETER_INTERPRETER_H
15+
#define LLVM_CLANG_INTERPRETER_INTERPRETER_H
16+
17+
#include "clang/Interpreter/Transaction.h"
18+
19+
#include "llvm/Support/Error.h"
20+
21+
#include <memory>
22+
#include <vector>
23+
24+
namespace llvm {
25+
namespace orc {
26+
class ThreadSafeContext;
27+
}
28+
class Module;
29+
} // namespace llvm
30+
31+
namespace clang {
32+
33+
class CompilerInstance;
34+
class DeclGroupRef;
35+
class IncrementalExecutor;
36+
class IncrementalParser;
37+
38+
/// Create a pre-configured \c CompilerInstance for incremental processing.
39+
class IncrementalCompilerBuilder {
40+
public:
41+
static llvm::Expected<std::unique_ptr<CompilerInstance>>
42+
create(std::vector<const char *> &ClangArgv);
43+
};
44+
45+
/// Provides top-level interfaces for incremental compilation and execution.
46+
class Interpreter {
47+
std::unique_ptr<llvm::orc::ThreadSafeContext> TSCtx;
48+
std::unique_ptr<IncrementalParser> IncrParser;
49+
std::unique_ptr<IncrementalExecutor> IncrExecutor;
50+
51+
Interpreter(std::unique_ptr<CompilerInstance> CI, llvm::Error &Err);
52+
53+
public:
54+
~Interpreter();
55+
static llvm::Expected<std::unique_ptr<Interpreter>>
56+
create(std::unique_ptr<CompilerInstance> CI);
57+
const CompilerInstance *getCompilerInstance() const;
58+
llvm::Expected<Transaction &> Parse(llvm::StringRef Code);
59+
llvm::Error Execute(Transaction &T);
60+
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);
66+
return llvm::Error::success();
67+
}
68+
};
69+
} // namespace clang
70+
71+
#endif // LLVM_CLANG_INTERPRETER_INTERPRETER_H
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//===--- Transaction.h - Incremental Compilation and Execution---*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// This file defines utilities tracking the incrementally processed pieces of
10+
// code.
11+
//
12+
//===----------------------------------------------------------------------===//
13+
14+
#ifndef LLVM_CLANG_INTERPRETER_TRANSACTION_H
15+
#define LLVM_CLANG_INTERPRETER_TRANSACTION_H
16+
17+
#include <memory>
18+
#include <vector>
19+
20+
namespace llvm {
21+
class Module;
22+
}
23+
24+
namespace clang {
25+
26+
class DeclGroupRef;
27+
28+
/// The class keeps track of various objects created as part of processing
29+
/// incremental inputs.
30+
struct Transaction {
31+
/// The decls created for the input.
32+
std::vector<clang::DeclGroupRef> Decls;
33+
34+
/// The llvm IR produced for the input.
35+
std::unique_ptr<llvm::Module> TheModule;
36+
};
37+
} // namespace clang
38+
39+
#endif // LLVM_CLANG_INTERPRETER_TRANSACTION_H

clang/include/clang/Sema/Sema.h

+5
Original file line numberDiff line numberDiff line change
@@ -7671,6 +7671,11 @@ class Sema final {
76717671
TemplateIdAnnotation *TypeConstraint,
76727672
TemplateTypeParmDecl *ConstrainedParameter,
76737673
SourceLocation EllipsisLoc);
7674+
bool BuildTypeConstraint(const CXXScopeSpec &SS,
7675+
TemplateIdAnnotation *TypeConstraint,
7676+
TemplateTypeParmDecl *ConstrainedParameter,
7677+
SourceLocation EllipsisLoc,
7678+
bool AllowUnexpandedPack);
76747679

76757680
bool AttachTypeConstraint(NestedNameSpecifierLoc NS,
76767681
DeclarationNameInfo NameInfo,

clang/lib/AST/DeclTemplate.cpp

+33-6
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,15 @@ TemplateParameterList::TemplateParameterList(const ASTContext& C,
6868
if (!IsPack &&
6969
TTP->getTemplateParameters()->containsUnexpandedParameterPack())
7070
ContainsUnexpandedParameterPack = true;
71-
} else if (const TypeConstraint *TC =
72-
cast<TemplateTypeParmDecl>(P)->getTypeConstraint()) {
73-
if (TC->getImmediatelyDeclaredConstraint()
74-
->containsUnexpandedParameterPack())
75-
ContainsUnexpandedParameterPack = true;
76-
HasConstrainedParameters = true;
71+
} else if (const auto *TTP = dyn_cast<TemplateTypeParmDecl>(P)) {
72+
if (const TypeConstraint *TC = TTP->getTypeConstraint()) {
73+
if (TC->getImmediatelyDeclaredConstraint()
74+
->containsUnexpandedParameterPack())
75+
ContainsUnexpandedParameterPack = true;
76+
}
77+
HasConstrainedParameters = TTP->hasTypeConstraint();
78+
} else {
79+
llvm_unreachable("unexpcted template parameter type");
7780
}
7881
// FIXME: If a default argument contains an unexpanded parameter pack, the
7982
// template parameter list does too.
@@ -86,6 +89,30 @@ TemplateParameterList::TemplateParameterList(const ASTContext& C,
8689
}
8790
}
8891

92+
bool TemplateParameterList::containsUnexpandedParameterPack() const {
93+
if (ContainsUnexpandedParameterPack)
94+
return true;
95+
if (!HasConstrainedParameters)
96+
return false;
97+
98+
// An implicit constrained parameter might have had a use of an unexpanded
99+
// pack added to it after the template parameter list was created. All
100+
// implicit parameters are at the end of the parameter list.
101+
for (const NamedDecl *Param : llvm::reverse(asArray())) {
102+
if (!Param->isImplicit())
103+
break;
104+
105+
if (const auto *TTP = dyn_cast<TemplateTypeParmDecl>(Param)) {
106+
const auto *TC = TTP->getTypeConstraint();
107+
if (TC && TC->getImmediatelyDeclaredConstraint()
108+
->containsUnexpandedParameterPack())
109+
return true;
110+
}
111+
}
112+
113+
return false;
114+
}
115+
89116
TemplateParameterList *
90117
TemplateParameterList::Create(const ASTContext &C, SourceLocation TemplateLoc,
91118
SourceLocation LAngleLoc,

0 commit comments

Comments
 (0)