Skip to content

Commit aefffa1

Browse files
authored
merge main into amd-staging (llvm#1936)
2 parents de89218 + bf2f86b commit aefffa1

File tree

162 files changed

+2434
-1431
lines changed

Some content is hidden

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

162 files changed

+2434
-1431
lines changed

clang-tools-extra/clang-include-fixer/IncludeFixer.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,7 @@ bool IncludeFixerActionFactory::runInvocation(
8989
assert(Invocation->getFrontendOpts().Inputs.size() == 1);
9090

9191
// Set up Clang.
92-
clang::CompilerInstance Compiler(PCHContainerOps);
93-
Compiler.setInvocation(std::move(Invocation));
92+
CompilerInstance Compiler(std::move(Invocation), std::move(PCHContainerOps));
9493
Compiler.setFileManager(Files);
9594

9695
// Create the compiler's actual diagnostics engine. We want to drop all

clang-tools-extra/clangd/Compiler.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,7 @@ prepareCompilerInstance(std::unique_ptr<clang::CompilerInvocation> CI,
145145
CI->getFrontendOpts().Inputs[0].getFile(), Buffer.get());
146146
}
147147

148-
auto Clang = std::make_unique<CompilerInstance>(
149-
std::make_shared<PCHContainerOperations>());
150-
Clang->setInvocation(std::move(CI));
148+
auto Clang = std::make_unique<CompilerInstance>(std::move(CI));
151149
Clang->createDiagnostics(*VFS, &DiagsClient, false);
152150

153151
if (auto VFSWithRemapping = createVFSFromCompilerInvocation(

clang-tools-extra/include-cleaner/unittests/RecordTest.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -618,14 +618,14 @@ TEST_F(PragmaIncludeTest, ExportInUnnamedBuffer) {
618618
llvm::MemoryBuffer::getMemBufferCopy(Extra.getValue(),
619619
/*BufferName=*/""));
620620

621-
auto Clang = std::make_unique<CompilerInstance>(
622-
std::make_shared<PCHContainerOperations>());
623-
Clang->createDiagnostics(*VFS);
621+
auto DiagOpts = llvm::makeIntrusiveRefCnt<DiagnosticOptions>();
622+
auto Diags = CompilerInstance::createDiagnostics(*VFS, DiagOpts.get());
623+
auto Invocation = std::make_unique<CompilerInvocation>();
624+
ASSERT_TRUE(CompilerInvocation::CreateFromArgs(*Invocation, {Filename.data()},
625+
*Diags, "clang"));
624626

625-
Clang->setInvocation(std::make_unique<CompilerInvocation>());
626-
ASSERT_TRUE(CompilerInvocation::CreateFromArgs(
627-
Clang->getInvocation(), {Filename.data()}, Clang->getDiagnostics(),
628-
"clang"));
627+
auto Clang = std::make_unique<CompilerInstance>(std::move(Invocation));
628+
Clang->createDiagnostics(*VFS);
629629

630630
auto *FM = Clang->createFileManager(VFS);
631631
ASSERT_TRUE(Clang->ExecuteAction(*Inputs.MakeAction()));

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ Improvements to Clang's diagnostics
389389
under the subgroup ``-Wunsafe-buffer-usage-in-libc-call``.
390390
- Diagnostics on chained comparisons (``a < b < c``) are now an error by default. This can be disabled with
391391
``-Wno-error=parentheses``.
392+
- Similarly, fold expressions over a comparison operator are now an error by default.
392393
- Clang now better preserves the sugared types of pointers to member.
393394
- Clang now better preserves the presence of the template keyword with dependent
394395
prefixes.

clang/include/clang/Basic/Diagnostic.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,6 +1429,25 @@ operator<<(const StreamingDiagnostic &DB, T *DC) {
14291429
return DB;
14301430
}
14311431

1432+
// Convert scoped enums to their underlying type, so that we don't have
1433+
// clutter the emitting code with `llvm::to_underlying()`.
1434+
// We also need to disable implicit conversion for the first argument,
1435+
// because classes that derive from StreamingDiagnostic define their own
1436+
// templated operator<< that accept a wide variety of types, leading
1437+
// to ambiguity.
1438+
template <typename T, typename U,
1439+
typename UnderlyingU = typename std::enable_if_t<
1440+
std::is_enum_v<std::remove_reference_t<U>>,
1441+
std::underlying_type<std::remove_reference_t<U>>>::type>
1442+
inline std::enable_if_t<
1443+
std::is_same_v<std::remove_const_t<T>, StreamingDiagnostic> &&
1444+
!std::is_convertible_v<U, UnderlyingU>,
1445+
const StreamingDiagnostic &>
1446+
operator<<(const T &DB, U &&SE) {
1447+
DB << llvm::to_underlying(SE);
1448+
return DB;
1449+
}
1450+
14321451
inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &DB,
14331452
SourceLocation L) {
14341453
DB.AddSourceRange(CharSourceRange::getTokenRange(L));

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7204,6 +7204,11 @@ def warn_consecutive_comparison : Warning<
72047204
"chained comparison 'X %0 Y %1 Z' does not behave the same as a mathematical expression">,
72057205
InGroup<Parentheses>, DefaultError;
72067206

7207+
def warn_comparison_in_fold_expression : Warning<
7208+
"comparison in fold expression would evaluate to '(X %0 Y) %0 Z' "
7209+
"which does not behave the same as a mathematical expression">,
7210+
InGroup<Parentheses>, DefaultError;
7211+
72077212
def warn_enum_constant_in_bool_context : Warning<
72087213
"converting the enum constant to a boolean">,
72097214
InGroup<IntInBoolContext>, DefaultIgnore;

clang/include/clang/Frontend/CompilerInstance.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@ class CompilerInstance : public ModuleLoader {
204204
void operator=(const CompilerInstance &) = delete;
205205
public:
206206
explicit CompilerInstance(
207+
std::shared_ptr<CompilerInvocation> Invocation =
208+
std::make_shared<CompilerInvocation>(),
207209
std::shared_ptr<PCHContainerOperations> PCHContainerOps =
208210
std::make_shared<PCHContainerOperations>(),
209211
ModuleCache *ModCache = nullptr);
@@ -251,18 +253,10 @@ class CompilerInstance : public ModuleLoader {
251253
/// @name Compiler Invocation and Options
252254
/// @{
253255

254-
bool hasInvocation() const { return Invocation != nullptr; }
255-
256-
CompilerInvocation &getInvocation() {
257-
assert(Invocation && "Compiler instance has no invocation!");
258-
return *Invocation;
259-
}
256+
CompilerInvocation &getInvocation() { return *Invocation; }
260257

261258
std::shared_ptr<CompilerInvocation> getInvocationPtr() { return Invocation; }
262259

263-
/// setInvocation - Replace the current invocation.
264-
void setInvocation(std::shared_ptr<CompilerInvocation> Value);
265-
266260
/// Indicates whether we should (re)build the global module index.
267261
bool shouldBuildGlobalModuleIndex() const;
268262

clang/include/clang/Sema/Sema.h

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,6 @@ enum class AssignmentAction {
220220
Casting,
221221
Passing_CFAudited
222222
};
223-
inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &DB,
224-
const AssignmentAction &AA) {
225-
DB << llvm::to_underlying(AA);
226-
return DB;
227-
}
228223

229224
namespace threadSafety {
230225
class BeforeSet;
@@ -7220,13 +7215,15 @@ class Sema final : public SemaBase {
72207215
ExprResult ActOnBinOp(Scope *S, SourceLocation TokLoc, tok::TokenKind Kind,
72217216
Expr *LHSExpr, Expr *RHSExpr);
72227217
ExprResult BuildBinOp(Scope *S, SourceLocation OpLoc, BinaryOperatorKind Opc,
7223-
Expr *LHSExpr, Expr *RHSExpr);
7218+
Expr *LHSExpr, Expr *RHSExpr,
7219+
bool ForFoldExpression = false);
72247220

72257221
/// CreateBuiltinBinOp - Creates a new built-in binary operation with
72267222
/// operator @p Opc at location @c TokLoc. This routine only supports
72277223
/// built-in operations; ActOnBinOp handles overloaded operators.
72287224
ExprResult CreateBuiltinBinOp(SourceLocation OpLoc, BinaryOperatorKind Opc,
7229-
Expr *LHSExpr, Expr *RHSExpr);
7225+
Expr *LHSExpr, Expr *RHSExpr,
7226+
bool ForFoldExpression = false);
72307227
void LookupBinOp(Scope *S, SourceLocation OpLoc, BinaryOperatorKind Opc,
72317228
UnresolvedSetImpl &Functions);
72327229

@@ -15471,12 +15468,6 @@ void Sema::PragmaStack<Sema::AlignPackInfo>::Act(SourceLocation PragmaLocation,
1547115468
llvm::StringRef StackSlotLabel,
1547215469
AlignPackInfo Value);
1547315470

15474-
inline const StreamingDiagnostic &
15475-
operator<<(const StreamingDiagnostic &DB, Sema::StringEvaluationContext Ctx) {
15476-
DB << llvm::to_underlying(Ctx);
15477-
return DB;
15478-
}
15479-
1548015471
} // end namespace clang
1548115472

1548215473
#endif

clang/lib/AST/ODRDiagsEmitter.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -461,10 +461,8 @@ bool ODRDiagsEmitter::diagnoseSubMismatchObjCMethod(
461461
}
462462
if (FirstMethod->getImplementationControl() !=
463463
SecondMethod->getImplementationControl()) {
464-
DiagError(ControlLevel)
465-
<< llvm::to_underlying(FirstMethod->getImplementationControl());
466-
DiagNote(ControlLevel) << llvm::to_underlying(
467-
SecondMethod->getImplementationControl());
464+
DiagError(ControlLevel) << FirstMethod->getImplementationControl();
465+
DiagNote(ControlLevel) << SecondMethod->getImplementationControl();
468466
return true;
469467
}
470468
if (FirstMethod->isThisDeclarationADesignatedInitializer() !=

clang/lib/CIR/CodeGen/CIRGenStmtOpenACCLoop.cpp

Lines changed: 89 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,103 @@
1313
#include "CIRGenBuilder.h"
1414
#include "CIRGenFunction.h"
1515
#include "CIRGenOpenACCClause.h"
16-
#include "mlir/Dialect/OpenACC/OpenACC.h"
16+
1717
#include "clang/AST/OpenACCClause.h"
1818
#include "clang/AST/StmtOpenACC.h"
1919

20+
#include "mlir/Dialect/OpenACC/OpenACC.h"
21+
2022
using namespace clang;
2123
using namespace clang::CIRGen;
2224
using namespace cir;
2325
using namespace mlir::acc;
2426

2527
mlir::LogicalResult
2628
CIRGenFunction::emitOpenACCLoopConstruct(const OpenACCLoopConstruct &s) {
27-
cgm.errorNYI(s.getSourceRange(), "OpenACC Loop Construct");
28-
return mlir::failure();
29+
mlir::Location start = getLoc(s.getSourceRange().getBegin());
30+
mlir::Location end = getLoc(s.getSourceRange().getEnd());
31+
llvm::SmallVector<mlir::Type> retTy;
32+
llvm::SmallVector<mlir::Value> operands;
33+
auto op = builder.create<LoopOp>(start, retTy, operands);
34+
35+
// TODO(OpenACC): In the future we are going to need to come up with a
36+
// transformation here that can teach the acc.loop how to figure out the
37+
// 'lowerbound', 'upperbound', and 'step'.
38+
//
39+
// -'upperbound' should fortunately be pretty easy as it should be
40+
// in the initialization section of the cir.for loop. In Sema, we limit to
41+
// just the forms 'Var = init', `Type Var = init`, or `Var = init` (where it
42+
// is an operator= call)`. However, as those are all necessary to emit for
43+
// the init section of the for loop, they should be inside the initial
44+
// cir.scope.
45+
//
46+
// -'upperbound' should be somewhat easy to determine. Sema is limiting this
47+
// to: ==, <, >, !=, <=, >= builtin operators, the overloaded 'comparison'
48+
// operations, and member-call expressions.
49+
//
50+
// For the builtin comparison operators, we can pretty well deduce based on
51+
// the comparison what the 'end' object is going to be, and the inclusive
52+
// nature of it.
53+
//
54+
// For the overloaded operators, Sema will ensure that at least one side of
55+
// the operator is the init variable, so we can deduce the comparison there
56+
// too. The standard places no real bounds on WHAT the comparison operators do
57+
// for a `RandomAccessIterator` however, so we'll have to just 'assume' they
58+
// do the right thing? Note that this might be incrementing by a different
59+
// 'object', not an integral, so it isn't really clear to me what we can do to
60+
// determine the other side.
61+
//
62+
// Member-call expressions are the difficult ones. I don't think there is
63+
// anything we can deduce from this to determine the 'end', so we might end up
64+
// having to go back to Sema and make this ill-formed.
65+
//
66+
// HOWEVER: What ACC dialect REALLY cares about is the tripcount, which you
67+
// cannot get (in the case of `RandomAccessIterator`) from JUST 'upperbound'
68+
// and 'lowerbound'. We will likely have to provide a 'recipe' equivalent to
69+
// `std::distance` instead. In the case of integer/pointers, it is fairly
70+
// simple to find: it is just the mathematical subtraction. Howver, in the
71+
// case of `RandomAccessIterator`, we have to enable the use of `operator-`.
72+
// FORTUNATELY the standard requires this to work correctly for
73+
// `RandomAccessIterator`, so we don't have to implement a `std::distance`
74+
// that loops through, like we would for a forward/etc iterator.
75+
//
76+
// 'step': Sema is currently allowing builtin ++,--, +=, -=, *=, /=, and =
77+
// operators. Additionally, it allows the equivalent for the operator-call, as
78+
// well as member-call.
79+
//
80+
// For builtin operators, we perhaps should refine the assignment here. It
81+
// doesn't really help us know the 'step' count at all, but we could perhaps
82+
// do one more step of analysis in Sema to allow something like Var = Var + 1.
83+
// For the others, this should get us the step reasonably well.
84+
//
85+
// For the overloaded operators, we have the same problems as for
86+
// 'upperbound', plus not really knowing what they do. Member-call expressions
87+
// are again difficult, and we might want to reconsider allowing these in
88+
// Sema.
89+
//
90+
91+
// Emit all clauses.
92+
{
93+
mlir::OpBuilder::InsertionGuard guardCase(builder);
94+
// Sets insertion point before the 'op', since every new expression needs to
95+
// be before the operation.
96+
builder.setInsertionPoint(op);
97+
makeClauseEmitter(op, *this, builder, s.getDirectiveKind(),
98+
s.getDirectiveLoc())
99+
.VisitClauseList(s.clauses());
100+
}
101+
102+
mlir::LogicalResult stmtRes = mlir::success();
103+
// Emit body.
104+
{
105+
mlir::Block &block = op.getRegion().emplaceBlock();
106+
mlir::OpBuilder::InsertionGuard guardCase(builder);
107+
builder.setInsertionPointToEnd(&block);
108+
LexicalScope ls{*this, start, builder.getInsertionBlock()};
109+
110+
stmtRes = emitStmt(s.getLoop(), /*useCurrentScope=*/true);
111+
builder.create<mlir::acc::YieldOp>(end);
112+
}
113+
114+
return stmtRes;
29115
}

0 commit comments

Comments
 (0)