diff --git a/CMakeLists.txt b/CMakeLists.txt index f6d1f71299f..93ea10b07b4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -417,6 +417,7 @@ append("-DOPAQUE_VTBLS" LDC_CXXFLAGS) append("\"-DLDC_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}\"" LDC_CXXFLAGS) append("-DLDC_LLVM_VER=${LDC_LLVM_VER}" LDC_CXXFLAGS) append("\"-DLDC_LIBDIR_SUFFIX=\\\"${LIB_SUFFIX}\\\"\"" LDC_CXXFLAGS) +append("-DLDC_HOST_FE_VER=${D_COMPILER_FE_VERSION}" LDC_CXXFLAGS) if(GENERATE_OFFTI) append("-DGENERATE_OFFTI" LDC_CXXFLAGS) diff --git a/cmake/Modules/FindDCompiler.cmake b/cmake/Modules/FindDCompiler.cmake index 61c2277b520..8c19d841e1f 100644 --- a/cmake/Modules/FindDCompiler.cmake +++ b/cmake/Modules/FindDCompiler.cmake @@ -8,6 +8,7 @@ # D_COMPILER_FLAGS - D compiler flags (could be passed in the DMD environment variable) # D_COMPILER_ID = {"DigitalMars", "LDMD", "LDC", "GDC"} # D_COMPILER_VERSION_STRING - String containing the compiler version, e.g. "DMD64 D Compiler v2.070.2" +# D_COMPILER_FE_VERSION - compiler front-end version, e.g. "2070" # D_COMPILER_DMD_COMPAT - true if the D compiler cmdline interface is compatible with DMD @@ -64,6 +65,8 @@ if (D_COMPILER) OUTPUT_VARIABLE D_COMPILER_VERSION_STRING ERROR_VARIABLE D_COMPILER_VERSION_STRING ERROR_QUIET) + string(REGEX MATCH " (D Compiler|based on DMD) v([0-9]+)\\.([0-9]+)" D_COMPILER_FE_VERSION "${D_COMPILER_VERSION_STRING}") + math(EXPR D_COMPILER_FE_VERSION ${CMAKE_MATCH_2}*1000+${CMAKE_MATCH_3}) # e.g., 2079 string(REGEX MATCH "^[^\r\n:]*" D_COMPILER_VERSION_STRING "${D_COMPILER_VERSION_STRING}") endif() @@ -71,6 +74,7 @@ endif() if (D_COMPILER_FOUND) message(STATUS "Found host D compiler ${D_COMPILER}, with default flags '${D_COMPILER_FLAGS}'") message(STATUS "Host D compiler version: ${D_COMPILER_VERSION_STRING}") + message(STATUS "Host D compiler front-end version: ${D_COMPILER_FE_VERSION}") else() message(FATAL_ERROR "No D compiler found! Try setting the 'D_COMPILER' variable or 'DMD' environment variable.") endif() diff --git a/dmd/cppmangle.d b/dmd/cppmangle.d index 85122773760..18d4f344f28 100644 --- a/dmd/cppmangle.d +++ b/dmd/cppmangle.d @@ -943,7 +943,7 @@ public: if (t.isImmutable() || t.isShared()) return error(t); - /* __c_long and __c_ulong get special mangling + /* magic structs __c_(u)long(long) get special mangling */ const id = t.sym.ident; //printf("struct id = '%s'\n", id.toChars()); @@ -951,6 +951,10 @@ public: return writeBasicType(t, 0, 'l'); else if (id == Id.__c_ulong) return writeBasicType(t, 0, 'm'); + else if (id == Id.__c_longlong) + return writeBasicType(t, 0, 'x'); + else if (id == Id.__c_ulonglong) + return writeBasicType(t, 0, 'y'); //printf("TypeStruct %s\n", t.toChars()); doSymbol(t); diff --git a/dmd/cppmanglewin.d b/dmd/cppmanglewin.d index e411c8256a2..0f89872951b 100644 --- a/dmd/cppmanglewin.d +++ b/dmd/cppmanglewin.d @@ -374,16 +374,18 @@ public: override void visit(TypeStruct type) { const id = type.sym.ident; - char c; + string c; if (id == Id.__c_long_double) - c = 'O'; // VC++ long double + c = "O"; // VC++ long double else if (id == Id.__c_long) - c = 'J'; // VC++ long + c = "J"; // VC++ long else if (id == Id.__c_ulong) - c = 'K'; // VC++ unsigned long - else - c = 0; - if (c) + c = "K"; // VC++ unsigned long + else if (id == Id.__c_longlong) + c = "_J"; // VC++ long long + else if (id == Id.__c_ulonglong) + c = "_K"; // VC++ unsigned long long + if (c.length) { if (type.isImmutable() || type.isShared()) { @@ -396,7 +398,7 @@ public: return; } mangleModifier(type); - buf.writeByte(c); + buf.writestring(c); } else { @@ -1025,7 +1027,8 @@ private: if (rettype.ty == Tstruct || rettype.ty == Tenum) { const id = rettype.toDsymbol(null).ident; - if (id != Id.__c_long_double && id != Id.__c_long && id != Id.__c_ulong) + if (id != Id.__c_long_double && id != Id.__c_long && id != Id.__c_ulong && + id != Id.__c_longlong && id != Id.__c_ulonglong) { tmp.buf.writeByte('?'); tmp.buf.writeByte('A'); diff --git a/dmd/id.d b/dmd/id.d index b7d2d435a07..dd6f9dfd7e1 100644 --- a/dmd/id.d +++ b/dmd/id.d @@ -111,6 +111,8 @@ immutable Msgtable[] msgtable = { "gate", "__gate" }, { "__c_long" }, { "__c_ulong" }, + { "__c_longlong" }, + { "__c_ulonglong" }, { "__c_long_double" }, { "cpp_type_info_ptr", "__cpp_type_info_ptr" }, { "_assert", "assert" }, diff --git a/dmd/id.h b/dmd/id.h index 81d30105eb5..39ac12a3e70 100644 --- a/dmd/id.h +++ b/dmd/id.h @@ -31,6 +31,8 @@ struct Id static Identifier *offsetof; static Identifier *__c_long; static Identifier *__c_ulong; + static Identifier *__c_longlong; + static Identifier *__c_ulonglong; static Identifier *__c_long_double; static Identifier *__switch; static Identifier *crt_constructor; diff --git a/dmd/mars.d b/dmd/mars.d index 9166b94d9c3..2dc4306e667 100644 --- a/dmd/mars.d +++ b/dmd/mars.d @@ -551,7 +551,14 @@ extern (C++) int mars_mainBody(ref Strings files, ref Strings libmodules) Objc._init(); builtin_init(); - version (IN_LLVM) {} else + version (IN_LLVM) + { + // LDC prints binary/version/config before entering this function. + // DMD prints the predefined versions as part of addDefaultVersionIdentifiers(). + // Let's do it here after initialization, as e.g. Objc.init() may add `D_ObjectiveC`. + printPredefinedVersions(); + } + else { printPredefinedVersions(); @@ -1610,8 +1617,7 @@ void addDefaultVersionIdentifiers() } // !IN_LLVM -// IN_LLVM replaced: `private` by `extern (C++)` -extern (C++) void printPredefinedVersions() +private void printPredefinedVersions() { if (global.params.verbose && global.versionids) { diff --git a/dmd/mars.h b/dmd/mars.h index 31fee5e86e9..b775a7ce1ca 100644 --- a/dmd/mars.h +++ b/dmd/mars.h @@ -102,7 +102,6 @@ void ensurePathToNameExists(Loc loc, const char *name); #if IN_LLVM int mars_mainBody(Strings &files, Strings &libmodules); -void printPredefinedVersions(); #endif const char *importHint(const char *s); diff --git a/driver/main.cpp b/driver/main.cpp index 2a9f0b74b65..10fa5fbcc65 100644 --- a/driver/main.cpp +++ b/driver/main.cpp @@ -1123,7 +1123,6 @@ int cppmain(int argc, char **argv) { void addDefaultVersionIdentifiers() { registerPredefinedVersions(); - printPredefinedVersions(); } void codegenModules(Modules &modules) { diff --git a/gen/abi.cpp b/gen/abi.cpp index c7735746047..62855c00dad 100644 --- a/gen/abi.cpp +++ b/gen/abi.cpp @@ -197,6 +197,7 @@ bool TargetABI::isMagicCppStruct(Type *t) { Identifier *id = static_cast(t)->sym->ident; return (id == Id::__c_long) || (id == Id::__c_ulong) || + (id == Id::__c_longlong) || (id == Id::__c_ulonglong) || (id == Id::__c_long_double); } diff --git a/gen/abi.h b/gen/abi.h index 89ad1175c8b..5fa553d4290 100644 --- a/gen/abi.h +++ b/gen/abi.h @@ -181,8 +181,8 @@ struct TargetABI { /// * complex number static bool isAggregate(Type *t); - /// The frontend uses magic structs to express the variable-sized C types - /// ((unsigned) long, long double) for C++ mangling purposes. + /// The frontend uses magic structs to express some primitive C types + /// ((unsigned) long (long), long double) for C++ mangling purposes. static bool isMagicCppStruct(Type *t); /// Returns true if the D type is a Plain-Old-Datatype, optionally excluding diff --git a/gen/target.cpp b/gen/target.cpp index 6eec49d28b9..c1b5091d16f 100644 --- a/gen/target.cpp +++ b/gen/target.cpp @@ -39,13 +39,15 @@ void Target::_init() { cppExceptions = true; - c_longsize = global.params.is64bit ? 8 : 4; + c_longsize = + global.params.is64bit && !triple.isWindowsMSVCEnvironment() ? 8 : 4; c_long_doublesize = realsize; classinfosize = 0; // unused maxStaticDataSize = std::numeric_limits::max(); - int64Mangle = triple.isOSDarwin() ? 'x' : 'l'; - uint64Mangle = triple.isOSDarwin() ? 'y' : 'm'; + // These C++ mangling characters are only used for 64-bit POSIX targets. + int64Mangle = 'l'; // C++ long + uint64Mangle = 'm'; // C++ unsigned long // {Float,Double,Real}Properties have been initialized with the D host // compiler's properties. diff --git a/runtime/druntime b/runtime/druntime index 3cca35e7457..b12b0142f31 160000 --- a/runtime/druntime +++ b/runtime/druntime @@ -1 +1 @@ -Subproject commit 3cca35e7457643e88ae285cfd9150a5634c5f50b +Subproject commit b12b0142f312d81771395024daf87c2f11becaa6 diff --git a/tests/d2/dmd-testsuite b/tests/d2/dmd-testsuite index 4f08cfc4e17..187c6313531 160000 --- a/tests/d2/dmd-testsuite +++ b/tests/d2/dmd-testsuite @@ -1 +1 @@ -Subproject commit 4f08cfc4e17bc0b2d5e56eb35c0a1f5de26674ee +Subproject commit 187c631353192339e5dabf44655c303bb6b22af7