Skip to content

Commit 333f75c

Browse files
committed
64-bit OSX: Mangle [u]long as C++ [u]int64_t
This is a breaking ABI change and affects LDC itself as mixed D/C++ code base. So we now need to check the front-end version of the D host compiler and adapt the corresponding C++ types accordingly.
1 parent 35ae79b commit 333f75c

File tree

6 files changed

+23
-15
lines changed

6 files changed

+23
-15
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/globals.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,11 @@ struct Global
330330

331331
extern Global global;
332332

333+
#if LDC_HOST_FE_VER >= 2079
334+
typedef uint64_t dinteger_t;
335+
typedef int64_t sinteger_t;
336+
typedef uint64_t uinteger_t;
337+
#else
333338
// Because int64_t and friends may be any integral type of the
334339
// correct size, we have to explicitly ask for the correct
335340
// integer type to get the correct mangling with dmd
@@ -346,6 +351,7 @@ typedef unsigned long long dinteger_t;
346351
typedef long long sinteger_t;
347352
typedef unsigned long long uinteger_t;
348353
#endif
354+
#endif
349355

350356
typedef int8_t d_int8;
351357
typedef uint8_t d_uns8;

dmd/identifier.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class Identifier : public RootObject
3838
static StringTable stringtable;
3939
static Identifier *generateId(const char *prefix);
4040
static Identifier *generateId(const char *prefix, size_t i);
41-
static Identifier *idPool(const char *s, size_t len);
41+
static Identifier *idPool(const char *s, d_size_t len);
4242

4343
static inline Identifier *idPool(const char *s)
4444
{

dmd/root/rmem.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@
1010
#ifndef ROOT_MEM_H
1111
#define ROOT_MEM_H
1212

13-
#include <stddef.h> // for size_t
13+
#include <stdint.h>
1414

15-
#if __APPLE__ && __i386__
16-
/* size_t is 'unsigned long', which makes it mangle differently
17-
* than D's 'uint'
18-
*/
19-
typedef unsigned d_size_t;
15+
#if __LP64__ || _M_X64
16+
#if LDC_HOST_FE_VER >= 2079 || _M_X64
17+
typedef uint64_t d_size_t;
2018
#else
21-
typedef size_t d_size_t;
19+
typedef unsigned long d_size_t;
20+
#endif
21+
#else
22+
typedef uint32_t d_size_t;
2223
#endif
2324

2425
struct Mem

driver/cache_pruning.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,10 @@
1010
#ifndef LDC_DRIVER_IR2OBJ_CACHE_PRUNING_H
1111
#define LDC_DRIVER_IR2OBJ_CACHE_PRUNING_H
1212

13-
#if __LP64__
14-
using d_ulong = unsigned long;
15-
#else
16-
using d_ulong = unsigned long long;
17-
#endif
13+
#include "globals.h"
1814

19-
void pruneCache(const char *cacheDirectoryPtr, size_t cacheDirectoryLen,
15+
void pruneCache(const char *cacheDirectoryPtr, d_size_t cacheDirectoryLen,
2016
uint32_t pruneIntervalSeconds, uint32_t expireIntervalSeconds,
21-
d_ulong sizeLimitBytes, uint32_t sizeLimitPercentage);
17+
uinteger_t sizeLimitBytes, uint32_t sizeLimitPercentage);
2218

2319
#endif

0 commit comments

Comments
 (0)