From 0a9ea7c70de2db1e8de3f75fbac61d302ef52375 Mon Sep 17 00:00:00 2001 From: Jordan Rose Date: Mon, 20 Aug 2012 17:04:45 +0000 Subject: [analyzer] The result of && or || is always a 1 or 0. Forgetting to at least cast the result was giving us Loc/NonLoc problems in SValBuilder (hitting an assertion). But the standard (both C and C++) does actually guarantee that && and || will result in the actual values 1 and 0, typed as 'int' in C and 'bool' in C++, and we can easily model that. PR13461 llvm-svn: 162209 --- clang/test/Analysis/logical-ops.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 clang/test/Analysis/logical-ops.c (limited to 'clang/test/Analysis/logical-ops.c') diff --git a/clang/test/Analysis/logical-ops.c b/clang/test/Analysis/logical-ops.c new file mode 100644 index 00000000000..a1223b39fa8 --- /dev/null +++ b/clang/test/Analysis/logical-ops.c @@ -0,0 +1,27 @@ +// RUN: %clang_cc1 -analyze -analyzer-checker=core,debug.ExprInspection -verify %s + +void clang_analyzer_eval(int); + +void testAnd(int i, int *p) { + int *nullP = 0; + int *knownP = &i; + clang_analyzer_eval((knownP && knownP) == 1); // expected-warning{{TRUE}} + clang_analyzer_eval((knownP && nullP) == 0); // expected-warning{{TRUE}} + clang_analyzer_eval((knownP && p) == 1); // expected-warning{{UNKNOWN}} +} + +void testOr(int i, int *p) { + int *nullP = 0; + int *knownP = &i; + clang_analyzer_eval((nullP || knownP) == 1); // expected-warning{{TRUE}} + clang_analyzer_eval((nullP || nullP) == 0); // expected-warning{{TRUE}} + clang_analyzer_eval((nullP || p) == 1); // expected-warning{{UNKNOWN}} +} + + +// PR13461 +int testTypeIsInt(int i, void *p) { + if (i | (p && p)) + return 1; + return 0; +} -- cgit v1.2.3