[cfe-users] Clang9 UBSan and GMP

Hans Ã…berg via cfe-users cfe-users at lists.llvm.org
Thu Oct 31 02:30:33 PDT 2019


> On 31 Oct 2019, at 01:53, David Blaikie <dblaikie at gmail.com> wrote:
> 
>> Yes, but assuming that the GMP adheres to the C standard, there should be no difference in the arithmetical values produced.
> 
> Not necessarily - C (well, I don't know the C standard as well as I know the C++ standard, admittedly) does allow various variations (implementation and unspecified behavior, for instance). eg: order of evaluation of function arguments (not that this is likely to vary due to optimizations - and doesn't with clang to the best of my knowledge, but as an example of the /sort/ of thing):
> 
>   int f() {
>     static int i = 0;
>     return i++;
>   }
>   int f2(int i, int j) {
>     return i;
>   }
>   int main() {
>     return f2(f(), f());
>   }
> 
> This program could exit with 0 or 1 - both results are valid interpretations of the program per the standard. (again, I don't know the C spec quite as well, so I'm not sure exactly what it says about this code)

Right, but that is something one would avoid when computing arithmetical results.





More information about the cfe-users mailing list