File tree Expand file tree Collapse file tree 2 files changed +20
-1
lines changed
lib/StaticAnalyzer/Checkers Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -253,12 +253,18 @@ void NonNullParamChecker::checkBeginFunction(CheckerContext &Context) const {
253
253
if (!ParameterNonNullMarks.test (Parameter->getFunctionScopeIndex ()))
254
254
continue ;
255
255
256
+ // 2. Check that parameter is a pointer.
257
+ // Nonnull attribute can be applied to non-pointers (by default
258
+ // __attribute__(nonnull) implies "all parameters").
259
+ if (!Parameter->getType ()->isPointerType ())
260
+ continue ;
261
+
256
262
Loc ParameterLoc = State->getLValue (Parameter, LocContext);
257
263
// We never consider top-level function parameters undefined.
258
264
auto StoredVal =
259
265
State->getSVal (ParameterLoc).castAs <DefinedOrUnknownSVal>();
260
266
261
- // 2 . Assume that it is indeed non-null
267
+ // 3 . Assume that it is indeed non-null
262
268
if (ProgramStateRef NewState = State->assume (StoredVal, true )) {
263
269
State = NewState;
264
270
}
Original file line number Diff line number Diff line change 1
1
// RUN: %clang_analyze_cc1 -verify -Wno-objc-root-class %s \
2
+ // RUN: -Wno-tautological-pointer-compare \
2
3
// RUN: -analyzer-checker=core \
3
4
// RUN: -analyzer-checker=nullability \
4
5
// RUN: -analyzer-checker=debug.ExprInspection
@@ -34,3 +35,15 @@ void f1(NestedNonnullMember *Root) {
34
35
clang_analyzer_eval (Grandson->Value != 0 ); // expected-warning{{TRUE}}
35
36
clang_analyzer_eval (foo ()->Child ->Value != 0 ); // expected-warning{{TRUE}}
36
37
}
38
+
39
+ // Check that we correctly process situations when non-pointer parameters
40
+ // get nonnul attributes.
41
+ // Original problem: rdar://problem/63150074
42
+ typedef struct {
43
+ long a;
44
+ } B;
45
+ __attribute__ ((nonnull)) void c(B x, int *y);
46
+
47
+ void c (B x, int *y) {
48
+ clang_analyzer_eval (y != 0 ); // expected-warning{{TRUE}}
49
+ }
You can’t perform that action at this time.
0 commit comments