diff options
author | Ted Kremenek <kremenek@apple.com> | 2011-02-18 02:27:00 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2011-02-18 02:27:00 +0000 |
commit | a7ced2cb4caa71ff09a4674bf4c7d9890eefb5e9 (patch) | |
tree | 1e2f33287dc978db9c0e3655bae75e76d9418aba /clang | |
parent | 14a552b2d71d4a4cf496953f62bc1337cbd8f9dc (diff) | |
download | bcm5719-llvm-a7ced2cb4caa71ff09a4674bf4c7d9890eefb5e9.tar.gz bcm5719-llvm-a7ced2cb4caa71ff09a4674bf4c7d9890eefb5e9.zip |
Fix assertion failure on -Warray-bounds for 32-bit builds of Clang.
llvm-svn: 125821
Diffstat (limited to 'clang')
-rw-r--r-- | clang/lib/Sema/SemaChecking.cpp | 5 | ||||
-rw-r--r-- | clang/test/SemaCXX/array-bounds.cpp | 6 |
2 files changed, 10 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index 6b1013d82dd..2cddac5f667 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -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; diff --git a/clang/test/SemaCXX/array-bounds.cpp b/clang/test/SemaCXX/array-bounds.cpp index 8c22865e79d..0286c01d85f 100644 --- a/clang/test/SemaCXX/array-bounds.cpp +++ b/clang/test/SemaCXX/array-bounds.cpp @@ -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)}} +} + |