[Bug sanitizer/104718] New: Leak reported for elided static variable

2022-02-28 Thread dlong at cadence dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104718

Bug ID: 104718
   Summary: Leak reported for elided static variable
   Product: gcc
   Version: 9.3.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: sanitizer
  Assignee: unassigned at gcc dot gnu.org
  Reporter: dlong at cadence dot com
CC: dodji at gcc dot gnu.org, dvyukov at gcc dot gnu.org,
jakub at gcc dot gnu.org, kcc at gcc dot gnu.org, marxin at 
gcc dot gnu.org
  Target Milestone: ---

Created attachment 52523
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52523&action=edit
test case showing incorrect leak report

This is a case where g++ is able to detect that a section of code is
not used, and as a result it seems to be more-or-less eliding a
static variable that references some dynamically allocated storage.

It seems that this is confusing the leak sanitizer, which reports
the storage for that variable as leaked.

Normally, static variables which reference dynamically allocated
memory at program exit are not shown as leaks.

If you compile the attached test with:
g++-9.3.0 -std=c++17 -O2 -fsanitize=address -DUSE2=true lsantest.cc -o lsantest
so that the mutex mut2 is not elided and then run ./lsantest, the
program exits cleanly and reports no leaks.

If you compile it with:
g++-9.3.0 -std=c++17 -O2 -fsanitize=address -DUSE2=false lsantest.cc -o
lsantest
so that mut2 can be elided and then run ./lsantest, the sanitizer
will report a leak at exit.

mut1 is never elided and never reported as a leak.

mut2 will not be reported as a leak if use2 is just static bool instead
of static bool const.  Nor will it be reported as a leak if mut2 is
not declared static.

[Bug c++/105071] New: Incorrect code with -Os and complex

2022-03-27 Thread dlong at cadence dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105071

Bug ID: 105071
   Summary: Incorrect code with -Os and complex
   Product: gcc
   Version: 9.3.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: dlong at cadence dot com
  Target Milestone: ---

Created attachment 52691
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52691&action=edit
.ii file for test case

64-bit Intel, RedHat Enterprise Linux 7.4

$ cat foo.cc
#include 
#include 

using namespace std;

void broken(complex x)
{
  complex x2=x*x;
  complex x3=x2*x;
  complex x4=x3*x;
  complex x5=x4*x;
  complex d=1.0+2.0/x+4.0/x2+8.0/x3+16.0/x4+32.0/x5;
  fprintf(stderr, "%e%+ej\n", real(d), imag(d));
}

int main(int argc, char **argv) {
  broken(complex(1.0, 0.00e+00));
  return 0;
}
$ g++-9 -Wall -o foo foo.cc && ./foo  # correct
6.30e+01+0.00e+00j
$ g++-9 -Wall -O2 -o foo foo.cc && ./foo  # also correct
6.30e+01+0.00e+00j
$ g++-9 -Wall -Os -o foo foo.cc && ./foo  # wrong
1.00e+00+0.00e+00j

If the +32.0/x5 at the end of the computation of d is
omitted, then -Os also gives the correct result.

$ g++-9 -v
Using built-in specs.
COLLECT_GCC=g++-9
COLLECT_LTO_WRAPPER=/grid/common/pkgsData/gcc-v9.3.0p3/Linux/RHEL7.0-2017-x86_64/libexec/gcc/x86_64-redhat-linux/9.3.0/lto-wrapper
Target: x86_64-redhat-linux
Configured with: /tmp/gcc-v9.3.0p3/gcc.source/configure
--prefix=/grid/common/pkgsData/gcc-v9.3.0p3/Linux/RHEL7.0-2017-x86_64
--with-pkgversion=Cadence --disable-libgcj --enable-threads=posix
--enable-shared --enable-checking=release --with-system-zlib
--enable-__cxa_atexit --disable-libunwind-exceptions
--with-linker-hash-style=gnu --enable-languages=c,c++,fortran --disable-nls
--enable-gnu-unique-object --enable-bootstrap --enable-plugin
--enable-initfini-array --enable-linker-build-id --enable-gnu-indirect-function
--enable-install-libiberty
--with-ld=/grid/common/pkgsData/gcc-v9.3.0p3/Linux/RHEL7.0-2017-x86_64/bin/ld
--with-as=/grid/common/pkgsData/gcc-v9.3.0p3/Linux/RHEL7.0-2017-x86_64/bin/as
--build=x86_64-redhat-linux --host=x86_64-redhat-linux --with-tune=generic
--enable-multiarch
Thread model: posix
gcc version 9.3.0 (Cadence)

[Bug sanitizer/103519] New: Address sanitizer check missing for AVX512 masked load

2021-12-01 Thread dlong at cadence dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103519

Bug ID: 103519
   Summary: Address sanitizer check missing for AVX512 masked load
   Product: gcc
   Version: 11.2.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: sanitizer
  Assignee: unassigned at gcc dot gnu.org
  Reporter: dlong at cadence dot com
CC: dodji at gcc dot gnu.org, dvyukov at gcc dot gnu.org,
jakub at gcc dot gnu.org, kcc at gcc dot gnu.org, marxin at 
gcc dot gnu.org
  Target Milestone: ---

Example with generated assembly available here: https://godbolt.org/z/WTo5sGThb

In this:

#include 

__m512d v;

void
access(float const *addr)
{
  __m512d val;
  __m256 val1;
  __mmask8 const k3 = 0x3f;
  val1=_mm256_maskz_loadu_ps(k3, addr);
  val=_mm512_cvtps_pd(val1);
  _mm512_storeu_pd((double *)&v, val);
}

when compiled with AVX512 instructions and -fsanitize=address, no address check
is generated for the maskz_load.

(FWIW, if the mask is folded into the conversion using maskz_cvtps_pd instead
then a check is generated.  However it's a check for a full 32-byte access even
though the CPU will only actually access 24-bytes due to the mask.)

[Bug sanitizer/103519] Address sanitizer check missing for AVX512 masked load

2021-12-01 Thread dlong at cadence dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103519

David Long  changed:

   What|Removed |Added

 CC||dlong at cadence dot com

--- Comment #1 from David Long  ---
(In case the godbolt link happens to disappear at some point, compilation
options are -mavx512f -mavx512vl -mfma -mbmi2 -O -fsanitize=address)