Skip to content

Commit 1d775af

Browse files
authored
Merge pull request #2650 from kinke/osx64_mangling
[2.079] WIP: 64-bit macOS (u)long mangling
2 parents db7aa1c + 5ac6c85 commit 1d775af

File tree

14 files changed

+45
-22
lines changed

14 files changed

+45
-22
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,7 @@ append("-DOPAQUE_VTBLS" LDC_CXXFLAGS)
417417
append("\"-DLDC_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}\"" LDC_CXXFLAGS)
418418
append("-DLDC_LLVM_VER=${LDC_LLVM_VER}" LDC_CXXFLAGS)
419419
append("\"-DLDC_LIBDIR_SUFFIX=\\\"${LIB_SUFFIX}\\\"\"" LDC_CXXFLAGS)
420+
append("-DLDC_HOST_FE_VER=${D_COMPILER_FE_VERSION}" LDC_CXXFLAGS)
420421

421422
if(GENERATE_OFFTI)
422423
append("-DGENERATE_OFFTI" LDC_CXXFLAGS)

cmake/Modules/FindDCompiler.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
# D_COMPILER_FLAGS - D compiler flags (could be passed in the DMD environment variable)
99
# D_COMPILER_ID = {"DigitalMars", "LDMD", "LDC", "GDC"}
1010
# D_COMPILER_VERSION_STRING - String containing the compiler version, e.g. "DMD64 D Compiler v2.070.2"
11+
# D_COMPILER_FE_VERSION - compiler front-end version, e.g. "2070"
1112
# D_COMPILER_DMD_COMPAT - true if the D compiler cmdline interface is compatible with DMD
1213

1314

@@ -64,13 +65,16 @@ if (D_COMPILER)
6465
OUTPUT_VARIABLE D_COMPILER_VERSION_STRING
6566
ERROR_VARIABLE D_COMPILER_VERSION_STRING
6667
ERROR_QUIET)
68+
string(REGEX MATCH " (D Compiler|based on DMD) v([0-9]+)\\.([0-9]+)" D_COMPILER_FE_VERSION "${D_COMPILER_VERSION_STRING}")
69+
math(EXPR D_COMPILER_FE_VERSION ${CMAKE_MATCH_2}*1000+${CMAKE_MATCH_3}) # e.g., 2079
6770
string(REGEX MATCH "^[^\r\n:]*" D_COMPILER_VERSION_STRING "${D_COMPILER_VERSION_STRING}")
6871
endif()
6972

7073

7174
if (D_COMPILER_FOUND)
7275
message(STATUS "Found host D compiler ${D_COMPILER}, with default flags '${D_COMPILER_FLAGS}'")
7376
message(STATUS "Host D compiler version: ${D_COMPILER_VERSION_STRING}")
77+
message(STATUS "Host D compiler front-end version: ${D_COMPILER_FE_VERSION}")
7478
else()
7579
message(FATAL_ERROR "No D compiler found! Try setting the 'D_COMPILER' variable or 'DMD' environment variable.")
7680
endif()

dmd/cppmangle.d

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -943,14 +943,18 @@ public:
943943
if (t.isImmutable() || t.isShared())
944944
return error(t);
945945

946-
/* __c_long and __c_ulong get special mangling
946+
/* magic structs __c_(u)long(long) get special mangling
947947
*/
948948
const id = t.sym.ident;
949949
//printf("struct id = '%s'\n", id.toChars());
950950
if (id == Id.__c_long)
951951
return writeBasicType(t, 0, 'l');
952952
else if (id == Id.__c_ulong)
953953
return writeBasicType(t, 0, 'm');
954+
else if (id == Id.__c_longlong)
955+
return writeBasicType(t, 0, 'x');
956+
else if (id == Id.__c_ulonglong)
957+
return writeBasicType(t, 0, 'y');
954958

955959
//printf("TypeStruct %s\n", t.toChars());
956960
doSymbol(t);

dmd/cppmanglewin.d

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -374,16 +374,18 @@ public:
374374
override void visit(TypeStruct type)
375375
{
376376
const id = type.sym.ident;
377-
char c;
377+
string c;
378378
if (id == Id.__c_long_double)
379-
c = 'O'; // VC++ long double
379+
c = "O"; // VC++ long double
380380
else if (id == Id.__c_long)
381-
c = 'J'; // VC++ long
381+
c = "J"; // VC++ long
382382
else if (id == Id.__c_ulong)
383-
c = 'K'; // VC++ unsigned long
384-
else
385-
c = 0;
386-
if (c)
383+
c = "K"; // VC++ unsigned long
384+
else if (id == Id.__c_longlong)
385+
c = "_J"; // VC++ long long
386+
else if (id == Id.__c_ulonglong)
387+
c = "_K"; // VC++ unsigned long long
388+
if (c.length)
387389
{
388390
if (type.isImmutable() || type.isShared())
389391
{
@@ -396,7 +398,7 @@ public:
396398
return;
397399
}
398400
mangleModifier(type);
399-
buf.writeByte(c);
401+
buf.writestring(c);
400402
}
401403
else
402404
{
@@ -1025,7 +1027,8 @@ private:
10251027
if (rettype.ty == Tstruct || rettype.ty == Tenum)
10261028
{
10271029
const id = rettype.toDsymbol(null).ident;
1028-
if (id != Id.__c_long_double && id != Id.__c_long && id != Id.__c_ulong)
1030+
if (id != Id.__c_long_double && id != Id.__c_long && id != Id.__c_ulong &&
1031+
id != Id.__c_longlong && id != Id.__c_ulonglong)
10291032
{
10301033
tmp.buf.writeByte('?');
10311034
tmp.buf.writeByte('A');

dmd/id.d

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ immutable Msgtable[] msgtable =
111111
{ "gate", "__gate" },
112112
{ "__c_long" },
113113
{ "__c_ulong" },
114+
{ "__c_longlong" },
115+
{ "__c_ulonglong" },
114116
{ "__c_long_double" },
115117
{ "cpp_type_info_ptr", "__cpp_type_info_ptr" },
116118
{ "_assert", "assert" },

dmd/id.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ struct Id
3131
static Identifier *offsetof;
3232
static Identifier *__c_long;
3333
static Identifier *__c_ulong;
34+
static Identifier *__c_longlong;
35+
static Identifier *__c_ulonglong;
3436
static Identifier *__c_long_double;
3537
static Identifier *__switch;
3638
static Identifier *crt_constructor;

dmd/mars.d

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,14 @@ extern (C++) int mars_mainBody(ref Strings files, ref Strings libmodules)
551551
Objc._init();
552552
builtin_init();
553553

554-
version (IN_LLVM) {} else
554+
version (IN_LLVM)
555+
{
556+
// LDC prints binary/version/config before entering this function.
557+
// DMD prints the predefined versions as part of addDefaultVersionIdentifiers().
558+
// Let's do it here after initialization, as e.g. Objc.init() may add `D_ObjectiveC`.
559+
printPredefinedVersions();
560+
}
561+
else
555562
{
556563
printPredefinedVersions();
557564

@@ -1610,8 +1617,7 @@ void addDefaultVersionIdentifiers()
16101617

16111618
} // !IN_LLVM
16121619

1613-
// IN_LLVM replaced: `private` by `extern (C++)`
1614-
extern (C++) void printPredefinedVersions()
1620+
private void printPredefinedVersions()
16151621
{
16161622
if (global.params.verbose && global.versionids)
16171623
{

dmd/mars.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ void ensurePathToNameExists(Loc loc, const char *name);
102102

103103
#if IN_LLVM
104104
int mars_mainBody(Strings &files, Strings &libmodules);
105-
void printPredefinedVersions();
106105
#endif
107106

108107
const char *importHint(const char *s);

driver/main.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1123,7 +1123,6 @@ int cppmain(int argc, char **argv) {
11231123

11241124
void addDefaultVersionIdentifiers() {
11251125
registerPredefinedVersions();
1126-
printPredefinedVersions();
11271126
}
11281127

11291128
void codegenModules(Modules &modules) {

gen/abi.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ bool TargetABI::isMagicCppStruct(Type *t) {
197197

198198
Identifier *id = static_cast<TypeStruct *>(t)->sym->ident;
199199
return (id == Id::__c_long) || (id == Id::__c_ulong) ||
200+
(id == Id::__c_longlong) || (id == Id::__c_ulonglong) ||
200201
(id == Id::__c_long_double);
201202
}
202203

0 commit comments

Comments
 (0)