When compiling my project with Clang, ASan, and Gnulib's stdint-h,
I find that PTRDIFF_MAX and SIZE_MAX expand to 1.

This does not happen if I either
- remove stdint-h from bootstrap.conf; or
- disable ASan; or
- use GCC.

I am reproducing the issue in a dummy project as follows:
0. git clone 'https://git.sr.ht/~blc/foo' && cd foo
1. ./test gcc
2. ./test gcc --enable-asan
3. ./test clang
4. ./test clang --enable-asan

Steps 1-3 end in
  bar> 13 `Hello, World!'
as expected, whereas step 4 ends in
  foo> Overflow 13 > 1
where 13 (the length of "Hello, World!") exceeds 1 (PTRDIFF_MAX).

This happens in the following function in src/foo.c:

  bool
  foo_string (char const str[const static 1])
  {
    size_t const len = strlen (str);
    bool ok = len <= (uintmax_t) PTRDIFF_MAX;
    if (ok)
      bar_string (str, len);
    else
      fprintf (stderr, "foo> Overflow %zu > %td\n", len, PTRDIFF_MAX);
    return ok;
  }

The files under src/ should be straightforward; the only complexities
should be in configure.ac (where I define a macro inspired by
gl_COMPILER_OPTION_IF and AX_CHECK_LINK_FLAG) and the 'test' script
which tries to set up ASan and all of its run time options for either
GCC or Clang.

Note that configure.ac enables UBSan as well if available, but disabling
that by passing --disable-ubsan to the 'test' script makes no observable
difference in the behaviour of the 'foo' program.

I have tried removing other header modules from bootstrap.conf,
but only the removal of stdint-h resolves the issue.

That's as far as I've been able to troubleshoot for now;
let me know if you have any further suggestions.

By the way, does it make sense to update the Info node
"(gnulib) Writing reliable code" to mention any of
_FORTIFY_SOURCE=3, GCC's -fhardened, or -fsanitize-trap=all in
place of the now-deprecated -fsanitize-undefined-trap-on-error?

Thanks,
-- 
Basil

$ uname -a
Linux tais 6.16.9+deb14-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.16.9-1 
(2025-09-27) x86_64 GNU/Linux

$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description:    Debian GNU/Linux forky/sid
Release:        n/a
Codename:       forky

$ gcc --version | head -1
gcc (Debian 15.2.0-4) 15.2.0

$ gcc -print-file-name=libasan.so
/usr/lib/gcc/x86_64-linux-gnu/15/libasan.so

$ clang --version
Debian clang version 19.1.7 (7)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/lib/llvm-19/bin

$ clang -print-file-name="libclang_rt.asan-$(uname -m).so"
/usr/lib/llvm-19/lib/clang/19/lib/linux/libclang_rt.asan-x86_64.so

Reply via email to