<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/63712>63712</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [flang] Fully test & support AVOID_NATIVE_UINT128_T
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          h-vetinari
      </td>
    </tr>
</table>

<pre>
    In trying to get flang usable in the conda-forge ecosystem (think of it as a cross-platform quasi-distribution; see #60730), One of the main remaining problems is that building _and running_  flang against the MSVC runtime fails with a linkage error for the symbol `__udivti3`, which is in compiler-rt but not the MSVC runtime.

Linking to compiler-rt has its own set of problems, though, so I perked up when I stumbled over the following [context](https://reviews.llvm.org/D150802#4451486) for `__udivti3`:

>> Hans Wennborg: Sharing in case anyone else runs into the same problem: This caused Chromium builds to fail on Windows due to not linking against compiler-rt's builtins library. It turns out this patch caused us to compile some code doing 128-bit arithmetic and calling the `__udivti3` runtime function. We worked around it by defining `_LIBCPP_HAS_NO_INT128` until we can make the builtins library part of all our builds.

> Mark de Wever: Interesting that this caused it. I expect the real cause is `std::to_char` for 128-bit values, there divisions are used. Does that mean the flag in `__config` is not set correctly? It was recently updated in [D134912](https://reviews.llvm.org/D134912).

Even though flang doesn't use libcxx, I followed down this 128-bit rabbit hole a bit, and after some searching I [found](https://github.com/llvm/llvm-project/blob/llvmorg-16.0.6/flang/include/flang/Common/uint128.h#L15-L20) `AVOID_NATIVE_UINT128_T`. However, even having built flang with that (plus https://github.com/llvm/llvm-project/commit/21bff9ca42e4735a52aa1e981b1ccd0d3b274b34), it still runs into missing `__udivti3` when trying to build a hello-world example. 

I ended up asking if building flang without native 128-bit types considered supported, and got the following response:

> @vzakhari: I do not think building with `AVOID_NATIVE_UINT128_T` is being tested or/and is fully functional. I remember trying to experimentally enable it would fail the runtime compilation because of the missing type conversion operators. The most reliable way to make sure that `AVOID_NATIVE_UINT128_T` works is to have at least one buildbot that uses it for Flang build and also runs some end-to-end testing. It seems to worth a separate issue.

Hence this issue. I don't know how hard it would be to set up an extra build bot, but that sounds like something that would be really helpful on platforms without native 128bit types, of which windows is a prime example.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVl1v2zoS_TX0y8CGRPnzwQ9pUqMGetsLNNs-GiNxZHFDkVqSsuL99YuhZCe3t7jYPiQ2LIozc-acM4Mh6LMl2ovVB7F6mmEfG-f3zfxCUVv0elY6dd0fLUR_1fYM0cGZItQG7Rn6gKUh0BZiQ1A5q3BeO38moMqFa4jUgpDb2Gj7Aq4GHQEDIFTehTDvDMba-Rb-02PQc6VD9Lrso3ZWFB8gEIGQxTrbFJmQOyEf4aslvoaDtagteOIPTqvzrjTUBtABYoMRyl4bxU9OaBX43vKxE0yJ4xm1DTHd9Me37498IOqWoEZtAgw6NoBgtH1BLsZ756F2Pp0P17Z0BsQ6O516pS9RF2KdcXpDo6uGM9AWKtd22pCfe84lgnV_j7YQ2ZPIHsb_n7V9mQB-_26DAXQM4AYLgSKXf6uVQ8bG9eeGvwUHR-jIv5CCvoOhIQtHCLFvS0MK3IXG9GtnjBs4klh9qJyN9BrF6knIbRNjF0TxIORByIOni6YhLIy5tAvnz0IenvJVts2kkMVyucqX27WQuwTLz1gUD-8rE8VHUXyET2gD_CBrS76teIBvDXrOg9HCQID26iwBmUCMEMMY3Qg5tnQrm998bnSACvtACh4b71rdt2PHA-PHTQRn4Ye2yg0BVE_8M7fATCjfCPAOaiE3IV0StQ1gdOnRXxdwjBB7bwO4njuoA3QYq-YWvg_vOgbBtawDRaAch8nldl4y672OTUtRV8B0rNCY1OuGfsbujYm9rVgKC_hBMLjUV_Sut4plVF5BUT1yn2_4fPzw-Oefp08P305fvp6OX55zueXb-DIDA0GFFlp8oRTz5yqhQ5-ohcaA6_2E5eLeP3j79gf6F1AEP-hCnptxtJE8hTgWhBNIEzw6L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