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: unassignedclangb...@nondot.org
Reporter: john.br...@arm.com
CC: llvm-bugs@lists.llvm.org, neeil...@live.com,
richard-l...@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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs