diff options
| author | Chris Lattner <sabre@nondot.org> | 2010-01-12 21:23:57 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2010-01-12 21:23:57 +0000 |
| commit | faa5417264d4fd3ec923b72f18a78c95a6ae143d (patch) | |
| tree | de8e25e87dd8ae199eac2b8c4fb800d793bfb7b0 /clang/test | |
| parent | 20aee9b9147fa2dcd9e50c0f84d15c87844db773 (diff) | |
| download | bcm5719-llvm-faa5417264d4fd3ec923b72f18a78c95a6ae143d.tar.gz bcm5719-llvm-faa5417264d4fd3ec923b72f18a78c95a6ae143d.zip | |
implement PR6004, warning about divide and remainder by zero.
llvm-svn: 93256
Diffstat (limited to 'clang/test')
| -rw-r--r-- | clang/test/Analysis/misc-ps.m | 12 | ||||
| -rw-r--r-- | clang/test/Sema/exprs.c | 8 | ||||
| -rw-r--r-- | clang/test/Sema/i-c-e.c | 5 | ||||
| -rw-r--r-- | clang/test/SemaTemplate/instantiate-expr-1.cpp | 3 | ||||
| -rw-r--r-- | clang/test/SemaTemplate/instantiate-static-var.cpp | 2 |
5 files changed, 20 insertions, 10 deletions
diff --git a/clang/test/Analysis/misc-ps.m b/clang/test/Analysis/misc-ps.m index f3ea13b1ea9..149be03ac26 100644 --- a/clang/test/Analysis/misc-ps.m +++ b/clang/test/Analysis/misc-ps.m @@ -91,16 +91,16 @@ void r6268365() { void divzeroassume(unsigned x, unsigned j) { x /= j; - if (j == 0) x /= 0; // no-warning - if (j == 0) x /= j; // no-warning - if (j == 0) x = x / 0; // no-warning + if (j == 0) x /= 0; // no static-analyzer warning expected-warning {{division by zero is undefined}} + if (j == 0) x /= j; // no static-analyzer warning + if (j == 0) x = x / 0; // no static-analyzer warning expected-warning {{division by zero is undefined}} } void divzeroassumeB(unsigned x, unsigned j) { x = x / j; - if (j == 0) x /= 0; // no-warning - if (j == 0) x /= j; // no-warning - if (j == 0) x = x / 0; // no-warning + if (j == 0) x /= 0; // no static-analyzer warning expected-warning {{division by zero is undefined}} + if (j == 0) x /= j; // no static-analyzer warning + if (j == 0) x = x / 0; // no static-analyzer warning expected-warning {{division by zero is undefined}} } // InitListExpr processing diff --git a/clang/test/Sema/exprs.c b/clang/test/Sema/exprs.c index e6cfa5fbe3e..b2f92e2c01f 100644 --- a/clang/test/Sema/exprs.c +++ b/clang/test/Sema/exprs.c @@ -114,3 +114,11 @@ test15_t test15(void) { // rdar://7446395 void test16(float x) { x == ((void*) 0); } // expected-error {{invalid operands to binary expression}} +// PR6004 +void test17(int x) { + x = x / 0; // expected-warning {{division by zero is undefined}} + x = x % 0; // expected-warning {{remainder by zero is undefined}} + x /= 0; // expected-warning {{division by zero is undefined}} + x %= 0; // expected-warning {{remainder by zero is undefined}} +} + diff --git a/clang/test/Sema/i-c-e.c b/clang/test/Sema/i-c-e.c index c561fe01c6e..97d9f43cfba 100644 --- a/clang/test/Sema/i-c-e.c +++ b/clang/test/Sema/i-c-e.c @@ -57,8 +57,9 @@ int comma3[(1,2)]; // expected-warning {{size of static array must be an integer // Pointer + __builtin_constant_p char pbcp[__builtin_constant_p(4) ? (intptr_t)&expr : 0]; // expected-error {{variable length array declaration not allowed at file scope}} -int illegaldiv1[1 || 1/0]; -int illegaldiv2[1/0]; // expected-error {{variable length array declaration not allowed at file scope}} +int illegaldiv1[1 || 1/0]; // expected-warning {{division by zero is undefined}} +int illegaldiv2[1/0]; // expected-error {{variable length array declaration not allowed at file scope}} \ + // expected-warning {{division by zero is undefined}} int illegaldiv3[INT_MIN / -1]; // expected-error {{variable length array declaration not allowed at file scope}} int chooseexpr[__builtin_choose_expr(1, 1, expr)]; diff --git a/clang/test/SemaTemplate/instantiate-expr-1.cpp b/clang/test/SemaTemplate/instantiate-expr-1.cpp index 663749ddce5..5752033fbd3 100644 --- a/clang/test/SemaTemplate/instantiate-expr-1.cpp +++ b/clang/test/SemaTemplate/instantiate-expr-1.cpp @@ -35,7 +35,8 @@ void test_BitfieldMinus() { template<int I, int J> struct BitfieldDivide { int bitfield : I / J; // expected-error{{expression is not an integer constant expression}} \ - // expected-note{{division by zero}} + // expected-note{{division by zero}} \ + // expected-warning {{division by zero is undefined}} }; void test_BitfieldDivide() { diff --git a/clang/test/SemaTemplate/instantiate-static-var.cpp b/clang/test/SemaTemplate/instantiate-static-var.cpp index 789fe3db872..1fcc36b43cc 100644 --- a/clang/test/SemaTemplate/instantiate-static-var.cpp +++ b/clang/test/SemaTemplate/instantiate-static-var.cpp @@ -2,7 +2,7 @@ template<typename T, T Divisor> class X { public: - static const T value = 10 / Divisor; // expected-error{{in-class initializer is not an integral constant expression}} + static const T value = 10 / Divisor; // expected-error{{in-class initializer is not an integral constant expression}} expected-warning {{division by zero is undefined}} }; int array1[X<int, 2>::value == 5? 1 : -1]; |

