[llvm-bugs] [Bug 37329] New: Missing optimization: *this in constructors should not alias with reference input parameters of the same type
via llvm-bugs
llvm-bugs at lists.llvm.org
Thu May 3 10:56:32 PDT 2018
https://bugs.llvm.org/show_bug.cgi?id=37329
Bug ID: 37329
Summary: Missing optimization: *this in constructors should not
alias with reference input parameters of the same type
Product: clang
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: C++
Assignee: unassignedclangbugs at nondot.org
Reporter: antoshkka at gmail.com
CC: dgregor at apple.com, llvm-bugs at lists.llvm.org
Following code
struct test {
char data[2] = {1, 2};
test(const test& v);
};
test::test(const test& v)
: data{ v.data[0], v.data[0] }
{}
Produces the following assembly:
test::test(test const&): # @test::test(test const&)
mov al, byte ptr [rsi]
mov byte ptr [rdi], al
mov al, byte ptr [rsi] <=== This line is not required
mov byte ptr [rdi + 1], al
ret
Line 'mov al, byte ptr [rsi]' is for cases when input argument `v` aliases
`this`. Clang already warns on code like `Y v(v)`.
warning: variable 'v' is uninitialized when used within its own initialization
[-Wuninitialized]
Y v(v);
~ ^
C++ Standard covers the above case and allows to assume that argument do not
alias with this.
[class.ctor] paragraph 14:
"During the construction of an object, if the value of the object or any of its
subobjects is accessed through a glvalue that is not obtained, directly or
indirectly, from the constructor’s this pointer, the value of the object or
subobject thus obtained is unspecified."
--
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/20180503/31f5030a/attachment-0001.html>
More information about the llvm-bugs
mailing list