Skip to content

Commit 41e1ac5

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merged main:4b15c0ed0a5d into amd-gfx:d0409751aeb8
Local branch amd-gfx d040975 Merged main:dc5341069315 into amd-gfx:1ab2a8935a2c Remote branch main 4b15c0e [Flang][HLFIR][OpenMP] Fix offloading tests broken by HLFIR (llvm#69457)
2 parents d040975 + 4b15c0e commit 41e1ac5

File tree

48 files changed

+1382
-225
lines changed

Some content is hidden

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

48 files changed

+1382
-225
lines changed

clang/CodeOwners.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ Modules & serialization
7575
Templates
7676
~~~~~~~~~
7777
| Erich Keane
78-
| erich.keane\@intel.com (email), ErichKeane (Phabricator), erichkeane (GitHub)
78+
| ekeane\@nvidia.com (email), ErichKeane (Phabricator), erichkeane (GitHub)
7979
8080

8181
Debug information
@@ -174,7 +174,7 @@ compiler.
174174
Attributes
175175
~~~~~~~~~~
176176
| Erich Keane
177-
| erich.keane\@intel.com (email), ErichKeane (Phabricator), erichkeane (GitHub)
177+
| ekeane\@nvidia.com (email), ErichKeane (Phabricator), erichkeane (GitHub)
178178
179179

180180
Inline assembly

clang/docs/ReleaseNotes.rst

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ C/C++ Language Potentially Breaking Changes
8585
``__has_c_attribute(warn_unused_result)``, 202003, 0
8686
``__has_c_attribute(gnu::warn_unused_result)``, 202003, 1
8787

88+
- Fixed a bug in finding matching `operator!=` while adding reversed `operator==` as
89+
outlined in "The Equality Operator You Are Looking For" (`P2468 <http://wg21.link/p2468r2>`_).
90+
Fixes (`#68901: <https://github.com/llvm/llvm-project/issues/68901>`_).
91+
8892
C++ Specific Potentially Breaking Changes
8993
-----------------------------------------
9094
- The name mangling rules for function templates has been changed to take into
@@ -356,6 +360,31 @@ Improvements to Clang's diagnostics
356360
nonportable construct that has different semantics from a constant-sized
357361
array. (`#62836 <https://github.com/llvm/llvm-project/issues/62836>`_)
358362

363+
- Clang changed the order in which it displays candidate functions on overloading failures.
364+
Previously, Clang used definition of ordering from the C++ Standard. The order defined in
365+
the Standard is partial and is not suited for sorting. Instead, Clang now uses a strict
366+
order that still attempts to push more relevant functions to the top by comparing their
367+
corresponding conversions. In some cases, this results in better order. E.g., for the
368+
following code
369+
370+
.. code-block:: cpp
371+
372+
struct Foo {
373+
operator int();
374+
operator const char*();
375+
};
376+
377+
void test() { Foo() - Foo(); }
378+
379+
Clang now produces a list with two most relevant builtin operators at the top,
380+
i.e. ``operator-(int, int)`` and ``operator-(const char*, const char*)``.
381+
Previously ``operator-(const char*, const char*)`` was the first element,
382+
but ``operator-(int, int)`` was only the 13th element in the output.
383+
However, new implementation does not take into account some aspects of
384+
C++ semantics, e.g. which function template is more specialized. This
385+
can sometimes lead to worse ordering.
386+
387+
359388
Bug Fixes in This Version
360389
-------------------------
361390
- Fixed an issue where a class template specialization whose declaration is
@@ -445,6 +474,8 @@ Bug Fixes in This Version
445474
- Clang now accepts anonymous members initialized with designated initializers
446475
inside templates.
447476
Fixes (`#65143 <https://github.com/llvm/llvm-project/issues/65143>`_)
477+
- Fix crash in formatting the real/imaginary part of a complex lvalue.
478+
Fixes (`#69218 <https://github.com/llvm/llvm-project/issues/69218>`_)
448479

449480
Bug Fixes to Compiler Builtins
450481
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/include/clang/Basic/DiagnosticCommonKinds.td

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,8 @@ def err_file_modified : Error<
356356
"file '%0' modified since it was first processed">, DefaultFatal;
357357
def err_file_too_large : Error<
358358
"sorry, unsupported: file '%0' is too large for Clang to process">;
359-
def err_include_too_large : Error<
360-
"sorry, this include generates a translation unit too large for"
361-
" Clang to process.">, DefaultFatal;
359+
def err_sloc_space_too_large : Error<
360+
"sorry, the translation unit is too large for Clang to process: ran out of source locations">, DefaultFatal;
362361
def err_unsupported_bom : Error<"%0 byte order mark detected in '%1', but "
363362
"encoding is not supported">, DefaultFatal;
364363
def err_unable_to_rename_temp : Error<

clang/include/clang/Basic/DiagnosticGroups.td

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,8 @@ def VariadicMacros : DiagGroup<"variadic-macros">;
849849
def VectorConversion : DiagGroup<"vector-conversion">; // clang specific
850850
def VexingParse : DiagGroup<"vexing-parse">;
851851
def VLAUseStaticAssert : DiagGroup<"vla-extension-static-assert">;
852-
def VLAExtension : DiagGroup<"vla-extension", [VLAUseStaticAssert]>;
852+
def VLACxxExtension : DiagGroup<"vla-cxx-extension", [VLAUseStaticAssert]>;
853+
def VLAExtension : DiagGroup<"vla-extension", [VLACxxExtension]>;
853854
def VLA : DiagGroup<"vla", [VLAExtension]>;
854855
def VolatileRegisterVar : DiagGroup<"volatile-register-var">;
855856
def Visibility : DiagGroup<"visibility">;
@@ -1086,7 +1087,8 @@ def Consumed : DiagGroup<"consumed">;
10861087
// warning should be active _only_ when -Wall is passed in, mark it as
10871088
// DefaultIgnore in addition to putting it here.
10881089
def All : DiagGroup<"all", [Most, Parentheses, Switch, SwitchBool,
1089-
MisleadingIndentation, PackedNonPod, VLAExtension]>;
1090+
MisleadingIndentation, PackedNonPod,
1091+
VLACxxExtension]>;
10901092

10911093
// Warnings that should be in clang-cl /w4.
10921094
def : DiagGroup<"CL4", [All, Extra]>;

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,9 @@ def ext_vla : Extension<"variable length arrays are a C99 feature">,
141141
// language modes, we warn as an extension but add the warning group to -Wall.
142142
def ext_vla_cxx : ExtWarn<
143143
"variable length arrays in C++ are a Clang extension">,
144-
InGroup<VLAExtension>;
144+
InGroup<VLACxxExtension>;
145145
def ext_vla_cxx_in_gnu_mode : Extension<ext_vla_cxx.Summary>,
146-
InGroup<VLAExtension>;
146+
InGroup<VLACxxExtension>;
147147
def ext_vla_cxx_static_assert : ExtWarn<
148148
"variable length arrays in C++ are a Clang extension; did you mean to use "
149149
"'static_assert'?">, InGroup<VLAUseStaticAssert>;

clang/lib/AST/APValue.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,10 @@ void APValue::printPretty(raw_ostream &Out, const PrintingPolicy &Policy,
841841
Out << *VD;
842842
ElemTy = VD->getType();
843843
}
844+
} else if (ElemTy->isAnyComplexType()) {
845+
// The lvalue refers to a complex type
846+
Out << (Path[I].getAsArrayIndex() == 0 ? ".real" : ".imag");
847+
ElemTy = ElemTy->castAs<ComplexType>()->getElementType();
844848
} else {
845849
// The lvalue must refer to an array.
846850
Out << '[' << Path[I].getAsArrayIndex() << ']';

clang/lib/Basic/SourceManager.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ FileID SourceManager::createFileIDImpl(ContentCache &File, StringRef Filename,
605605
unsigned FileSize = File.getSize();
606606
if (!(NextLocalOffset + FileSize + 1 > NextLocalOffset &&
607607
NextLocalOffset + FileSize + 1 <= CurrentLoadedOffset)) {
608-
Diag.Report(IncludePos, diag::err_include_too_large);
608+
Diag.Report(IncludePos, diag::err_sloc_space_too_large);
609609
noteSLocAddressSpaceUsage(Diag);
610610
return FileID();
611611
}
@@ -663,10 +663,16 @@ SourceManager::createExpansionLocImpl(const ExpansionInfo &Info,
663663
return SourceLocation::getMacroLoc(LoadedOffset);
664664
}
665665
LocalSLocEntryTable.push_back(SLocEntry::get(NextLocalOffset, Info));
666-
// FIXME: Produce a proper diagnostic for this case.
667-
assert(NextLocalOffset + Length + 1 > NextLocalOffset &&
668-
NextLocalOffset + Length + 1 <= CurrentLoadedOffset &&
669-
"Ran out of source locations!");
666+
if (NextLocalOffset + Length + 1 <= NextLocalOffset ||
667+
NextLocalOffset + Length + 1 > CurrentLoadedOffset) {
668+
Diag.Report(SourceLocation(), diag::err_sloc_space_too_large);
669+
// FIXME: call `noteSLocAddressSpaceUsage` to report details to users and
670+
// use a source location from `Info` to point at an error.
671+
// Currently, both cause Clang to run indefinitely, this needs to be fixed.
672+
// FIXME: return an error instead of crashing. Returning invalid source
673+
// locations causes compiler to run indefinitely.
674+
llvm::report_fatal_error("ran out of source locations");
675+
}
670676
// See createFileID for that +1.
671677
NextLocalOffset += Length + 1;
672678
return SourceLocation::getMacroLoc(NextLocalOffset - (Length + 1));

clang/lib/Sema/SemaOverload.cpp

Lines changed: 74 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@
3838
#include "llvm/ADT/STLExtras.h"
3939
#include "llvm/ADT/SmallPtrSet.h"
4040
#include "llvm/ADT/SmallString.h"
41+
#include "llvm/ADT/SmallVector.h"
4142
#include "llvm/Support/Casting.h"
4243
#include <algorithm>
44+
#include <cstddef>
4345
#include <cstdlib>
4446
#include <optional>
4547

@@ -960,18 +962,13 @@ static bool shouldAddReversedEqEq(Sema &S, SourceLocation OpLoc,
960962
return true;
961963
}
962964
// Otherwise the search scope is the namespace scope of which F is a member.
963-
LookupResult NonMembers(S, NotEqOp, OpLoc,
964-
Sema::LookupNameKind::LookupOperatorName);
965-
S.LookupName(NonMembers,
966-
S.getScopeForContext(EqFD->getEnclosingNamespaceContext()));
967-
NonMembers.suppressAccessDiagnostics();
968-
for (NamedDecl *Op : NonMembers) {
969-
auto *FD = Op->getAsFunction();
970-
if(auto* UD = dyn_cast<UsingShadowDecl>(Op))
971-
FD = UD->getUnderlyingDecl()->getAsFunction();
972-
if (FunctionsCorrespond(S.Context, EqFD, FD) &&
973-
declaresSameEntity(cast<Decl>(EqFD->getDeclContext()),
974-
cast<Decl>(Op->getDeclContext())))
965+
for (NamedDecl *Op : EqFD->getEnclosingNamespaceContext()->lookup(NotEqOp)) {
966+
auto *NotEqFD = Op->getAsFunction();
967+
if (auto *UD = dyn_cast<UsingShadowDecl>(Op))
968+
NotEqFD = UD->getUnderlyingDecl()->getAsFunction();
969+
if (FunctionsCorrespond(S.Context, EqFD, NotEqFD) && S.isVisible(NotEqFD) &&
970+
declaresSameEntity(cast<Decl>(EqFD->getEnclosingNamespaceContext()),
971+
cast<Decl>(Op->getLexicalDeclContext())))
975972
return false;
976973
}
977974
return true;
@@ -12017,6 +12014,7 @@ static unsigned RankDeductionFailure(const DeductionFailureInfo &DFI) {
1201712014
}
1201812015

1201912016
namespace {
12017+
1202012018
struct CompareOverloadCandidatesForDisplay {
1202112019
Sema &S;
1202212020
SourceLocation Loc;
@@ -12054,13 +12052,9 @@ struct CompareOverloadCandidatesForDisplay {
1205412052
if (L->Viable) {
1205512053
if (!R->Viable) return true;
1205612054

12057-
// TODO: introduce a tri-valued comparison for overload
12058-
// candidates. Would be more worthwhile if we had a sort
12059-
// that could exploit it.
12060-
if (isBetterOverloadCandidate(S, *L, *R, SourceLocation(), CSK))
12061-
return true;
12062-
if (isBetterOverloadCandidate(S, *R, *L, SourceLocation(), CSK))
12063-
return false;
12055+
if (int Ord = CompareConversions(*L, *R))
12056+
return Ord < 0;
12057+
// Use other tie breakers.
1206412058
} else if (R->Viable)
1206512059
return false;
1206612060

@@ -12112,30 +12106,8 @@ struct CompareOverloadCandidatesForDisplay {
1211212106
}
1211312107

1211412108
// If there's any ordering between the defined conversions...
12115-
// FIXME: this might not be transitive.
12116-
assert(L->Conversions.size() == R->Conversions.size());
12117-
12118-
int leftBetter = 0;
12119-
unsigned I = (L->IgnoreObjectArgument || R->IgnoreObjectArgument);
12120-
for (unsigned E = L->Conversions.size(); I != E; ++I) {
12121-
switch (CompareImplicitConversionSequences(S, Loc,
12122-
L->Conversions[I],
12123-
R->Conversions[I])) {
12124-
case ImplicitConversionSequence::Better:
12125-
leftBetter++;
12126-
break;
12127-
12128-
case ImplicitConversionSequence::Worse:
12129-
leftBetter--;
12130-
break;
12131-
12132-
case ImplicitConversionSequence::Indistinguishable:
12133-
break;
12134-
}
12135-
}
12136-
if (leftBetter > 0) return true;
12137-
if (leftBetter < 0) return false;
12138-
12109+
if (int Ord = CompareConversions(*L, *R))
12110+
return Ord < 0;
1213912111
} else if (RFailureKind == ovl_fail_bad_conversion)
1214012112
return false;
1214112113

@@ -12157,10 +12129,66 @@ struct CompareOverloadCandidatesForDisplay {
1215712129
SourceLocation RLoc = GetLocationForCandidate(R);
1215812130

1215912131
// Put candidates without locations (e.g. builtins) at the end.
12160-
if (LLoc.isInvalid()) return false;
12161-
if (RLoc.isInvalid()) return true;
12132+
if (LLoc.isValid() && RLoc.isValid())
12133+
return S.SourceMgr.isBeforeInTranslationUnit(LLoc, RLoc);
12134+
if (LLoc.isValid() && !RLoc.isValid())
12135+
return true;
12136+
if (RLoc.isValid() && !LLoc.isValid())
12137+
return false;
12138+
assert(!LLoc.isValid() && !RLoc.isValid());
12139+
// For builtins and other functions without locations, fallback to the order
12140+
// in which they were added into the candidate set.
12141+
return L < R;
12142+
}
1216212143

12163-
return S.SourceMgr.isBeforeInTranslationUnit(LLoc, RLoc);
12144+
private:
12145+
struct ConversionSignals {
12146+
unsigned KindRank = 0;
12147+
ImplicitConversionRank Rank = ICR_Exact_Match;
12148+
12149+
static ConversionSignals ForSequence(ImplicitConversionSequence &Seq) {
12150+
ConversionSignals Sig;
12151+
Sig.KindRank = Seq.getKindRank();
12152+
if (Seq.isStandard())
12153+
Sig.Rank = Seq.Standard.getRank();
12154+
else if (Seq.isUserDefined())
12155+
Sig.Rank = Seq.UserDefined.After.getRank();
12156+
// We intend StaticObjectArgumentConversion to compare the same as
12157+
// StandardConversion with ICR_ExactMatch rank.
12158+
return Sig;
12159+
}
12160+
12161+
static ConversionSignals ForObjectArgument() {
12162+
// We intend StaticObjectArgumentConversion to compare the same as
12163+
// StandardConversion with ICR_ExactMatch rank. Default give us that.
12164+
return {};
12165+
}
12166+
};
12167+
12168+
// Returns -1 if conversions in L are considered better.
12169+
// 0 if they are considered indistinguishable.
12170+
// 1 if conversions in R are better.
12171+
int CompareConversions(const OverloadCandidate &L,
12172+
const OverloadCandidate &R) {
12173+
// We cannot use `isBetterOverloadCandidate` because it is defined
12174+
// according to the C++ standard and provides a partial order, but we need
12175+
// a total order as this function is used in sort.
12176+
assert(L.Conversions.size() == R.Conversions.size());
12177+
for (unsigned I = 0, N = L.Conversions.size(); I != N; ++I) {
12178+
auto LS = L.IgnoreObjectArgument && I == 0
12179+
? ConversionSignals::ForObjectArgument()
12180+
: ConversionSignals::ForSequence(L.Conversions[I]);
12181+
auto RS = R.IgnoreObjectArgument
12182+
? ConversionSignals::ForObjectArgument()
12183+
: ConversionSignals::ForSequence(R.Conversions[I]);
12184+
if (std::tie(LS.KindRank, LS.Rank) != std::tie(RS.KindRank, RS.Rank))
12185+
return std::tie(LS.KindRank, LS.Rank) < std::tie(RS.KindRank, RS.Rank)
12186+
? -1
12187+
: 1;
12188+
}
12189+
// FIXME: find a way to compare templates for being more or less
12190+
// specialized that provides a strict weak ordering.
12191+
return 0;
1216412192
}
1216512193
};
1216612194
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// RUN: rm -rf %t
2+
// RUN: mkdir %t
3+
// RUN: split-file %s %t
4+
//
5+
// RUN: %clang_cc1 -std=c++20 %t/A.cppm -emit-module-interface -o %t/A.pcm
6+
// RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t -I%t %t/p2468r2.cpp -verify
7+
8+
//--- A.cppm
9+
module;
10+
export module A;
11+
export {
12+
namespace NS {
13+
struct S {};
14+
bool operator==(S, int);
15+
} // namespace NS
16+
}
17+
18+
namespace NS { bool operator!=(S, int); } // Not visible.
19+
20+
21+
//--- p2468r2.cpp
22+
// expected-no-diagnostics
23+
import A;
24+
bool x = 0 == NS::S(); // Ok. operator!= from module A is not visible.

0 commit comments

Comments
 (0)