<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 - After 350404, clang drops volatile load"
href="https://bugs.llvm.org/show_bug.cgi?id=40642">40642</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>After 350404, clang drops volatile load
</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>hans@chromium.org
</td>
</tr>
<tr>
<th>CC</th>
<td>aaron@aaronballman.com, htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>Reproducer:
$ cat /tmp/c.cc
template <class T> struct S {
void foo() {
if (true)
reinterpret_cast<const volatile unsigned char*>(m_ptr)[0];
}
int* m_ptr;
};
void f(S<int> *x) {
x->foo();
}
With r350403:
$ /work/llvm.monorepo/build.release/bin/clang.good -cc1 -triple
x86_64-unknown-linux-gnu -S -emit-llvm /tmp/c.cc -o - | grep -A999 'define
linkonce_odr void @_ZN1SIiE3fooEv'
define linkonce_odr void @_ZN1SIiE3fooEv(%struct.S* %this) #0 comdat align 2 {
entry:
%this.addr = alloca %struct.S*, align 8
store %struct.S* %this, %struct.S** %this.addr, align 8
%this1 = load %struct.S*, %struct.S** %this.addr, align 8
%m_ptr = getelementptr inbounds %struct.S, %struct.S* %this1, i32 0, i32 0
%0 = load i32*, i32** %m_ptr, align 8
%1 = bitcast i32* %0 to i8*
%arrayidx = getelementptr inbounds i8, i8* %1, i64 0
%2 = load volatile i8, i8* %arrayidx, align 1
ret void
}
With r350404:
$ /work/llvm.monorepo/build.release/bin/clang.bad -cc1 -triple
x86_64-unknown-linux-gnu -S -emit-llvm /tmp/c.cc -o - | grep -A999 'define
linkonce_odr void @_ZN1SIiE3fooEv'
define linkonce_odr void @_ZN1SIiE3fooEv(%struct.S* %this) #0 comdat align 2 {
entry:
%this.addr = alloca %struct.S*, align 8
store %struct.S* %this, %struct.S** %this.addr, align 8
%this1 = load %struct.S*, %struct.S** %this.addr, align 8
%m_ptr = getelementptr inbounds %struct.S, %struct.S* %this1, i32 0, i32 0
%0 = load i32*, i32** %m_ptr, align 8
%1 = bitcast i32* %0 to i8*
%arrayidx = getelementptr inbounds i8, i8* %1, i64 0
ret void
}
Note that "%2 = load volatile i8, i8* %arrayidx, align 1" is missing.
Adding a void cast, i.e. "(void)reinterpret_cast<const volatile unsigned
char*>(m_ptr)[0];" makes the load appear also with r350404.
The regression was caught by test failures in pdfium
(<a href="https://bugs.chromium.org/p/chromium/issues/detail?id=929475">https://bugs.chromium.org/p/chromium/issues/detail?id=929475</a>)</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>