[LLVMbugs] [Bug 20644] New: Too strong optimization with -O2 generates invalid code
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Wed Aug 13 02:52:01 PDT 2014
http://llvm.org/bugs/show_bug.cgi?id=20644
Bug ID: 20644
Summary: Too strong optimization with -O2 generates invalid
code
Product: clang
Version: unspecified
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: C++
Assignee: unassignedclangbugs at nondot.org
Reporter: sylvestre at debian.org
CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
Classification: Unclassified
The following code compiled with -O2:
clang++ -O2 -Wall -g -o segfault segfault.cpp && ./segfault
is segfaulting with 3.4, 3.5 and trunk. gcc is fine.
Commenting some items in the switch/case or commenting the cout removes the
segfault.
LLDB is confused too. It seems that fractional is wrongly optimized:
Process 10217 launched: '/tmp/segfault' (x86_64)
0x2
00
Process 10217 stopped
* thread #1: tid = 10217, 0x0000000000400afb
segfault`InterPrediction::test(SampleYVector const&) [inlined]
getMargins(fractional=<unavailable>) + 6 at segault.cpp:47, name = 'segfault',
stop reason = invalid address (fault address: 0x1000400c08)
frame #0: 0x0000000000400afb segfault`InterPrediction::test(SampleYVector
const&) [inlined] getMargins(fractional=<unavailable>) + 6 at segault.cpp:47
44 void getMargins(const int fractional, int &topLeftMargin)
45 {
46 switch (fractional)
-> 47 {
48 case 0:
49 topLeftMargin = 0;
50 break;
(lldb) p fractional
error: Couldn't materialize struct: size of variable fractional (4) disagrees
with the ValueObject's size (0)
Errored out in Execute, couldn't PrepareToExecuteJITExpression
------------------------
#include <iostream>
class SampleYVector
{
public:
SampleYVector()
:x(0)
,y(0)
{}
SampleYVector(int x_, int y_)
:x(x_)
,y(y_)
{}
SampleYVector& operator&= (const int mask)
{
x &= mask;
y &= mask;
return *this;
}
int x;
int y;
};
SampleYVector operator& (const SampleYVector &lhs, const int mask)
{
SampleYVector temp(lhs);
temp &= mask;
return temp;
}
struct InterPrediction
{
public:
int leftDataMargin;
void test(const SampleYVector &mv);
};
void getMargins(const int fractional, int &topLeftMargin)
{
switch (fractional)
{
case 0:
topLeftMargin = 0;
break;
case 1:
topLeftMargin = 3;
break;
case 2:
topLeftMargin = 3;
break;
case 3:
topLeftMargin = 2;
break;
}
}
void InterPrediction::test(const SampleYVector &mv)
{
const SampleYVector mvFrac = mv & 3;
std::cout << mvFrac.x << "x" << mvFrac.y << '\n';
const int fractionalX = 0;
std::cout << fractionalX << mvFrac.x << std::endl;
getMargins(mvFrac.x, leftDataMargin);
}
int main()
{
SampleYVector mv(0, 2);
InterPrediction interPrediction;
interPrediction.test(mv);
return 0;
}
------------------------
Initially reported:
http://bugs.debian.org/758007
--
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/20140813/7d26d3af/attachment.html>
More information about the llvm-bugs
mailing list