Skip to content

Commit 252173d

Browse files
Fix #5095: LDC fails to build on Windows with DMD/MSVC due to real_t confusion (#5098)
1 parent f99d732 commit 252173d

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ set(ALTERNATIVE_MALLOC_O "" CACHE STRING "If specified, adds ALTERNATIVE_M
9797
# Most linux distributions have a policy of not bundling dependencies like zlib
9898
set(PHOBOS_SYSTEM_ZLIB OFF CACHE BOOL "Use system zlib instead of Phobos' vendored version")
9999

100+
# Force use of softfloat for compiler
101+
option(LDC_FORCE_SOFTFLOAT_REAL "Force LDC to be built with 80-bit real in software" OFF)
102+
100103
if(D_VERSION EQUAL 1)
101104
message(FATAL_ERROR "D version 1 is no longer supported.
102105
Please consider using D version 2 or checkout the 'd1' git branch for the last version supporting D version 1.")
@@ -135,6 +138,7 @@ if(NOT MSVC_IDE)
135138
endif()
136139

137140
if(MSVC)
141+
set(LDC_FORCE_SOFTFLOAT_REAL ON)
138142
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
139143
message(STATUS "Let D host compiler output 64-bit object files")
140144
append("-m64" DFLAGS_BASE)
@@ -166,6 +170,11 @@ if(MSVC)
166170
endforeach()
167171
endif()
168172

173+
if (LDC_FORCE_SOFTFLOAT_REAL)
174+
append("-version=LDC_real_softfloat" DFLAGS_LDC)
175+
append("-DLDC_real_softfloat" LDC_CXXFLAGS)
176+
endif()
177+
169178
# Use separate compiler flags for the frontend and for the LDC-specific parts,
170179
# as enabling warnings on the DMD frontend only leads to a lot of clutter in
171180
# the output (LLVM_CXXFLAGS sometimes already includes -Wall).

dmd/root/longdouble.d

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,14 @@
1111

1212
module dmd.root.longdouble;
1313

14-
version (CRuntime_Microsoft)
14+
version (LDC_real_softfloat)
1515
{
16+
version = EnableSoftfloat;
17+
alias longdouble = longdouble_soft;
18+
}
19+
else version (CRuntime_Microsoft)
20+
{
21+
version = EnableSoftfloat;
1622
static if (real.sizeof > 8)
1723
alias longdouble = real;
1824
else
@@ -23,7 +29,7 @@ else
2329

2430
// longdouble_soft needed when building the backend with
2531
// Visual C or the frontend with LDC on Windows
26-
version (CRuntime_Microsoft):
32+
version (EnableSoftfloat):
2733
extern (C++):
2834
nothrow:
2935
@nogc:
@@ -71,7 +77,7 @@ bool initFPU()
7177
return true;
7278
}
7379

74-
version(unittest) version(CRuntime_Microsoft)
80+
version(unittest)
7581
extern(D) shared static this()
7682
{
7783
initFPU(); // otherwise not guaranteed to be run before pure unittest below

dmd/root/longdouble.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@
1111

1212
#pragma once
1313

14-
#if !_MSC_VER // has native 10 byte doubles
14+
#if defined(LDC_real_softfloat)
15+
#define USE_LONGDOUBLE_SOFTFLOAT 1
16+
#elif defined(_MSC_VER)
17+
#define USE_LONGDOUBLE_SOFTFLOAT 1
18+
#endif
19+
20+
#if !USE_LONGDOUBLE_SOFTFLOAT // has native 10 byte doubles
1521
#include <stdio.h>
1622
typedef long double longdouble;
1723
typedef volatile long double volatile_longdouble;

0 commit comments

Comments
 (0)