[CIR] Support CXXRewrittenBinaryOperator in emitLValue
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 88/100
Research direction
Start in clang/lib/CIR/CodeGen/CIRGenFunction.cpp at CIRGenFunction::emitLValue and compare the classic Clang handling in clang/lib/CodeGen/CGExpr.cpp. Review the existing rewritten-operator visitors in CIRGenExprScalar.cpp, CIRGenExprAggregate.cpp, and CIRGenExprComplex.cpp, then add coverage in clang/test/CIR/CodeGen/cxx-rewritten-binary-operator.cpp. Done means the reproducer no longer emits the Not Yet Implemented error and the test passes.
Written by the indexing model from the issue text.
Description
Description
When generating ClangIR for a C++20 rewritten binary operator (e.g. rewritten comparison using operator<=>) whose evaluation produces an lvalue (such as binding a reference to the result), ClangIR emits a "Not Yet Implemented" error:
error: ClangIR code gen Not Yet Implemented: emitLValue: CXXRewrittenBinaryOperator
This is located in clang/lib/CIR/CodeGen/CIRGenFunction.cpp under CIRGenFunction::emitLValue:
case Expr::CXXRewrittenBinaryOperatorClass:
getCIRGenModule().errorNYI(e->getSourceRange(),
"emitLValue: CXXRewrittenBinaryOperator");
return LValue();
Minimal Reproducer
Compiling the following C++20 test case with -fclangir -emit-cir:
struct SpaceshipLValueResult {
int &operator<(int) const;
};
struct LValueItem {
SpaceshipLValueResult operator<=>(const LValueItem &) const;
};
void cxx_rewritten_binary_operator_lvalue_expr() {
LValueItem a;
LValueItem b;
int &ref = (a < b);
}
Output:
error: ClangIR code gen Not Yet Implemented: emitLValue: CXXRewrittenBinaryOperator
Reference Implementation
In classic Clang CodeGen (clang/lib/CodeGen/CGExpr.cpp), CXXRewrittenBinaryOperator evaluates its underlying semantic form via getSemanticForm():
case Expr::CXXRewrittenBinaryOperatorClass:
return EmitLValue(cast<CXXRewrittenBinaryOperator>(E)->getSemanticForm(),
IsKnownNonNull);
Other expression emitters in ClangIR already implement CXXRewrittenBinaryOperator by delegating to getSemanticForm():
clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp(VisitCXXRewrittenBinaryOperator)clang/lib/CIR/CodeGen/CIRGenExprAggregate.cpp(VisitCXXRewrittenBinaryOperator)clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp(VisitCXXRewrittenBinaryOperator)
Supporting CXXRewrittenBinaryOperator in CIRGenFunction::emitLValue (clang/lib/CIR/CodeGen/CIRGenFunction.cpp) and adding corresponding test cases to clang/test/CIR/CodeGen/cxx-rewritten-binary-operator.cpp will bring parity with classic CodeGen and complete coverage for rewritten binary operators across all CIR expression emitters.
- Dominant language
- LLVM
- Stars
- 40.6k
- Forks
- 18.7k
- Avg merge
- 18h 16m
- Merged PRs (30d)
- 417
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from llvm/llvm-project
-
website
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
llvm/llvm-project#224961 ·
-
lldb test-suite
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
llvm/llvm-project#224948 · 1 comment ·
-
mlir
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
llvm/llvm-project#224908 · 1 comment ·
-
libc
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
llvm/llvm-project#224587 · 2 comments · 1 assignee ·
-
HLSL
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
llvm/llvm-project#224413 ·
All issues in llvm/llvm-project
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
objectionary/eo#8869 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
EricSpencer00/Resilient#4824 · 1 comment ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
objectionary/jeo-maven-plugin#1758 ·
-
generics
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100