<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 - Incorrectly lift a modulo computation outside an if statement"
href="https://bugs.llvm.org/show_bug.cgi?id=47578">47578</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Incorrectly lift a modulo computation outside an if statement
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>10.0
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</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>-New Bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>k.even-mendoza@imperial.ac.uk
</td>
</tr>
<tr>
<th>CC</th>
<td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>#include <stdio.h>
static long r = 0;
static long *m[1] = {&r};
static int i = 1;
static int *pi = &i;
int main() {
unsigned x = 0;
if (i) { // Evaluates to true
++x; // Guaranteed to be reached, and afterwards x == 1
int test = pi == (int*) 1;
}
printf("x = %d\n", x);
// At this point, x == 1
if (!x) { // Evaluates to false
i = 7UL % (m[0] == (long*) 1); // Unreachable. (It would have UB if it
*were* reachable, becuase of a mod by zero.)
}
}
Get "floating point exception" with -02, Ubuntun, and clang-6/Clang-10.
The bug is no appearing with -O0 flag.
Restor the bug:
clang-10 -O2 -w test1.c
./a.out
Floating point exception (core dumped)
======
clang-10 -O0 -w test1.c
./a.out
x = 1
I tried with two versions, both got the bugs:
1) from llvm trunk: clang version 10.0.0 (trunk), Target:
x86_64-unknown-linux-gnu, Thread model: posix, InstalledDir:
/home/user42/llvm-csmith-0/llvm-install/bin (from 03/09/2020)
2) Ubuntu's: clang version 10.0.0-4ubuntu1~18.04.2, Target:
x86_64-pc-linux-gnu, Thread model: posix, InstalledDir: /usr/bin</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>