Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge upstream v2.108.1 #4640

Merged
merged 7 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# LDC master

#### Big news
- Frontend, druntime and Phobos are at version [2.108.0+](https://dlang.org/changelog/2.108.0.html). (#4591, #4615, #4619, #4622, #4623)
- Frontend, druntime and Phobos are at version [2.108.1](https://dlang.org/changelog/2.108.0.html). (#4591, #4615, #4619, #4622, #4623, #4640)
- 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)
- 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)

Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ include(GetLinuxDistribution)
set(LDC_VERSION "1.38.0") # May be overridden by git hash tag
set(DMDFE_MAJOR_VERSION 2)
set(DMDFE_MINOR_VERSION 108)
set(DMDFE_PATCH_VERSION 0)
set(DMDFE_PATCH_VERSION 1)

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

Expand Down
15 changes: 12 additions & 3 deletions dmd/cparse.d
Original file line number Diff line number Diff line change
Expand Up @@ -1922,6 +1922,14 @@ final class CParser(AST) : Parser!AST
auto s = cparseFunctionDefinition(id, dt.isTypeFunction(), specifier);
typedefTab.setDim(typedefTabLengthSave);
symbols = symbolsSave;
if (specifier.mod & MOD.x__stdcall)
{
// If this function is __stdcall, wrap it in a LinkDeclaration so that
// it's extern(Windows) when imported in D.
auto decls = new AST.Dsymbols(1);
(*decls)[0] = s;
s = new AST.LinkDeclaration(s.loc, LINK.windows, decls);
}
symbols.push(s);
return;
}
Expand Down Expand Up @@ -2074,13 +2082,14 @@ final class CParser(AST) : Parser!AST
}
}
s = applySpecifier(s, specifier);
if (level == LVL.local)
if (level == LVL.local || (specifier.mod & MOD.x__stdcall))
{
// Wrap the declaration in `extern (C) { declaration }`
// Wrap the declaration in `extern (C/Windows) { declaration }`
// Necessary for function pointers, but harmless to apply to all.
auto decls = new AST.Dsymbols(1);
(*decls)[0] = s;
s = new AST.LinkDeclaration(s.loc, linkage, decls);
const lkg = specifier.mod & MOD.x__stdcall ? LINK.windows : linkage;
s = new AST.LinkDeclaration(s.loc, lkg, decls);
}
symbols.push(s);
}
Expand Down
16 changes: 10 additions & 6 deletions dmd/escape.d
Original file line number Diff line number Diff line change
Expand Up @@ -1542,7 +1542,7 @@ private bool inferReturn(FuncDeclaration fd, VarDeclaration v, bool returnScope)
* e = expression to be returned by value
* er = where to place collected data
* live = if @live semantics apply, i.e. expressions `p`, `*p`, `**p`, etc., all return `p`.
* retRefTransition = if `e` is returned through a `return ref scope` function call
* retRefTransition = if `e` is returned through a `return (ref) scope` function call
*/
public
void escapeByValue(Expression e, EscapeByResults* er, bool live = false, bool retRefTransition = false)
Expand Down Expand Up @@ -1786,7 +1786,7 @@ void escapeByValue(Expression e, EscapeByResults* er, bool live = false, bool re
}
}
else
escapeByValue(arg, er, live, retRefTransition);
escapeByValue(arg, er, live, true);
}
else if (psr == ScopeRef.ReturnRef || psr == ScopeRef.ReturnRef_Scope)
{
Expand Down Expand Up @@ -1941,7 +1941,7 @@ void escapeByValue(Expression e, EscapeByResults* er, bool live = false, bool re
* e = expression to be returned by 'ref'
* er = where to place collected data
* live = if @live semantics apply, i.e. expressions `p`, `*p`, `**p`, etc., all return `p`.
* retRefTransition = if `e` is returned through a `return ref scope` function call
* retRefTransition = if `e` is returned through a `return (ref) scope` function call
*/
private
void escapeByRef(Expression e, EscapeByResults* er, bool live = false, bool retRefTransition = false)
Expand Down Expand Up @@ -2189,14 +2189,18 @@ struct EscapeByResults
import dmd.root.array: Array;

/**
* Whether the variable / expression went through a `return ref scope` function call
* Whether the variable / expression went through a `return (ref) scope` function call
*
* This is needed for the dip1000 by default transition, since the rules for
* disambiguating `return scope ref` have changed. Therefore, functions in legacy code
* can be mistakenly treated as `return ref` making the compiler believe stack variables
* are being escaped, which is an error even in `@system` code. By keeping track of this
* information, variables escaped through `return ref` can be treated as a deprecation instead
* of error, see test/fail_compilation/dip1000_deprecation.d
*
* Additionally, return scope can be inferred wrongly instead of scope, in which
* case the code could give false positives even without @safe or dip1000:
* https://issues.dlang.org/show_bug.cgi?id=23657
*/
private Array!bool refRetRefTransition;
private Array!bool expRetRefTransition;
Expand All @@ -2218,7 +2222,7 @@ struct EscapeByResults
* Escape variable `v` by reference
* Params:
* v = variable to escape
* retRefTransition = `v` is escaped through a `return ref scope` function call
* retRefTransition = `v` is escaped through a `return (ref) scope` function call
*/
void pushRef(VarDeclaration v, bool retRefTransition)
{
Expand All @@ -2230,7 +2234,7 @@ struct EscapeByResults
* Escape a reference to expression `e`
* Params:
* e = expression to escape
* retRefTransition = `e` is escaped through a `return ref scope` function call
* retRefTransition = `e` is escaped through a `return (ref) scope` function call
*/
void pushExp(Expression e, bool retRefTransition)
{
Expand Down
6 changes: 4 additions & 2 deletions dmd/expressionsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -15348,8 +15348,10 @@ Expression resolveLoc(Expression exp, const ref Loc loc, Scope* sc)
Expression visitSlice(SliceExp exp)
{
exp.e1 = exp.e1.resolveLoc(loc, sc);
exp.lwr = exp.lwr.resolveLoc(loc, sc);
exp.upr = exp.upr.resolveLoc(loc, sc);
if (exp.lwr)
exp.lwr = exp.lwr.resolveLoc(loc, sc);
if (exp.upr)
exp.upr = exp.upr.resolveLoc(loc, sc);

return exp;
}
Expand Down
2 changes: 1 addition & 1 deletion packaging/dlang-tools_version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v2.108.0
v2.108.1
2 changes: 1 addition & 1 deletion packaging/reggae_version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9a67d1a1f863c676f30b06ac606b34a792abebdd
563fb9247a93a352a0999afebe810cbd740c6502
1 change: 1 addition & 0 deletions runtime/druntime/src/importc.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ typedef unsigned long long __uint64_t;
#define __ptr64
#define __unaligned
#define _NO_CRT_STDIO_INLINE 1
#define _stdcall __stdcall

// This header disables the Windows API Annotations macros
// Need to include sal.h to get the pragma once to prevent macro redefinition.
Expand Down
2 changes: 1 addition & 1 deletion runtime/phobos
Submodule phobos updated 1 files
+3 −3 std/logger/core.d
17 changes: 17 additions & 0 deletions tests/dmd/compilable/imports/test24511_c.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
typedef void (*CFunctionPointer)();
typedef void (__stdcall *StdCallFunctionPointer)();

void cFunction()
{}

void __stdcall stdcallFunction()
{}

void __stdcall takesCFunctionPointer(CFunctionPointer f)
{}

void takesStdCallFunctionPointer(StdCallFunctionPointer f)
{}

typedef void (__stdcall *StdCallFunctionPointerTakingCFunctionPointer)(CFunctionPointer f);
typedef void (*CFunctionPointerTakingStdCallFunctionPointer)(StdCallFunctionPointer f);
16 changes: 16 additions & 0 deletions tests/dmd/compilable/returnscope_without_safe.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Stack pointers are being escaped here, but without
// @safe and dip1000, it should still be allowed
// because return scope could have been inferred incorrectly,
// and it breaks existing code:
// https://issues.dlang.org/show_bug.cgi?id=23657

int* identity(return scope int* x);

auto identityAuto(int* x) => x;

int* f()
{
int x;
return identity(&x);
return identityAuto(&x);
}
4 changes: 4 additions & 0 deletions tests/dmd/compilable/test22727.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ __stdcall int foostdcall(int a) { return a; }

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

#if _MSC_VER
int _stdcall foostdcall3(int a) { return a; } // test issue 24509
#endif

int __stdcall (*fp1)(int a) = &foostdcall;

int (__stdcall *fp2)(int a) = &foostdcall2;
31 changes: 31 additions & 0 deletions tests/dmd/compilable/test24511.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// (disabled for LDC, would require full triple:) rEQUIRED_ARGS: -os=windows
// EXTRA_SOURCES: imports/test24511_c.c
// DISABLED: osx
// This is disabled on macOS because ld complains about _main being undefined
// when clang attempts to preprocess the C file.

// LDC: don't bother cross-compiling (incl. -preprocessing), only run on Windows
// DISABLED: linux freebsd dragonflybsd netbsd openbsd

import test24511_c;

static assert(__traits(getLinkage, CFunctionPointer) == "C");
static assert(__traits(getLinkage, StdCallFunctionPointer) == "Windows");
static assert(__traits(getLinkage, cFunction) == "C");
static assert(__traits(getLinkage, stdcallFunction) == "Windows");

static assert(__traits(getLinkage, takesCFunctionPointer) == "Windows");
static if (is(typeof(&takesCFunctionPointer) ParamsA == __parameters))
static assert(__traits(getLinkage, ParamsA[0]) == "C");

static assert(__traits(getLinkage, takesStdCallFunctionPointer) == "C");
static if (is(typeof(&takesStdCallFunctionPointer) ParamsB == __parameters))
static assert(__traits(getLinkage, ParamsB[0]) == "Windows");

static assert(__traits(getLinkage, StdCallFunctionPointerTakingCFunctionPointer) == "Windows");
static if (is(typeof(&StdCallFunctionPointerTakingCFunctionPointer) ParamsC == __parameters))
static assert(__traits(getLinkage, ParamsC[0]) == "C");

static assert(__traits(getLinkage, CFunctionPointerTakingStdCallFunctionPointer) == "C");
static if (is(typeof(&CFunctionPointerTakingStdCallFunctionPointer) ParamsD == __parameters))
static assert(__traits(getLinkage, ParamsD[0]) == "Windows");
6 changes: 6 additions & 0 deletions tests/dmd/runnable/imports/issue18919b.d
Original file line number Diff line number Diff line change
Expand Up @@ -248,3 +248,9 @@ void func12(const(char)*[] args = [baseName(__FILE__.ptr),
printf(" %s", arg);
printf("\n");
}

// https://issues.dlang.org/show_bug.cgi?id=24519
void func13(string file = __FILE__[])
{
printf("%s: %s\n", __FUNCTION__.ptr, file.ptr);
}
4 changes: 4 additions & 0 deletions tests/dmd/runnable/issue18919.d
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ imports.issue18919b.func9.fp: issue18919b.d:216 imports.issue18919b
imports.issue18919b.func10: expr1=imports.issue18919b, expr2=imports.issue18919b
imports.issue18919b.func11: issue18919b.d:233 imports.issue18919b
imports.issue18919b.func12: issue18919.d issue18919.main void issue18919.main() issue18919
imports.issue18919b.func13: runnable/issue18919.d
---
*/
import imports.issue18919b;

#line 26

void main()
{
func1();
Expand All @@ -44,4 +47,5 @@ void main()
func10();
func11();
func12();
func13();
}
Loading