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

            Bug ID: 101665
           Summary: -fno-delete-null-pointer checks ineffective for
                    attribute nonnull parameters
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

As discussed in
https://gcc.gnu.org/pipermail/gcc-patches/2021-July/576225.html:

> The manual says -fno-delete-null-pointer-checks is supposed to
> prevent the removal of the null function argument test so I'd
> expect adding attribute optimize ("no-delete-null-pointer-checks")
> to the definition of the function to have that effect but in my
> testing it didn't work (and didn't give a warning for the two
> attributes on the same declarataion).  

$ cat a.c && gcc -O2 -S -Wall -fdump-tree-optimized=/dev/stdout a.c
__attribute__ ((nonnull))
void f (int *);

#pragma GCC optimize "no-delete-null-pointer-checks"

__attribute__ ((optimize ("no-delete-null-pointer-checks")))
void f (int *p)
{
  if (p == 0)
    __builtin_abort ();
}

a.c: In function ‘f’:
a.c:9:6: warning: ‘nonnull’ argument ‘p’ compared to NULL [-Wnonnull-compare]
    9 |   if (p == 0)
      |      ^

;; Function f (f, funcdef_no=0, decl_uid=1943, cgraph_uid=1, symbol_order=0)

__attribute__((optimize ("no-delete-null-pointer-checks",
"no-delete-null-pointer-checks")))
__attribute__((nonnull))
void f (int * p)
{
  <bb 2> [local count: 1073741824]:
  return;

}

Reply via email to