Skip to content

Commit 86a6b2f

Browse files
author
git apple-llvm automerger
committed
Merge commit 'd53b3c69d577' from apple/stable/20200108 into swift/release/5.3
2 parents 44243db + d53b3c6 commit 86a6b2f

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

clang/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,12 +253,18 @@ void NonNullParamChecker::checkBeginFunction(CheckerContext &Context) const {
253253
if (!ParameterNonNullMarks.test(Parameter->getFunctionScopeIndex()))
254254
continue;
255255

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+
256262
Loc ParameterLoc = State->getLValue(Parameter, LocContext);
257263
// We never consider top-level function parameters undefined.
258264
auto StoredVal =
259265
State->getSVal(ParameterLoc).castAs<DefinedOrUnknownSVal>();
260266

261-
// 2. Assume that it is indeed non-null
267+
// 3. Assume that it is indeed non-null
262268
if (ProgramStateRef NewState = State->assume(StoredVal, true)) {
263269
State = NewState;
264270
}

clang/test/Analysis/UserNullabilityAnnotations.m

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %clang_analyze_cc1 -verify -Wno-objc-root-class %s \
2+
// RUN: -Wno-tautological-pointer-compare \
23
// RUN: -analyzer-checker=core \
34
// RUN: -analyzer-checker=nullability \
45
// RUN: -analyzer-checker=debug.ExprInspection
@@ -34,3 +35,15 @@ void f1(NestedNonnullMember *Root) {
3435
clang_analyzer_eval(Grandson->Value != 0); // expected-warning{{TRUE}}
3536
clang_analyzer_eval(foo()->Child->Value != 0); // expected-warning{{TRUE}}
3637
}
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+
}

0 commit comments

Comments
 (0)