Skip to content

Commit 6216d62

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merged main:4b86a7f3860a into origin/amd-gfx:f4d4324cdfe7
Local branch origin/amd-gfx f4d4324 Merged main:7722d7519ca2 into origin/amd-gfx:309388c91aaf Remote branch main 4b86a7f [clang-format] Update the minimum python version requirement
2 parents f4d4324 + 4b86a7f commit 6216d62

File tree

115 files changed

+4855
-1798
lines changed

Some content is hidden

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

115 files changed

+4855
-1798
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,9 @@ Bug Fixes in This Version
278278
considered an error in C23 mode and are allowed as an extension in earlier language modes.
279279

280280
- Remove the ``static`` specifier for the value of ``_FUNCTION_`` for static functions, in MSVC compatibility mode.
281+
- Fixed a modules crash where exception specifications were not propagated properly (#GH121245, relanded in #GH129982)
282+
- Fixed a problematic case with recursive deserialization within ``FinishedDeserializing()`` where
283+
``PassInterestingDeclsToConsumer()`` was called before the declarations were safe to be passed. (#GH129982)
281284

282285
Bug Fixes to Compiler Builtins
283286
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/include/clang/Serialization/ASTReader.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,11 +1176,11 @@ class ASTReader
11761176
/// Number of Decl/types that are currently deserializing.
11771177
unsigned NumCurrentElementsDeserializing = 0;
11781178

1179-
/// Set true while we are in the process of passing deserialized
1180-
/// "interesting" decls to consumer inside FinishedDeserializing().
1181-
/// This is used as a guard to avoid recursively repeating the process of
1179+
/// Set false while we are in a state where we cannot safely pass deserialized
1180+
/// "interesting" decls to the consumer inside FinishedDeserializing().
1181+
/// This is used as a guard to avoid recursively entering the process of
11821182
/// passing decls to consumer.
1183-
bool PassingDeclsToConsumer = false;
1183+
bool CanPassDeclsToConsumer = true;
11841184

11851185
/// The set of identifiers that were read while the AST reader was
11861186
/// (recursively) loading declarations.

clang/lib/Format/FormatToken.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,10 @@ struct FormatToken {
746746
return isOneOf(tok::star, tok::amp, tok::ampamp);
747747
}
748748

749+
bool isPlacementOperator() const {
750+
return isOneOf(tok::kw_new, tok::kw_delete);
751+
}
752+
749753
bool isUnaryOperator() const {
750754
switch (Tok.getKind()) {
751755
case tok::plus:

clang/lib/Format/FormatTokenLexer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -610,9 +610,9 @@ bool FormatTokenLexer::precedesOperand(FormatToken *Tok) {
610610
tok::r_brace, tok::l_square, tok::semi, tok::exclaim,
611611
tok::colon, tok::question, tok::tilde) ||
612612
Tok->isOneOf(tok::kw_return, tok::kw_do, tok::kw_case, tok::kw_throw,
613-
tok::kw_else, tok::kw_new, tok::kw_delete, tok::kw_void,
614-
tok::kw_typeof, Keywords.kw_instanceof, Keywords.kw_in) ||
615-
Tok->isBinaryOperator();
613+
tok::kw_else, tok::kw_void, tok::kw_typeof,
614+
Keywords.kw_instanceof, Keywords.kw_in) ||
615+
Tok->isPlacementOperator() || Tok->isBinaryOperator();
616616
}
617617

618618
bool FormatTokenLexer::canPrecedeRegexLiteral(FormatToken *Prev) {

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,6 +1639,31 @@ class AnnotatingParser {
16391639
case tok::kw_operator:
16401640
if (Style.isProto())
16411641
break;
1642+
// Handle C++ user-defined conversion function.
1643+
if (IsCpp && CurrentToken) {
1644+
const auto *Info = CurrentToken->Tok.getIdentifierInfo();
1645+
// What follows Tok is an identifier or a non-operator keyword.
1646+
if (Info && !(CurrentToken->isPlacementOperator() ||
1647+
CurrentToken->is(tok::kw_co_await) ||
1648+
Info->isCPlusPlusOperatorKeyword())) {
1649+
FormatToken *LParen;
1650+
if (CurrentToken->startsSequence(tok::kw_decltype, tok::l_paren,
1651+
tok::kw_auto, tok::r_paren)) {
1652+
// Skip `decltype(auto)`.
1653+
LParen = CurrentToken->Next->Next->Next->Next;
1654+
} else {
1655+
// Skip to l_paren.
1656+
for (LParen = CurrentToken->Next;
1657+
LParen && LParen->isNot(tok::l_paren); LParen = LParen->Next) {
1658+
}
1659+
}
1660+
if (LParen && LParen->is(tok::l_paren)) {
1661+
Tok->setFinalizedType(TT_FunctionDeclarationName);
1662+
LParen->setFinalizedType(TT_FunctionDeclarationLParen);
1663+
break;
1664+
}
1665+
}
1666+
}
16421667
while (CurrentToken &&
16431668
!CurrentToken->isOneOf(tok::l_paren, tok::semi, tok::r_paren)) {
16441669
if (CurrentToken->isOneOf(tok::star, tok::amp))
@@ -2999,7 +3024,7 @@ class AnnotatingParser {
29993024
return TT_UnaryOperator;
30003025
if (PrevToken->is(TT_TypeName))
30013026
return TT_PointerOrReference;
3002-
if (PrevToken->isOneOf(tok::kw_new, tok::kw_delete) && Tok.is(tok::ampamp))
3027+
if (PrevToken->isPlacementOperator() && Tok.is(tok::ampamp))
30033028
return TT_BinaryOperator;
30043029

30053030
const FormatToken *NextToken = Tok.getNextNonComment();
@@ -3071,12 +3096,10 @@ class AnnotatingParser {
30713096
if (InTemplateArgument && NextToken->Tok.isAnyIdentifier())
30723097
return TT_BinaryOperator;
30733098

3074-
// "&&" followed by "(", "*", or "&" is quite unlikely to be two successive
3075-
// unary "&".
3076-
if (Tok.is(tok::ampamp) &&
3077-
NextToken->isOneOf(tok::l_paren, tok::star, tok::amp)) {
3099+
// "&&" followed by "*" or "&" is quite unlikely to be two successive unary
3100+
// "&".
3101+
if (Tok.is(tok::ampamp) && NextToken->isOneOf(tok::star, tok::amp))
30783102
return TT_BinaryOperator;
3079-
}
30803103

30813104
// This catches some cases where evaluation order is used as control flow:
30823105
// aaa && aaa->f();
@@ -3791,7 +3814,7 @@ static bool isFunctionDeclarationName(const LangOptions &LangOpts,
37913814
return Next;
37923815
if (Next->is(TT_OverloadedOperator))
37933816
continue;
3794-
if (Next->isOneOf(tok::kw_new, tok::kw_delete, tok::kw_co_await)) {
3817+
if (Next->isPlacementOperator() || Next->is(tok::kw_co_await)) {
37953818
// For 'new[]' and 'delete[]'.
37963819
if (Next->Next &&
37973820
Next->Next->startsSequence(tok::l_square, tok::r_square)) {
@@ -4802,7 +4825,7 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
48024825
spaceRequiredBeforeParens(Right);
48034826
}
48044827
if (Style.SpaceBeforeParens == FormatStyle::SBPO_Custom &&
4805-
Left.isOneOf(tok::kw_new, tok::kw_delete) &&
4828+
Left.isPlacementOperator() &&
48064829
Right.isNot(TT_OverloadedOperatorLParen) &&
48074830
!(Line.MightBeFunctionDecl && Left.is(TT_FunctionDeclarationName))) {
48084831
const auto *RParen = Right.MatchingParen;
@@ -4845,7 +4868,7 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
48454868
return Style.SpaceBeforeParensOptions.AfterControlStatements ||
48464869
spaceRequiredBeforeParens(Right);
48474870
}
4848-
if (Left.isOneOf(tok::kw_new, tok::kw_delete) ||
4871+
if (Left.isPlacementOperator() ||
48494872
(Left.is(tok::r_square) && Left.MatchingParen &&
48504873
Left.MatchingParen->Previous &&
48514874
Left.MatchingParen->Previous->is(tok::kw_delete))) {

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2923,10 +2923,16 @@ static void handleWorkGroupSize(Sema &S, Decl *D, const ParsedAttr &AL) {
29232923
if (!S.checkUInt32Argument(AL, E, WGSize[i], i,
29242924
/*StrictlyUnsigned=*/true))
29252925
return;
2926-
if (WGSize[i] == 0) {
2927-
S.Diag(AL.getLoc(), diag::err_attribute_argument_is_zero)
2928-
<< AL << E->getSourceRange();
2929-
return;
2926+
}
2927+
2928+
if (!llvm::all_of(WGSize, [](uint32_t Size) { return Size == 0; })) {
2929+
for (unsigned i = 0; i < 3; ++i) {
2930+
const Expr *E = AL.getArgAsExpr(i);
2931+
if (WGSize[i] == 0) {
2932+
S.Diag(AL.getLoc(), diag::err_attribute_argument_is_zero)
2933+
<< AL << E->getSourceRange();
2934+
return;
2935+
}
29302936
}
29312937
}
29322938

clang/lib/Serialization/ASTReader.cpp

Lines changed: 87 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -10182,12 +10182,12 @@ void ASTReader::visitTopLevelModuleMaps(
1018210182
}
1018310183

1018410184
void ASTReader::finishPendingActions() {
10185-
while (
10186-
!PendingIdentifierInfos.empty() || !PendingDeducedFunctionTypes.empty() ||
10187-
!PendingDeducedVarTypes.empty() || !PendingIncompleteDeclChains.empty() ||
10188-
!PendingDeclChains.empty() || !PendingMacroIDs.empty() ||
10189-
!PendingDeclContextInfos.empty() || !PendingUpdateRecords.empty() ||
10190-
!PendingObjCExtensionIvarRedeclarations.empty()) {
10185+
while (!PendingIdentifierInfos.empty() ||
10186+
!PendingDeducedFunctionTypes.empty() ||
10187+
!PendingDeducedVarTypes.empty() || !PendingDeclChains.empty() ||
10188+
!PendingMacroIDs.empty() || !PendingDeclContextInfos.empty() ||
10189+
!PendingUpdateRecords.empty() ||
10190+
!PendingObjCExtensionIvarRedeclarations.empty()) {
1019110191
// If any identifiers with corresponding top-level declarations have
1019210192
// been loaded, load those declarations now.
1019310193
using TopLevelDeclsMap =
@@ -10235,13 +10235,6 @@ void ASTReader::finishPendingActions() {
1023510235
}
1023610236
PendingDeducedVarTypes.clear();
1023710237

10238-
// For each decl chain that we wanted to complete while deserializing, mark
10239-
// it as "still needs to be completed".
10240-
for (unsigned I = 0; I != PendingIncompleteDeclChains.size(); ++I) {
10241-
markIncompleteDeclChain(PendingIncompleteDeclChains[I]);
10242-
}
10243-
PendingIncompleteDeclChains.clear();
10244-
1024510238
// Load pending declaration chains.
1024610239
for (unsigned I = 0; I != PendingDeclChains.size(); ++I)
1024710240
loadPendingDeclChain(PendingDeclChains[I].first,
@@ -10479,6 +10472,43 @@ void ASTReader::finishPendingActions() {
1047910472
for (auto *ND : PendingMergedDefinitionsToDeduplicate)
1048010473
getContext().deduplicateMergedDefinitonsFor(ND);
1048110474
PendingMergedDefinitionsToDeduplicate.clear();
10475+
10476+
// For each decl chain that we wanted to complete while deserializing, mark
10477+
// it as "still needs to be completed".
10478+
for (Decl *D : PendingIncompleteDeclChains)
10479+
markIncompleteDeclChain(D);
10480+
PendingIncompleteDeclChains.clear();
10481+
10482+
assert(PendingIdentifierInfos.empty() &&
10483+
"Should be empty at the end of finishPendingActions");
10484+
assert(PendingDeducedFunctionTypes.empty() &&
10485+
"Should be empty at the end of finishPendingActions");
10486+
assert(PendingDeducedVarTypes.empty() &&
10487+
"Should be empty at the end of finishPendingActions");
10488+
assert(PendingDeclChains.empty() &&
10489+
"Should be empty at the end of finishPendingActions");
10490+
assert(PendingMacroIDs.empty() &&
10491+
"Should be empty at the end of finishPendingActions");
10492+
assert(PendingDeclContextInfos.empty() &&
10493+
"Should be empty at the end of finishPendingActions");
10494+
assert(PendingUpdateRecords.empty() &&
10495+
"Should be empty at the end of finishPendingActions");
10496+
assert(PendingObjCExtensionIvarRedeclarations.empty() &&
10497+
"Should be empty at the end of finishPendingActions");
10498+
assert(PendingFakeDefinitionData.empty() &&
10499+
"Should be empty at the end of finishPendingActions");
10500+
assert(PendingDefinitions.empty() &&
10501+
"Should be empty at the end of finishPendingActions");
10502+
assert(PendingWarningForDuplicatedDefsInModuleUnits.empty() &&
10503+
"Should be empty at the end of finishPendingActions");
10504+
assert(PendingBodies.empty() &&
10505+
"Should be empty at the end of finishPendingActions");
10506+
assert(PendingAddedClassMembers.empty() &&
10507+
"Should be empty at the end of finishPendingActions");
10508+
assert(PendingMergedDefinitionsToDeduplicate.empty() &&
10509+
"Should be empty at the end of finishPendingActions");
10510+
assert(PendingIncompleteDeclChains.empty() &&
10511+
"Should be empty at the end of finishPendingActions");
1048210512
}
1048310513

1048410514
void ASTReader::diagnoseOdrViolations() {
@@ -10792,47 +10822,54 @@ void ASTReader::FinishedDeserializing() {
1079210822
--NumCurrentElementsDeserializing;
1079310823

1079410824
if (NumCurrentElementsDeserializing == 0) {
10795-
// Propagate exception specification and deduced type updates along
10796-
// redeclaration chains.
10797-
//
10798-
// We do this now rather than in finishPendingActions because we want to
10799-
// be able to walk the complete redeclaration chains of the updated decls.
10800-
while (!PendingExceptionSpecUpdates.empty() ||
10801-
!PendingDeducedTypeUpdates.empty() ||
10802-
!PendingUndeducedFunctionDecls.empty()) {
10803-
auto ESUpdates = std::move(PendingExceptionSpecUpdates);
10804-
PendingExceptionSpecUpdates.clear();
10805-
for (auto Update : ESUpdates) {
10806-
ProcessingUpdatesRAIIObj ProcessingUpdates(*this);
10807-
auto *FPT = Update.second->getType()->castAs<FunctionProtoType>();
10808-
auto ESI = FPT->getExtProtoInfo().ExceptionSpec;
10809-
if (auto *Listener = getContext().getASTMutationListener())
10810-
Listener->ResolvedExceptionSpec(cast<FunctionDecl>(Update.second));
10811-
for (auto *Redecl : Update.second->redecls())
10812-
getContext().adjustExceptionSpec(cast<FunctionDecl>(Redecl), ESI);
10813-
}
10825+
{
10826+
// Guard variable to avoid recursively entering the process of passing
10827+
// decls to consumer.
10828+
SaveAndRestore GuardPassingDeclsToConsumer(CanPassDeclsToConsumer, false);
1081410829

10815-
auto DTUpdates = std::move(PendingDeducedTypeUpdates);
10816-
PendingDeducedTypeUpdates.clear();
10817-
for (auto Update : DTUpdates) {
10818-
ProcessingUpdatesRAIIObj ProcessingUpdates(*this);
10819-
// FIXME: If the return type is already deduced, check that it matches.
10820-
getContext().adjustDeducedFunctionResultType(Update.first,
10821-
Update.second);
10822-
}
10830+
// Propagate exception specification and deduced type updates along
10831+
// redeclaration chains.
10832+
//
10833+
// We do this now rather than in finishPendingActions because we want to
10834+
// be able to walk the complete redeclaration chains of the updated decls.
10835+
while (!PendingExceptionSpecUpdates.empty() ||
10836+
!PendingDeducedTypeUpdates.empty() ||
10837+
!PendingUndeducedFunctionDecls.empty()) {
10838+
auto ESUpdates = std::move(PendingExceptionSpecUpdates);
10839+
PendingExceptionSpecUpdates.clear();
10840+
for (auto Update : ESUpdates) {
10841+
ProcessingUpdatesRAIIObj ProcessingUpdates(*this);
10842+
auto *FPT = Update.second->getType()->castAs<FunctionProtoType>();
10843+
auto ESI = FPT->getExtProtoInfo().ExceptionSpec;
10844+
if (auto *Listener = getContext().getASTMutationListener())
10845+
Listener->ResolvedExceptionSpec(cast<FunctionDecl>(Update.second));
10846+
for (auto *Redecl : Update.second->redecls())
10847+
getContext().adjustExceptionSpec(cast<FunctionDecl>(Redecl), ESI);
10848+
}
1082310849

10824-
auto UDTUpdates = std::move(PendingUndeducedFunctionDecls);
10825-
PendingUndeducedFunctionDecls.clear();
10826-
// We hope we can find the deduced type for the functions by iterating
10827-
// redeclarations in other modules.
10828-
for (FunctionDecl *UndeducedFD : UDTUpdates)
10829-
(void)UndeducedFD->getMostRecentDecl();
10830-
}
10850+
auto DTUpdates = std::move(PendingDeducedTypeUpdates);
10851+
PendingDeducedTypeUpdates.clear();
10852+
for (auto Update : DTUpdates) {
10853+
ProcessingUpdatesRAIIObj ProcessingUpdates(*this);
10854+
// FIXME: If the return type is already deduced, check that it
10855+
// matches.
10856+
getContext().adjustDeducedFunctionResultType(Update.first,
10857+
Update.second);
10858+
}
1083110859

10832-
if (ReadTimer)
10833-
ReadTimer->stopTimer();
10860+
auto UDTUpdates = std::move(PendingUndeducedFunctionDecls);
10861+
PendingUndeducedFunctionDecls.clear();
10862+
// We hope we can find the deduced type for the functions by iterating
10863+
// redeclarations in other modules.
10864+
for (FunctionDecl *UndeducedFD : UDTUpdates)
10865+
(void)UndeducedFD->getMostRecentDecl();
10866+
}
10867+
10868+
if (ReadTimer)
10869+
ReadTimer->stopTimer();
1083410870

10835-
diagnoseOdrViolations();
10871+
diagnoseOdrViolations();
10872+
}
1083610873

1083710874
// We are not in recursive loading, so it's safe to pass the "interesting"
1083810875
// decls to the consumer.

clang/lib/Serialization/ASTReaderDecl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4309,12 +4309,12 @@ Decl *ASTReader::ReadDeclRecord(GlobalDeclID ID) {
43094309
void ASTReader::PassInterestingDeclsToConsumer() {
43104310
assert(Consumer);
43114311

4312-
if (PassingDeclsToConsumer)
4312+
if (!CanPassDeclsToConsumer)
43134313
return;
43144314

43154315
// Guard variable to avoid recursively redoing the process of passing
43164316
// decls to consumer.
4317-
SaveAndRestore GuardPassingDeclsToConsumer(PassingDeclsToConsumer, true);
4317+
SaveAndRestore GuardPassingDeclsToConsumer(CanPassDeclsToConsumer, false);
43184318

43194319
// Ensure that we've loaded all potentially-interesting declarations
43204320
// that need to be eagerly loaded.

clang/test/Analysis/Checkers/WebKit/retain-ptr-ctor-adopt-use-arc.mm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// UNSUPPORTED: target={{.*}}-zos{{.*}}, target={{.*}}-aix{{.*}}
12
// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.webkit.RetainPtrCtorAdoptChecker -fobjc-arc -verify %s
23

34
#include "objc-mock-types.h"

clang/test/Analysis/Checkers/WebKit/retain-ptr-ctor-adopt-use.mm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// UNSUPPORTED: target={{.*}}-zos{{.*}}, target={{.*}}-aix{{.*}}
12
// RUN: %clang_analyze_cc1 -analyzer-checker=alpha.webkit.RetainPtrCtorAdoptChecker -verify %s
23

34
#include "objc-mock-types.h"

0 commit comments

Comments
 (0)