[llvm-bugs] [Bug 47578] New: Incorrectly lift a modulo computation outside an if statement
via llvm-bugs
llvm-bugs at lists.llvm.org
Fri Sep 18 08:34:01 PDT 2020
https://bugs.llvm.org/show_bug.cgi?id=47578
Bug ID: 47578
Summary: Incorrectly lift a modulo computation outside an if
statement
Product: clang
Version: 10.0
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: -New Bugs
Assignee: unassignedclangbugs at nondot.org
Reporter: k.even-mendoza at imperial.ac.uk
CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org,
neeilans at live.com, richard-llvm at metafoo.co.uk
#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
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200918/239b86c7/attachment.html>
More information about the llvm-bugs
mailing list