Skip to content

Commit 4159e61

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merged main:65c9c9235075 into amd-gfx:41e1ac5101a9
Local branch amd-gfx 41e1ac5 Merged main:4b15c0ed0a5d into amd-gfx:d0409751aeb8 Remote branch main 65c9c92 [NFC] use `StringSet::insert(iter, iter)` instead for loop to insert (llvm#69851)
2 parents 41e1ac5 + 65c9c92 commit 4159e61

File tree

9 files changed

+79
-57
lines changed

9 files changed

+79
-57
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,27 +37,6 @@ These changes are ones which we think may surprise users when upgrading to
3737
Clang |release| because of the opportunity they pose for disruption to existing
3838
code bases.
3939

40-
- Fix a bug in reversed argument for templated operators.
41-
This breaks code in C++20 which was previously accepted in C++17. Eg:
42-
43-
.. code-block:: cpp
44-
45-
struct P {};
46-
template<class S> bool operator==(const P&, const S&);
47-
48-
struct A : public P {};
49-
struct B : public P {};
50-
51-
// This equality is now ambiguous in C++20.
52-
bool ambiguous(A a, B b) { return a == b; }
53-
54-
template<class S> bool operator!=(const P&, const S&);
55-
// Ok. Found a matching operator!=.
56-
bool fine(A a, B b) { return a == b; }
57-
58-
To reduce such widespread breakages, as an extension, Clang accepts this code
59-
with an existing warning ``-Wambiguous-reversed-operator`` warning.
60-
Fixes `GH <https://github.com/llvm/llvm-project/issues/53954>`_.
6140

6241
C/C++ Language Potentially Breaking Changes
6342
-------------------------------------------

clang/lib/ARCMigrate/ObjCMT.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,7 @@ class ObjCMigrateASTConsumer : public ASTConsumer {
123123
NSIntegerTypedefed(nullptr), NSUIntegerTypedefed(nullptr),
124124
Remapper(remapper), FileMgr(fileMgr), PPRec(PPRec), PP(PP),
125125
IsOutputFile(isOutputFile), FoundationIncluded(false) {
126-
// FIXME: StringSet should have insert(iter, iter) to use here.
127-
for (const std::string &Val : AllowList)
128-
AllowListFilenames.insert(Val);
126+
AllowListFilenames.insert(AllowList.begin(), AllowList.end());
129127
}
130128

131129
protected:

clang/lib/AST/Interp/ByteCodeExprGen.cpp

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -817,8 +817,8 @@ bool ByteCodeExprGen<Emitter>::VisitArrayInitLoopExpr(
817817
assert(Initializing);
818818
assert(!DiscardResult);
819819
// TODO: This compiles to quite a lot of bytecode if the array is larger.
820-
// Investigate compiling this to a loop, or at least try to use
821-
// the AILE's Common expr.
820+
// Investigate compiling this to a loop.
821+
822822
const Expr *SubExpr = E->getSubExpr();
823823
size_t Size = E->getArraySize().getZExtValue();
824824
std::optional<PrimType> ElemT = classify(SubExpr->getType());
@@ -853,7 +853,33 @@ template <class Emitter>
853853
bool ByteCodeExprGen<Emitter>::VisitOpaqueValueExpr(const OpaqueValueExpr *E) {
854854
if (Initializing)
855855
return this->visitInitializer(E->getSourceExpr());
856-
return this->visit(E->getSourceExpr());
856+
857+
PrimType SubExprT = classify(E->getSourceExpr()).value_or(PT_Ptr);
858+
if (auto It = OpaqueExprs.find(E); It != OpaqueExprs.end())
859+
return this->emitGetLocal(SubExprT, It->getSecond(), E);
860+
861+
if (!this->visit(E->getSourceExpr()))
862+
return false;
863+
864+
// At this point we either have the evaluated source expression or a pointer
865+
// to an object on the stack. We want to create a local variable that stores
866+
// this value.
867+
std::optional<unsigned> LocalIndex =
868+
allocateLocalPrimitive(E, SubExprT, /*IsConst=*/true);
869+
if (!LocalIndex)
870+
return false;
871+
if (!this->emitSetLocal(SubExprT, *LocalIndex, E))
872+
return false;
873+
874+
// Here the local variable is created but the value is removed from the stack,
875+
// so we put it back, because the caller might need it.
876+
if (!this->emitGetLocal(SubExprT, *LocalIndex, E))
877+
return false;
878+
879+
// FIXME: Ideally the cached value should be cleaned up later.
880+
OpaqueExprs.insert({E, *LocalIndex});
881+
882+
return true;
857883
}
858884

859885
template <class Emitter>

clang/lib/Sema/SemaOverload.cpp

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7685,7 +7685,7 @@ bool Sema::CheckNonDependentConversions(
76857685
QualType ParamType = ParamTypes[I + Offset];
76867686
if (!ParamType->isDependentType()) {
76877687
unsigned ConvIdx = PO == OverloadCandidateParamOrder::Reversed
7688-
? Args.size() - 1 - (ThisConversions + I)
7688+
? 0
76897689
: (ThisConversions + I);
76907690
Conversions[ConvIdx]
76917691
= TryCopyInitialization(*this, Args[I], ParamType,
@@ -10082,19 +10082,11 @@ getImplicitObjectParamType(ASTContext &Context, const FunctionDecl *F) {
1008210082
return M->getFunctionObjectParameterReferenceType();
1008310083
}
1008410084

10085-
// As a Clang extension, allow ambiguity among F1 and F2 if they represent
10086-
// represent the same entity.
10087-
static bool allowAmbiguity(ASTContext &Context, const FunctionDecl *F1,
10088-
const FunctionDecl *F2) {
10085+
static bool haveSameParameterTypes(ASTContext &Context, const FunctionDecl *F1,
10086+
const FunctionDecl *F2) {
1008910087
if (declaresSameEntity(F1, F2))
1009010088
return true;
10091-
if (F1->isTemplateInstantiation() && F2->isTemplateInstantiation() &&
10092-
declaresSameEntity(F1->getPrimaryTemplate(), F2->getPrimaryTemplate())) {
10093-
return true;
10094-
}
10095-
// TODO: It is not clear whether comparing parameters is necessary (i.e.
10096-
// different functions with same params). Consider removing this (as no test
10097-
// fail w/o it).
10089+
1009810090
auto NextParam = [&](const FunctionDecl *F, unsigned &I, bool First) {
1009910091
if (First) {
1010010092
if (std::optional<QualType> T = getImplicitObjectParamType(Context, F))
@@ -10279,14 +10271,14 @@ bool clang::isBetterOverloadCandidate(
1027910271
case ImplicitConversionSequence::Worse:
1028010272
if (Cand1.Function && Cand2.Function &&
1028110273
Cand1.isReversed() != Cand2.isReversed() &&
10282-
allowAmbiguity(S.Context, Cand1.Function, Cand2.Function)) {
10274+
haveSameParameterTypes(S.Context, Cand1.Function, Cand2.Function)) {
1028310275
// Work around large-scale breakage caused by considering reversed
1028410276
// forms of operator== in C++20:
1028510277
//
10286-
// When comparing a function against a reversed function, if we have a
10287-
// better conversion for one argument and a worse conversion for the
10288-
// other, the implicit conversion sequences are treated as being equally
10289-
// good.
10278+
// When comparing a function against a reversed function with the same
10279+
// parameter types, if we have a better conversion for one argument and
10280+
// a worse conversion for the other, the implicit conversion sequences
10281+
// are treated as being equally good.
1029010282
//
1029110283
// This prevents a comparison function from being considered ambiguous
1029210284
// with a reversed form that is written in the same way.
@@ -14457,7 +14449,7 @@ ExprResult Sema::CreateOverloadedBinOp(SourceLocation OpLoc,
1445714449
llvm::SmallVector<FunctionDecl*, 4> AmbiguousWith;
1445814450
for (OverloadCandidate &Cand : CandidateSet) {
1445914451
if (Cand.Viable && Cand.Function && Cand.isReversed() &&
14460-
allowAmbiguity(Context, Cand.Function, FnDecl)) {
14452+
haveSameParameterTypes(Context, Cand.Function, FnDecl)) {
1446114453
for (unsigned ArgIdx = 0; ArgIdx < 2; ++ArgIdx) {
1446214454
if (CompareImplicitConversionSequences(
1446314455
*this, OpLoc, Cand.Conversions[ArgIdx],

clang/test/AST/Interp/arrays.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -372,9 +372,6 @@ namespace ZeroInit {
372372
}
373373

374374
namespace ArrayInitLoop {
375-
/// FIXME: The ArrayInitLoop for the decomposition initializer in g() has
376-
/// f(n) as its CommonExpr. We need to evaluate that exactly once and not
377-
/// N times as we do right now.
378375
struct X {
379376
int arr[3];
380377
};
@@ -386,8 +383,7 @@ namespace ArrayInitLoop {
386383
auto [a, b, c] = f(n).arr;
387384
return a + b + c;
388385
}
389-
static_assert(g() == 6); // expected-error {{failed}} \
390-
// expected-note {{15 == 6}}
386+
static_assert(g() == 6, "");
391387
}
392388

393389
namespace StringZeroFill {

clang/test/AST/Interp/cxx20.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,3 +733,15 @@ namespace ConstexprArrayInitLoopExprDestructors
733733
return f();
734734
}
735735
}
736+
737+
namespace NonPrimitiveOpaqueValue
738+
{
739+
struct X {
740+
int x;
741+
constexpr operator bool() const { return x != 0; }
742+
};
743+
744+
constexpr int ternary() { return X(0) ?: X(0); }
745+
746+
static_assert(!ternary(), "");
747+
}

lldb/docs/resources/debugging.rst

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,26 @@ child processes.
213213
The same goes for ``printf``. If it's called in a child process you won't see
214214
the output.
215215

216-
In these cases consider either interactive debugging ``lldb-server`` or
216+
In these cases consider interactive debugging ``lldb-server`` or
217217
working out a more specific command such that it does not have to spawn a
218218
subprocess. For example if you start with ``platform`` mode, work out what
219219
``gdbserver`` mode process it spawns and run that command instead.
220220

221+
Another option if you have ``strace`` available is to trace the whole process
222+
tree and inspect the logs after the session has ended. ::
223+
224+
$ strace -ff -o log -p $(pidof lldb-server)
225+
226+
This will log all syscalls made by ``lldb-server`` and processes that it forks.
227+
``-ff`` tells ``strace`` to trace child processes and write the results to a
228+
separate file for each process, named using the prefix given by ``-o``.
229+
230+
Search the log files for specific terms to find the process you're interested
231+
in. For example, to find a process that acted as a ``gdbserver`` instance::
232+
233+
$ grep "gdbserver" log.*
234+
log.<N>:execve("<...>/lldb-server", [<...> "gdbserver", <...>) = 0
235+
221236
Remote Debugging
222237
----------------
223238

llvm/include/llvm/ADT/STLExtras.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,11 +1291,15 @@ class indexed_accessor_range_base {
12911291
}
12921292

12931293
/// Compare this range with another.
1294-
template <typename OtherT> bool operator==(const OtherT &rhs) const {
1295-
return std::equal(begin(), end(), rhs.begin(), rhs.end());
1296-
}
1297-
template <typename OtherT> bool operator!=(const OtherT &rhs) const {
1298-
return !(*this == rhs);
1294+
template <typename OtherT>
1295+
friend bool operator==(const indexed_accessor_range_base &lhs,
1296+
const OtherT &rhs) {
1297+
return std::equal(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
1298+
}
1299+
template <typename OtherT>
1300+
friend bool operator!=(const indexed_accessor_range_base &lhs,
1301+
const OtherT &rhs) {
1302+
return !(lhs == rhs);
12991303
}
13001304

13011305
/// Return the size of this range.

llvm/include/llvm/Config/llvm-config.h.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
/* Indicate that this is LLVM compiled from the amd-gfx branch. */
1818
#define LLVM_HAVE_BRANCH_AMD_GFX
19-
#define LLVM_MAIN_REVISION 478354
19+
#define LLVM_MAIN_REVISION 478358
2020

2121
/* Define if LLVM_ENABLE_DUMP is enabled */
2222
#cmakedefine LLVM_ENABLE_DUMP

0 commit comments

Comments
 (0)