<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/63495>63495</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Specification of __builtin_addc
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
mglisse
</td>
</tr>
</table>
<pre>
Hello,
the documentation for the clang extension `__builtin_addc` (https://clang.llvm.org/docs/LanguageExtensions.html#multiprecision-arithmetic-builtins) is very limited, it essentially gives the prototype and nothing else
```c
unsigned __builtin_addc (unsigned x, unsigned y, unsigned carryin, unsigned *carryout);
```
Gcc is currently implementing this builtin (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79173) for compatibility, and they interpret the spec in a rather wide manner as a sum of 3 arbitrary integers, with carryout as 1 if there is an overflow (even when the carry should be 2).
Some of us think that the use of the term "carry" means that if `carryin` is not 0 or 1, this function has undefined behavior.
Could you please clarify the documentation? And in case you go with the second interpretation, could you add that check in UBSAN?
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJxkVEFvqzgQ_jXOZdSImISUA4e0XXYPq71Ue66MGfDsMzayx8ljf_2TIe1T2ygCPPZ8_r5vPFYx0ugQG3F6EqeXnUpsfGim0VKMuOt8vzR_obVeyGdRvIjiwgah9zpN6FgxeQeDD5Cj2io3Av5kdDHHRVW8vXWJLJN7U32vRVWAkI-GeY6ivAjZCtmuWXtrr9Peh1HItvc6Ctn-rdyY1Ih_vOPFveHJCllOyTLNATXl8IMKxGZCJv1w3ywKWQNFuGJYwNJEjL2Qz0AMGCM6JmXtAiNdMa7M5-DZ8zIjKNeD82woK7ERN82iKra_3sbJra718Pv3WSlknR-rfubNP0bLp5FWISzkPsWEvKxhn1jIWpRPX1hswz-1ziJ1CgEd2wVomi3msmTybCjCndJ300et96NLd8e7NP5P1ioh22j87a1L416PJMqWelG-nOvDucyW5kJrP82KqSNLvCrJjrHBBcgxhjkgr5bGGTWQAwVBscEAN-oRJuUcBlARFMQ0gR-gBBU64qDCBjFiiBn3Rmzg3YaccQAaMnTALFs58FcMg_W3LA-v6OBm0G0nMadBND7ZHjoEKWS931x79RPmbVOuPLkfwEZtjFNcJ_InY5hASLniCClhQuXitpSGfLDfy1YVmYzzDAX4AIfMfLV-SE6v3WFUhOR6HCiXtkOjruTDnc32fF55Lj7BbFHFtZMCDQt86zVRtnBxfTZW54U5Z_SbV6vrqP06fS_FliSfQX9sofp-E6IN6h8Z6d-n18s_omx3fVP2dVmrHTaH6vFcHcuyLHam6apCVkrWshz0qZd9cVL16VCda13JgzrqHTWykGVRyaM8HB9Pxf5UntRQDMXxEeW5wLM4Fjgpsh99vqMYEzZVeaxPO6s6tHG9gqR0eIN1UkiZb6TQ5JyHLo1RHAtLkeNvFCa22LzOqGkgvV1HfvjSjLsUbPPl_BOb1O21n4RsM9r99TAH_x9qFrJdOeSLaOX4KwAA__8crrpa">