<html>
<head>
<base href="https://bugs.llvm.org/">
</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 - Clang stop detecting UBs after a divide by zero"
href="https://bugs.llvm.org/show_bug.cgi?id=46124">46124</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Clang stop detecting UBs after a divide by zero
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>C++
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>haoxintu@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>This code test1.cc
#include<iostream>
int main () {
int a = 1;
for (int i = 0; i < 10; ++i) {
a /= i; // Error: division by zero on the first iteration
}
int b = 0;
int bb = 0 / b;
0 / 0;
std::cout << "ok" << std::endl;
return 0;
}
$clang++-trunk -w -fsanitize=integer-divide-by-zero test1.cc ; ./a.out
test1.cc:5:11: runtime error: division by zero
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior example.cpp:5:11 in
UndefinedBehaviorSanitizer:DEADLYSIGNAL
==1==ERROR: UndefinedBehaviorSanitizer: FPE on unknown address 0x000000431817
(pc 0x000000431817 bp 0x7fff88ddde50 sp 0x7fff88ddde20 T1)
#0 0x431817 (/app/output.s+0x431817)
#1 0x7f56e7e59b96 (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
#2 0x4031e9 (/app/output.s+0x4031e9)
UndefinedBehaviorSanitizer can not provide additional info.
SUMMARY: UndefinedBehaviorSanitizer: FPE (/app/output.s+0x431817)
==1==ABORTING
Clang only detects one runtime error in for statement but leaves out detecting
the statements following ones.
In test2.cc
#include<iostream>
int main () {
/*
int a = 1;
for (int i = 0; i < 10; ++i) {
a /= i; // Error: division by zero on the first iteration
}
*/
int b = 0;
int bb = 0 / b;
0 / 0;
std::cout << "ok" << std::endl;
return 0;
}
$clang++-trunk -fsanitize=integer-divide-by-zero test2.cc ; ./a.out
test2.cc:11:16: runtime error: division by zero
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior example.cpp:11:16 in
UndefinedBehaviorSanitizer:DEADLYSIGNAL
==1==ERROR: UndefinedBehaviorSanitizer: FPE on unknown address 0x0000004317fd
(pc 0x0000004317fd bp 0x7ffd6c2922f0 sp 0x7ffd6c2922d0 T1)
#0 0x4317fd (/app/output.s+0x4317fd)
#1 0x7fe566be1b96 (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
#2 0x4031e9 (/app/output.s+0x4031e9)
UndefinedBehaviorSanitizer can not provide additional info.
SUMMARY: UndefinedBehaviorSanitizer: FPE (/app/output.s+0x4317fd)
==1==ABORTING
In gcc-trunk
$./g++ -w -fsanitize=integer-divide-by-zero test2.cc ; ./a.out
test.cc:11:16: runtime error: division by zero
test.cc:12:7: runtime error: division by zero
ok
Should the main function return from "return 0" rather than exit directly from
the for statement?
I also file a bug report in GCC, they confirmed this limitation immediately.
<a href="https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95385">https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95385</a></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>