<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/97225>97225</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Should undefined symbols in msvc stl(_Literal_zero_is_expected) be processed in IR generation or sema
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
GkvJwa
</td>
</tr>
</table>
<pre>
Found that using msvc's stl to compile chromium(https://github.com/microsoft/STL/issues/4359#issuecomment-2042911928)
The cause of the error is as described in this link(https://github.com/oneapi-src/oneDPL/pull/1568#issue-2283898641), mscv(cl.exe) will optimize the if expr here, therefore cef specially patched chromum(https://github.com/chromiumembedded/cef/commit/cb1830e16ccf54cfb676933c35d189864f02a276), make the compilation pass
But recently I continued to analyze this compilation error.
I found that it was caused
```
1.use default operator
friend constexpr std::strong_ordering operator<=>(A,
A) = default;
2.called
static_assert(A a < A b, "");
```
so I reproduced it with the following code
```
$ cat a.cpp
#include <stdint.h>
#include <compare>
#include <limits>
namespace base {
class TimeDelta {
public:
constexpr TimeDelta() = default;
constexpr explicit TimeDelta(int64_t delta_us) : delta_(delta_us) {}
// _Literal_zero_is_expected
//constexpr bool operator<(TimeDelta other) const;
friend constexpr std::strong_ordering operator<=>(TimeDelta,
TimeDelta) = default;
private:
int64_t delta_ = 0;
};
// constexpr bool TimeDelta::operator<(TimeDelta other) const {
// return delta_ < other.delta_;
// }
} // namespace base
static_assert(base::TimeDelta(2) < base::TimeDelta(100), "");
class Foo {
public:
void foo1() { foo2(base::TimeDelta(1)); }
private:
void foo2(base::TimeDelta wait_delta) {
if (wait_delta <= base::TimeDelta()) {
return;
}
}
base::TimeDelta b_;
};
int main() {
Foo foo;
foo.foo1();
return 0;
}
```
```
$ clang-cl.exe -cc1 -emit-obj -internal-isystem "C:\\Program Files\\Microsoft Visual Studio\\2022\\Professional\\VC\\Tools\\MSVC\\14.40.33807\\include" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.22621.0\\ucrt" -fms-extensions -std=c++20 -o "a.obj" "a.cpp"
```
What is very interesting is that if override operator<(above commented code), using clang+mscv stl will not generate the symbols of std::_Literal_zero::_Literal_zero in base::operator<=>
For this reason, I debugged and found that it was not InImmediateFunctionContext
https://github.com/llvm/llvm-project/blob/4066a3206012cded6de2e286732dca721d37bcd3/clang/include/clang/Sema/Sema.h#L10309-L10315
After that, without overriding the operator, I want to optimize this expression
```
if (_Zero != 0) {
_Literal_zero_is_expected();
}
```
But reading code, it is not very good to process it in buildIfStmt, so should it be processed in IR Gen?
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJykV92O6ygSfhr6phTLhiROLnLRnWxGvXtWGm0fzUh7E2EoJ5yDwQKc7p6nXwFxfnrSvTtaKbIDBUVVfVXFZ-692hvEFZk9kdnmgQ_hYN3ql5_Hv7_yh8bK99XWDkZCOPAAg1dmD50_CkJrDz5oCBaE7XqlEcTB2U4NHaGLQwi9J-yR0C2h270Kh6EphO0I3XZKOOttGwjdvnz_RuhWeT-gJ3Q7ZbMloSyNhe06NGFCyyldVtWSLghdknJDysf8_H5AEHzwCLaFcEBA56wD5YF7kOiFUw1KUAbCQXnQyvz82jBrkPdq4p3Ig82v0bh-0JrQbTWbL0bTJpQu2GK5mE-raBNdQ-fFkdCF0AW-IaFLeFVag-2D6tQfmKxTLeBb7-CADuOWEP-01iEIbMH3KBTX-h16HsQBZQ7mf4vlGHHsGpQSZZzCNj5t16kYYdFUC1ZiNReinU1F28zr-ZIxwWaySi60JeW0no-O8J_Z3IwpD8oa6Ln315F_GgI4FGiCfodnENYEZQaUMRe44fo9uaz8jZKETnGt5hnaS2apAK_cZ0DladW8PP3SsCoi1hJbPugAtkfHg3VZ1jqFRkZLfEhR9kHGiLFHH5w1-511El3M3fM-tiZsQ9jfCF08ErrOeuAxgkfYZjyHsKcsoYXgWo-m-cCDEjvuPboQNQ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