Re: failure with Clang's memory sanitizer: use-of-uninitialized-value

2019-03-29 Thread Vincent Lefevre
On 2019-03-29 06:20:31 +0100, Niels Möller wrote:
> A bit unobvious what MPN_COPY expands to, but possibly some assembly
> that the clang analyzer can't reason about?

I've just looked at the Clang documentation, and it says:

  MemorySanitizer requires that all program code is instrumented. This
  also includes any libraries that the program depends on, even libc.
  Failing to achieve this may result in false reports. For the same
  reason you may need to replace all inline assembly code that writes
  to memory with a pure C/C++ code.

So, indeed, one should recompile GMP with Clang and without asm code.
(BTW, if one needs to also recompile libc, this seems rather
impracticable.)

-- 
Vincent Lefèvre  - Web: 
100% accessible validated (X)HTML - Blog: 
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)
___
gmp-bugs mailing list
gmp-bugs@gmplib.org
https://gmplib.org/mailman/listinfo/gmp-bugs


Re: failure with Clang's memory sanitizer: use-of-uninitialized-value

2019-03-28 Thread Niels Möller
Marc Glisse  writes:

> Just recompiling GMP with CC='clang-7 -fsanitize=memory' (and
> --disable-shared) gives the more specific
>
> ==28897==WARNING: MemorySanitizer: use-of-uninitialized-value
> #0 0x498856 in mpn_bc_get_str /tmp/g/mpn/get_str.c:239:7

Looks like the branch on rp[1] here,

  ul = rp[1];  
  while (ul != 0)  // <---

rp[1] appears initialized with

  MPN_COPY (rp + 1, up, un);

A bit unobvious what MPN_COPY expands to, but possibly some assembly
that the clang analyzer can't reason about? Since the result of the
function is as expected, it seems unlikely that ul doesn't hold the
proper input value.

Regards,
/Niels

-- 
Niels Möller. PGP-encrypted email is preferred. Keyid 368C6677.
Internet email is subject to wholesale government surveillance.
___
gmp-bugs mailing list
gmp-bugs@gmplib.org
https://gmplib.org/mailman/listinfo/gmp-bugs


Re: failure with Clang's memory sanitizer: use-of-uninitialized-value

2019-03-28 Thread Marc Glisse

On Thu, 28 Mar 2019, Niels Möller wrote:


Vincent Lefevre  writes:


On my Debian/unstable x86_64 machine (with GMP 6.1.2):

#include 

int main (void)
{
  mpz_t z;

  mpz_init (z);
  mpz_set_ui (z, 1);
  mpz_dump (z);
  mpz_clear (z);

  return 0;
}

compiled with: clang-7 -fsanitize=memory -o tst tst.c -lgmp


Is -fsanitize=memory reliable when the C compiler doesn't get to see all
the source files? Do you get the same result of you recompile gmp using
CC='clang-7 -fsanitize=memory'? If you also recompile with
--disable-assembly?


Just recompiling GMP with CC='clang-7 -fsanitize=memory' (and 
--disable-shared) gives the more specific


==28897==WARNING: MemorySanitizer: use-of-uninitialized-value
#0 0x498856 in mpn_bc_get_str /tmp/g/mpn/get_str.c:239:7
#1 0x497843 in __gmpn_get_str /tmp/g/mpn/get_str.c:430:12
#2 0x496e83 in __gmpz_get_str /home/glisse/repos/gmp/mpz/get_str.c:96:14
#3 0x496af7 in __gmpz_dump /home/glisse/repos/gmp/mpz/dump.c:45:9
#4 0x4969ec in main /tmp/b.c:9:3
#5 0x7f743f2ef09a in __libc_start_main 
(/lib/x86_64-linux-gnu/libc.so.6+0x2409a)
#6 0x41e2a9 in _start (/tmp/a.out+0x41e2a9)

SUMMARY: MemorySanitizer: use-of-uninitialized-value 
/tmp/g/mpn/get_str.c:239:7 in mpn_bc_get_str

Exiting

while adding --disable-assembly lets the program run without error.

--
Marc Glisse
___
gmp-bugs mailing list
gmp-bugs@gmplib.org
https://gmplib.org/mailman/listinfo/gmp-bugs