Skip to content

Commit e48aa2a

Browse files
committed
Merge from 'master' to 'sycl-web' (#36)
CONFLICT (content): Merge conflict in clang/test/lit.cfg.py
2 parents 3aa6cac + f69c74d commit e48aa2a

File tree

110 files changed

+2035
-1000
lines changed

Some content is hidden

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

110 files changed

+2035
-1000
lines changed

clang-tools-extra/clangd/Selection.cpp

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ using ast_type_traits::DynTypedNode;
5252
// On traversing an AST node, its token range is erased from the unclaimed set.
5353
// The tokens actually removed are associated with that node, and hit-tested
5454
// against the selection to determine whether the node is selected.
55-
template <typename T>
56-
class IntervalSet {
55+
template <typename T> class IntervalSet {
5756
public:
5857
IntervalSet(llvm::ArrayRef<T> Range) { UnclaimedRanges.insert(Range); }
5958

@@ -78,7 +77,7 @@ class IntervalSet {
7877
--Overlap.first;
7978
// ...unless B isn't selected at all.
8079
if (Overlap.first->end() <= Claim.begin())
81-
++Overlap.first;
80+
++Overlap.first;
8281
}
8382
if (Overlap.first == Overlap.second)
8483
return Out;
@@ -118,8 +117,7 @@ class IntervalSet {
118117
};
119118

120119
// Disjoint sorted unclaimed ranges of expanded tokens.
121-
std::set<llvm::ArrayRef<T>, RangeLess>
122-
UnclaimedRanges;
120+
std::set<llvm::ArrayRef<T>, RangeLess> UnclaimedRanges;
123121
};
124122

125123
// Sentinel value for the selectedness of a node where we've seen no tokens yet.
@@ -148,11 +146,37 @@ bool shouldIgnore(const syntax::Token &Tok) {
148146
return Tok.kind() == tok::comment || Tok.kind() == tok::semi;
149147
}
150148

149+
// Determine whether 'Target' is the first expansion of the macro
150+
// argument whose top-level spelling location is 'SpellingLoc'.
151+
bool isFirstExpansion(FileID Target, SourceLocation SpellingLoc,
152+
const SourceManager &SM) {
153+
SourceLocation Prev = SpellingLoc;
154+
while (true) {
155+
// If the arg is expanded multiple times, getMacroArgExpandedLocation()
156+
// returns the first expansion.
157+
SourceLocation Next = SM.getMacroArgExpandedLocation(Prev);
158+
// So if we reach the target, target is the first-expansion of the
159+
// first-expansion ...
160+
if (SM.getFileID(Next) == Target)
161+
return true;
162+
163+
// Otherwise, if the FileID stops changing, we've reached the innermost
164+
// macro expansion, and Target was on a different branch.
165+
if (SM.getFileID(Next) == SM.getFileID(Prev))
166+
return false;
167+
168+
Prev = Next;
169+
}
170+
return false;
171+
}
172+
151173
// SelectionTester can determine whether a range of tokens from the PP-expanded
152174
// stream (corresponding to an AST node) is considered selected.
153175
//
154176
// When the tokens result from macro expansions, the appropriate tokens in the
155177
// main file are examined (macro invocation or args). Similarly for #includes.
178+
// However, only the first expansion of a given spelled token is considered
179+
// selected.
156180
//
157181
// It tests each token in the range (not just the endpoints) as contiguous
158182
// expanded tokens may not have contiguous spellings (with macros).
@@ -260,9 +284,14 @@ class SelectionTester {
260284
// Handle tokens that were passed as a macro argument.
261285
SourceLocation ArgStart = SM.getTopMacroCallerLoc(StartLoc);
262286
if (SM.getFileID(ArgStart) == SelFile) {
263-
SourceLocation ArgEnd = SM.getTopMacroCallerLoc(Batch.back().location());
264-
return testTokenRange(SM.getFileOffset(ArgStart),
265-
SM.getFileOffset(ArgEnd));
287+
if (isFirstExpansion(FID, ArgStart, SM)) {
288+
SourceLocation ArgEnd =
289+
SM.getTopMacroCallerLoc(Batch.back().location());
290+
return testTokenRange(SM.getFileOffset(ArgStart),
291+
SM.getFileOffset(ArgEnd));
292+
} else {
293+
/* fall through and treat as part of the macro body */
294+
}
266295
}
267296

268297
// Handle tokens produced by non-argument macro expansion.
@@ -346,7 +375,7 @@ std::string printNodeToString(const DynTypedNode &N, const PrintingPolicy &PP) {
346375
}
347376
#endif
348377

349-
bool isImplicit(const Stmt* S) {
378+
bool isImplicit(const Stmt *S) {
350379
// Some Stmts are implicit and shouldn't be traversed, but there's no
351380
// "implicit" attribute on Stmt/Expr.
352381
// Unwrap implicit casts first if present (other nodes too?).
@@ -611,7 +640,7 @@ class SelectionVisitor : public RecursiveASTVisitor<SelectionVisitor> {
611640
// int (*[[s]])();
612641
else if (auto *VD = llvm::dyn_cast<VarDecl>(D))
613642
return VD->getLocation();
614-
} else if (const auto* CCI = N.get<CXXCtorInitializer>()) {
643+
} else if (const auto *CCI = N.get<CXXCtorInitializer>()) {
615644
// : [[b_]](42)
616645
return CCI->getMemberLocation();
617646
}
@@ -747,10 +776,10 @@ const Node *SelectionTree::commonAncestor() const {
747776
return Ancestor != Root ? Ancestor : nullptr;
748777
}
749778

750-
const DeclContext& SelectionTree::Node::getDeclContext() const {
751-
for (const Node* CurrentNode = this; CurrentNode != nullptr;
779+
const DeclContext &SelectionTree::Node::getDeclContext() const {
780+
for (const Node *CurrentNode = this; CurrentNode != nullptr;
752781
CurrentNode = CurrentNode->Parent) {
753-
if (const Decl* Current = CurrentNode->ASTNode.get<Decl>()) {
782+
if (const Decl *Current = CurrentNode->ASTNode.get<Decl>()) {
754783
if (CurrentNode != this)
755784
if (auto *DC = dyn_cast<DeclContext>(Current))
756785
return *DC;

clang-tools-extra/clangd/Selection.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ namespace clangd {
6464
//
6565
// SelectionTree tries to behave sensibly in the presence of macros, but does
6666
// not model any preprocessor concepts: the output is a subset of the AST.
67+
// When a macro argument is specifically selected, only its first expansion is
68+
// selected in the AST. (Returning a selection forest is unreasonably difficult
69+
// for callers to handle correctly.)
6770
//
6871
// Comments, directives and whitespace are completely ignored.
6972
// Semicolons are also ignored, as the AST generally does not model them well.
@@ -127,15 +130,15 @@ class SelectionTree {
127130
Selection Selected;
128131
// Walk up the AST to get the DeclContext of this Node,
129132
// which is not the node itself.
130-
const DeclContext& getDeclContext() const;
133+
const DeclContext &getDeclContext() const;
131134
// Printable node kind, like "CXXRecordDecl" or "AutoTypeLoc".
132135
std::string kind() const;
133136
// If this node is a wrapper with no syntax (e.g. implicit cast), return
134137
// its contents. (If multiple wrappers are present, unwraps all of them).
135-
const Node& ignoreImplicit() const;
138+
const Node &ignoreImplicit() const;
136139
// If this node is inside a wrapper with no syntax (e.g. implicit cast),
137140
// return that wrapper. (If multiple are present, unwraps all of them).
138-
const Node& outerImplicit() const;
141+
const Node &outerImplicit() const;
139142
};
140143
// The most specific common ancestor of all the selected nodes.
141144
// Returns nullptr if the common ancestor is the root.

clang-tools-extra/clangd/unittests/SelectionTests.cpp

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ TEST(SelectionTest, CommonAncestor) {
415415

416416
// Regression test: this used to match the injected X, not the outer X.
417417
TEST(SelectionTest, InjectedClassName) {
418-
const char* Code = "struct ^X { int x; };";
418+
const char *Code = "struct ^X { int x; };";
419419
auto AST = TestTU::withCode(Annotations(Code).code()).build();
420420
auto T = makeSelectionTree(Code, AST);
421421
ASSERT_EQ("CXXRecordDecl", nodeKind(T.commonAncestor())) << T;
@@ -508,7 +508,8 @@ TEST(SelectionTest, IncludedFile) {
508508
}
509509

510510
TEST(SelectionTest, MacroArgExpansion) {
511-
// If a macro arg is expanded several times, we consider them all selected.
511+
// If a macro arg is expanded several times, we only consider the first one
512+
// selected.
512513
const char *Case = R"cpp(
513514
int mul(int, int);
514515
#define SQUARE(X) mul(X, X);
@@ -517,15 +518,8 @@ TEST(SelectionTest, MacroArgExpansion) {
517518
Annotations Test(Case);
518519
auto AST = TestTU::withCode(Test.code()).build();
519520
auto T = makeSelectionTree(Case, AST);
520-
// Unfortunately, this makes the common ancestor the CallExpr...
521-
// FIXME: hack around this by picking one?
522-
EXPECT_EQ("CallExpr", T.commonAncestor()->kind());
523-
EXPECT_FALSE(T.commonAncestor()->Selected);
524-
EXPECT_EQ(2u, T.commonAncestor()->Children.size());
525-
for (const auto* N : T.commonAncestor()->Children) {
526-
EXPECT_EQ("IntegerLiteral", N->kind());
527-
EXPECT_TRUE(N->Selected);
528-
}
521+
EXPECT_EQ("IntegerLiteral", T.commonAncestor()->kind());
522+
EXPECT_TRUE(T.commonAncestor()->Selected);
529523

530524
// Verify that the common assert() macro doesn't suffer from this.
531525
// (This is because we don't associate the stringified token with the arg).
@@ -542,7 +536,7 @@ TEST(SelectionTest, MacroArgExpansion) {
542536
}
543537

544538
TEST(SelectionTest, Implicit) {
545-
const char* Test = R"cpp(
539+
const char *Test = R"cpp(
546540
struct S { S(const char*); };
547541
int f(S);
548542
int x = f("^");

clang-tools-extra/clangd/unittests/XRefsTests.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,18 @@ TEST(LocateSymbol, All) {
338338
#define ADDRESSOF(X) &X;
339339
int *j = ADDRESSOF(^i);
340340
)cpp",
341-
341+
R"cpp(// Macro argument appearing multiple times in expansion
342+
#define VALIDATE_TYPE(x) (void)x;
343+
#define ASSERT(expr) \
344+
do { \
345+
VALIDATE_TYPE(expr); \
346+
if (!expr); \
347+
} while (false)
348+
bool [[waldo]]() { return true; }
349+
void foo() {
350+
ASSERT(wa^ldo());
351+
}
352+
)cpp",
342353
R"cpp(// Symbol concatenated inside macro (not supported)
343354
int *pi;
344355
#define POINTER(X) p ## X;

clang/include/clang/AST/Expr.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4021,14 +4021,14 @@ class StmtExpr : public Expr {
40214021
Stmt *SubStmt;
40224022
SourceLocation LParenLoc, RParenLoc;
40234023
public:
4024-
// FIXME: Does type-dependence need to be computed differently?
4025-
// FIXME: Do we need to compute instantiation instantiation-dependence for
4026-
// statements? (ugh!)
40274024
StmtExpr(CompoundStmt *substmt, QualType T,
4028-
SourceLocation lp, SourceLocation rp) :
4025+
SourceLocation lp, SourceLocation rp, bool InDependentContext) :
4026+
// Note: we treat a statement-expression in a dependent context as always
4027+
// being value- and instantiation-dependent. This matches the behavior of
4028+
// lambda-expressions and GCC.
40294029
Expr(StmtExprClass, T, VK_RValue, OK_Ordinary,
4030-
T->isDependentType(), false, false, false),
4031-
SubStmt(substmt), LParenLoc(lp), RParenLoc(rp) { }
4030+
T->isDependentType(), InDependentContext, InDependentContext, false),
4031+
SubStmt(substmt), LParenLoc(lp), RParenLoc(rp) {}
40324032

40334033
/// Build an empty statement expression.
40344034
explicit StmtExpr(EmptyShell Empty) : Expr(StmtExprClass, Empty) { }

clang/include/clang/Driver/Options.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1466,6 +1466,8 @@ def fmodule_name_EQ : Joined<["-"], "fmodule-name=">, Group<f_Group>,
14661466
def fmodule_name : Separate<["-"], "fmodule-name">, Alias<fmodule_name_EQ>;
14671467
def fmodule_implementation_of : Separate<["-"], "fmodule-implementation-of">,
14681468
Flags<[CC1Option]>, Alias<fmodule_name_EQ>;
1469+
def fsystem_module : Flag<["-"], "fsystem-module">, Flags<[CC1Option]>,
1470+
HelpText<"Build this module as a system module. Only used with -emit-module">;
14691471
def fmodule_map_file : Joined<["-"], "fmodule-map-file=">,
14701472
Group<f_Group>, Flags<[DriverOption,CC1Option]>, MetaVarName<"<file>">,
14711473
HelpText<"Load this module map file">;

clang/include/clang/Frontend/FrontendOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,9 @@ class FrontendOptions {
297297
/// Should a temporary file be used during compilation.
298298
unsigned UseTemporary : 1;
299299

300+
/// When using -emit-module, treat the modulemap as a system module.
301+
unsigned IsSystemModule : 1;
302+
300303
CodeCompleteOptions CodeCompleteOpts;
301304

302305
/// Specifies the output format of the AST.

clang/include/clang/Sema/Sema.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5107,7 +5107,7 @@ class Sema final {
51075107
LabelDecl *TheDecl);
51085108

51095109
void ActOnStartStmtExpr();
5110-
ExprResult ActOnStmtExpr(SourceLocation LPLoc, Stmt *SubStmt,
5110+
ExprResult ActOnStmtExpr(Scope *S, SourceLocation LPLoc, Stmt *SubStmt,
51115111
SourceLocation RPLoc); // "({..})"
51125112
// Handle the final expression in a statement expression.
51135113
ExprResult ActOnStmtExprResult(ExprResult E);

clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,10 @@ ANALYZER_OPTION(bool, ShouldEmitFixItHintsAsRemarks, "fixits-as-remarks",
310310
"Emit fix-it hints as remarks for testing purposes",
311311
false)
312312

313+
ANALYZER_OPTION(bool, ShouldApplyFixIts, "apply-fixits",
314+
"Apply the fix-it hints to the files",
315+
false)
316+
313317
//===----------------------------------------------------------------------===//
314318
// Unsigned analyzer options.
315319
//===----------------------------------------------------------------------===//

clang/lib/AST/ASTImporter.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6631,8 +6631,9 @@ ExpectedStmt ASTNodeImporter::VisitStmtExpr(StmtExpr *E) {
66316631
if (Err)
66326632
return std::move(Err);
66336633

6634-
return new (Importer.getToContext()) StmtExpr(
6635-
ToSubStmt, ToType, ToLParenLoc, ToRParenLoc);
6634+
return new (Importer.getToContext())
6635+
StmtExpr(ToSubStmt, ToType, ToLParenLoc, ToRParenLoc,
6636+
E->isInstantiationDependent());
66366637
}
66376638

66386639
ExpectedStmt ASTNodeImporter::VisitUnaryOperator(UnaryOperator *E) {

clang/lib/AST/ExprConstant.cpp

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3047,15 +3047,22 @@ static void expandArray(APValue &Array, unsigned Index) {
30473047
/// is trivial. Note that this is never true for a union type with fields
30483048
/// (because the copy always "reads" the active member) and always true for
30493049
/// a non-class type.
3050+
static bool isReadByLvalueToRvalueConversion(const CXXRecordDecl *RD);
30503051
static bool isReadByLvalueToRvalueConversion(QualType T) {
30513052
CXXRecordDecl *RD = T->getBaseElementTypeUnsafe()->getAsCXXRecordDecl();
3052-
if (!RD || (RD->isUnion() && !RD->field_empty()))
3053-
return true;
3053+
return !RD || isReadByLvalueToRvalueConversion(RD);
3054+
}
3055+
static bool isReadByLvalueToRvalueConversion(const CXXRecordDecl *RD) {
3056+
// FIXME: A trivial copy of a union copies the object representation, even if
3057+
// the union is empty.
3058+
if (RD->isUnion())
3059+
return !RD->field_empty();
30543060
if (RD->isEmpty())
30553061
return false;
30563062

30573063
for (auto *Field : RD->fields())
3058-
if (isReadByLvalueToRvalueConversion(Field->getType()))
3064+
if (!Field->isUnnamedBitfield() &&
3065+
isReadByLvalueToRvalueConversion(Field->getType()))
30593066
return true;
30603067

30613068
for (auto &BaseSpec : RD->bases())
@@ -5460,22 +5467,6 @@ static bool HandleUnionActiveMemberChange(EvalInfo &Info, const Expr *LHSExpr,
54605467
return true;
54615468
}
54625469

5463-
/// Determine if a class has any fields that might need to be copied by a
5464-
/// trivial copy or move operation.
5465-
static bool hasFields(const CXXRecordDecl *RD) {
5466-
if (!RD || RD->isEmpty())
5467-
return false;
5468-
for (auto *FD : RD->fields()) {
5469-
if (FD->isUnnamedBitfield())
5470-
continue;
5471-
return true;
5472-
}
5473-
for (auto &Base : RD->bases())
5474-
if (hasFields(Base.getType()->getAsCXXRecordDecl()))
5475-
return true;
5476-
return false;
5477-
}
5478-
54795470
namespace {
54805471
typedef SmallVector<APValue, 8> ArgVector;
54815472
}
@@ -5546,7 +5537,8 @@ static bool HandleFunctionCall(SourceLocation CallLoc,
55465537
const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(Callee);
55475538
if (MD && MD->isDefaulted() &&
55485539
(MD->getParent()->isUnion() ||
5549-
(MD->isTrivial() && hasFields(MD->getParent())))) {
5540+
(MD->isTrivial() &&
5541+
isReadByLvalueToRvalueConversion(MD->getParent())))) {
55505542
assert(This &&
55515543
(MD->isCopyAssignmentOperator() || MD->isMoveAssignmentOperator()));
55525544
LValue RHS;
@@ -5633,7 +5625,8 @@ static bool HandleConstructorCall(const Expr *E, const LValue &This,
56335625
// actually read them.
56345626
if (Definition->isDefaulted() && Definition->isCopyOrMoveConstructor() &&
56355627
(Definition->getParent()->isUnion() ||
5636-
(Definition->isTrivial() && hasFields(Definition->getParent())))) {
5628+
(Definition->isTrivial() &&
5629+
isReadByLvalueToRvalueConversion(Definition->getParent())))) {
56375630
LValue RHS;
56385631
RHS.setFrom(Info.Ctx, ArgValues[0]);
56395632
return handleLValueToRValueConversion(

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1951,9 +1951,9 @@ void CodeGenModule::SetFunctionAttributes(GlobalDecl GD, llvm::Function *F,
19511951
}
19521952
}
19531953

1954-
void CodeGenModule::addUsedGlobal(llvm::GlobalValue *GV) {
1955-
assert(!GV->isDeclaration() &&
1956-
"Only globals with definition can force usage.");
1954+
void CodeGenModule::addUsedGlobal(llvm::GlobalValue *GV, bool SkipCheck) {
1955+
assert(SkipCheck || (!GV->isDeclaration() &&
1956+
"Only globals with definition can force usage."));
19571957
LLVMUsed.emplace_back(GV);
19581958
}
19591959

@@ -4275,9 +4275,17 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D,
42754275
}
42764276
}
42774277

4278-
if (!IsHIPPinnedShadowVar)
4278+
// HIPPinnedShadowVar should remain in the final code object irrespective of
4279+
// whether it is used or not within the code. Add it to used list, so that
4280+
// it will not get eliminated when it is unused. Also, it is an extern var
4281+
// within device code, and it should *not* get initialized within device code.
4282+
if (IsHIPPinnedShadowVar)
4283+
addUsedGlobal(GV, /*SkipCheck=*/true);
4284+
else
42794285
GV->setInitializer(Init);
4280-
if (emitter) emitter->finalize(GV);
4286+
4287+
if (emitter)
4288+
emitter->finalize(GV);
42814289

42824290
// If it is safe to mark the global 'constant', do so now.
42834291
GV->setConstant(!NeedsGlobalCtor && !NeedsGlobalDtor &&

clang/lib/CodeGen/CodeGenModule.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1050,7 +1050,7 @@ class CodeGenModule : public CodeGenTypeCache {
10501050
void MaybeHandleStaticInExternC(const SomeDecl *D, llvm::GlobalValue *GV);
10511051

10521052
/// Add a global to a list to be added to the llvm.used metadata.
1053-
void addUsedGlobal(llvm::GlobalValue *GV);
1053+
void addUsedGlobal(llvm::GlobalValue *GV, bool SkipCheck = false);
10541054

10551055
/// Add a global to a list to be added to the llvm.compiler.used metadata.
10561056
void addCompilerUsedGlobal(llvm::GlobalValue *GV);

0 commit comments

Comments
 (0)