-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
internal pointers in C++ classes cause bugs with D struct move semantics on calls by value #70
Comments
… arguments. Destructors were being called twice for C++ struct or class value arguments of D functions. In D dtors get called by the callee, whereas in C++ that responsibility rests upon the caller. But in order to simplify the DMD code and open the possibility of calling D functions taking C++ struct/class arguments from C++ code possible, making an exception for C++ struct/class arguments seems like the preferable choice.
… arguments. Destructors were being called twice for C++ struct or class value arguments of D functions. In D dtors get called by the callee, whereas in C++ that responsibility rests upon the caller. But in order to simplify the DMD code and open the possibility of calling D functions taking C++ struct/class arguments from C++ code possible, making an exception for C++ struct/class arguments seems like the preferable choice.
|
6eec174 should help with |
|
This is simply due to a load actually: postinvoke10: ; preds = %postinvoke6
%.loadFromMemory_bitCastAddress = bitcast %struct.B* %__slB57 to { i64, i8* }* ; [#uses = 1]
%.X86_64_C_struct_rewrite_putResult = load { i64, i8* }, { i64, i8* }* %.loadFromMemory_bitCastAddress ; [#uses = 1]
invoke void @"_D17copy_ctor_issue704fun1FS6\E2\84\82cpp1B1BZv"({ i64, i8* } %.X86_64_C_struct_rewrite_putResult) #0
to label %postinvoke12 unwind label %landingPad11
ABIArgInfo DefaultABIInfo::classifyArgumentType(QualType Ty) const {
Ty = useFirstFieldIfTransparentUnion(Ty);
if (isAggregateTypeForABI(Ty)) {
// Records with non-trivial destructors/copy-constructors should not be
// passed by value.
if (CGCXXABI::RecordArgABI RAA = getRecordArgABI(Ty, getCXXABI()))
return getNaturalAlignIndirect(Ty, RAA == CGCXXABI::RAA_DirectInMemory);
return getNaturalAlignIndirect(Ty);
} |
…tor by ref. Passing by LLVM value makes a copy of the argument after the copy ctor call and may break internal pointers, see test case by @timotheecour. This mimicks what Clang does.
|
This should be fixed by affee89! |
likewise with these cases: |
…never selects an overload taking rvalue ref parameters unless the argument is a rvalue ref return value from a C++ function. There are several options to properly support C++ rvalue references, but although this may be slightly too intrusive (new storage class) this also is the simplest. A test case making use of std::move was added.
|
Although the test case worked, the wrong ctor was called (move instead of copy), so Hopefully this is now definitely fixed by 273e521. |
|
reopening: return by value is broken (causing crashes for the simplest opencv program): prints: |
|
should be fixed once https://github.com/Syniurge/Calypso/tree/avoid-memcpy-cpp-record-returnvalue is merged |
…tor by ref. Passing by LLVM value makes a copy of the argument after the copy ctor call and may break internal pointers, see test case by @timotheecour. This mimicks what Clang does.
…never selects an overload taking rvalue ref parameters unless the argument is a rvalue ref return value from a C++ function. There are several options to properly support C++ rvalue references, but although this may be slightly too intrusive (new storage class) this also is the simplest. A test case making use of std::move was added.
…never selects an overload taking rvalue ref parameters unless the argument is a rvalue ref return value from a C++ function. There are several options to properly support C++ rvalue references, but although this may be slightly too intrusive (new storage class) this also is the simplest. A test case making use of std::move was added.
eg: return by value cv::Mat causes crash on ~Mat
BUG:D20180110T195539
This seems to cause serious bugs when using real-world libraries, eg opencv's cv::Mat which has a field step of type MatStep with:
I suspect internal pointers causes any code that returns by value an opencv cv::Mat to crash when the ~Mat is called (inside
fastFreefunction which callsfree):Indeed, with debugging, inside the
~Mat,step.p == step.bufbecomes false even though it should be true (and was true while inside C++ test_mat)simplified case (may or may not be a reduction of above case)
related issues (not necessarily involving internal pointers but involving move semantics instead of calling copy ctor
another
bug: an empty C++ ctor is needed for calypso when no move/copy ctor is provided ; even though not needed in C++, giving this error:Error: constructor ℂcpp.tims.B.B.this (int x) is not callable using argument types ()BUG:D20180111T124115
if C++ provides a move ctor, and if that move ctor releases resources (cf function
resourceabove), the following code would cause a bug:BUG:D20180111T170655
discussion of potential fix
how about calling copy ctor instead of move ctor (as would be the case in C++) in these cases:
this behavior (special handling of move semantics) would hold for regular D structs that embed a D/C++ struct by value , eg:
The text was updated successfully, but these errors were encountered: