Skip to content

Commit fc50ee0

Browse files
authored
Merge branch 'release/20.x' into issue138712
2 parents a13945b + 53393e2 commit fc50ee0

Some content is hidden

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

44 files changed

+421
-145
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,9 @@ C++2c Feature Support
314314

315315
- Implemented `P3176R1 The Oxford variadic comma <https://wg21.link/P3176R1>`_
316316

317+
- The error produced when doing arithmetic operations on enums of different types
318+
can be disabled with ``-Wno-enum-enum-conversion``. (#GH92340)
319+
317320
C++23 Feature Support
318321
^^^^^^^^^^^^^^^^^^^^^
319322
- Removed the restriction to literal types in constexpr functions in C++23 mode.
@@ -909,6 +912,8 @@ Bug Fixes in This Version
909912
being deleted has a potentially throwing destructor (#GH118660).
910913
- Clang now outputs correct values when #embed data contains bytes with negative
911914
signed char values (#GH102798).
915+
- Fix crash due to unknown references and pointer implementation and handling of
916+
base classes. (GH139452)
912917

913918
Bug Fixes to Compiler Builtins
914919
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -1467,6 +1472,9 @@ Crash and bug fixes
14671472
- The ``unix.BlockInCriticalSection`` now recognizes the ``lock()`` member function
14681473
as expected, even if it's inherited from a base class. Fixes (#GH104241).
14691474

1475+
- Fixed a crash when C++20 parenthesized initializer lists are used. This issue
1476+
was causing a crash in clang-tidy. (#GH136041)
1477+
14701478
Improvements
14711479
^^^^^^^^^^^^
14721480

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7567,9 +7567,13 @@ def warn_arith_conv_mixed_enum_types_cxx20 : Warning<
75677567
"%sub{select_arith_conv_kind}0 "
75687568
"different enumeration types%diff{ ($ and $)|}1,2 is deprecated">,
75697569
InGroup<DeprecatedEnumEnumConversion>;
7570-
def err_conv_mixed_enum_types_cxx26 : Error<
7570+
7571+
def err_conv_mixed_enum_types: Error <
75717572
"invalid %sub{select_arith_conv_kind}0 "
75727573
"different enumeration types%diff{ ($ and $)|}1,2">;
7574+
def zzzz_warn_conv_mixed_enum_types_cxx26 : Warning <
7575+
err_conv_mixed_enum_types.Summary>,
7576+
InGroup<EnumEnumConversion>, DefaultError;
75737577

75747578
def warn_arith_conv_mixed_anon_enum_types : Warning<
75757579
warn_arith_conv_mixed_enum_types.Summary>,

clang/lib/AST/ExprConstant.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3311,7 +3311,11 @@ static bool HandleLValueBase(EvalInfo &Info, const Expr *E, LValue &Obj,
33113311
return false;
33123312

33133313
// Extract most-derived object and corresponding type.
3314-
DerivedDecl = D.MostDerivedType->getAsCXXRecordDecl();
3314+
// FIXME: After implementing P2280R4 it became possible to get references
3315+
// here. We do MostDerivedType->getAsCXXRecordDecl() in several other
3316+
// locations and if we see crashes in those locations in the future
3317+
// it may make more sense to move this fix into Lvalue::set.
3318+
DerivedDecl = D.MostDerivedType.getNonReferenceType()->getAsCXXRecordDecl();
33153319
if (!CastToDerivedClass(Info, E, Obj, DerivedDecl, D.MostDerivedPathLength))
33163320
return false;
33173321

clang/lib/Format/ContinuationIndenter.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1452,7 +1452,9 @@ unsigned ContinuationIndenter::getNewLineColumn(const LineState &State) {
14521452
(PreviousNonComment->ClosesTemplateDeclaration ||
14531453
PreviousNonComment->ClosesRequiresClause ||
14541454
(PreviousNonComment->is(TT_AttributeMacro) &&
1455-
Current.isNot(tok::l_paren)) ||
1455+
Current.isNot(tok::l_paren) &&
1456+
!Current.endsSequence(TT_StartOfName, TT_AttributeMacro,
1457+
TT_PointerOrReference)) ||
14561458
PreviousNonComment->isOneOf(
14571459
TT_AttributeRParen, TT_AttributeSquare, TT_FunctionAnnotationRParen,
14581460
TT_JavaAnnotation, TT_LeadingJavaAnnotation))) ||

clang/lib/Format/Format.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3743,8 +3743,10 @@ reformat(const FormatStyle &Style, StringRef Code,
37433743
tooling::Replacements Replaces =
37443744
Formatter(*Env, Style, Status).process().first;
37453745
// add a replacement to remove the "x = " from the result.
3746-
Replaces = Replaces.merge(
3747-
tooling::Replacements(tooling::Replacement(FileName, 0, 4, "")));
3746+
if (Code.starts_with("x = ")) {
3747+
Replaces = Replaces.merge(
3748+
tooling::Replacements(tooling::Replacement(FileName, 0, 4, "")));
3749+
}
37483750
// apply the reformatting changes and the removal of "x = ".
37493751
if (applyAllReplacements(Code, Replaces))
37503752
return {Replaces, 0};

clang/lib/Sema/SemaExpr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1519,7 +1519,7 @@ static void checkEnumArithmeticConversions(Sema &S, Expr *LHS, Expr *RHS,
15191519
// In C++ 26, usual arithmetic conversions between 2 different enum types
15201520
// are ill-formed.
15211521
if (S.getLangOpts().CPlusPlus26)
1522-
DiagID = diag::err_conv_mixed_enum_types_cxx26;
1522+
DiagID = diag::zzzz_warn_conv_mixed_enum_types_cxx26;
15231523
else if (!L->castAs<EnumType>()->getDecl()->hasNameForLinkage() ||
15241524
!R->castAs<EnumType>()->getDecl()->hasNameForLinkage()) {
15251525
// If either enumeration type is unnamed, it's less likely that the

clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -379,9 +379,9 @@ void DynamicTypePropagation::checkPostCall(const CallEvent &Call,
379379
// aggregates, and in such case no top-frame constructor will be called.
380380
// Figure out if we need to do anything in this case.
381381
// FIXME: Instead of relying on the ParentMap, we should have the
382-
// trigger-statement (InitListExpr in this case) available in this
383-
// callback, ideally as part of CallEvent.
384-
if (isa_and_nonnull<InitListExpr>(
382+
// trigger-statement (InitListExpr or CXXParenListInitExpr in this case)
383+
// available in this callback, ideally as part of CallEvent.
384+
if (isa_and_nonnull<InitListExpr, CXXParenListInitExpr>(
385385
LCtx->getParentMap().getParent(Ctor->getOriginExpr())))
386386
return;
387387

clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -637,9 +637,10 @@ void ExprEngine::handleConstructor(const Expr *E,
637637
// FIXME: For now this code essentially bails out. We need to find the
638638
// correct target region and set it.
639639
// FIXME: Instead of relying on the ParentMap, we should have the
640-
// trigger-statement (InitListExpr in this case) passed down from CFG or
641-
// otherwise always available during construction.
642-
if (isa_and_nonnull<InitListExpr>(LCtx->getParentMap().getParent(E))) {
640+
// trigger-statement (InitListExpr or CXXParenListInitExpr in this case)
641+
// passed down from CFG or otherwise always available during construction.
642+
if (isa_and_nonnull<InitListExpr, CXXParenListInitExpr>(
643+
LCtx->getParentMap().getParent(E))) {
643644
MemRegionManager &MRMgr = getSValBuilder().getRegionManager();
644645
Target = loc::MemRegionVal(MRMgr.getCXXTempObjectRegion(E, LCtx));
645646
CallOpts.IsCtorOrDtorWithImproperlyModeledTargetRegion = true;
@@ -1010,7 +1011,8 @@ void ExprEngine::VisitCXXNewExpr(const CXXNewExpr *CNE, ExplodedNode *Pred,
10101011
// values are properly placed inside the required region, however if an
10111012
// initializer list is used, this doesn't happen automatically.
10121013
auto *Init = CNE->getInitializer();
1013-
bool isInitList = isa_and_nonnull<InitListExpr>(Init);
1014+
bool isInitList =
1015+
isa_and_nonnull<InitListExpr, CXXParenListInitExpr>(Init);
10141016

10151017
QualType ObjTy =
10161018
isInitList ? Init->getType() : CNE->getType()->getPointeeType();

clang/test/Analysis/PR135665.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %clang_analyze_cc1 -std=c++20 -analyzer-checker=core -verify %s
2+
3+
// expected-no-diagnostics
4+
5+
template<typename... F>
6+
struct overload : public F...
7+
{
8+
using F::operator()...;
9+
};
10+
11+
template<typename... F>
12+
overload(F&&...) -> overload<F...>;
13+
14+
int main()
15+
{
16+
const auto l = overload([](const int* i) {});
17+
18+
return 0;
19+
}

clang/test/SemaCXX/constant-expression-p2280r4.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,3 +179,24 @@ namespace extern_reference_used_as_unknown {
179179
int y;
180180
constinit int& g = (x,y); // expected-warning {{left operand of comma operator has no effect}}
181181
}
182+
183+
namespace GH139452 {
184+
struct Dummy {
185+
explicit operator bool() const noexcept { return true; }
186+
};
187+
188+
struct Base { int error; };
189+
struct Derived : virtual Base { };
190+
191+
template <class R>
192+
constexpr R get_value() {
193+
const auto& derived_val = Derived{};
194+
if (derived_val.error != 0)
195+
/* nothing */;
196+
return R{};
197+
}
198+
199+
int f() {
200+
return !get_value<Dummy>(); // contextually convert the function call result to bool
201+
}
202+
}

0 commit comments

Comments
 (0)