Rework our handling of copy construction of temporaries, which was a
poor (and wrong) approximation of the actual rules governing when to
build a copy and when it can be elided.
The correct implementation is actually simpler than the
approximation. When we only enumerate constructors as part of
initialization (e.g., for direct initialization or when we're copying
from a class type or one of its derived classes), we don't create a
copy. When we enumerate all conversion functions, we do create a
copy. Before, we created some extra copies and missed some
others. The new test copy-initialization.cpp shows a case where we
missed creating a (required, non-elidable) copy as part of a
user-defined conversion, which resulted in a miscompile. This commit
also fixes PR6757, where the missing copy made us reject well-formed
code in the ternary operator.
This commit also cleans up our handling of copy elision in the case
where we create an extra copy of a temporary object, which became
necessary now that we produce the right copies. The code that seeks to
find the temporary object being copied has moved into
Expr::getTemporaryObject(); it used to have two different
not-quite-the-same implementations, one in Sema and one in CodeGen.
Note that we still do not attempt to perform the named return value
optimization, so we miss copy elisions for return values and throw
expressions.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@100196 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-02 22:24:57 +04:00
|
|
|
// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -o - %s | FileCheck %s
|
|
|
|
|
|
|
|
struct Foo {
|
|
|
|
Foo();
|
|
|
|
Foo(const Foo&);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Bar {
|
|
|
|
Bar();
|
|
|
|
operator const Foo&() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
void f(Foo);
|
|
|
|
|
2011-07-09 21:41:47 +04:00
|
|
|
// CHECK: define void @_Z1g3Foo(%struct.Foo* %foo)
|
Rework our handling of copy construction of temporaries, which was a
poor (and wrong) approximation of the actual rules governing when to
build a copy and when it can be elided.
The correct implementation is actually simpler than the
approximation. When we only enumerate constructors as part of
initialization (e.g., for direct initialization or when we're copying
from a class type or one of its derived classes), we don't create a
copy. When we enumerate all conversion functions, we do create a
copy. Before, we created some extra copies and missed some
others. The new test copy-initialization.cpp shows a case where we
missed creating a (required, non-elidable) copy as part of a
user-defined conversion, which resulted in a miscompile. This commit
also fixes PR6757, where the missing copy made us reject well-formed
code in the ternary operator.
This commit also cleans up our handling of copy elision in the case
where we create an extra copy of a temporary object, which became
necessary now that we produce the right copies. The code that seeks to
find the temporary object being copied has moved into
Expr::getTemporaryObject(); it used to have two different
not-quite-the-same implementations, one in Sema and one in CodeGen.
Note that we still do not attempt to perform the named return value
optimization, so we miss copy elisions for return values and throw
expressions.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@100196 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-02 22:24:57 +04:00
|
|
|
void g(Foo foo) {
|
|
|
|
// CHECK: call void @_ZN3BarC1Ev
|
|
|
|
// CHECK: @_ZNK3BarcvRK3FooEv
|
|
|
|
// CHECK: call void @_Z1f3Foo
|
|
|
|
f(Bar());
|
|
|
|
// CHECK: call void @_ZN3FooC1Ev
|
|
|
|
// CHECK: call void @_Z1f3Foo
|
|
|
|
f(Foo());
|
|
|
|
// CHECK: call void @_ZN3FooC1ERKS_
|
|
|
|
// CHECK: call void @_Z1f3Foo
|
|
|
|
f(foo);
|
|
|
|
// CHECK: ret
|
|
|
|
}
|
|
|
|
|