[llvm-bugs] [Bug 49599] New: Signed integer overflow causes program to skip the epilogue and fall into another function
via llvm-bugs
llvm-bugs at lists.llvm.org
Mon Mar 15 17:41:22 PDT 2021
https://bugs.llvm.org/show_bug.cgi?id=49599
Bug ID: 49599
Summary: Signed integer overflow causes program to skip the
epilogue and fall into another function
Product: clang
Version: trunk
Hardware: PC
OS: All
Status: NEW
Severity: release blocker
Priority: P
Component: C++
Assignee: unassignedclangbugs at nondot.org
Reporter: m13253 at hotmail.com
CC: blitzrakete at gmail.com, dgregor at apple.com,
erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
richard-llvm at metafoo.co.uk
Comment:
Clang 13 simply does not generate any code for f1 after the undefined behavior
point. So any call onto f1 will eventually ends up fell into f2.
Although the compiler can do anything with an undefined behavior, including
simply crashing, infinite loop, playing some music, or nuke the earth without
violating the C++ specification. I still hope this undefined behavior won't be
that surprising.
This issue is not observed in C frontend, or Clang 12.
Godbolt link for your convenience: https://godbolt.org/z/r3nWrE
Source code:
#include <stdio.h>
void f1(void) {
for(int i = 0; i >= 0; i++) {
// Undefined behavior
}
}
void f2(void) {
puts("Formatting /dev/sda1...");
// system("mkfs -t btrfs -f /dev/sda1");
}
// Prevents inlining
void (*volatile p1)(void) = f1;
void (*volatile p2)(void) = f2;
int main(void) {
puts(__VERSION__);
p1();
return 0;
}
Output:
Clang 13.0.0 (https://github.com/llvm/llvm-project.git
fcdf7f6224610a51dc2ff47f2f1e3377329b64a7)
Formatting /dev/sda1...
--
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/20210316/563af764/attachment.html>
More information about the llvm-bugs
mailing list