diff options
| author | Ted Kremenek <kremenek@apple.com> | 2011-02-16 01:57:07 +0000 |
|---|---|---|
| committer | Ted Kremenek <kremenek@apple.com> | 2011-02-16 01:57:07 +0000 |
| commit | 64699befcd5d173d787ae7ac8db0f859f4dd0067 (patch) | |
| tree | 1dd04658531bcce5f5f29cb5386bb8c50f6df025 /clang/test | |
| parent | af1c83fbe7e8eb6c5450231ba26ef08f7e5a29ef (diff) | |
| download | bcm5719-llvm-64699befcd5d173d787ae7ac8db0f859f4dd0067.tar.gz bcm5719-llvm-64699befcd5d173d787ae7ac8db0f859f4dd0067.zip | |
Add trivial buffer overflow checking in Sema.
llvm-svn: 125640
Diffstat (limited to 'clang/test')
| -rw-r--r-- | clang/test/Analysis/out-of-bounds.c | 2 | ||||
| -rw-r--r-- | clang/test/Sema/array-bounds.c | 16 |
2 files changed, 17 insertions, 1 deletions
diff --git a/clang/test/Analysis/out-of-bounds.c b/clang/test/Analysis/out-of-bounds.c index d8e4ad915a0..b8d6e442ff5 100644 --- a/clang/test/Analysis/out-of-bounds.c +++ b/clang/test/Analysis/out-of-bounds.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-check-buffer-overflows -verify %s +// RUN: %clang_cc1 -Wno-array-bounds -analyze -analyzer-check-objc-mem -analyzer-check-buffer-overflows -verify %s // Tests doing an out-of-bounds access after the end of an array using: // - constant integer index diff --git a/clang/test/Sema/array-bounds.c b/clang/test/Sema/array-bounds.c new file mode 100644 index 00000000000..b540885547b --- /dev/null +++ b/clang/test/Sema/array-bounds.c @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 -verify %s + +int foo() { + int x[2]; + int y[2]; + int *p = &y[2]; // no-warning + (void) sizeof(x[2]); // no-warning + y[2] = 2; // expected-warning{{array index excedes last array element}} + return x[2] + // expected-warning{{array index excedes last array element}} + y[-1] + // expected-warning{{array index precedes first array element}} + x[sizeof(x)] + // expected-warning{{array index excedes last array element}} + x[sizeof(x) / sizeof(x[0])] + // expected-warning{{array index excedes last array element}} + x[sizeof(x) / sizeof(x[0]) - 1] + // no-warning + x[sizeof(x[2])]; // expected-warning{{array index excedes last array element}} +} + |

