public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/110238] New: Incorrect "comparison between pointer and zero character constant" warning when comparing pointer to unsigned null pointer constant
@ 2023-06-13 15:00 nora at norasandler dot com
  2023-06-13 15:16 ` [Bug c/110238] [10/11/12/13/14 Regression] " pinskia at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: nora at norasandler dot com @ 2023-06-13 15:00 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110238

            Bug ID: 110238
           Summary: Incorrect "comparison between pointer and zero
                    character constant" warning when comparing pointer to
                    unsigned null pointer constant
           Product: gcc
           Version: 13.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: nora at norasandler dot com
  Target Milestone: ---

This warning looks like it's intended to catch comparisons to null character
constants (e.g. '\0') but is also triggered by a comparison to 0u. Comparing to
other null pointer constants (0, 0l, 0ul) doesn't trigger this warning.


Preprocessed source code
========================

# 0 "compare_to_null.c"
# 0 "<built-in>"
# 0 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 0 "<command-line>" 2
# 1 "compare_to_null.c"
int main(void) {
    int *x = 0;
    return (x == 0u);
}

Compiler warning
==============
$ gcc-13 a-compare_to_null.i
compare_to_null.c: In function ‘main’:
compare_to_null.c:3:15: warning: comparison between pointer and zero character
constant [-Wpointer-compare]
    3 |     return (x == 0u);
      |               ^~
compare_to_null.c:3:13: note: did you mean to dereference the pointer?
    3 |     return (x == 0u);
      |             ^


Version/system info
============
$ gcc -v -save-temps compare_to_null.c 
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/11/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu
11.3.0-1ubuntu1~22.04.1' --with-bugurl=file:///usr/share/doc/gcc-11/README.Bugs
--enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,m2 --prefix=/usr
--with-gcc-major-version-only --program-suffix=-11
--program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu
--enable-libstdcxx-debug --enable-libstdcxx-time=yes
--with-default-libstdcxx-abi=new --enable-gnu-unique-object
--disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib
--enable-libphobos-checking=release --with-target-system-zlib=auto
--enable-objc-gc=auto --enable-multiarch --disable-werror --enable-cet
--with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32
--enable-multilib --with-tune=generic
--enable-offload-targets=nvptx-none=/build/gcc-11-aYxV0E/gcc-11-11.3.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-11-aYxV0E/gcc-11-11.3.0/debian/tmp-gcn/usr
--without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu
--host=x86_64-linux-gnu --target=x86_64-linux-gnu
--with-build-config=bootstrap-lto-lean --enable-link-serialization=2
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.3.0 (Ubuntu 11.3.0-1ubuntu1~22.04.1) 
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-mtune=generic' '-march=x86-64'
'-dumpdir' 'a-'
 /usr/lib/gcc/x86_64-linux-gnu/11/cc1 -E -quiet -v -imultiarch x86_64-linux-gnu
compare_to_null.c -mtune=generic -march=x86-64 -fpch-preprocess
-fasynchronous-unwind-tables -fstack-protector-strong -Wformat
-Wformat-security -fstack-clash-protection -fcf-protection -o
a-compare_to_null.i
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/11/include-fixed"
ignoring nonexistent directory
"/usr/lib/gcc/x86_64-linux-gnu/11/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc/x86_64-linux-gnu/11/include
 /usr/local/include
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-mtune=generic' '-march=x86-64'
'-dumpdir' 'a-'
 /usr/lib/gcc/x86_64-linux-gnu/11/cc1 -fpreprocessed a-compare_to_null.i -quiet
-dumpdir a- -dumpbase compare_to_null.c -dumpbase-ext .c -mtune=generic
-march=x86-64 -version -fasynchronous-unwind-tables -fstack-protector-strong
-Wformat -Wformat-security -fstack-clash-protection -fcf-protection -o
a-compare_to_null.s
GNU C17 (Ubuntu 11.3.0-1ubuntu1~22.04.1) version 11.3.0 (x86_64-linux-gnu)
        compiled by GNU C version 11.3.0, GMP version 6.2.1, MPFR version
4.1.0, MPC version 1.2.1, isl version isl-0.24-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU C17 (Ubuntu 11.3.0-1ubuntu1~22.04.1) version 11.3.0 (x86_64-linux-gnu)
        compiled by GNU C version 11.3.0, GMP version 6.2.1, MPFR version
4.1.0, MPC version 1.2.1, isl version isl-0.24-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: e13e2dc98bfa673227c4000e476a9388
compare_to_null.c: In function ‘main’:
compare_to_null.c:3:15: warning: comparison between pointer and zero character
constant [-Wpointer-compare]
    3 |     return (x == 0u);
      |               ^~
compare_to_null.c:3:13: note: did you mean to dereference the pointer?
    3 |     return (x == 0u);
      |             ^
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-mtune=generic' '-march=x86-64'
'-dumpdir' 'a-'
 as -v --64 -o a-compare_to_null.o a-compare_to_null.s
GNU assembler version 2.38 (x86_64-linux-gnu) using BFD version (GNU Binutils
for Ubuntu) 2.38
COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/11/:/usr/lib/gcc/x86_64-linux-gnu/11/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/11/:/usr/lib/gcc/x86_64-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/11/:/usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/11/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/11/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-mtune=generic' '-march=x86-64'
'-dumpdir' 'a.'
 /usr/lib/gcc/x86_64-linux-gnu/11/collect2 -plugin
/usr/lib/gcc/x86_64-linux-gnu/11/liblto_plugin.so
-plugin-opt=/usr/lib/gcc/x86_64-linux-gnu/11/lto-wrapper
-plugin-opt=-fresolution=a.res -plugin-opt=-pass-through=-lgcc
-plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lc
-plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s --build-id
--eh-frame-hdr -m elf_x86_64 --hash-style=gnu --as-needed -dynamic-linker
/lib64/ld-linux-x86-64.so.2 -pie -z now -z relro
/usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/Scrt1.o
/usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/crti.o
/usr/lib/gcc/x86_64-linux-gnu/11/crtbeginS.o -L/usr/lib/gcc/x86_64-linux-gnu/11
-L/usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu
-L/usr/lib/gcc/x86_64-linux-gnu/11/../../../../lib -L/lib/x86_64-linux-gnu
-L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib
-L/usr/lib/gcc/x86_64-linux-gnu/11/../../.. a-compare_to_null.o -lgcc
--push-state --as-needed -lgcc_s --pop-state -lc -lgcc --push-state --as-needed
-lgcc_s --pop-state /usr/lib/gcc/x86_64-linux-gnu/11/crtendS.o
/usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/crtn.o
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-mtune=generic' '-march=x86-64'
'-dumpdir' 'a.'

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c/110238] [10/11/12/13/14 Regression] Incorrect "comparison between pointer and zero character constant" warning when comparing pointer to unsigned null pointer constant
  2023-06-13 15:00 [Bug c/110238] New: Incorrect "comparison between pointer and zero character constant" warning when comparing pointer to unsigned null pointer constant nora at norasandler dot com
@ 2023-06-13 15:16 ` pinskia at gcc dot gnu.org
  2023-07-07 10:45 ` [Bug c/110238] [11/12/13/14 " rguenth at gcc dot gnu.org
  2024-03-08 15:34 ` law at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-06-13 15:16 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110238

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |10.5
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2023-06-13
            Summary|Incorrect "comparison       |[10/11/12/13/14 Regression]
                   |between pointer and zero    |Incorrect "comparison
                   |character constant" warning |between pointer and zero
                   |when comparing pointer to   |character constant" warning
                   |unsigned null pointer       |when comparing pointer to
                   |constant                    |unsigned null pointer
                   |                            |constant
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed, introduced with r7-5677-ga9342885b149 .

So I think the issue is in char_type_p we have:
```
static bool
char_type_p (tree type)
{
  return (type == char_type_node
         || type == unsigned_char_type_node
         || type == signed_char_type_node
         || type == char16_type_node
         || type == char32_type_node);
}
```

In C, there is no distinct type for char32_type_node so it is the same as
unsigned here and it returns true for that case .

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c/110238] [11/12/13/14 Regression] Incorrect "comparison between pointer and zero character constant" warning when comparing pointer to unsigned null pointer constant
  2023-06-13 15:00 [Bug c/110238] New: Incorrect "comparison between pointer and zero character constant" warning when comparing pointer to unsigned null pointer constant nora at norasandler dot com
  2023-06-13 15:16 ` [Bug c/110238] [10/11/12/13/14 Regression] " pinskia at gcc dot gnu.org
@ 2023-07-07 10:45 ` rguenth at gcc dot gnu.org
  2024-03-08 15:34 ` law at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-07-07 10:45 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110238

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|10.5                        |11.5

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 10 branch is being closed.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c/110238] [11/12/13/14 Regression] Incorrect "comparison between pointer and zero character constant" warning when comparing pointer to unsigned null pointer constant
  2023-06-13 15:00 [Bug c/110238] New: Incorrect "comparison between pointer and zero character constant" warning when comparing pointer to unsigned null pointer constant nora at norasandler dot com
  2023-06-13 15:16 ` [Bug c/110238] [10/11/12/13/14 Regression] " pinskia at gcc dot gnu.org
  2023-07-07 10:45 ` [Bug c/110238] [11/12/13/14 " rguenth at gcc dot gnu.org
@ 2024-03-08 15:34 ` law at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: law at gcc dot gnu.org @ 2024-03-08 15:34 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110238

Jeffrey A. Law <law at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |law at gcc dot gnu.org
           Priority|P3                          |P2

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-03-08 15:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-13 15:00 [Bug c/110238] New: Incorrect "comparison between pointer and zero character constant" warning when comparing pointer to unsigned null pointer constant nora at norasandler dot com
2023-06-13 15:16 ` [Bug c/110238] [10/11/12/13/14 Regression] " pinskia at gcc dot gnu.org
2023-07-07 10:45 ` [Bug c/110238] [11/12/13/14 " rguenth at gcc dot gnu.org
2024-03-08 15:34 ` law at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).