forked from ldc-developers/ldc
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make C++ structs go through LDC's toArgTypes() which follows the same…
… ABIs that Clang follows, remove LangPlugin::passAggregateArgumentByRef(). toArgTypes should be able to handle C++ non-dynamic records, while C++ dynamic classes are never passed through registers during function calls. Fixes issue #121. The decision to pass a record in registers remains fragile regarding the expectations of C++ compilers. This is only an issue for extern(C++) functions defined in D that need to be passed to C++ code however. Also backport the two changes by 18a4606 to prevent byval argument copies without copy ctor calls.
- Loading branch information
Showing
11 changed files
with
206 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
// RUN: %ldc -cpp-cachedir=%t.cache -of %t %s | ||
// RUN: %t > %t.out | ||
// RUN: FileCheck %s < %t.out | ||
|
||
pragma(cppmap, "record_func_params.h"); | ||
|
||
import (C++) *; | ||
import std.stdio : writeln; | ||
|
||
// TODO: check that extern(C++) functions match the expected C++ ABI? | ||
|
||
void testStructS(TestStructS s) | ||
{ | ||
writeln("StructS"); | ||
writeln("a = ", s.a); | ||
writeln(""); | ||
} | ||
|
||
void testStructM(TestStructM s) | ||
{ | ||
writeln("StructM"); | ||
writeln("a = ", s.a, | ||
", b = ", s.b, | ||
", c = ", s.c); | ||
writeln(""); | ||
} | ||
|
||
void testStructL(TestStructL s) | ||
{ | ||
writeln("StructL"); | ||
writeln("a = ", s.a, | ||
", b = ", s.b, | ||
", c = ", s.c, | ||
", d = ", s.d); | ||
writeln(""); | ||
} | ||
|
||
void testStructXL(TestStructXL s) | ||
{ | ||
writeln("StructXL"); | ||
writeln("a = ", s.a, | ||
", b = ", s.b, | ||
", c = ", s.c, | ||
", d = ", s.d, | ||
", e = ", s.e); | ||
writeln(""); | ||
} | ||
|
||
void testStructFloatS(TestStructFloatS s) | ||
{ | ||
writeln("StructFloatS"); | ||
writeln("a = ", s.a); | ||
writeln(""); | ||
} | ||
|
||
void testStructFloatM(TestStructFloatM s) | ||
{ | ||
writeln("StructFloatM"); | ||
writeln("a = ", s.a, | ||
", b = ", s.b, | ||
", c = ", s.c); | ||
writeln(""); | ||
} | ||
|
||
void testStructMixed(TestStructMixed s) | ||
{ | ||
writeln("StructMixed"); | ||
writeln("a = ", s.a, | ||
", b = ", s.b, | ||
", c = ", s.c, | ||
", d = ", s.d); | ||
writeln(""); | ||
} | ||
|
||
void testDC(DynamicClass c) | ||
{ | ||
c.makeMeDynamic(); | ||
} | ||
|
||
void main() | ||
{ | ||
TestStructS s1 = { 38 }; | ||
testStructS(s1); | ||
// CHECK: StructS | ||
// CHECK: a = 38 | ||
|
||
TestStructM s2 = { 21, 735, 50000 }; | ||
testStructM(s2); | ||
// CHECK: StructM | ||
// CHECK: a = 21, b = 735, c = 50000 | ||
|
||
TestStructL s3 = { 85, 434, 90000, 222222 }; | ||
testStructL(s3); | ||
// CHECK: StructL | ||
// CHECK: a = 85, b = 434, c = 90000, d = 222222 | ||
|
||
TestStructXL s4 = { 13, 838, 10001, 747474, 8513214 }; | ||
testStructXL(s4); | ||
// CHECK: StructXL | ||
// CHECK: a = 13, b = 838, c = 10001, d = 747474, e = 8513214 | ||
|
||
TestStructFloatS s5 = { 40.0 }; | ||
testStructFloatS(s5); | ||
// CHECK: StructFloatS | ||
// CHECK: a = 40 | ||
|
||
TestStructFloatM s6 = { 78.0, 548.24, 963.14 }; | ||
testStructFloatM(s6); | ||
// CHECK: StructFloatM | ||
// CHECK: a = 78, b = 548.24, c = 963.14 | ||
|
||
TestStructMixed s7 = { 42.5555, 200000000000, 521.9, 500 }; | ||
testStructMixed(s7); | ||
// CHECK: StructMixed | ||
// CHECK: a = 42.5555, b = 200000000000, c = 521.9, d = 500 | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
struct TestStructS | ||
{ | ||
short a; | ||
}; | ||
|
||
struct TestStructM | ||
{ | ||
int a; | ||
int b; | ||
int c; | ||
}; | ||
|
||
struct TestStructL | ||
{ | ||
int a; | ||
int b; | ||
int c; | ||
int d; | ||
}; | ||
|
||
struct TestStructXL | ||
{ | ||
int a; | ||
int b; | ||
int c; | ||
int d; | ||
int e; | ||
}; | ||
|
||
struct TestStructFloatS | ||
{ | ||
float a; | ||
}; | ||
|
||
struct TestStructFloatM | ||
{ | ||
float a; | ||
float b; | ||
float c; | ||
}; | ||
|
||
struct TestStructMixed | ||
{ | ||
double a; | ||
long b; | ||
float c; | ||
int d; | ||
}; | ||
|
||
class DynamicClass | ||
{ | ||
virtual void makeMeDynamic() {} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters