Skip to content

Commit 7755ba9

Browse files
committed
Merge remote-tracking branch 'origin/main' into vplan-narrow-interleave
2 parents 3599a52 + f4043f4 commit 7755ba9

File tree

123 files changed

+1013
-716
lines changed

Some content is hidden

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

123 files changed

+1013
-716
lines changed

clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,11 @@ static bool sameValue(const Expr *E1, const Expr *E2) {
176176
cast<StringLiteral>(E2)->getString();
177177
case Stmt::DeclRefExprClass:
178178
return cast<DeclRefExpr>(E1)->getDecl() == cast<DeclRefExpr>(E2)->getDecl();
179+
case Stmt::CStyleCastExprClass:
180+
case Stmt::CXXStaticCastExprClass:
181+
case Stmt::CXXFunctionalCastExprClass:
182+
return sameValue(cast<ExplicitCastExpr>(E1)->getSubExpr(),
183+
cast<ExplicitCastExpr>(E2)->getSubExpr());
179184
default:
180185
return false;
181186
}
@@ -206,10 +211,13 @@ void UseDefaultMemberInitCheck::registerMatchers(MatchFinder *Finder) {
206211
cxxBoolLiteral(), cxxNullPtrLiteralExpr(), implicitValueInitExpr(),
207212
declRefExpr(to(anyOf(enumConstantDecl(), ConstExpRef))));
208213

214+
auto ExplicitCastExpr = castExpr(hasSourceExpression(InitBase));
215+
auto InitMatcher = anyOf(InitBase, ExplicitCastExpr);
216+
209217
auto Init =
210-
anyOf(initListExpr(anyOf(allOf(initCountIs(1), hasInit(0, InitBase)),
218+
anyOf(initListExpr(anyOf(allOf(initCountIs(1), hasInit(0, InitMatcher)),
211219
initCountIs(0), hasType(arrayType()))),
212-
InitBase);
220+
InitBase, ExplicitCastExpr);
213221

214222
Finder->addMatcher(
215223
cxxConstructorDecl(forEachConstructorInitializer(

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ Changes in existing checks
159159

160160
- Improved :doc:`modernize-use-default-member-init
161161
<clang-tidy/checks/modernize/use-default-member-init>` check by matching
162-
``constexpr`` and ``static`` values on member initialization.
162+
``constexpr`` and ``static``` values on member initialization and by detecting
163+
explicit casting of built-in types within member list initialization.
163164

164165
- Improved :doc:`modernize-use-ranges
165166
<clang-tidy/checks/modernize/use-ranges>` check by updating suppress

clang-tools-extra/test/clang-tidy/checkers/modernize/use-default-member-init.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,4 +536,40 @@ namespace PR122480 {
536536
// CHECK-FIXES: int b{STATIC_VAL};
537537
};
538538

539+
class CStyleCastInit {
540+
CStyleCastInit() : a{(int)1.23}, b{(float)42}, c{(double)'C'} {}
541+
// CHECK-MESSAGES: :[[@LINE-1]]:50: warning: member initializer for 'c' is redundant [modernize-use-default-member-init]
542+
// CHECK-FIXES: CStyleCastInit() {}
543+
544+
int a;
545+
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use default member initializer for 'a' [modernize-use-default-member-init]
546+
// CHECK-FIXES: int a{(int)1.23};
547+
float b;
548+
// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use default member initializer for 'b' [modernize-use-default-member-init]
549+
// CHECK-FIXES: float b{(float)42};
550+
double c{(double)'C'};
551+
};
552+
553+
class StaticCastInit {
554+
StaticCastInit() : m(static_cast<int>(9.99)), n(static_cast<char>(65)) {}
555+
// CHECK-MESSAGES: :[[@LINE-1]]:49: warning: member initializer for 'n' is redundant [modernize-use-default-member-init]
556+
// CHECK-FIXES: StaticCastInit() {}
557+
int m;
558+
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use default member initializer for 'm' [modernize-use-default-member-init]
559+
// CHECK-FIXES: int m{static_cast<int>(9.99)};
560+
char n{static_cast<char>(65)};
561+
};
562+
563+
class FunctionalCastInit {
564+
FunctionalCastInit() : a(int(5.67)), b(float(2)), c(double('C')) {}
565+
// CHECK-MESSAGES: :[[@LINE-1]]:40: warning: member initializer for 'b' is redundant [modernize-use-default-member-init]
566+
int a;
567+
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use default member initializer for 'a' [modernize-use-default-member-init]
568+
// CHECK-FIXES: int a{int(5.67)};
569+
float b{float(2)};
570+
double c;
571+
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use default member initializer for 'c' [modernize-use-default-member-init]
572+
// CHECK-FIXES: double c{double('C')};
573+
};
574+
539575
} //namespace PR122480

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/Sema/Sema.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10755,11 +10755,6 @@ class Sema final : public SemaBase {
1075510755
SourceLocation EndLoc);
1075610756
void ActOnForEachDeclStmt(DeclGroupPtrTy Decl);
1075710757

10758-
/// DiagnoseDiscardedExprMarkedNodiscard - Given an expression that is
10759-
/// semantically a discarded-value expression, diagnose if any [[nodiscard]]
10760-
/// value has been discarded.
10761-
void DiagnoseDiscardedExprMarkedNodiscard(const Expr *E);
10762-
1076310758
/// DiagnoseUnusedExprResult - If the statement passed in is an expression
1076410759
/// whose result is unused, warn.
1076510760
void DiagnoseUnusedExprResult(const Stmt *S, unsigned DiagID);

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/Sema/SemaExprMember.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1136,7 +1136,6 @@ Sema::BuildMemberReferenceExpr(Expr *BaseExpr, QualType BaseExprType,
11361136
if (Converted.isInvalid())
11371137
return true;
11381138
BaseExpr = Converted.get();
1139-
DiagnoseDiscardedExprMarkedNodiscard(BaseExpr);
11401139
return false;
11411140
};
11421141
auto ConvertBaseExprToGLValue = [&] {

clang/lib/Sema/SemaStmt.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -413,10 +413,6 @@ void DiagnoseUnused(Sema &S, const Expr *E, std::optional<unsigned> DiagID) {
413413
}
414414
} // namespace
415415

416-
void Sema::DiagnoseDiscardedExprMarkedNodiscard(const Expr *E) {
417-
DiagnoseUnused(*this, E, std::nullopt);
418-
}
419-
420416
void Sema::DiagnoseUnusedExprResult(const Stmt *S, unsigned DiagID) {
421417
if (const LabelStmt *Label = dyn_cast_if_present<LabelStmt>(S))
422418
S = Label->getSubStmt();

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"

clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p2.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,19 +164,21 @@ struct X {
164164

165165
[[nodiscard]] X get_X();
166166
// cxx11-warning@-1 {{use of the 'nodiscard' attribute is a C++17 extension}}
167+
[[nodiscard]] X* get_Ptr();
168+
// cxx11-warning@-1 {{use of the 'nodiscard' attribute is a C++17 extension}}
167169
void f() {
170+
get_X(); // expected-warning{{ignoring return value of function declared with 'nodiscard' attribute}}
171+
(void) get_X();
168172
(void) get_X().variant_member;
169173
(void) get_X().anonymous_struct_member;
170174
(void) get_X().data_member;
171175
(void) get_X().static_data_member;
172-
// expected-warning@-1 {{ignoring return value of function declared with 'nodiscard' attribute}}
173176
(void) get_X().unscoped_enum;
174-
// expected-warning@-1 {{ignoring return value of function declared with 'nodiscard' attribute}}
175177
(void) get_X().scoped_enum;
176-
// expected-warning@-1 {{ignoring return value of function declared with 'nodiscard' attribute}}
177178
(void) get_X().implicit_object_member_function();
178179
(void) get_X().static_member_function();
179-
// expected-warning@-1 {{ignoring return value of function declared with 'nodiscard' attribute}}
180+
(void) get_Ptr()->implicit_object_member_function();
181+
(void) get_Ptr()->static_member_function();
180182
#if __cplusplus >= 202302L
181183
(void) get_X().explicit_object_member_function();
182184
#endif

0 commit comments

Comments
 (0)