[llvm-bugs] [Bug 45238] New: Could warn for more uses of null pointer

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Mar 18 08:32:46 PDT 2020


https://bugs.llvm.org/show_bug.cgi?id=45238

            Bug ID: 45238
           Summary: Could warn for more uses of null pointer
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Frontend
          Assignee: unassignedclangbugs at nondot.org
          Reporter: john.brawn at arm.com
                CC: llvm-bugs at lists.llvm.org, neeilans at live.com,
                    richard-llvm at metafoo.co.uk

For the following functions:

  int fn1() {
    int *var;
    return *var;
  }
  int fn2() {
    int *var = 0;
    return *var;
  }
  int fn3() {
    return *(int*)0;
  }

With -Wall we give a warning for fn1 and fn3, but not fn2:

tmp.c:3:11: warning: variable 'var' is uninitialized when used here
[-Wuninitialized]
  return *var;
          ^~~
tmp.c:2:11: note: initialize the variable 'var' to silence this warning
  int *var;
          ^
           = 0
tmp.c:10:10: warning: indirection of non-volatile null pointer will be deleted,
not trap [-Wnull-dereference]
  return *(int*)0;
         ^~~~~~~~
tmp.c:10:10: note: consider using __builtin_trap() or qualifying pointer with
'volatile'


It looks like we should be able to warn for fn2 as well, given that we can warn
for use of var when it's uninitialized.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200318/52e361f1/attachment.html>


More information about the llvm-bugs mailing list