Skip to content

Commit 2c88914

Browse files
committed
Merge remote-tracking branch 'origin/master' into merge-2.110
2 parents 2e6d917 + 843844d commit 2c88914

File tree

13 files changed

+119
-28
lines changed

13 files changed

+119
-28
lines changed

.cirrus.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ install_ubuntu_prerequisites_template: &INSTALL_UBUNTU_PREREQUISITES_TEMPLATE
202202
environment:
203203
CIRRUS_CLONE_DEPTH: 50
204204
HOST_LDC_VERSION: 1.31.0
205-
LLVM_VERSION: 18.1.6
205+
LLVM_VERSION: 18.1.8
206206
GITHUB_TOKEN: ENCRYPTED[0955bd48c8d4e5391446fc0149d0719ad0b63df27ec9e6c180a5730a5b10dc7f28f09d1383423db158d21380ee2b022a]
207207

208208
task:

.github/actions/1-setup/action.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ runs:
110110
- name: Install D host compiler
111111
uses: dlang-community/setup-dlang@v1
112112
with:
113-
compiler: ldc-latest
113+
# macOS arm64: use LDC v1.39.0 using LLVM v17, as Xcode v16
114+
compiler: ${{ inputs.arch == 'arm64' && 'ldc-1.39.0' || 'ldc-latest' }}
114115
- name: 'Posix: Clear LD_LIBRARY_PATH env variable' # don't use host druntime/Phobos .so/.dylib etc.
115116
if: runner.os != 'Windows'
116117
shell: bash

.github/workflows/main.yml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ concurrency:
1111

1212
env:
1313
CLANG_VERSION: 15.0.6
14-
LLVM_VERSION: 18.1.6
14+
LLVM_VERSION: 18.1.8
1515

1616
jobs:
1717
build-native:
@@ -62,7 +62,6 @@ jobs:
6262
-DD_COMPILER_FLAGS="-gcc=/usr/bin/c++ -O -flto=full -defaultlib=phobos2-ldc-lto,druntime-ldc-lto -L-exported_symbol '-L__*' -L-w"
6363
-DEXTRA_CXXFLAGS=-flto=full
6464
with_pgo: true
65-
llvm_version: 17.0.6 # FIXME: sporadic 'libc++abi: Pure virtual function called!' compiler crashes with LLVM 18 (see https://github.com/ldc-developers/ldc/pull/4604, https://github.com/ldc-developers/ldc/pull/4541)
6665

6766
- job_name: Windows x64
6867
os: windows-2022
@@ -95,20 +94,26 @@ jobs:
9594
with:
9695
submodules: true
9796
fetch-depth: 50
98-
- name: 'macOS 14: Switch to Xcode v14.3.1'
97+
- name: 'macOS 14: Switch to Xcode 16 Beta 4'
9998
if: matrix.os == 'macos-14'
100-
run: sudo xcode-select -switch /Applications/Xcode_14.3.1.app
99+
run: sudo xcode-select -switch /Applications/Xcode_16_beta_4.app
101100
- name: Install prerequisites
102101
uses: ./.github/actions/1-setup
103102
with:
104-
clang_version: ${{ runner.os == 'Windows' && '18.1.6' || env.CLANG_VERSION }}
103+
clang_version: ${{ runner.os == 'Windows' && '18.1.8' || env.CLANG_VERSION }}
105104
llvm_version: ${{ matrix.llvm_version || env.LLVM_VERSION }}
106105
arch: ${{ matrix.arch }}
107106
- name: Build bootstrap LDC
107+
if: matrix.os != 'macos-14'
108108
uses: ./.github/actions/2-build-bootstrap
109109
with:
110110
cmake_flags: ${{ matrix.bootstrap_cmake_flags }}
111111
arch: ${{ matrix.arch }}
112+
# FIXME: on macOS arm64, LLVM 18 (from LDC) and LLVM 17 (from Xcode 16) seem incompatible,
113+
# leading to sporadic 'libc++abi: Pure virtual function called!' compiler crashes
114+
- name: 'macOS 14: Use host LDC (with Xcode-compatible LLVM version) as bootstrap LDC'
115+
if: matrix.os == 'macos-14'
116+
run: ln -s $(dirname $(dirname $(which ldmd2))) ../bootstrap-ldc
112117
- name: Build LDC with PGO instrumentation & gather profile from compiling default libs
113118
if: matrix.with_pgo
114119
uses: ./.github/actions/2a-build-pgo

.github/workflows/supported_llvm_versions.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
os: ubuntu-20.04
2020
host_dc: ldc-1.19.0
2121
# FIXME: no usable official package available yet
22-
llvm_version: https://github.com/ldc-developers/llvm-project/releases/download/ldc-v18.1.6/llvm-18.1.6-linux-x86_64.tar.xz
22+
llvm_version: https://github.com/ldc-developers/llvm-project/releases/download/ldc-v18.1.8/llvm-18.1.8-linux-x86_64.tar.xz
2323
cmake_flags: -DRT_SUPPORT_SANITIZERS=ON
2424
- job_name: macOS 14, LLVM 17, latest LDC beta
2525
os: macos-14

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
#### Big news
44
- Frontend, druntime and Phobos are at version [2.110.0](https://dlang.org/changelog/2.110.0.html). (#4707)
5+
- LLVM for prebuilt packages bumped to v18.1.8 (incl. macOS arm64). (#4712)
56
- Android: NDK for prebuilt package bumped from r26d to r27. (#4711)
7+
- ldc2.conf: %%ldcconfigpath%% placeholder added - specifies the directory where current configuration file is located. (#4717)
68

79
#### Platform support
810

driver/configfile.d

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import core.stdc.stdio;
1818
import core.stdc.string;
1919

2020

21-
string prepareBinDir(const(char)* binDir)
21+
string normalizeSlashes(const(char)* binDir)
2222
{
2323
immutable len = strlen(binDir);
2424
auto res = binDir[0 .. len].dup;
@@ -96,6 +96,26 @@ unittest
9696
assert(replace(test4, pattern, "word") == "a word, yet other words");
9797
}
9898

99+
struct CfgPaths
100+
{
101+
string cfgBaseDir; /// ldc2.conf directory
102+
string ldcBinaryDir; /// ldc2.exe binary dir
103+
104+
this(const(char)* cfPath, const(char)* binDir)
105+
{
106+
import dmd.root.filename: FileName;
107+
108+
cfgBaseDir = normalizeSlashes(FileName.path(cfPath));
109+
ldcBinaryDir = normalizeSlashes(binDir);
110+
}
111+
}
112+
113+
string replacePlaceholders(string str, CfgPaths cfgPaths)
114+
{
115+
return str
116+
.replace("%%ldcbinarypath%%", cfgPaths.ldcBinaryDir)
117+
.replace("%%ldcconfigpath%%", cfgPaths.cfgBaseDir);
118+
}
99119

100120
extern(C++) struct ConfigFile
101121
{
@@ -117,8 +137,7 @@ private:
117137
{
118138
switches.setDim(0);
119139
postSwitches.setDim(0);
120-
121-
immutable dBinDir = prepareBinDir(binDir);
140+
const cfgPaths = CfgPaths(cfPath, binDir);
122141

123142
try
124143
{
@@ -156,7 +175,7 @@ private:
156175
output.reserve(input.vals.length);
157176
foreach (sw; input.vals)
158177
{
159-
const finalSwitch = sw.replace("%%ldcbinarypath%%", dBinDir) ~ '\0';
178+
const finalSwitch = sw.replacePlaceholders(cfgPaths) ~ '\0';
160179
output.push(finalSwitch.ptr);
161180
}
162181
}
@@ -168,7 +187,7 @@ private:
168187
applyArray(_libDirs, libDirs);
169188

170189
if (auto rpath = findScalarSetting(sections, "rpath"))
171-
this.rpathcstr = (rpath.val.replace("%%ldcbinarypath%%", dBinDir) ~ '\0').ptr;
190+
this.rpathcstr = (rpath.val.replacePlaceholders(cfgPaths) ~ '\0').ptr;
172191

173192
return true;
174193
}

driver/linker-msvc.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,11 @@ int linkObjToBinaryMSVC(llvm::StringRef outputPath,
292292
std::string linker = opts::linker;
293293
if (linker.empty()) {
294294
#ifdef _WIN32
295-
// default to lld-link.exe for LTO
296-
linker = opts::isUsingLTO() ? "lld-link.exe" : "link.exe";
295+
// Default to lld-link.exe for LTO, otherwise Microsoft's link.exe.
296+
// Try not to accidentally use a GNU link.exe (if in PATH before the MSVC
297+
// bin dir).
298+
linker = opts::isUsingLTO() ? "lld-link.exe"
299+
: msvcEnv.tryResolveToolPath("link.exe");
297300
#else
298301
linker = "lld-link";
299302
#endif

driver/tool.cpp

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,15 @@ int executeToolAndWait(const Loc &loc, const std::string &tool_,
286286
namespace windows {
287287

288288
namespace {
289+
290+
// cached 'singleton', lazily initialized (as that can be very expensive)
291+
const VSOptions &getVSOptions() {
292+
static VSOptions vsOptions;
293+
if (!vsOptions.VSInstallDir)
294+
vsOptions.initialize();
295+
return vsOptions;
296+
}
297+
289298
bool setupMsvcEnvironmentImpl(
290299
bool forPreprocessingOnly,
291300
std::vector<std::pair<std::wstring, wchar_t *>> *rollback) {
@@ -318,12 +327,9 @@ bool setupMsvcEnvironmentImpl(
318327
const bool x64 = triple.isArch64Bit();
319328
const auto begin = std::chrono::steady_clock::now();
320329

321-
static VSOptions vsOptions; // cache, as this can be expensive
322-
if (!vsOptions.VSInstallDir) {
323-
vsOptions.initialize();
324-
if (!vsOptions.VSInstallDir)
325-
return false;
326-
}
330+
auto &vsOptions = getVSOptions();
331+
if (!vsOptions.VSInstallDir)
332+
return false;
327333

328334
// cache the environment variable prefixes too
329335
static llvm::SmallVector<const char *, 2> binPaths;
@@ -446,6 +452,15 @@ MsvcEnvironmentScope::~MsvcEnvironmentScope() {
446452
}
447453
}
448454

455+
std::string
456+
MsvcEnvironmentScope::tryResolveToolPath(const char *fileName) const {
457+
const bool x64 = global.params.targetTriple->isArch64Bit();
458+
const char *secondaryBindir = nullptr;
459+
if (auto bindir = getVSOptions().getVCBinDir(x64, secondaryBindir))
460+
return (llvm::Twine(bindir) + "\\" + fileName).str();
461+
return fileName;
462+
}
463+
449464
} // namespace windows
450465

451466
#endif // _WIN32

driver/tool.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ struct MsvcEnvironmentScope {
5858

5959
~MsvcEnvironmentScope();
6060

61+
// Tries to return the absolute path to a VC tool, falling back to the file
62+
// name.
63+
std::string tryResolveToolPath(const char *fileName) const;
64+
6165
private:
6266
// for each changed env var: name & original value
6367
std::vector<std::pair<std::wstring, wchar_t *>> rollback;

ir/irtypeaggr.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ AggrTypeBuilder::AggrTypeBuilder(unsigned offset) : m_offset(offset) {
4242
void AggrTypeBuilder::addType(llvm::Type *type, unsigned size) {
4343
const unsigned fieldAlignment = getABITypeAlign(type);
4444
assert(fieldAlignment);
45-
assert((m_offset & (fieldAlignment - 1)) == 0 && "Field is misaligned");
45+
// If the field offset does not have natural alignment, mark the aggregate as
46+
// packed for IR.
47+
if ((m_offset & (fieldAlignment - 1)) != 0) {
48+
m_packed = true;
49+
}
4650
m_defaultTypes.push_back(type);
4751
m_offset += size;
4852
m_fieldIndex++;

tests/compilable/gh4719.d

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// RUN: %ldc -c %s
2+
// RUN: %ldc -c %s -O
3+
4+
struct TraceBuf {
5+
align(1) uint args;
6+
}
7+
8+
// Test correct compilation (no error) of the context pointer type for the delegate of `foo`.
9+
void foo() {
10+
byte[2] fixDescs;
11+
TraceBuf fixLog;
12+
13+
auto dlg = delegate() {
14+
fixDescs[0] = 1;
15+
fixLog.args = 1;
16+
};
17+
}
18+
19+
class TraceClass {
20+
align(1)
21+
uint args;
22+
}
23+
24+
// Test correct compilation (no error) of the context pointer type for the delegate of `foo2`.
25+
void foo2() {
26+
byte[2] fixDescs;
27+
scope TraceClass fixLog;
28+
29+
auto dlg = delegate() {
30+
fixDescs[0] = 1;
31+
fixLog.args = 1;
32+
};
33+
}

tests/dmd/runnable/ldc_extern_weak.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// REQUIRED_ARGS(osx): -L-undefined -Ldynamic_lookup
77

88
// the linker on macOS-arm64 emits a warning
9-
// TRANSFORM_OUTPUT(osx): remove_lines("warning: -undefined dynamic_lookup may not work with chained fixups")
9+
// TRANSFORM_OUTPUT(osx): remove_lines("warning:.* -undefined dynamic_lookup")
1010

1111
extern __gshared pragma(LDC_extern_weak) int nonExistent;
1212

tools/timetrace2txt.d

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -249,16 +249,21 @@ struct Node
249249
// Output in milliseconds.
250250
outputTextFile.writef(duration_format_string, cast(double)(this.duration) / 1000);
251251

252-
if (last_child)
253-
indentstring[$-1] = '';
254-
outputTextFile.write(indentstring);
255-
outputTextFile.write("- ", this.name);
252+
if (indentstring.length > 0) {
253+
outputTextFile.write(indentstring[0..$-1]);
254+
if (last_child)
255+
outputTextFile.write("");
256+
else
257+
outputTextFile.write("");
258+
}
259+
260+
outputTextFile.write("", this.name);
256261
outputTextFile.write(", ", this.detail);
257262
outputTextFile.writeln(", ", this.location);
258263
if (last_child)
259264
indentstring[$-1] = ' ';
260265

261-
wchar[] child_indentstring = indentstring ~ " |";
266+
wchar[] child_indentstring = indentstring ~ " ";
262267
foreach (i, ref child; this.children) {
263268
child.printTree(child_indentstring, i == this.children.length-1);
264269
}

0 commit comments

Comments
 (0)