[PATCH] D45476: [C++2a] Implement operator<=> CodeGen and ExprConstant

Eric Fiselier via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 10 00:39:25 PDT 2018


EricWF created this revision.
EricWF added reviewers: rsmith, aaron.ballman, majnemer, rnk, compnerd.
Herald added a subscriber: mgorny.

This patch tackles long hanging fruit for the builtin operator<=> expressions. It is currently needs some cleanup before landing, but I want to get some initial feedback.

The main changes are:

- Lookup, build, and store the required standard library types and expressions in `ASTContext`. By storing them in ASTContext we don't need to store (and duplicate) the required expressions in the BinaryOperator AST nodes. The AST data is built in `Sema` the first time a <=> operator is seen. Does this need to serialized/deserialized?

- Implement [expr.spaceship] checking, including diagnosing narrowing conversions. The diagnostics emitted for non-constexpr narrowing conversions could be improved, which I'll do before this lands.

- Implement `ExprConstant` for builtin spaceship operators. This is a bit messy. It attempts to re-use the `IntExprEvaluator::VisitBinaryOperator` implementation, which it does by moving it into a separate `BinOpEvaluatorBase` evaluator, which `IntExprEvaluator` now derives from. Feel free to suggest a better way to structure this.

- Implement builitin operator<=> support in `CodeGenAgg`. It does this using `Select` nodes instead of `Phi` nodes. IDK if this implementation is preferable to conditional branches.

When I implemented it using conditional branches, LLVM would optimize it into `Select` anyway, except in the case of FP comparisons. Is there a reason FP cmps shouldn't use `Select`?
Additionally, the code gen does not yet support complex or vector types, as normal scalar-returning binary operators does. Initially I emitted the required comparisons using `ScalarExprEmitter::VisitBinaryOperator`, but this caused the operand expressions to be emitted once for every required cmp.


Repository:
  rC Clang

https://reviews.llvm.org/D45476

Files:
  include/clang/AST/ASTContext.h
  include/clang/AST/ComparisonCategories.h
  include/clang/AST/Expr.h
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/Overload.h
  include/clang/Sema/Sema.h
  lib/AST/CMakeLists.txt
  lib/AST/ComparisonCategories.cpp
  lib/AST/ExprConstant.cpp
  lib/CodeGen/CGExpr.cpp
  lib/CodeGen/CGExprAgg.cpp
  lib/Sema/SemaDeclCXX.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaOverload.cpp
  lib/Serialization/ASTReaderStmt.cpp
  lib/Serialization/ASTWriterStmt.cpp
  test/CodeGenCXX/Inputs/std-compare.h
  test/CodeGenCXX/cxx2a-compare.cpp
  test/PCH/Inputs/std-compare.h
  test/PCH/cxx2a-compare.cpp
  test/SemaCXX/Inputs/std-compare.h
  test/SemaCXX/compare-cxx2a.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45476.141799.patch
Type: text/x-patch
Size: 131065 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180410/0e126ca7/attachment-0001.bin>


More information about the cfe-commits mailing list