<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 - program with #pragma pack(1) and __int128 behaves differents under O1 and higher optimization"
href="https://bugs.llvm.org/show_bug.cgi?id=49316">49316</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>program with #pragma pack(1) and __int128 behaves differents under O1 and higher optimization
</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>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</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>zhan3299@purdue.edu
</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>Following code has different behaviors under different optimization level. I am
not sure whether it is caused by asan or optimization, tbh.
$ cat test.c
#pragma pack(1)
struct {
char a;
__int128 b;
} c;
__int128 *d = &c.b;
int main() { *d = 0; }
In short, when compiling with '-O0', the exit code is 0. But when compiling
with '-O1', the exit code is 139 (segment fault).
O0 (program returns 0): <a href="https://godbolt.org/z/x3d68s">https://godbolt.org/z/x3d68s</a>
O1 (program returns 139): <a href="https://godbolt.org/z/bef6T9">https://godbolt.org/z/bef6T9</a>
O2 (program returns 139): <a href="https://godbolt.org/z/brvz77">https://godbolt.org/z/brvz77</a>
O3 (program returns 139): <a href="https://godbolt.org/z/K8sEaa">https://godbolt.org/z/K8sEaa</a>
Os (program returns 129): <a href="https://godbolt.org/z/PxToY5">https://godbolt.org/z/PxToY5</a>
I further use asan to report more details:
O0 (normal): <a href="https://godbolt.org/z/5G9bbv">https://godbolt.org/z/5G9bbv</a>
O1 (segfault): <a href="https://godbolt.org/z/3ob34b">https://godbolt.org/z/3ob34b</a>
AddressSanitizer:DEADLYSIGNAL
=================================================================
==1==ERROR: AddressSanitizer: SEGV on unknown address (pc 0x0000004f3ddc bp
0x000000000000 sp 0x7ffead06c7b0 T0)
==1==The signal is caused by a READ memory access.
==1==Hint: this fault was caused by a dereference of a high value address (see
register values below). Disassemble the provided pc to learn which register
was used.
#0 0x4f3ddc (/app/output.s+0x4f3ddc)
#1 0x7f4b493950b2 (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
#2 0x41adad (/app/output.s+0x41adad)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV (/app/output.s+0x4f3ddc)
==1==ABORTING</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>