Skip to content

Reset killed bounds for in-scope variables only #926

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions clang/lib/Sema/SemaBounds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2266,10 +2266,13 @@ namespace {

// KilledBounds stores a mapping of statements to all variables whose
// bounds are killed by each statement. Here we reset the bounds of all
// variables killed by the statement S to the normalized declared bounds.
// variables that are in scope at the statement S and whose bounds are
// killed by S to the normalized declared bounds.
for (const VarDecl *V : I->second) {
if (BoundsExpr *Bounds = S.NormalizeBounds(V))
State.ObservedBounds[V] = Bounds;
if (State.ObservedBounds.find(V) != State.ObservedBounds.end()) {
if (BoundsExpr *Bounds = S.NormalizeBounds(V))
State.ObservedBounds[V] = Bounds;
}
}
}

Expand Down
28 changes: 28 additions & 0 deletions clang/test/CheckedC/inferred-bounds/widened-bounds.c
Original file line number Diff line number Diff line change
Expand Up @@ -1266,3 +1266,31 @@ void f34(_Nt_array_ptr<char> p : count(i), int i, int flag) {
// CHECK: 2: *(p + i + 1)
// CHECK: upper_bound(p) = 1
}

void f35(void) {
int i, j;
for (;;) {
i = 1;
j = 2;
_Nt_array_ptr<char> p : count(i + j) = 0;
if (p[i + j]) {
return;
}
}

// CHECK: In function: f35
// CHECK: [B5]
// CHECK: 1: int i;
// CHECK: 2: int j;
// CHECK: [B4]
// CHECK: T: for (; ; )
// CHECK: [B3]
// CHECK: 1: i = 1
// CHECK: 2: j = 2
// CHECK: 3: _Nt_array_ptr<char> p : count(i + j) = 0;
// CHECK: 4: p[i + j] (ImplicitCastExpr, LValueToRValue, char)
// CHECK: T: if [B3.4]
// CHECK: [B2]
// CHECK: 1: return;
// CHECK: upper_bound(p) = 1
}