<html>
<head>
<base href="http://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - Divide by zero check confused by loop"
href="http://llvm.org/bugs/show_bug.cgi?id=15585">15585</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Divide by zero check confused by loop
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>3.2
</td>
</tr>
<tr>
<th>Hardware</th>
<td>Macintosh
</td>
</tr>
<tr>
<th>OS</th>
<td>MacOS X
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>Static Analyzer
</td>
</tr>
<tr>
<th>Assignee</th>
<td>kremenek@apple.com
</td>
</tr>
<tr>
<th>Reporter</th>
<td>aneumann@mpi-inf.mpg.de
</td>
</tr>
<tr>
<th>CC</th>
<td>llvmbugs@cs.uiuc.edu
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>Hello,
I've been trying out the static analyzer. Apparently the divide by zero check
is easily confused. Consider the following piece of code:
#include <iostream>
using namespace std;
void f1() {
for(int x=10; x>0; x--);
int j = 0;
int i = 5/j;
cout << i << endl;
}
void f2() {
int j = 0;
int i = 5/j;
cout << i << endl;
}
int main() {
f1();
f2();
return 0;
}
The analyzer does not see the divide by zero in f1(), only in f2(). Since I see
no reason why a loop in the function should prevent the detection of this
divide by zero, I submit this bug report.
I also copypaste the verbose output
infmb1800:skip list aneumann$ scan-build-mp-3.2 -v -v -v clang++-mp-3.2
sa_test.cpp
scan-build: Using '/opt/local/libexec/llvm-3.2/bin/clang' for static analysis
scan-build: Emitting reports for this run to
'/var/folders/f3/s_kr99qx01g03x4f4q73clvr0000gp/T/scan-build-2013-03-25-10'.
clang++-mp-3.2 sa_test.cpp
[LOCATION]: /Volumes/NO NAME/code/skip list
#SHELL (cd '/Volumes/NO NAME/code/skip list' &&
'/opt/local/libexec/llvm-3.2/bin/clang++' '-cc1' '-triple'
'x86_64-apple-macosx10.7.0' '-analyze' '-disable-free' '-main-file-name'
'sa_test.cpp' '-analyzer-store=region' '-analyzer-opt-analyze-nested-blocks'
'-analyzer-eagerly-assume' '-analyzer-checker=core' '-analyzer-checker=unix'
'-analyzer-checker=osx' '-analyzer-checker=deadcode'
'-analyzer-checker=security.insecureAPI.UncheckedReturn'
'-analyzer-checker=security.insecureAPI.getpw'
'-analyzer-checker=security.insecureAPI.gets'
'-analyzer-checker=security.insecureAPI.mktemp'
'-analyzer-checker=security.insecureAPI.mkstemp'
'-analyzer-checker=security.insecureAPI.vfork' '-analyzer-output' 'plist' '-w'
'-mrelocation-model' 'pic' '-pic-level' '2' '-mdisable-fp-elim' '-masm-verbose'
'-munwind-tables' '-target-cpu' 'core2' '-target-linker-version' '134.9'
'-resource-dir' '/opt/local/libexec/llvm-3.2/bin/../lib/clang/3.2'
'-fmodule-cache-path'
'/var/folders/f3/s_kr99qx01g03x4f4q73clvr0000gp/T/clang-module-cache'
'-fdeprecated-macro' '-fdebug-compilation-dir' '/Volumes/NO NAME/code/skip
list' '-ferror-limit' '19' '-fmessage-length' '0' '-stack-protector' '1'
'-mstackrealign' '-fblocks' '-fobjc-runtime=macosx-10.7.0'
'-fobjc-dispatch-method=mixed' '-fobjc-default-synthesize-properties'
'-fencode-extended-block-signature' '-fcxx-exceptions' '-fexceptions'
'-fdiagnostics-show-option' '-analyzer-display-progress'
'-analyzer-output=html' '-o'
'/var/folders/f3/s_kr99qx01g03x4f4q73clvr0000gp/T/scan-build-2013-03-25-10'
'-x' 'c++' 'sa_test.cpp')
ANALYZE (Syntax): sa_test.cpp f1
ANALYZE (Syntax): sa_test.cpp f2
ANALYZE (Syntax): sa_test.cpp main
ANALYZE (Path): sa_test.cpp main
sa_test.cpp:13:11: warning: Division by zero
int i = 5/j;
~^~
1 warning generated.
scan-build: 1 bugs found.
scan-build: Run 'scan-view
/var/folders/f3/s_kr99qx01g03x4f4q73clvr0000gp/T/scan-build-2013-03-25-10' to
examine bug reports.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>