https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82869
Bug ID: 82869 Summary: c_associated does not always give false for null pointers Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: james.s.spencer at gmail dot com Target Milestone: --- I think if a pointer, p, is C_NULL_PTR then c_associated(p) should always return false. However, I do not see this with gfortran 7.2.0with -fsanitize=address or when the pointer is initialised when declared. $ gfortran -v Using built-in specs. COLLECT_GCC=gfortran COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/7.2.0/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: /build/gcc/src/gcc/configure --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/ --enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-shared --enable-threads=posix --enable-libmpx --with-system-zlib --with-isl --enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch --disable-libssp --enable-gnu-unique-object --enable-linker-build-id --enable-lto --enable-plugin --enable-install-libiberty --with-linker-hash-style=gnu --enable-gnu-indirect-function --disable-multilib --disable-werror --enable-checking=release --enable-default-pie --enable-default-ssp Thread model: posix gcc version 7.2.0 (GCC) $ cat test.f90 use, intrinsic :: iso_c_binding type(c_ptr) :: p p = c_null_ptr print *, '(Expect F) ', c_associated(p) end $ gfortran test.f90 && ./a.out (Expect F) F $ gfortran -fsanitize=address && ./a.out (Expect F) T Using -fsanitize=address changes the result. I only see this under (arch) linux, the behaviour on my mac laptop running macOS 10.13 with gfortran 7.2.0 is the expected case in both invocations. The behaviour under -fsanitize=address is not consistent though: $ cat test2.f90 use, intrinsic :: iso_c_binding type(c_ptr) :: p p = c_null_ptr print *, '(Expect F F) ', c_associated(p), c_associated(c_null_ptr) end $ gfortran test2.f90 && ./a.out (Expect F F) F F $ gfortran -fsanitize=address test2.f90 && ./a.out (Expect F F) F T Finally a case which I can reproduce on both linux and macOS 10.13 and doesn't involve -fsanitize=address: $ cat test3.f90 use, intrinsic :: iso_c_binding type(c_ptr) :: p = c_null_ptr print *, '(Expect F F) ', c_associated(p), c_associated(c_null_ptr) end $ gfortran test3.f90 && ./a.out (Expect F F) T T gfortran 6.3.0 (running on a Debian 9 machine) gives the expected result in all three cases.