mirror of
https://github.com/intel/llvm.git
synced 2026-01-26 21:53:12 +08:00
Fix assertion failure on -Warray-bounds for 32-bit builds of Clang.
llvm-svn: 125821
This commit is contained in:
@@ -3109,11 +3109,14 @@ void Sema::CheckArrayAccess(const clang::ArraySubscriptExpr *E) {
|
||||
return;
|
||||
|
||||
if (!index.isNegative()) {
|
||||
const llvm::APInt &size = ArrayTy->getSize();
|
||||
llvm::APInt size = ArrayTy->getSize();
|
||||
if (!size.isStrictlyPositive())
|
||||
return;
|
||||
if (size.getBitWidth() > index.getBitWidth())
|
||||
index = index.sext(size.getBitWidth());
|
||||
else if (size.getBitWidth() < index.getBitWidth())
|
||||
size = size.sext(index.getBitWidth());
|
||||
|
||||
if (index.slt(size))
|
||||
return;
|
||||
|
||||
|
||||
@@ -85,3 +85,9 @@ int test_no_warn_macro_unreachable() {
|
||||
ARR_IN_MACRO(1, arr, SIZE); // expected-warning{{array index of '10' indexes past the end of an array (that contains 10 elements)}}
|
||||
}
|
||||
|
||||
// This exhibited an assertion failure for a 32-bit build of Clang.
|
||||
int test_pr9240() {
|
||||
short array[100]; // expected-note {{array 'array' declared here}}
|
||||
return array[(unsigned long long) 100]; // expected-warning {{array index of '100' indexes past the end of an array (that contains 100 elements)}}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user