llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang
            
<details>
<summary>Changes</summary>
Currently CXXRewrittenBinaryOperator::getDecomposedForm(...) may crash if the
spaceship operator returns a comparison category by reference. This because
IgnoreImplicitAsWritten() does not look through CXXConstructExpr. The fix is to
use IgnoreUnlessSpelledInSource() which will look though CXXConstructExpr.

This fixes: https://github.com/llvm/llvm-project/issues/64162

--
Full diff: https://github.com/llvm/llvm-project/pull/66270.diff

2 Files Affected:

- (modified) clang/lib/AST/ExprCXX.cpp (+1-1) 
- (modified) clang/test/SemaCXX/compare-cxx2a.cpp (+23) 


<pre>
diff --git a/clang/lib/AST/ExprCXX.cpp b/clang/lib/AST/ExprCXX.cpp
index efb64842fb6d96d..06163255f9b5e54 100644
--- a/clang/lib/AST/ExprCXX.cpp
+++ b/clang/lib/AST/ExprCXX.cpp
@@ -111,7 +111,7 @@ CXXRewrittenBinaryOperator::getDecomposedForm() const {
     return Result;
 
   // Otherwise, we expect a &lt;=&gt; to now be on the LHS.
-  E = Result.LHS-&gt;IgnoreImplicitAsWritten();
+  E = Result.LHS-&gt;IgnoreUnlessSpelledInSource();
   if (auto *BO = dyn_cast&lt;BinaryOperator&gt;(E)) {
     assert(BO-&gt;getOpcode() == BO_Cmp);
     Result.LHS = BO-&gt;getLHS();
diff --git a/clang/test/SemaCXX/compare-cxx2a.cpp 
b/clang/test/SemaCXX/compare-cxx2a.cpp
index 619e16aa7458179..15a0baccfca17a2 100644
--- a/clang/test/SemaCXX/compare-cxx2a.cpp
+++ b/clang/test/SemaCXX/compare-cxx2a.cpp
@@ -479,3 +479,26 @@ void DoSomething() {
                                                   // expected-note  
{{undefined function &#x27;operator++&#x27; cannot be used in a constant 
expression}}
 }
 }
+
+namespace GH64162 {
+struct S {
+    const std::strong_ordering&amp; operator&lt;=&gt;(const S&amp;) const = 
default;
+};
+bool test(S s) {
+    return s &lt; s; // We expect this not to crash anymore
+}
+
+// Following example never crashed but worth adding in because it is related
+struct A {};
+bool operator&lt;(A, int);
+
+struct B {
+    operator A();
+};
+
+struct C {
+    B operator&lt;=&gt;(C);
+};
+
+bool f(C c) { return c &lt; c; }
+}
</pre>
</details>


https://github.com/llvm/llvm-project/pull/66270
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to