Skip to content

Commit e4d1da9

Browse files
committed
Merge from 'master' to 'sycl-web' (intel#2)
CONFLICT (content): Merge conflict in clang/lib/Sema/SemaDecl.cpp CONFLICT (content): Merge conflict in clang/lib/Sema/Sema.cpp
2 parents 84f4398 + b670ab7 commit e4d1da9

File tree

98 files changed

+2871
-909
lines changed

Some content is hidden

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

98 files changed

+2871
-909
lines changed

clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -203,14 +203,15 @@ void RenamerClangTidyCheck::check(const MatchFinder::MatchResult &Result) {
203203
}
204204

205205
if (const auto *Loc = Result.Nodes.getNodeAs<TypeLoc>("typeLoc")) {
206+
UnqualTypeLoc Unqual = Loc->getUnqualifiedLoc();
206207
NamedDecl *Decl = nullptr;
207-
if (const auto &Ref = Loc->getAs<TagTypeLoc>())
208+
if (const auto &Ref = Unqual.getAs<TagTypeLoc>())
208209
Decl = Ref.getDecl();
209-
else if (const auto &Ref = Loc->getAs<InjectedClassNameTypeLoc>())
210+
else if (const auto &Ref = Unqual.getAs<InjectedClassNameTypeLoc>())
210211
Decl = Ref.getDecl();
211-
else if (const auto &Ref = Loc->getAs<UnresolvedUsingTypeLoc>())
212+
else if (const auto &Ref = Unqual.getAs<UnresolvedUsingTypeLoc>())
212213
Decl = Ref.getDecl();
213-
else if (const auto &Ref = Loc->getAs<TemplateTypeParmTypeLoc>())
214+
else if (const auto &Ref = Unqual.getAs<TemplateTypeParmTypeLoc>())
214215
Decl = Ref.getDecl();
215216
// further TypeLocs handled below
216217

clang-tools-extra/test/clang-tidy/checkers/bugprone-reserved-identifier-invert.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ template <class Up>
5757
inline reference_wrapper<const Up>
5858
cref(const Up &u) noexcept {
5959
// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: declaration uses identifier 'u', which is not a reserved identifier [bugprone-reserved-identifier]
60-
// CHECK-FIXES: {{^}}cref(const Up &__u) noexcept {{{$}}
60+
// CHECK-FIXES: {{^}}cref(const _Up &__u) noexcept {{{$}}
6161
return reference_wrapper<const Up>(u);
6262
}
6363

clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -532,3 +532,16 @@ using namespace FOO_NS;
532532

533533
using namespace FOO_NS::InlineNamespace;
534534
// CHECK-FIXES: {{^}}using namespace foo_ns::inline_namespace;
535+
536+
void QualifiedTypeLocTest(THIS___Structure);
537+
// CHECK-FIXES: {{^}}void QualifiedTypeLocTest(this_structure);{{$}}
538+
void QualifiedTypeLocTest(THIS___Structure &);
539+
// CHECK-FIXES: {{^}}void QualifiedTypeLocTest(this_structure &);{{$}}
540+
void QualifiedTypeLocTest(THIS___Structure &&);
541+
// CHECK-FIXES: {{^}}void QualifiedTypeLocTest(this_structure &&);{{$}}
542+
void QualifiedTypeLocTest(const THIS___Structure);
543+
// CHECK-FIXES: {{^}}void QualifiedTypeLocTest(const this_structure);{{$}}
544+
void QualifiedTypeLocTest(const THIS___Structure &);
545+
// CHECK-FIXES: {{^}}void QualifiedTypeLocTest(const this_structure &);{{$}}
546+
void QualifiedTypeLocTest(volatile THIS___Structure &);
547+
// CHECK-FIXES: {{^}}void QualifiedTypeLocTest(volatile this_structure &);{{$}}

clang/include/clang/Sema/ExternalSemaSource.h

+9
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,15 @@ class ExternalSemaSource : public ExternalASTSource {
193193
llvm::MapVector<const FunctionDecl *, std::unique_ptr<LateParsedTemplate>>
194194
&LPTMap) {}
195195

196+
/// Read the set of decls to be checked for deferred diags.
197+
///
198+
/// The external source should append its own potentially emitted function
199+
/// and variable decls which may cause deferred diags. Note that this routine
200+
/// may be invoked multiple times; the external source should take care not to
201+
/// introduce the same declarations repeatedly.
202+
virtual void ReadDeclsToCheckForDeferredDiags(
203+
llvm::SmallVector<Decl *, 4> &Decls) {}
204+
196205
/// \copydoc Sema::CorrectTypo
197206
/// \note LookupKind must correspond to a valid Sema::LookupNameKind
198207
///

clang/include/clang/Sema/MultiplexExternalSemaSource.h

+9
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,15 @@ class MultiplexExternalSemaSource : public ExternalSemaSource {
332332
llvm::MapVector<const FunctionDecl *, std::unique_ptr<LateParsedTemplate>>
333333
&LPTMap) override;
334334

335+
/// Read the set of decls to be checked for deferred diags.
336+
///
337+
/// The external source should append its own potentially emitted function
338+
/// and variable decls which may cause deferred diags. Note that this routine
339+
/// may be invoked multiple times; the external source should take care not to
340+
/// introduce the same declarations repeatedly.
341+
void ReadDeclsToCheckForDeferredDiags(
342+
llvm::SmallVector<Decl *, 4> &Decls) override;
343+
335344
/// \copydoc ExternalSemaSource::CorrectTypo
336345
/// \note Returns the first nonempty correction.
337346
TypoCorrection CorrectTypo(const DeclarationNameInfo &Typo,

clang/include/clang/Sema/Sema.h

+24-37
Original file line numberDiff line numberDiff line change
@@ -1615,6 +1615,18 @@ class Sema final {
16151615

16161616
void emitAndClearUnusedLocalTypedefWarnings();
16171617

1618+
private:
1619+
/// Function or variable declarations to be checked for whether the deferred
1620+
/// diagnostics should be emitted.
1621+
SmallVector<Decl *, 4> DeclsToCheckForDeferredDiags;
1622+
1623+
public:
1624+
// Emit all deferred diagnostics.
1625+
void emitDeferredDiags();
1626+
// Emit any deferred diagnostics for FD and erase them from the map in which
1627+
// they're stored.
1628+
void emitDeferredDiags(FunctionDecl *FD, bool ShowCallStack);
1629+
16181630
enum TUFragmentKind {
16191631
/// The global module fragment, between 'module;' and a module-declaration.
16201632
Global,
@@ -3901,7 +3913,8 @@ class Sema final {
39013913
TemplateDiscarded, // Discarded due to uninstantiated templates
39023914
Unknown,
39033915
};
3904-
FunctionEmissionStatus getEmissionStatus(FunctionDecl *Decl);
3916+
FunctionEmissionStatus getEmissionStatus(FunctionDecl *Decl,
3917+
bool Final = false);
39053918

39063919
// Whether the callee should be ignored in CUDA/HIP/OpenMP host/device check.
39073920
bool shouldIgnoreInHostDeviceCheck(FunctionDecl *Callee);
@@ -9925,22 +9938,10 @@ class Sema final {
99259938
/// Pop OpenMP function region for non-capturing function.
99269939
void popOpenMPFunctionRegion(const sema::FunctionScopeInfo *OldFSI);
99279940

9928-
/// Check whether we're allowed to call Callee from the current function.
9929-
void checkOpenMPDeviceFunction(SourceLocation Loc, FunctionDecl *Callee,
9930-
bool CheckForDelayedContext = true);
9931-
9932-
/// Check whether we're allowed to call Callee from the current function.
9933-
void checkOpenMPHostFunction(SourceLocation Loc, FunctionDecl *Callee,
9934-
bool CheckCaller = true);
9935-
99369941
/// Check if the expression is allowed to be used in expressions for the
99379942
/// OpenMP devices.
99389943
void checkOpenMPDeviceExpr(const Expr *E);
99399944

9940-
/// Finishes analysis of the deferred functions calls that may be declared as
9941-
/// host/nohost during device/host compilation.
9942-
void finalizeOpenMPDelayedAnalysis();
9943-
99449945
/// Checks if a type or a declaration is disabled due to the owning extension
99459946
/// being disabled, and emits diagnostic messages if it is disabled.
99469947
/// \param D type or declaration to be checked.
@@ -10131,6 +10132,11 @@ class Sema final {
1013110132
void
1013210133
checkDeclIsAllowedInOpenMPTarget(Expr *E, Decl *D,
1013310134
SourceLocation IdLoc = SourceLocation());
10135+
/// Finishes analysis of the deferred functions calls that may be declared as
10136+
/// host/nohost during device/host compilation.
10137+
void finalizeOpenMPDelayedAnalysis(const FunctionDecl *Caller,
10138+
const FunctionDecl *Callee,
10139+
SourceLocation Loc);
1013410140
/// Return true inside OpenMP declare target region.
1013510141
bool isInOpenMPDeclareTargetContext() const {
1013610142
return DeclareTargetNestingLevel > 0;
@@ -11517,18 +11523,6 @@ class Sema final {
1151711523
/* Caller = */ FunctionDeclAndLoc>
1151811524
DeviceKnownEmittedFns;
1151911525

11520-
/// A partial call graph maintained during CUDA/OpenMP device code compilation
11521-
/// to support deferred diagnostics.
11522-
///
11523-
/// Functions are only added here if, at the time they're considered, they are
11524-
/// not known-emitted. As soon as we discover that a function is
11525-
/// known-emitted, we remove it and everything it transitively calls from this
11526-
/// set and add those functions to DeviceKnownEmittedFns.
11527-
llvm::DenseMap</* Caller = */ CanonicalDeclPtr<FunctionDecl>,
11528-
/* Callees = */ llvm::MapVector<CanonicalDeclPtr<FunctionDecl>,
11529-
SourceLocation>>
11530-
DeviceCallGraph;
11531-
1153211526
/// Diagnostic builder for CUDA/OpenMP devices errors which may or may not be
1153311527
/// deferred.
1153411528
///
@@ -11603,14 +11597,6 @@ class Sema final {
1160311597
llvm::Optional<unsigned> PartialDiagId;
1160411598
};
1160511599

11606-
/// Indicate that this function (and thus everything it transtively calls)
11607-
/// will be codegen'ed, and emit any deferred diagnostics on this function and
11608-
/// its (transitive) callees.
11609-
void markKnownEmitted(
11610-
Sema &S, FunctionDecl *OrigCaller, FunctionDecl *OrigCallee,
11611-
SourceLocation OrigLoc,
11612-
const llvm::function_ref<bool(Sema &, FunctionDecl *)> IsKnownEmitted);
11613-
1161411600
/// Creates a DeviceDiagBuilder that emits the diagnostic if the current context
1161511601
/// is "used as device code".
1161611602
///
@@ -12478,10 +12464,11 @@ class Sema final {
1247812464
/// codegen'ed yet.
1247912465
bool checkSYCLDeviceFunction(SourceLocation Loc, FunctionDecl *Callee);
1248012466

12481-
/// Emit diagnostic that can't be emitted with deferred diagnostics mechanism.
12482-
/// At this step we imply that all device functions are marked with
12483-
/// sycl_device attribute.
12484-
void finalizeSYCLDelayedAnalysis();
12467+
/// Finishes analysis of the deferred functions calls that may be declared as
12468+
/// host during device compilation.
12469+
void finalizeSYCLDelayedAnalysis(const FunctionDecl *Caller,
12470+
const FunctionDecl *Callee,
12471+
SourceLocation Loc);
1248512472
};
1248612473

1248712474
template <typename AttrType>

clang/include/clang/Serialization/ASTBitCodes.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,10 @@ namespace serialization {
650650
PP_CONDITIONAL_STACK = 62,
651651

652652
/// A table of skipped ranges within the preprocessing record.
653-
PPD_SKIPPED_RANGES = 63
653+
PPD_SKIPPED_RANGES = 63,
654+
655+
/// Record code for the Decls to be checked for deferred diags.
656+
DECLS_TO_CHECK_FOR_DEFERRED_DIAGS = 64,
654657
};
655658

656659
/// Record types used within a source manager block.

clang/include/clang/Serialization/ASTReader.h

+9
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,12 @@ class ASTReader
890890
// A list of late parsed template function data.
891891
SmallVector<uint64_t, 1> LateParsedTemplates;
892892

893+
/// The IDs of all decls to be checked for deferred diags.
894+
///
895+
/// Sema tracks these to emit deferred diags.
896+
SmallVector<uint64_t, 4> DeclsToCheckForDeferredDiags;
897+
898+
893899
public:
894900
struct ImportedSubmodule {
895901
serialization::SubmoduleID ID;
@@ -1983,6 +1989,9 @@ class ASTReader
19831989
void ReadUnusedLocalTypedefNameCandidates(
19841990
llvm::SmallSetVector<const TypedefNameDecl *, 4> &Decls) override;
19851991

1992+
void ReadDeclsToCheckForDeferredDiags(
1993+
llvm::SmallVector<Decl *, 4> &Decls) override;
1994+
19861995
void ReadReferencedSelectors(
19871996
SmallVectorImpl<std::pair<Selector, SourceLocation>> &Sels) override;
19881997

clang/include/clang/Tooling/Syntax/Tree.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ class Node {
126126
// FactoryImpl sets CanModify flag.
127127
friend class FactoryImpl;
128128

129+
void setRole(NodeRole NR);
130+
129131
Tree *Parent;
130132
Node *NextSibling;
131133
unsigned Kind : 16;
@@ -171,8 +173,11 @@ class Tree : public Node {
171173
/// Prepend \p Child to the list of children and and sets the parent pointer.
172174
/// A very low-level operation that does not check any invariants, only used
173175
/// by TreeBuilder and FactoryImpl.
174-
/// EXPECTS: Role != NodeRoleDetached.
176+
/// EXPECTS: Role != Detached.
175177
void prependChildLowLevel(Node *Child, NodeRole Role);
178+
/// Like the previous overload, but does not set role for \p Child.
179+
/// EXPECTS: Child->Role != Detached
180+
void prependChildLowLevel(Node *Child);
176181
friend class TreeBuilder;
177182
friend class FactoryImpl;
178183

clang/lib/Format/ContinuationIndenter.cpp

+18-1
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,7 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
634634
State.Stack.back().NoLineBreak = true;
635635

636636
if (Style.AlignAfterOpenBracket != FormatStyle::BAS_DontAlign &&
637+
!State.Stack.back().IsCSharpGenericTypeConstraint &&
637638
Previous.opensScope() && Previous.isNot(TT_ObjCMethodExpr) &&
638639
(Current.isNot(TT_LineComment) || Previous.BlockKind == BK_BracedInit))
639640
State.Stack.back().Indent = State.Column + Spaces;
@@ -715,6 +716,8 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
715716
} else if (Previous.is(TT_InheritanceColon)) {
716717
State.Stack.back().Indent = State.Column;
717718
State.Stack.back().LastSpace = State.Column;
719+
} else if (Current.is(TT_CSharpGenericTypeConstraintColon)) {
720+
State.Stack.back().ColonPos = State.Column;
718721
} else if (Previous.opensScope()) {
719722
// If a function has a trailing call, indent all parameters from the
720723
// opening parenthesis. This avoids confusing indents like:
@@ -924,7 +927,13 @@ unsigned ContinuationIndenter::addTokenOnNewLine(LineState &State,
924927
unsigned ContinuationIndenter::getNewLineColumn(const LineState &State) {
925928
if (!State.NextToken || !State.NextToken->Previous)
926929
return 0;
930+
927931
FormatToken &Current = *State.NextToken;
932+
933+
if (State.Stack.back().IsCSharpGenericTypeConstraint &&
934+
Current.isNot(TT_CSharpGenericTypeConstraint))
935+
return State.Stack.back().ColonPos + 2;
936+
928937
const FormatToken &Previous = *Current.Previous;
929938
// If we are continuing an expression, we want to use the continuation indent.
930939
unsigned ContinuationIndent =
@@ -1106,9 +1115,11 @@ unsigned ContinuationIndenter::moveStateToNextToken(LineState &State,
11061115
assert(State.Stack.size());
11071116
const FormatToken &Current = *State.NextToken;
11081117

1118+
if (Current.is(TT_CSharpGenericTypeConstraint))
1119+
State.Stack.back().IsCSharpGenericTypeConstraint = true;
11091120
if (Current.isOneOf(tok::comma, TT_BinaryOperator))
11101121
State.Stack.back().NoLineBreakInOperand = false;
1111-
if (Current.is(TT_InheritanceColon))
1122+
if (Current.isOneOf(TT_InheritanceColon, TT_CSharpGenericTypeConstraintColon))
11121123
State.Stack.back().AvoidBinPacking = true;
11131124
if (Current.is(tok::lessless) && Current.isNot(TT_OverloadedOperator)) {
11141125
if (State.Stack.back().FirstLessLess == 0)
@@ -1329,6 +1340,11 @@ void ContinuationIndenter::moveStatePastScopeOpener(LineState &State,
13291340
if (!Current.opensScope())
13301341
return;
13311342

1343+
// Don't allow '<' or '(' in C# generic type constraints to start new scopes.
1344+
if (Current.isOneOf(tok::less, tok::l_paren) &&
1345+
State.Stack.back().IsCSharpGenericTypeConstraint)
1346+
return;
1347+
13321348
if (Current.MatchingParen && Current.BlockKind == BK_Block) {
13331349
moveStateToNewBlock(State);
13341350
return;
@@ -1393,6 +1409,7 @@ void ContinuationIndenter::moveStatePastScopeOpener(LineState &State,
13931409
(State.Line->Type == LT_ObjCDecl && ObjCBinPackProtocolList);
13941410

13951411
AvoidBinPacking =
1412+
(State.Stack.back().IsCSharpGenericTypeConstraint) ||
13961413
(Style.Language == FormatStyle::LK_JavaScript && EndsInComma) ||
13971414
(State.Line->MustBeDeclaration && !BinPackDeclaration) ||
13981415
(!State.Line->MustBeDeclaration && !Style.BinPackArguments) ||

clang/lib/Format/ContinuationIndenter.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,8 @@ struct ParenState {
208208
LastOperatorWrapped(true), ContainsLineBreak(false),
209209
ContainsUnwrappedBuilder(false), AlignColons(true),
210210
ObjCSelectorNameFound(false), HasMultipleNestedBlocks(false),
211-
NestedBlockInlined(false), IsInsideObjCArrayLiteral(false) {}
211+
NestedBlockInlined(false), IsInsideObjCArrayLiteral(false),
212+
IsCSharpGenericTypeConstraint(false) {}
212213

213214
/// \brief The token opening this parenthesis level, or nullptr if this level
214215
/// is opened by fake parenthesis.
@@ -329,6 +330,8 @@ struct ParenState {
329330
/// array literal.
330331
bool IsInsideObjCArrayLiteral : 1;
331332

333+
bool IsCSharpGenericTypeConstraint : 1;
334+
332335
bool operator<(const ParenState &Other) const {
333336
if (Indent != Other.Indent)
334337
return Indent < Other.Indent;
@@ -366,6 +369,8 @@ struct ParenState {
366369
return ContainsUnwrappedBuilder;
367370
if (NestedBlockInlined != Other.NestedBlockInlined)
368371
return NestedBlockInlined;
372+
if (IsCSharpGenericTypeConstraint != Other.IsCSharpGenericTypeConstraint)
373+
return IsCSharpGenericTypeConstraint;
369374
return false;
370375
}
371376
};

clang/lib/Format/TokenAnnotator.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -3620,6 +3620,9 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line,
36203620
if (Left.isOneOf(TT_CSharpNamedArgumentColon, TT_AttributeColon) ||
36213621
Right.isOneOf(TT_CSharpNamedArgumentColon, TT_AttributeColon))
36223622
return false;
3623+
// Only break after commas for generic type constraints.
3624+
if (Line.First->is(TT_CSharpGenericTypeConstraint))
3625+
return Left.is(TT_CSharpGenericTypeConstraintComma);
36233626
} else if (Style.Language == FormatStyle::LK_Java) {
36243627
if (Left.isOneOf(Keywords.kw_throws, Keywords.kw_extends,
36253628
Keywords.kw_implements))

clang/lib/Format/UnwrappedLineParser.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -1460,6 +1460,11 @@ void UnwrappedLineParser::parseStructuralElement() {
14601460

14611461
nextToken();
14621462
if (FormatTok->Tok.is(tok::l_brace)) {
1463+
// Block kind should probably be set to BK_BracedInit for any language.
1464+
// C# needs this change to ensure that array initialisers and object
1465+
// initialisers are indented the same way.
1466+
if (Style.isCSharp())
1467+
FormatTok->BlockKind = BK_BracedInit;
14631468
nextToken();
14641469
parseBracedList();
14651470
} else if (Style.Language == FormatStyle::LK_Proto &&
@@ -1652,7 +1657,7 @@ bool UnwrappedLineParser::tryToParseBracedList() {
16521657
bool UnwrappedLineParser::parseBracedList(bool ContinueOnSemicolons,
16531658
tok::TokenKind ClosingBraceKind) {
16541659
bool HasError = false;
1655-
1660+
16561661
// FIXME: Once we have an expression parser in the UnwrappedLineParser,
16571662
// replace this by using parseAssigmentExpression() inside.
16581663
do {

clang/lib/Sema/MultiplexExternalSemaSource.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,12 @@ void MultiplexExternalSemaSource::ReadExtVectorDecls(
275275
Sources[i]->ReadExtVectorDecls(Decls);
276276
}
277277

278+
void MultiplexExternalSemaSource::ReadDeclsToCheckForDeferredDiags(
279+
llvm::SmallVector<Decl *, 4> &Decls) {
280+
for(size_t i = 0; i < Sources.size(); ++i)
281+
Sources[i]->ReadDeclsToCheckForDeferredDiags(Decls);
282+
}
283+
278284
void MultiplexExternalSemaSource::ReadUnusedLocalTypedefNameCandidates(
279285
llvm::SmallSetVector<const TypedefNameDecl *, 4> &Decls) {
280286
for(size_t i = 0; i < Sources.size(); ++i)

0 commit comments

Comments
 (0)