[valgrind] [Bug 442168] Floating-point erroneous behavior with memcheck with regards to class (isfinite(), etc.)

2021-09-23 Thread Xavier Roche
https://bugs.kde.org/show_bug.cgi?id=442168

--- Comment #7 from Xavier Roche  ---
(In reply to Julian Seward from comment #4)
> (In reply to Xavier Roche from comment #2)
> 
> > The difference between the correctly executed code under valgrind and the
> > faulty one:
> 
> > -   movsd   %xmm0, (%rsp)   # 8-byte Spill
> > +   vmovsd  %xmm0, (%rsp)   # 8-byte Spill
> 
> Can you give some more information about why you think the change from
> movsd to vmovsd causes the error?  Also, which one gives correct execution
> and which doesn't?

The correct one is movsd; the faulty one is vmovsd. This only happens with
clang-12 [12.0.0-3ubuntu1~20.04.3] (not clang-11) and only when running
valgrind.

g++-10 (Ubuntu 10.3.0-1ubuntu1~20.04) does not trigger the problem either.

So this is a specific clang-12 issue.

As for the reason, I'm not fluent enough on x86-64 assembly to make any
educated guess unfortunately. This might have nothing to do with vmovsd

-- 
You are receiving this mail because:
You are watching all bug changes.

[valgrind] [Bug 442168] Floating-point erroneous behavior with memcheck with regards to class (isfinite(), etc.)

2021-09-23 Thread Xavier Roche
https://bugs.kde.org/show_bug.cgi?id=442168

--- Comment #6 from Xavier Roche  ---
Created attachment 141820
  --> https://bugs.kde.org/attachment.cgi?id=141820=edit
ASM diff between working program with valgrind (clang-11) and the faulty one
(clang12)

clang-12 -S -std=c++20 -stdlib=libc++ -O2 -march=corei7-avx isfinite-bug.cpp -o
/tmp/isfinite-bug-12.S
clang-11 -S -std=c++20 -stdlib=libc++ -O2 -march=corei7-avx isfinite-bug.cpp -o
/tmp/isfinite-bug-11.S
diff -udb /tmp/isfinite-bug-11.S /tmp/isfinite-bug-12.S >
/tmp/isfinite-bug-clang-11-clang-12.diff

-- 
You are receiving this mail because:
You are watching all bug changes.

[valgrind] [Bug 442168] Floating-point erroneous behavior with memecheck with regards to class (isfinite(), etc.)

2021-09-08 Thread Xavier Roche
https://bugs.kde.org/show_bug.cgi?id=442168

--- Comment #2 from Xavier Roche  ---
Additional notes: isolating the faulty function

static double (*volatile pvalidate)(double a) = validate;  // used in
minimalTest
double validate(double a)
{
return std::isfinite(a) ? a : 1.0f;
}

The difference between the correctly executed code under valgrind and the
faulty one:

 _Z8validated:   # @_Z8validated
pushq   %rax
.cfi_def_cfa_offset 16
-   movsd   %xmm0, (%rsp)   # 8-byte Spill
+   vmovsd  %xmm0, (%rsp)   # 8-byte Spill
callq  
_Z8isfiniteIdENSt3__19enable_ifIXaasr3std13is_arithmeticIT_EE5valuesr3std14numeric_limitsIS2_EE12has_infinityEbE4typeES2_
-   movsd   (%rsp), %xmm0   # 8-byte Reload
+   vmovsd  (%rsp), %xmm0   # 8-byte Reload
 # xmm0 = mem[0],zero
testb   %al, %al
jne .LBB6_2
 # %bb.1:
-   movsd   .LCPI6_0(%rip), %xmm0   # xmm0 = mem[0],zero
+   vmovsd  .LCPI6_0(%rip), %xmm0   # xmm0 = mem[0],zero
 .LBB6_2:
popq%rax
retq

-- 
You are receiving this mail because:
You are watching all bug changes.

[valgrind] [Bug 442168] Floating-point erroneous behavior with memecheck with regards to class (isfinite(), etc.)

2021-09-08 Thread Xavier Roche
https://bugs.kde.org/show_bug.cgi?id=442168

--- Comment #1 from Xavier Roche  ---
Bug also present with valgrind-3.18.0.GIT
(cadf0432290b0bc147c7b5dd54c63bc94986743c)

-- 
You are receiving this mail because:
You are watching all bug changes.

[valgrind] [Bug 442168] New: Floating-point erroneous behavior with memecheck with regards to class (isfinite(), etc.)

2021-09-08 Thread Xavier Roche
https://bugs.kde.org/show_bug.cgi?id=442168

Bug ID: 442168
   Summary: Floating-point erroneous behavior with memecheck with
regards to class (isfinite(), etc.)
   Product: valgrind
   Version: 3.15 SVN
  Platform: Other
OS: Linux
Status: REPORTED
  Severity: normal
  Priority: NOR
 Component: memcheck
  Assignee: jsew...@acm.org
  Reporter: xavier.ro...@algolia.com
  Target Milestone: ---

Created attachment 141383
  --> https://bugs.kde.org/attachment.cgi?id=141383=edit
Minimal program demonstrating floating-point erroneous behavior with memcheck

SUMMARY

Floating-point erroneous behavior with memecheck with regards to class
(isfinite(), etc.), leading to consider -NaN as a finite number.


STEPS TO REPRODUCE
1. Compile the attached reproducible minimal case with clang-12 in at least O2
and -march=corei7-avx

clang-12 -std=c++20 -stdlib=libc++ -O2 -march=corei7-avx
isfinite-bug-with-clang12-O2-corei7-avx.cpp -lc++ -lm -o isfinite-bug

2. Run without valgrind

./isfinite-bug

3. Run with valgrind (valgrind --tool=memcheck)

valgrind --tool=memcheck ./isfinite-bug


OBSERVED RESULT

Run without valgrind: "All right" is emitted

Run with valgrind: "Error: expected 1 and got -nan" is emitted


EXPECTED RESULT

The valgrind version should always emit "All right"


SOFTWARE/OS VERSIONS
Linux, Ubuntu, 5.4.0-80-generic

ADDITIONAL INFORMATION
The issue is reproduced using valgrind-3.15.0

It requires:
* clang-12
* At least O2
* -march=corei7-avx

It is _not_ reproduced with an earlier version of clang (tested version:
clang-11), which hints of a recent special NaN/fp class optimization.

At this stage, I can not guarantee that this is a valgrind issue, or a
undefined-behavior-generated-code that happen to work without valgrind.

I'm available for any additional information.

-- 
You are receiving this mail because:
You are watching all bug changes.