[cfe-users] Clang9 UBSan and GMP

2019-10-25 Thread Hans Åberg via cfe-users
[Please cc me, as I am not on the list.]

When compiling GMP 6.1.2 with MacPorts clang9 on MacOS 10.15, the check gives 
one error, but if turning on UBSan ‘undefined’, it passes without a report. 
Should it not report what it thinks is the issue?


___
cfe-users mailing list
cfe-users@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users


Re: [cfe-users] Clang9 UBSan and GMP

2019-10-25 Thread David Blaikie via cfe-users
You mentioned "the check gives one error" - which check?

On Fri, Oct 25, 2019 at 8:21 AM Hans Åberg via cfe-users <
cfe-users@lists.llvm.org> wrote:

> [Please cc me, as I am not on the list.]
>
> When compiling GMP 6.1.2 with MacPorts clang9 on MacOS 10.15, the check
> gives one error, but if turning on UBSan ‘undefined’, it passes without a
> report. Should it not report what it thinks is the issue?
>
>
> ___
> cfe-users mailing list
> cfe-users@lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users
>
___
cfe-users mailing list
cfe-users@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users


Re: [cfe-users] Clang9 UBSan and GMP

2019-10-25 Thread David Blaikie via cfe-users
UBSan adds code to check things, it necessarily changes optimizations by
having those checks in. It shouldn't affect the behavior of programs that
don't exhibit UB (but I imagine it could affect the behavior of programs
relying on specific IB  (Implementation Defined Behavior)).

Reducing a test case to better understand your code & be able to portably
demonstrate the issue would help to get traction on understanding the
behavior, seeing if it's a clang bug, etc.

On Fri, Oct 25, 2019 at 1:49 PM Hans Åberg  wrote:

> It is just an abort trap. The ‘make check' also passes if turning off
> optimization. I would have expected UBSan to not change anything in
> optimization, but merely report the issues it finds. Apparently it finds
> nothing, so it may suggest a compiler bug.
>
>
> > On 25 Oct 2019, at 22:34, David Blaikie  wrote:
> >
> > Hard to know what might be happening - what sort of failure you're
> seeing, etc. Perhaps UBSan is stabilizing/changing unspecified rather than
> undefined behavior - or the test is failing due to some undefined behavior
> that UBSan doesn't catch, etc.
> >
>
>
___
cfe-users mailing list
cfe-users@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users


Re: [cfe-users] Clang9 UBSan and GMP

2019-10-25 Thread David Blaikie via cfe-users
Hard to know what might be happening - what sort of failure you're seeing,
etc. Perhaps UBSan is stabilizing/changing unspecified rather than
undefined behavior - or the test is failing due to some undefined behavior
that UBSan doesn't catch, etc.

On Fri, Oct 25, 2019 at 11:25 AM Hans Åberg  wrote:

> The ‘make check’ of GMP 6.1.2. One of the tests fail, but with any UBSan
> ‘undefined’ option enabled (in ‘configure’), none.
>
> > On 25 Oct 2019, at 18:35, David Blaikie  wrote:
> >
> > You mentioned "the check gives one error" - which check?
>
>
___
cfe-users mailing list
cfe-users@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users


Re: [cfe-users] Clang9 UBSan and GMP

2019-10-25 Thread David Blaikie via cfe-users
It's hard to know if it's the compiler's fault without a test case - due to
the nature of undefined behavior and other things (implementation defined
behavior and unspecified behavior) in C++, that the program behaves as
expected with another compiler or another set of flags doesn't give a
strong indication as to where the problem is (in the code, in one of the
compilers, etc).

- Dave

On Fri, Oct 25, 2019 at 2:22 PM Hans Åberg  wrote:

> It is not my code, it belongs to gmp-6.1.2, I merely happened to come a
> cross it. It passes on gcc9, so there is something that clang9 does.
>
>
> > On 25 Oct 2019, at 23:15, David Blaikie  wrote:
> >
> > It's pretty hard to conclude whether it's a bug in your code or in the
> compiler, or both, without narrowing down a test case.
>
>
___
cfe-users mailing list
cfe-users@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users


Re: [cfe-users] Clang9 UBSan and GMP

2019-10-25 Thread David Blaikie via cfe-users
It's pretty hard to conclude whether it's a bug in your code or in the
compiler, or both, without narrowing down a test case.

On Fri, Oct 25, 2019 at 2:01 PM Hans Åberg  wrote:

> So then there probably is an issue with the optimization.
>
> Just run 'gmp-6.1.2’ with MacPorts clang 9.0.0; I got:
> ../../../gmp-6.1.2/test-driver: line 107: 70037 Abort trap: 6
>  "$@" > $log_file 2>&1
> FAIL: t-sqrlo
>
> With Apple clang 11.0.0 (clang-1100.0.33.8), I got another ‘make check’
> error, also only when using optimization:
> ../../../gmp-6.1.2/test-driver: line 107: 30266 Segmentation fault: 11
> "$@" > $log_file 2>&1
> FAIL: t-toom53
>
>
> > On 25 Oct 2019, at 22:53, David Blaikie  wrote:
> >
> > UBSan adds code to check things, it necessarily changes optimizations by
> having those checks in. It shouldn't affect the behavior of programs that
> don't exhibit UB (but I imagine it could affect the behavior of programs
> relying on specific IB  (Implementation Defined Behavior)).
> >
> > Reducing a test case to better understand your code & be able to
> portably demonstrate the issue would help to get traction on understanding
> the behavior, seeing if it's a clang bug, etc.
>
>
___
cfe-users mailing list
cfe-users@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users


Re: [cfe-users] Clang9 UBSan and GMP

2019-10-25 Thread David Blaikie via cfe-users
Yeah, coming across compiler bugs does happen - but more often it's bugs in
input programs. (one of the reasons compiler engineers aren't likely to
jump on reproducing and reducing misbehaving programs, because on the odds,
it's not a bug in the compiler)

On Fri, Oct 25, 2019 at 3:12 PM Hans Åberg  wrote:

> The sources are available at [1]; it is written in C, not C++. I was was
> hoping that that something like UBSan would shed light on it, but the
> original question is answered: it changes optimization. The GMP developers
> say that they have caught some compiler bugs, but that is hard to do and
> time consuming.
>
> 1. https://gmplib.org
>
>
> > On 25 Oct 2019, at 23:38, David Blaikie  wrote:
> >
> > It's hard to know if it's the compiler's fault without a test case - due
> to the nature of undefined behavior and other things (implementation
> defined behavior and unspecified behavior) in C++, that the program behaves
> as expected with another compiler or another set of flags doesn't give a
> strong indication as to where the problem is (in the code, in one of the
> compilers, etc).
> >
>
>
___
cfe-users mailing list
cfe-users@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users


Re: [cfe-users] Clang9 UBSan and GMP

2019-10-25 Thread David Blaikie via cfe-users
UBSan doesn't catch everything - you could also try ASan and/or valgrind,
etc. (MSan if you want, but that's a bit fussier/more work to use)

On Fri, Oct 25, 2019 at 3:16 PM Hans Åberg  wrote:

> That is the reason I tried the UBSan, but as it changes optimization, it
> does not wrok.
>
>
> > On 26 Oct 2019, at 00:14, David Blaikie  wrote:
> >
> > Yeah, coming across compiler bugs does happen - but more often it's bugs
> in input programs. (one of the reasons compiler engineers aren't likely to
> jump on reproducing and reducing misbehaving programs, because on the odds,
> it's not a bug in the compiler)
>
>
___
cfe-users mailing list
cfe-users@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users


Re: [cfe-users] Clang9 UBSan and GMP

2019-10-25 Thread Matthew Fernandez via cfe-users
Hans, it’s challenging to give sensible advice/guesses without knowing which 
test is failing. Maybe I missed this information in the replies (please CC the 
list if you want follow up answers from more than just David). I am not a GMP 
developer, but note that GMP is regularly tested with ubsan and results are 
included at https://gmplib.org/devel/tm/gmp/date.html 
.

> On Oct 25, 2019, at 15:32, David Blaikie via cfe-users 
>  wrote:
> 
> UBSan doesn't catch everything - you could also try ASan and/or valgrind, 
> etc. (MSan if you want, but that's a bit fussier/more work to use)
> 
> On Fri, Oct 25, 2019 at 3:16 PM Hans Åberg  > wrote:
> That is the reason I tried the UBSan, but as it changes optimization, it does 
> not wrok.
> 
> 
> > On 26 Oct 2019, at 00:14, David Blaikie  > > wrote:
> > 
> > Yeah, coming across compiler bugs does happen - but more often it's bugs in 
> > input programs. (one of the reasons compiler engineers aren't likely to 
> > jump on reproducing and reducing misbehaving programs, because on the odds, 
> > it's not a bug in the compiler)
> 
> ___
> cfe-users mailing list
> cfe-users@lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users

___
cfe-users mailing list
cfe-users@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users


Re: [cfe-users] Clang9 UBSan and GMP

2019-10-25 Thread Hans Åberg via cfe-users
It is not my code, it belongs to gmp-6.1.2, I merely happened to come a cross 
it. It passes on gcc9, so there is something that clang9 does.


> On 25 Oct 2019, at 23:15, David Blaikie  wrote:
> 
> It's pretty hard to conclude whether it's a bug in your code or in the 
> compiler, or both, without narrowing down a test case.

___
cfe-users mailing list
cfe-users@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users


Re: [cfe-users] Clang9 UBSan and GMP

2019-10-25 Thread Hans Åberg via cfe-users
The sources are available at [1]; it is written in C, not C++. I was was hoping 
that that something like UBSan would shed light on it, but the original 
question is answered: it changes optimization. The GMP developers say that they 
have caught some compiler bugs, but that is hard to do and time consuming.

1. https://gmplib.org


> On 25 Oct 2019, at 23:38, David Blaikie  wrote:
> 
> It's hard to know if it's the compiler's fault without a test case - due to 
> the nature of undefined behavior and other things (implementation defined 
> behavior and unspecified behavior) in C++, that the program behaves as 
> expected with another compiler or another set of flags doesn't give a strong 
> indication as to where the problem is (in the code, in one of the compilers, 
> etc).
> 

___
cfe-users mailing list
cfe-users@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users


Re: [cfe-users] Clang9 UBSan and GMP

2019-10-25 Thread Hans Åberg via cfe-users
The ‘make check’ of GMP 6.1.2. One of the tests fail, but with any UBSan 
‘undefined’ option enabled (in ‘configure’), none.

> On 25 Oct 2019, at 18:35, David Blaikie  wrote:
> 
> You mentioned "the check gives one error" - which check?

___
cfe-users mailing list
cfe-users@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users


Re: [cfe-users] Clang9 UBSan and GMP

2019-10-25 Thread Hans Åberg via cfe-users
So then there probably is an issue with the optimization.

Just run 'gmp-6.1.2’ with MacPorts clang 9.0.0; I got:
../../../gmp-6.1.2/test-driver: line 107: 70037 Abort trap: 6   "$@" > 
$log_file 2>&1
FAIL: t-sqrlo

With Apple clang 11.0.0 (clang-1100.0.33.8), I got another ‘make check’ error, 
also only when using optimization:
../../../gmp-6.1.2/test-driver: line 107: 30266 Segmentation fault: 11  "$@" > 
$log_file 2>&1
FAIL: t-toom53


> On 25 Oct 2019, at 22:53, David Blaikie  wrote:
> 
> UBSan adds code to check things, it necessarily changes optimizations by 
> having those checks in. It shouldn't affect the behavior of programs that 
> don't exhibit UB (but I imagine it could affect the behavior of programs 
> relying on specific IB  (Implementation Defined Behavior)).
> 
> Reducing a test case to better understand your code & be able to portably 
> demonstrate the issue would help to get traction on understanding the 
> behavior, seeing if it's a clang bug, etc.

___
cfe-users mailing list
cfe-users@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users


Re: [cfe-users] Clang9 UBSan and GMP

2019-10-25 Thread Hans Åberg via cfe-users
That is the reason I tried the UBSan, but as it changes optimization, it does 
not wrok.


> On 26 Oct 2019, at 00:14, David Blaikie  wrote:
> 
> Yeah, coming across compiler bugs does happen - but more often it's bugs in 
> input programs. (one of the reasons compiler engineers aren't likely to jump 
> on reproducing and reducing misbehaving programs, because on the odds, it's 
> not a bug in the compiler)

___
cfe-users mailing list
cfe-users@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users


Re: [cfe-users] Clang9 UBSan and GMP

2019-10-25 Thread Hans Åberg via cfe-users
It is just an abort trap. The ‘make check' also passes if turning off 
optimization. I would have expected UBSan to not change anything in 
optimization, but merely report the issues it finds. Apparently it finds 
nothing, so it may suggest a compiler bug.


> On 25 Oct 2019, at 22:34, David Blaikie  wrote:
> 
> Hard to know what might be happening - what sort of failure you're seeing, 
> etc. Perhaps UBSan is stabilizing/changing unspecified rather than undefined 
> behavior - or the test is failing due to some undefined behavior that UBSan 
> doesn't catch, etc.
> 

___
cfe-users mailing list
cfe-users@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users


Re: [cfe-users] Clang9 UBSan and GMP

2019-10-25 Thread David Blaikie via cfe-users
On Fri, Oct 25, 2019 at 5:55 PM Matthew Fernandez <
matthew.fernan...@gmail.com> wrote:

> Hans, it’s challenging to give sensible advice/guesses without knowing
> which test is failing. Maybe I missed this information in the replies
> (please CC the list if you want follow up answers from more than just
> David).
>

That's my fault - Hans not subscribed to the list, so the emails have to be
approved by a moderator (me) & I hadn't gotten around to it. Approved them
all so they should now show up.


> I am not a GMP developer, but note that GMP is regularly tested with ubsan
> and results are included at https://gmplib.org/devel/tm/gmp/date.html.
>
> On Oct 25, 2019, at 15:32, David Blaikie via cfe-users <
> cfe-users@lists.llvm.org> wrote:
>
> UBSan doesn't catch everything - you could also try ASan and/or valgrind,
> etc. (MSan if you want, but that's a bit fussier/more work to use)
>
> On Fri, Oct 25, 2019 at 3:16 PM Hans Åberg  wrote:
>
>> That is the reason I tried the UBSan, but as it changes optimization, it
>> does not wrok.
>>
>>
>> > On 26 Oct 2019, at 00:14, David Blaikie  wrote:
>> >
>> > Yeah, coming across compiler bugs does happen - but more often it's
>> bugs in input programs. (one of the reasons compiler engineers aren't
>> likely to jump on reproducing and reducing misbehaving programs, because on
>> the odds, it's not a bug in the compiler)
>>
>> ___
> cfe-users mailing list
> cfe-users@lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users
>
>
>
___
cfe-users mailing list
cfe-users@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users


Re: [cfe-users] Clang9 UBSan and GMP

2019-10-25 Thread Hans Åberg via cfe-users
The GMP developers felt it was a compiler bug, so I think I will leave it at 
that. But thanks for the tips.


> On 26 Oct 2019, at 00:32, David Blaikie  wrote:
> 
> UBSan doesn't catch everything - you could also try ASan and/or valgrind, 
> etc. (MSan if you want, but that's a bit fussier/more work to use)

___
cfe-users mailing list
cfe-users@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users