[cfe-users] Clang9 UBSan and GMP

David Blaikie via cfe-users cfe-users at lists.llvm.org
Thu Oct 31 10:40:18 PDT 2019


On Thu, Oct 31, 2019 at 2:30 AM Hans Ã…berg <haberg-1 at telia.com> wrote:

>
> > 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.
>

One would try to, yes - but that's sort of what the whole discussion is
resolving around: Is the code correct? I don't know. I wouldn't assume it
is (I'm not assuming it isn't either) - but without a reduced test case
that gets to the root of the difference in behavior, we don't know if the
code is correct.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-users/attachments/20191031/f1793cd1/attachment.html>


More information about the cfe-users mailing list