Skip to content

Commit e0e37c9

Browse files
committed
Return rvalue reference from temporary argument
This fixes compilation issues with GCC and C++23: ``` error: cannot bind non-const lvalue reference of type 'llvm::OptimizationRemarkMissed&' to an rvalue of type 'llvm::OptimizationRemarkMissed' ``` Closes #105778
1 parent 538b8f8 commit e0e37c9

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

llvm/include/llvm/Analysis/OptimizationRemarkEmitter.h

+5
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ class OptimizationRemarkEmitter {
6969
/// Output the remark via the diagnostic handler and to the
7070
/// optimization record file.
7171
void emit(DiagnosticInfoOptimizationBase &OptDiag);
72+
/// Also allow r-value for OptDiag to allow emitting a temporarily-constructed
73+
/// diagnostic.
74+
void emit(DiagnosticInfoOptimizationBase &&OptDiag) {
75+
emit(static_cast<DiagnosticInfoOptimizationBase &>(OptDiag));
76+
}
7277

7378
/// Take a lambda that returns a remark which will be emitted. Second
7479
/// argument is only used to restrict this to functions.

llvm/include/llvm/IR/DiagnosticInfo.h

+18-6
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <iterator>
3131
#include <optional>
3232
#include <string>
33+
#include <utility>
3334

3435
namespace llvm {
3536

@@ -625,14 +626,14 @@ operator<<(RemarkT &R,
625626
/// Also allow r-value for the remark to allow insertion into a
626627
/// temporarily-constructed remark.
627628
template <class RemarkT>
628-
RemarkT &
629+
RemarkT &&
629630
operator<<(RemarkT &&R,
630631
std::enable_if_t<
631632
std::is_base_of<DiagnosticInfoOptimizationBase, RemarkT>::value,
632633
StringRef>
633634
S) {
634635
R.insert(S);
635-
return R;
636+
return std::move(R);
636637
}
637638

638639
template <class RemarkT>
@@ -647,14 +648,14 @@ operator<<(RemarkT &R,
647648
}
648649

649650
template <class RemarkT>
650-
RemarkT &
651+
RemarkT &&
651652
operator<<(RemarkT &&R,
652653
std::enable_if_t<
653654
std::is_base_of<DiagnosticInfoOptimizationBase, RemarkT>::value,
654655
DiagnosticInfoOptimizationBase::Argument>
655656
A) {
656657
R.insert(A);
657-
return R;
658+
return std::move(R);
658659
}
659660

660661
template <class RemarkT>
@@ -669,14 +670,14 @@ operator<<(RemarkT &R,
669670
}
670671

671672
template <class RemarkT>
672-
RemarkT &
673+
RemarkT &&
673674
operator<<(RemarkT &&R,
674675
std::enable_if_t<
675676
std::is_base_of<DiagnosticInfoOptimizationBase, RemarkT>::value,
676677
DiagnosticInfoOptimizationBase::setIsVerbose>
677678
V) {
678679
R.insert(V);
679-
return R;
680+
return std::move(R);
680681
}
681682

682683
template <class RemarkT>
@@ -690,6 +691,17 @@ operator<<(RemarkT &R,
690691
return R;
691692
}
692693

694+
template <class RemarkT>
695+
RemarkT &&
696+
operator<<(RemarkT &&R,
697+
std::enable_if_t<
698+
std::is_base_of<DiagnosticInfoOptimizationBase, RemarkT>::value,
699+
DiagnosticInfoOptimizationBase::setExtraArgs>
700+
EA) {
701+
R.insert(EA);
702+
return std::move(R);
703+
}
704+
693705
/// Common features for diagnostics dealing with optimization remarks
694706
/// that are used by IR passes.
695707
class DiagnosticInfoIROptimization : public DiagnosticInfoOptimizationBase {

llvm/lib/Analysis/InlineAdvisor.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ static raw_ostream &operator<<(raw_ostream &R, const ore::NV &Arg) {
338338
}
339339

340340
template <class RemarkT>
341-
RemarkT &operator<<(RemarkT &&R, const InlineCost &IC) {
341+
RemarkT &operator<<(RemarkT &R, const InlineCost &IC) {
342342
using namespace ore;
343343
if (IC.isAlways()) {
344344
R << "(cost=always)";
@@ -352,6 +352,12 @@ RemarkT &operator<<(RemarkT &&R, const InlineCost &IC) {
352352
R << ": " << ore::NV("Reason", Reason);
353353
return R;
354354
}
355+
356+
template <class RemarkT>
357+
RemarkT &&operator<<(RemarkT &&R, const InlineCost &IC) {
358+
static_cast<RemarkT &>(R) << IC;
359+
return std::move(R);
360+
}
355361
} // namespace llvm
356362

357363
std::string llvm::inlineCostStr(const InlineCost &IC) {

0 commit comments

Comments
 (0)