Skip to content

Commit abdb844

Browse files
Change warning to assert
1 parent d7581c8 commit abdb844

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

clang/lib/3C/AVarBoundsInfo.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,8 @@ ABounds *AvarBoundsInference::getPreferredBound(BoundsKey BK) {
242242
if (NeedsBasePointer && BI->LowerBounds.find(BK) != BI->LowerBounds.end())
243243
BaseVar = BI->LowerBounds[BK];
244244

245-
if (NeedsBasePointer && BaseVar == 0)
246-
llvm::errs() << "Lower bound pointer required for " << BK
247-
<< " but not available.\n";
245+
assert("Lower bound required but not available." &&
246+
(!NeedsBasePointer || BaseVar != 0));
248247

249248
const auto &BKindMap = CurrIterInferBounds[BK];
250249
// Utility to check if the map contains a non-empty set of bounds for a

clang/test/3C/range_bounds_flow.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,3 +187,17 @@ void foo_caller(unsigned long l) {
187187
// expected-note@-2 {{}}
188188
// expected-note@-3 {{}}
189189
}
190+
191+
192+
// Lower bound inference for `b` fails because `a` is out of scope. If `a` were
193+
// in scope, it would be used as a lower bound.
194+
void bar(int *b) {
195+
// CHECK_ALL: void bar(_Array_ptr<int> __3c_tmp_b : count(0 + 1)) _Checked {
196+
// CHECK_ALL: _Array_ptr<int> b : bounds(__3c_tmp_b, __3c_tmp_b + 0 + 1) = __3c_tmp_b;
197+
int *a;
198+
// CHECK_ALL: _Array_ptr<int> a : count(0 + 1) = ((void *)0);
199+
b = a;
200+
// CHECK_ALL: __3c_tmp_b = a, b = __3c_tmp_b;
201+
b++;
202+
b[0];
203+
}

0 commit comments

Comments
 (0)