Skip to content

Commit 4d51285

Browse files
authored
Merge pull request #4640 from kinke/merge_stable
Merge upstream v2.108.1
2 parents f259534 + b974302 commit 4d51285

File tree

15 files changed

+110
-16
lines changed

15 files changed

+110
-16
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# LDC master
22

33
#### Big news
4-
- Frontend, druntime and Phobos are at version [2.108.0+](https://dlang.org/changelog/2.108.0.html). (#4591, #4615, #4619, #4622, #4623)
4+
- Frontend, druntime and Phobos are at version [2.108.1](https://dlang.org/changelog/2.108.0.html). (#4591, #4615, #4619, #4622, #4623, #4640)
55
- Support for [LLVM 18](https://releases.llvm.org/18.1.0/docs/ReleaseNotes.html). The prebuilt packages use v18.1.4 (except for macOS arm64). (#4599, #4605, #4607, #4604, #4628)
66
- Android: Switch to native ELF TLS, supported since API level 29 (Android v10), dropping our former custom TLS emulation (requiring a modified LLVM and a legacy ld.bfd linker). The prebuilt packages themselves require Android v10+ (armv7a) / v11+ (aarch64) too, and are built with NDK r26d. Shared druntime and Phobos libraries are now available (`-link-defaultlib-shared`), as on regular Linux. (#4618)
77

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ include(GetLinuxDistribution)
120120
set(LDC_VERSION "1.38.0") # May be overridden by git hash tag
121121
set(DMDFE_MAJOR_VERSION 2)
122122
set(DMDFE_MINOR_VERSION 108)
123-
set(DMDFE_PATCH_VERSION 0)
123+
set(DMDFE_PATCH_VERSION 1)
124124

125125
set(DMD_VERSION ${DMDFE_MAJOR_VERSION}.${DMDFE_MINOR_VERSION}.${DMDFE_PATCH_VERSION})
126126

dmd/cparse.d

+12-3
Original file line numberDiff line numberDiff line change
@@ -1922,6 +1922,14 @@ final class CParser(AST) : Parser!AST
19221922
auto s = cparseFunctionDefinition(id, dt.isTypeFunction(), specifier);
19231923
typedefTab.setDim(typedefTabLengthSave);
19241924
symbols = symbolsSave;
1925+
if (specifier.mod & MOD.x__stdcall)
1926+
{
1927+
// If this function is __stdcall, wrap it in a LinkDeclaration so that
1928+
// it's extern(Windows) when imported in D.
1929+
auto decls = new AST.Dsymbols(1);
1930+
(*decls)[0] = s;
1931+
s = new AST.LinkDeclaration(s.loc, LINK.windows, decls);
1932+
}
19251933
symbols.push(s);
19261934
return;
19271935
}
@@ -2074,13 +2082,14 @@ final class CParser(AST) : Parser!AST
20742082
}
20752083
}
20762084
s = applySpecifier(s, specifier);
2077-
if (level == LVL.local)
2085+
if (level == LVL.local || (specifier.mod & MOD.x__stdcall))
20782086
{
2079-
// Wrap the declaration in `extern (C) { declaration }`
2087+
// Wrap the declaration in `extern (C/Windows) { declaration }`
20802088
// Necessary for function pointers, but harmless to apply to all.
20812089
auto decls = new AST.Dsymbols(1);
20822090
(*decls)[0] = s;
2083-
s = new AST.LinkDeclaration(s.loc, linkage, decls);
2091+
const lkg = specifier.mod & MOD.x__stdcall ? LINK.windows : linkage;
2092+
s = new AST.LinkDeclaration(s.loc, lkg, decls);
20842093
}
20852094
symbols.push(s);
20862095
}

dmd/escape.d

+10-6
Original file line numberDiff line numberDiff line change
@@ -1542,7 +1542,7 @@ private bool inferReturn(FuncDeclaration fd, VarDeclaration v, bool returnScope)
15421542
* e = expression to be returned by value
15431543
* er = where to place collected data
15441544
* live = if @live semantics apply, i.e. expressions `p`, `*p`, `**p`, etc., all return `p`.
1545-
* retRefTransition = if `e` is returned through a `return ref scope` function call
1545+
* retRefTransition = if `e` is returned through a `return (ref) scope` function call
15461546
*/
15471547
public
15481548
void escapeByValue(Expression e, EscapeByResults* er, bool live = false, bool retRefTransition = false)
@@ -1786,7 +1786,7 @@ void escapeByValue(Expression e, EscapeByResults* er, bool live = false, bool re
17861786
}
17871787
}
17881788
else
1789-
escapeByValue(arg, er, live, retRefTransition);
1789+
escapeByValue(arg, er, live, true);
17901790
}
17911791
else if (psr == ScopeRef.ReturnRef || psr == ScopeRef.ReturnRef_Scope)
17921792
{
@@ -1941,7 +1941,7 @@ void escapeByValue(Expression e, EscapeByResults* er, bool live = false, bool re
19411941
* e = expression to be returned by 'ref'
19421942
* er = where to place collected data
19431943
* live = if @live semantics apply, i.e. expressions `p`, `*p`, `**p`, etc., all return `p`.
1944-
* retRefTransition = if `e` is returned through a `return ref scope` function call
1944+
* retRefTransition = if `e` is returned through a `return (ref) scope` function call
19451945
*/
19461946
private
19471947
void escapeByRef(Expression e, EscapeByResults* er, bool live = false, bool retRefTransition = false)
@@ -2189,14 +2189,18 @@ struct EscapeByResults
21892189
import dmd.root.array: Array;
21902190

21912191
/**
2192-
* Whether the variable / expression went through a `return ref scope` function call
2192+
* Whether the variable / expression went through a `return (ref) scope` function call
21932193
*
21942194
* This is needed for the dip1000 by default transition, since the rules for
21952195
* disambiguating `return scope ref` have changed. Therefore, functions in legacy code
21962196
* can be mistakenly treated as `return ref` making the compiler believe stack variables
21972197
* are being escaped, which is an error even in `@system` code. By keeping track of this
21982198
* information, variables escaped through `return ref` can be treated as a deprecation instead
21992199
* of error, see test/fail_compilation/dip1000_deprecation.d
2200+
*
2201+
* Additionally, return scope can be inferred wrongly instead of scope, in which
2202+
* case the code could give false positives even without @safe or dip1000:
2203+
* https://issues.dlang.org/show_bug.cgi?id=23657
22002204
*/
22012205
private Array!bool refRetRefTransition;
22022206
private Array!bool expRetRefTransition;
@@ -2218,7 +2222,7 @@ struct EscapeByResults
22182222
* Escape variable `v` by reference
22192223
* Params:
22202224
* v = variable to escape
2221-
* retRefTransition = `v` is escaped through a `return ref scope` function call
2225+
* retRefTransition = `v` is escaped through a `return (ref) scope` function call
22222226
*/
22232227
void pushRef(VarDeclaration v, bool retRefTransition)
22242228
{
@@ -2230,7 +2234,7 @@ struct EscapeByResults
22302234
* Escape a reference to expression `e`
22312235
* Params:
22322236
* e = expression to escape
2233-
* retRefTransition = `e` is escaped through a `return ref scope` function call
2237+
* retRefTransition = `e` is escaped through a `return (ref) scope` function call
22342238
*/
22352239
void pushExp(Expression e, bool retRefTransition)
22362240
{

dmd/expressionsem.d

+4-2
Original file line numberDiff line numberDiff line change
@@ -15348,8 +15348,10 @@ Expression resolveLoc(Expression exp, const ref Loc loc, Scope* sc)
1534815348
Expression visitSlice(SliceExp exp)
1534915349
{
1535015350
exp.e1 = exp.e1.resolveLoc(loc, sc);
15351-
exp.lwr = exp.lwr.resolveLoc(loc, sc);
15352-
exp.upr = exp.upr.resolveLoc(loc, sc);
15351+
if (exp.lwr)
15352+
exp.lwr = exp.lwr.resolveLoc(loc, sc);
15353+
if (exp.upr)
15354+
exp.upr = exp.upr.resolveLoc(loc, sc);
1535315355

1535415356
return exp;
1535515357
}

packaging/dlang-tools_version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v2.108.0
1+
v2.108.1

packaging/reggae_version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
9a67d1a1f863c676f30b06ac606b34a792abebdd
1+
563fb9247a93a352a0999afebe810cbd740c6502

runtime/druntime/src/importc.h

+1
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ typedef unsigned long long __uint64_t;
135135
#define __ptr64
136136
#define __unaligned
137137
#define _NO_CRT_STDIO_INLINE 1
138+
#define _stdcall __stdcall
138139

139140
// This header disables the Windows API Annotations macros
140141
// Need to include sal.h to get the pragma once to prevent macro redefinition.

runtime/phobos

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
typedef void (*CFunctionPointer)();
2+
typedef void (__stdcall *StdCallFunctionPointer)();
3+
4+
void cFunction()
5+
{}
6+
7+
void __stdcall stdcallFunction()
8+
{}
9+
10+
void __stdcall takesCFunctionPointer(CFunctionPointer f)
11+
{}
12+
13+
void takesStdCallFunctionPointer(StdCallFunctionPointer f)
14+
{}
15+
16+
typedef void (__stdcall *StdCallFunctionPointerTakingCFunctionPointer)(CFunctionPointer f);
17+
typedef void (*CFunctionPointerTakingStdCallFunctionPointer)(StdCallFunctionPointer f);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Stack pointers are being escaped here, but without
2+
// @safe and dip1000, it should still be allowed
3+
// because return scope could have been inferred incorrectly,
4+
// and it breaks existing code:
5+
// https://issues.dlang.org/show_bug.cgi?id=23657
6+
7+
int* identity(return scope int* x);
8+
9+
auto identityAuto(int* x) => x;
10+
11+
int* f()
12+
{
13+
int x;
14+
return identity(&x);
15+
return identityAuto(&x);
16+
}

tests/dmd/compilable/test22727.c

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ __stdcall int foostdcall(int a) { return a; }
66

77
int __stdcall foostdcall2(int a) { return a; }
88

9+
#if _MSC_VER
10+
int _stdcall foostdcall3(int a) { return a; } // test issue 24509
11+
#endif
12+
913
int __stdcall (*fp1)(int a) = &foostdcall;
1014

1115
int (__stdcall *fp2)(int a) = &foostdcall2;

tests/dmd/compilable/test24511.d

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// (disabled for LDC, would require full triple:) rEQUIRED_ARGS: -os=windows
2+
// EXTRA_SOURCES: imports/test24511_c.c
3+
// DISABLED: osx
4+
// This is disabled on macOS because ld complains about _main being undefined
5+
// when clang attempts to preprocess the C file.
6+
7+
// LDC: don't bother cross-compiling (incl. -preprocessing), only run on Windows
8+
// DISABLED: linux freebsd dragonflybsd netbsd openbsd
9+
10+
import test24511_c;
11+
12+
static assert(__traits(getLinkage, CFunctionPointer) == "C");
13+
static assert(__traits(getLinkage, StdCallFunctionPointer) == "Windows");
14+
static assert(__traits(getLinkage, cFunction) == "C");
15+
static assert(__traits(getLinkage, stdcallFunction) == "Windows");
16+
17+
static assert(__traits(getLinkage, takesCFunctionPointer) == "Windows");
18+
static if (is(typeof(&takesCFunctionPointer) ParamsA == __parameters))
19+
static assert(__traits(getLinkage, ParamsA[0]) == "C");
20+
21+
static assert(__traits(getLinkage, takesStdCallFunctionPointer) == "C");
22+
static if (is(typeof(&takesStdCallFunctionPointer) ParamsB == __parameters))
23+
static assert(__traits(getLinkage, ParamsB[0]) == "Windows");
24+
25+
static assert(__traits(getLinkage, StdCallFunctionPointerTakingCFunctionPointer) == "Windows");
26+
static if (is(typeof(&StdCallFunctionPointerTakingCFunctionPointer) ParamsC == __parameters))
27+
static assert(__traits(getLinkage, ParamsC[0]) == "C");
28+
29+
static assert(__traits(getLinkage, CFunctionPointerTakingStdCallFunctionPointer) == "C");
30+
static if (is(typeof(&CFunctionPointerTakingStdCallFunctionPointer) ParamsD == __parameters))
31+
static assert(__traits(getLinkage, ParamsD[0]) == "Windows");

tests/dmd/runnable/imports/issue18919b.d

+6
Original file line numberDiff line numberDiff line change
@@ -248,3 +248,9 @@ void func12(const(char)*[] args = [baseName(__FILE__.ptr),
248248
printf(" %s", arg);
249249
printf("\n");
250250
}
251+
252+
// https://issues.dlang.org/show_bug.cgi?id=24519
253+
void func13(string file = __FILE__[])
254+
{
255+
printf("%s: %s\n", __FUNCTION__.ptr, file.ptr);
256+
}

tests/dmd/runnable/issue18919.d

+4
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,13 @@ imports.issue18919b.func9.fp: issue18919b.d:216 imports.issue18919b
2020
imports.issue18919b.func10: expr1=imports.issue18919b, expr2=imports.issue18919b
2121
imports.issue18919b.func11: issue18919b.d:233 imports.issue18919b
2222
imports.issue18919b.func12: issue18919.d issue18919.main void issue18919.main() issue18919
23+
imports.issue18919b.func13: runnable/issue18919.d
2324
---
2425
*/
2526
import imports.issue18919b;
2627

28+
#line 26
29+
2730
void main()
2831
{
2932
func1();
@@ -44,4 +47,5 @@ void main()
4447
func10();
4548
func11();
4649
func12();
50+
func13();
4751
}

0 commit comments

Comments
 (0)