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 stable #4768

Merged
merged 10 commits into from
Oct 28, 2024
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.110.0](https://dlang.org/changelog/2.110.0.html). (#4707, #4737, #4749)
- Frontend, druntime and Phobos are at version [2.110.0](https://dlang.org/changelog/2.110.0.html). (#4707, #4737, #4749, #4768)
- LLVM for prebuilt packages bumped to v18.1.8 (incl. macOS arm64). (#4712)
- Android: NDK for prebuilt package bumped from r26d to r27. (#4711)
- ldc2.conf: %%ldcconfigpath%% placeholder added - specifies the directory where current configuration file is located. (#4717)
Expand Down
2 changes: 1 addition & 1 deletion dmd/dcast.d
Original file line number Diff line number Diff line change
Expand Up @@ -2336,7 +2336,7 @@ Expression castTo(Expression e, Scope* sc, Type t, Type att = null)
Type tb = t.toBasetype();
Type typeb = e.type.toBasetype();

if (e.hexString && !e.committed)
if (e.hexString && !e.committed && tb.nextOf().isintegral)
{
const szx = cast(ubyte) tb.nextOf().size();
if (szx != se.sz && (e.len % szx) == 0)
Expand Down
2 changes: 1 addition & 1 deletion dmd/dinterpret.d
Original file line number Diff line number Diff line change
Expand Up @@ -6136,7 +6136,7 @@ public:
{
auto se = e1.isStringExp();
// Allow casting a hex string literal to short[], int[] or long[]
if (se && se.hexString && se.postfix == StringExp.NoPostfix)
if (se && se.hexString && se.postfix == StringExp.NoPostfix && e.to.nextOf().isintegral)
{
const sz = cast(size_t) e.to.nextOf().size;
if ((se.len % sz) != 0)
Expand Down
2 changes: 1 addition & 1 deletion dmd/enumsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ void enumSemantic(Scope* sc, EnumDeclaration ed)

if (ed.members.length == 0)
{
.error(ed.loc, "%s `%s enum `%s` must have at least one member", ed.kind, ed.toPrettyChars, ed.toChars());
.error(ed.loc, "%s `%s` enum `%s` must have at least one member", ed.kind, ed.toPrettyChars, ed.toChars());
ed.errors = true;
ed.semanticRun = PASS.semanticdone;
return;
Expand Down
8 changes: 4 additions & 4 deletions dmd/hdrgen.d
Original file line number Diff line number Diff line change
Expand Up @@ -1726,10 +1726,10 @@ void toCBuffer(Dsymbol s, ref OutBuffer buf, ref HdrGenState hgs)
//printf("FuncDeclaration::toCBuffer() '%s'\n", f.toChars());
if (stcToBuffer(buf, f.storage_class))
buf.writeByte(' ');
typeToBuffer(f.type, f.ident, buf, hgs);
auto tf = f.type.isTypeFunction();
typeToBuffer(tf, f.ident, buf, hgs);

if (hgs.hdrgen)
if (hgs.hdrgen && tf)
{
// if the return type is missing (e.g. ref functions or auto)
// https://issues.dlang.org/show_bug.cgi?id=20090
Expand Down Expand Up @@ -1864,9 +1864,9 @@ void toCBuffer(Dsymbol s, ref OutBuffer buf, ref HdrGenState hgs)
if (stcToBuffer(buf, d.storage_class))
buf.writeByte(' ');
buf.writestring("invariant");
if(auto es = d.fbody.isExpStatement())
auto es = d.fbody.isExpStatement();
if (es && es.exp && es.exp.op == EXP.assert_)
{
assert(es.exp && es.exp.op == EXP.assert_);
buf.writestring(" (");
(cast(AssertExp)es.exp).e1.expressionToBuffer(buf, hgs);
buf.writestring(");");
Expand Down
1 change: 1 addition & 0 deletions dmd/parse.d
Original file line number Diff line number Diff line change
Expand Up @@ -9749,6 +9749,7 @@ immutable PREC[EXP.max + 1] precedence =
EXP.assign : PREC.assign,
EXP.construct : PREC.assign,
EXP.blit : PREC.assign,
EXP.loweredAssignExp : PREC.assign,
EXP.addAssign : PREC.assign,
EXP.minAssign : PREC.assign,
EXP.concatenateAssign : PREC.assign,
Expand Down
4 changes: 3 additions & 1 deletion dmd/typesem.d
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,9 @@ extern (D) MATCH callMatch(TypeFunction tf, Type tthis, ArgumentList argumentLis
L1:
if (parameterList.varargs == VarArg.typesafe && u + 1 == nparams) // if last varargs param
{
auto trailingArgs = args[u .. $];
Expression[] trailingArgs;
if (args.length >= u)
trailingArgs = args[u .. $];
if (auto vmatch = matchTypeSafeVarArgs(tf, p, trailingArgs, pMessage))
return vmatch < match ? vmatch : match;
// Error message was already generated in `matchTypeSafeVarArgs`
Expand Down
1 change: 1 addition & 0 deletions runtime/druntime/src/importc.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#define __alignof _Alignof
#define __vector_size__ vector_size
#define __typeof typeof
#define __typeof__ typeof

/********************
* Clang nullability extension used by macOS headers.
Expand Down
2 changes: 1 addition & 1 deletion runtime/phobos
22 changes: 21 additions & 1 deletion tests/dmd/compilable/extra-files/vcg-ast.d.cg
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ void main()
values();
return 0;
}
import imports.vcg_ast_import;
template imported()
{
import imported = imports.vcg_ast_import;
}
alias myImport = vcg_ast_import;
R!int
{
struct _R
Expand Down Expand Up @@ -137,6 +143,21 @@ mixin _d_cmain!();
}
}
}
imported!()
{
import object;
struct O
{
invariant
{
}
invariant
{
__invariant0();
}
}

}
RTInfo!(C)
{
enum immutable(void)* RTInfo = null;
Expand All @@ -161,4 +182,3 @@ RTInfo!(_R)
enum immutable(void)* RTInfo = null;

}

4 changes: 4 additions & 0 deletions tests/dmd/compilable/imports/vcg_ast_import.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
struct O
{
invariant() {}
}
4 changes: 4 additions & 0 deletions tests/dmd/compilable/test24760.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// https://issues.dlang.org/show_bug.cgi?id=24760

long f(int e = 0, uint[] optional...) => optional.length;
long f0() => f(); // compiler segfaults
5 changes: 5 additions & 0 deletions tests/dmd/compilable/vcg-ast-arraylength.d
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,9 @@ void main()

static assert(is(typeof(a.length = 0) == size_t));
static assert(is(typeof(a.length = f.length = 0) == size_t));

// https://issues.dlang.org/show_bug.cgi?id=24790
struct S { int[] payload; }
S s;
s.payload.length += 3;
}
12 changes: 12 additions & 0 deletions tests/dmd/compilable/vcg-ast.d
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ REQUIRED_ARGS: -vcg-ast -o-
PERMUTE_ARGS:
OUTPUT_FILES: compilable/vcg-ast.d.cg
TRANSFORM_OUTPUT: remove_lines(LDC_profile_instr)
EXTRA_FILES: imports/vcg_ast_import.d
TEST_OUTPUT_FILE: extra-files/vcg-ast.d.cg
*/

Expand Down Expand Up @@ -64,3 +65,14 @@ void main()
{
values!wchar_t;
}

// https://issues.dlang.org/show_bug.cgi?id=24764

import imports.vcg_ast_import;

template imported()
{
import imported = imports.vcg_ast_import;
}

alias myImport = imported!();
69 changes: 69 additions & 0 deletions tests/dmd/compilable/vcg_ast_compilable.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
REQUIRED_ARGS: -vcg-ast -o-
OUTPUT_FILES: compilable/vcg_ast_compilable.d.cg
TEST_OUTPUT:
---
=== compilable/vcg_ast_compilable.d.cg
import object;
auto binaryFun(E)(E b)
{
return 'a' == b;
}
void find(Element)(Element needle) if (is(typeof(binaryFun(needle))))
{
}
void find()(string needle)
{
}
void splitter()
{
find(3);
find("");
}
binaryFun!int
{
auto pure nothrow @nogc @safe bool binaryFun(int b)
{
return 97 == b;
}

}
find!int
{
pure nothrow @nogc @safe void find(int needle)
{
}

}
binaryFun!string
{
auto _error_ binaryFun
{
__error__
}

}
find!()
{
pure nothrow @nogc @safe void find(string needle)
{
}

}
---
*/

// https://issues.dlang.org/show_bug.cgi?id=24431
auto binaryFun(E)(E b)
{
return 'a' == b;
}

void find(Element)(Element needle) if (is(typeof(binaryFun(needle)))) { }
void find()(string needle) { }

void splitter()
{
find!int(3);
find!()("");
}
7 changes: 7 additions & 0 deletions tests/dmd/fail_compilation/diag24812.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
TEST_OUTPUT:
---
fail_compilation/diag24812.d(7): Error: enum `diag24812.Foo` enum `Foo` must have at least one member
---
*/
enum Foo {}
10 changes: 9 additions & 1 deletion tests/dmd/fail_compilation/hexstring.d
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ fail_compilation/hexstring.d(39): perhaps remove postfix `c` from hex str
fail_compilation/hexstring.d(40): Error: hex string with `dstring` type needs to be multiple of 4 bytes, not 5
fail_compilation/hexstring.d(41): Error: cannot implicitly convert expression `x"11223344"d` of type `dstring` to `immutable(float[])`
fail_compilation/hexstring.d(42): Error: cannot implicitly convert expression `x"1122"w` of type `wstring` to `immutable(ubyte[])`
fail_compilation/hexstring.d(50): Error: array cast from `string` to `S[]` is not supported at compile time
fail_compilation/hexstring.d(28): Error: cannot implicitly convert expression `x"123F"` of type `string` to `ubyte[]`
---
*/
immutable ubyte[] s0 = x"123F";
static assert(s0[0] == 0x12);
static assert(s0[1] == 0x3F);
immutable byte[] s1 = x"123F";

enum E(X) = cast(X[]) x"AABBCCDD";
static assert(E!int[0] == 0xAABBCCDD);

Expand All @@ -40,3 +40,11 @@ immutable uint[] f11 = cast(immutable uint[]) x"AABBCCDD"c;
immutable uint[] f12 = x"1122334455"d;
immutable float[] f13 = x"11223344"d;
immutable ubyte[] f14 = x"1122"w;

// https://issues.dlang.org/show_bug.cgi?id=24832
struct S
{
ushort l0, l1, l2, l3, l4, l5;
}

immutable S[] returnValues = cast(S[]) x"FFFFFFFFFFFFFFFFFFFFFFFF";
18 changes: 18 additions & 0 deletions tests/dmd/runnable/test24819.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import core.stdc.stdio;

pragma(inline, true)
double sqrt(double x)
{
static import core.math;
return core.math.sqrt(x);
}

int main()
{
double q = -5.0;
double r = q + 1.0;
double result = sqrt(-r);
//printf("%f\n", result);
assert(result == 2);
return 0;
}
Loading