Skip to content

clang with -Wnull-dereference doesn't produce expected warning #113068

@tklengyel

Description

@tklengyel

Greetings,
while compiling the following program with -Wnull-dereference no warning is produced by clang (Ubuntu clang version 20.0.0 (++20241009053718+c198f775cdcd-1~exp1~20241009053853.1977):

#include <stdio.h>

int main(int argc, char **argv)
{
    int *yikes = NULL;
    *yikes = 1;

    fprintf(stdout, "Hello world!\n");

    return *yikes;
}

Expected result would be like what you get with gcc (although it only seems to work with gcc if you have optimizations enabled and not with -O0):

$ gcc -O1 -Wnull-dereference -o yikes yikes.c
yikes.c: In function ‘main’:
yikes.c:8:12: warning: null pointer dereference [-Wnull-dereference]
    8 |     *yikes = 1;
      |     ~~~~~~~^~~
yikes.c:12:12: warning: null pointer dereference [-Wnull-dereference]
   12 |     return *yikes;
      |            ^~~~~~

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerfalse-negativeWarning doesn't fire when it should

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions