Skip to content

Commit

Permalink
Merge upstream stable (#3852)
Browse files Browse the repository at this point in the history
* Merge upstream stable (dlang/dmd@58e4db9880)

* Support noreturn-typed global variables

By representing them as a dummy 0 byte.

Fixes a recent addition in dmd-testsuite's compilable/noreturn1.d.

* Disable some new tests using functions with noreturn params

See #3853.

* dmd-testsuite: Slightly adapt new dshell/dll_cxx.d

* Merge upstream stable (dlang/dmd@501d47b9ae)

* Update v1.28.0 changelog

* Fix unused-variable warning
  • Loading branch information
kinke authored Oct 19, 2021
2 parents 22e8a8c + 72224f0 commit 6a240b6
Show file tree
Hide file tree
Showing 34 changed files with 325 additions and 130 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# LDC 1.28.0 (2021-10-13)
# LDC 1.28.0 (2021-10-20)

#### Big news
- Frontend, druntime and Phobos are at version [2.098.0+](https://dlang.org/changelog/2.098.0.html). (#3821, #3839, #3844)
- Frontend, druntime and Phobos are at version [2.098.0+](https://dlang.org/changelog/2.098.0.html). (#3821, #3839, #3844, #3852)
- Windows: `-dllimport=defaultLibsOnly` (e.g., implied by `-link-defaultlib-shared -fvisibility=hidden`) doesn't require `-linkonce-templates` anymore. (#3816)
- dcompute: Add support for OpenCL image I/O. (#3835)

Expand Down
44 changes: 25 additions & 19 deletions dmd/aggregate.d
Original file line number Diff line number Diff line change
Expand Up @@ -483,31 +483,36 @@ extern (C++) abstract class AggregateDeclaration : ScopeDsymbol
* Align sizes of 0, as we may not know array sizes yet.
* Params:
* alignment = struct alignment that is in effect
* size = alignment requirement of field
* memalignsize = natural alignment of field
* poffset = pointer to offset to be aligned
*/
extern (D) static void alignmember(structalign_t alignment, uint size, uint* poffset) pure nothrow @safe
extern (D) static void alignmember(structalign_t alignment, uint memalignsize, uint* poffset) pure nothrow @safe
{
//printf("alignment = %d, size = %d, offset = %d\n",alignment,size,offset);
switch (alignment)
{
case cast(structalign_t)1:
// No alignment
break;
//debug printf("alignment = %u %d, size = %u, offset = %u\n", alignment.get(), alignment.isPack(), memalignsize, *poffset);
uint alignvalue;

case cast(structalign_t)STRUCTALIGN_DEFAULT:
if (alignment.isDefault())
{
// Alignment in Target::fieldalignsize must match what the
// corresponding C compiler's default alignment behavior is.
assert(size > 0 && !(size & (size - 1)));
*poffset = (*poffset + size - 1) & ~(size - 1);
break;

default:
alignvalue = memalignsize;
}
else if (alignment.isPack()) // #pragma pack semantics
{
alignvalue = alignment.get();
if (memalignsize < alignvalue)
alignvalue = memalignsize; // align to min(memalignsize, alignment)
}
else if (alignment.get() > 1)
{
// Align on alignment boundary, which must be a positive power of 2
assert(alignment > 0 && !(alignment & (alignment - 1)));
*poffset = (*poffset + alignment - 1) & ~(alignment - 1);
break;
alignvalue = alignment.get();
}
else
return;

assert(alignvalue > 0 && !(alignvalue & (alignvalue - 1)));
*poffset = (*poffset + alignvalue - 1) & ~(alignvalue - 1);
}

/****************************************
Expand All @@ -529,7 +534,8 @@ extern (C++) abstract class AggregateDeclaration : ScopeDsymbol
uint ofs = *nextoffset;

const uint actualAlignment =
alignment == STRUCTALIGN_DEFAULT ? memalignsize : alignment;
alignment.isDefault() || alignment.isPack() && memalignsize < alignment.get()
? memalignsize : alignment.get();

// Ensure no overflow
bool overflow;
Expand All @@ -538,7 +544,7 @@ extern (C++) abstract class AggregateDeclaration : ScopeDsymbol
if (overflow) assert(0);

// Skip no-op for noreturn without custom aligment
if (memsize != 0 || alignment != STRUCTALIGN_DEFAULT)
if (memsize != 0 || !alignment.isDefault())
alignmember(alignment, memalignsize, &ofs);

uint memoffset = ofs;
Expand Down
4 changes: 2 additions & 2 deletions dmd/aliasthis.d
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ Expression resolveAliasThis(Scope* sc, Expression e, bool gag = false, bool find
Loc loc = e.loc;
Type tthis = (e.op == TOK.type ? e.type : null);
const flags = DotExpFlag.noAliasThis | (gag ? DotExpFlag.gag : 0);
uint olderrors = gag ? global.startGagging() : 0;
e = dotExp(e.type, sc, e, ad.aliasthis.ident, flags);
if (!e || findOnly)
return e;
return gag && global.endGagging(olderrors) ? null : e;

uint olderrors = gag ? global.startGagging() : 0;
if (tthis && ad.aliasthis.sym.needThis())
{
if (e.op == TOK.variable)
Expand Down
9 changes: 3 additions & 6 deletions dmd/attrib.d
Original file line number Diff line number Diff line change
Expand Up @@ -696,12 +696,9 @@ extern (C++) final class AlignDeclaration : AttribDeclaration
{
Expressions* exps; /// Expression(s) yielding the desired alignment,
/// the largest value wins
enum structalign_t UNKNOWN = 0; /// alignment not yet computed
static assert(STRUCTALIGN_DEFAULT != UNKNOWN);

/// the actual alignment, `UNKNOWN` until it's either set to the value of `ealign`
/// or `STRUCTALIGN_DEFAULT` if `ealign` is null ( / an error ocurred)
structalign_t salign = UNKNOWN;
/// the actual alignment is Unknown until it's either set to the value of `ealign`
/// or the default if `ealign` is null ( / an error ocurred)
structalign_t salign;


extern (D) this(const ref Loc loc, Expression exp, Dsymbols* decl)
Expand Down
21 changes: 10 additions & 11 deletions dmd/clone.d
Original file line number Diff line number Diff line change
Expand Up @@ -1079,17 +1079,16 @@ private DtorDeclaration buildWindowsCppDtor(AggregateDeclaration ad, DtorDeclara
auto ftype = new TypeFunction(ParameterList(params), Type.tvoidptr, LINK.cpp, dtor.storage_class);
auto func = new DtorDeclaration(dtor.loc, dtor.loc, dtor.storage_class, Id.cppdtor);
func.type = ftype;
if (dtor.fbody)
{
const loc = dtor.loc;
auto stmts = new Statements;
auto call = new CallExp(loc, dtor, null);
call.directcall = true;
stmts.push(new ExpStatement(loc, call));
stmts.push(new ReturnStatement(loc, new CastExp(loc, new ThisExp(loc), Type.tvoidptr)));
func.fbody = new CompoundStatement(loc, stmts);
func.generated = true;
}

// Always generate the function with body, because it is not exported from DLLs.
const loc = dtor.loc;
auto stmts = new Statements;
auto call = new CallExp(loc, dtor, null);
call.directcall = true;
stmts.push(new ExpStatement(loc, call));
stmts.push(new ReturnStatement(loc, new CastExp(loc, new ThisExp(loc), Type.tvoidptr)));
func.fbody = new CompoundStatement(loc, stmts);
func.generated = true;

auto sc2 = sc.push();
sc2.stc &= ~STC.static_; // not a static destructor
Expand Down
22 changes: 17 additions & 5 deletions dmd/cparse.d
Original file line number Diff line number Diff line change
Expand Up @@ -2524,6 +2524,7 @@ final class CParser(AST) : Parser!AST
AST.Type cparseTypeName()
{
Specifier specifier;
specifier.packalign.setDefault();
auto tspec = cparseSpecifierQualifierList(LVL.global, specifier);
Identifier id;
return cparseDeclarator(DTR.xabstract, tspec, id, specifier);
Expand Down Expand Up @@ -2583,6 +2584,7 @@ final class CParser(AST) : Parser!AST
}

Specifier specifier;
specifier.packalign.setDefault();
auto tspec = cparseDeclarationSpecifiers(LVL.prototype, specifier);
if (tspec && specifier.mod & MOD.xconst)
{
Expand Down Expand Up @@ -2960,6 +2962,7 @@ final class CParser(AST) : Parser!AST
* enum gnu-attributes (opt) identifier
*/
Specifier specifier;
specifier.packalign.setDefault();
if (token.value == TOK.__attribute__)
cparseGnuAttributes(specifier);

Expand Down Expand Up @@ -2996,6 +2999,7 @@ final class CParser(AST) : Parser!AST
* https://gcc.gnu.org/onlinedocs/gcc/Enumerator-Attributes.html
*/
Specifier specifierx;
specifierx.packalign.setDefault();
cparseGnuAttributes(specifierx);
}

Expand All @@ -3013,6 +3017,7 @@ final class CParser(AST) : Parser!AST
* https://gcc.gnu.org/onlinedocs/gcc/Enumerator-Attributes.html
*/
Specifier specifierx;
specifierx.packalign.setDefault();
cparseGnuAttributes(specifierx);
}

Expand Down Expand Up @@ -3141,6 +3146,11 @@ final class CParser(AST) : Parser!AST
Specifier specifier;
specifier.packalign = this.packalign;
auto tspec = cparseSpecifierQualifierList(LVL.member, specifier);
if (tspec && specifier.mod & MOD.xconst)
{
tspec = toConst(tspec);
specifier.mod = MOD.xnone; // 'used' it
}

/* If a declarator does not follow, it is unnamed
*/
Expand Down Expand Up @@ -3214,9 +3224,6 @@ final class CParser(AST) : Parser!AST
width = cparseConstantExp();
}

if (specifier.mod & MOD.xconst)
dt = toConst(dt);

/* GNU Extensions
* struct-declarator:
* declarator gnu-attributes (opt)
Expand Down Expand Up @@ -3451,6 +3458,11 @@ final class CParser(AST) : Parser!AST
return false;
continue;

case TOK.leftCurly:
if (!skipBraces(t))
return false;
continue;

default:
any = true; // assume token was part of an a-e
t = peek(t);
Expand Down Expand Up @@ -4142,7 +4154,7 @@ final class CParser(AST) : Parser!AST
SCW scw; /// storage-class specifiers
MOD mod; /// type qualifiers
AST.Expressions* alignExps; /// alignment
structalign_t packalign = STRUCTALIGN_DEFAULT; /// #pragma pack alignment value
structalign_t packalign; /// #pragma pack alignment value
}

/***********************
Expand Down Expand Up @@ -4318,7 +4330,7 @@ final class CParser(AST) : Parser!AST
(*decls)[0] = s;
s = new AST.AlignDeclaration(s.loc, specifier.alignExps, decls);
}
else if (specifier.packalign != STRUCTALIGN_DEFAULT)
else if (!specifier.packalign.isDefault())
{
//printf(" applying packalign %d\n", cast(int)specifier.packalign);
// Wrap #pragma pack in an AlignDeclaration
Expand Down
32 changes: 31 additions & 1 deletion dmd/dcast.d
Original file line number Diff line number Diff line change
Expand Up @@ -1446,6 +1446,29 @@ MATCH implicitConvTo(Expression e, Type t)
if (tb.ty == Tpointer && e.e1.op == TOK.string_)
e.e1.accept(this);
}

override void visit(TupleExp e)
{
result = e.type.implicitConvTo(t);
if (result != MATCH.nomatch)
return;

/* If target type is a tuple of same length, test conversion of
* each expression to the corresponding type in the tuple.
*/
TypeTuple totuple = t.isTypeTuple();
if (totuple && e.exps.length == totuple.arguments.length)
{
result = MATCH.exact;
foreach (i, ex; *e.exps)
{
auto to = (*totuple.arguments)[i].type;
MATCH mi = ex.implicitConvTo(to);
if (mi < result)
result = mi;
}
}
}
}

scope ImplicitConvTo v = new ImplicitConvTo(t);
Expand Down Expand Up @@ -2182,13 +2205,20 @@ Expression castTo(Expression e, Scope* sc, Type t, Type att = null)
return;
}

/* If target type is a tuple of same length, cast each expression to
* the corresponding type in the tuple.
*/
TypeTuple totuple;
if (auto tt = t.isTypeTuple())
totuple = e.exps.length == tt.arguments.length ? tt : null;

TupleExp te = e.copy().isTupleExp();
te.e0 = e.e0 ? e.e0.copy() : null;
te.exps = e.exps.copy();
for (size_t i = 0; i < te.exps.dim; i++)
{
Expression ex = (*te.exps)[i];
ex = ex.castTo(sc, t);
ex = ex.castTo(sc, totuple ? (*totuple.arguments)[i].type : t);
(*te.exps)[i] = ex;
}
result = te;
Expand Down
2 changes: 1 addition & 1 deletion dmd/dclass.d
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ version (IN_LLVM) {} else

if (!b.sym.alignsize)
b.sym.alignsize = target.ptrsize;
alignmember(b.sym.alignsize, b.sym.alignsize, &offset);
alignmember(structalign_t(cast(ushort)b.sym.alignsize), b.sym.alignsize, &offset);
assert(bi < vtblInterfaces.dim);

BaseClass* bv = (*vtblInterfaces)[bi];
Expand Down
2 changes: 1 addition & 1 deletion dmd/declaration.d
Original file line number Diff line number Diff line change
Expand Up @@ -1982,7 +1982,7 @@ extern (C++) class TypeInfoDeclaration : VarDeclaration
storage_class = STC.static_ | STC.gshared;
visibility = Visibility(Visibility.Kind.public_);
linkage = LINK.c;
alignment = target.ptrsize;
alignment.set(target.ptrsize);
}

static TypeInfoDeclaration create(Type tinfo)
Expand Down
16 changes: 14 additions & 2 deletions dmd/dinterpret.d
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import dmd.mtype;
import dmd.printast;
import dmd.root.rmem;
import dmd.root.array;
import dmd.root.ctfloat;
import dmd.root.region;
import dmd.root.rootobject;
import dmd.statement;
Expand Down Expand Up @@ -6023,12 +6024,23 @@ version (IN_LLVM)
}
if (e.to.ty == Tsarray)
e1 = resolveSlice(e1);
if (e.to.toBasetype().ty == Tbool && e1.type.ty == Tpointer)

auto tobt = e.to.toBasetype();
if (tobt.ty == Tbool && e1.type.ty == Tpointer)
{
emplaceExp!(IntegerExp)(pue, e.loc, e1.op != TOK.null_, e.to);
result = pue.exp();
return;
}
else if (tobt.isTypeBasic() && e1.op == TOK.null_)
{
if (tobt.isintegral())
emplaceExp!(IntegerExp)(pue, e.loc, 0, e.to);
else if (tobt.isreal())
emplaceExp!(RealExp)(pue, e.loc, CTFloat.zero, e.to);
result = pue.exp();
return;
}
result = ctfeCast(pue, e.loc, e.type, e.to, e1);
}

Expand Down Expand Up @@ -6305,7 +6317,7 @@ version (IN_LLVM)
auto tsa = cast(TypeSArray)v.type;
auto len = cast(size_t)tsa.dim.toInteger();
UnionExp ue = void;
result = createBlockDuplicatedArrayLiteral(&ue, ex.loc, v.type, ex, len);
result = createBlockDuplicatedArrayLiteral(&ue, e.loc, v.type, result, len);
if (result == ue.exp())
result = ue.copy();
(*se.elements)[i] = result;
Expand Down
6 changes: 5 additions & 1 deletion dmd/dscope.d
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,11 @@ version (IN_LLVM)
return ad.salign;
}
else
return STRUCTALIGN_DEFAULT;
{
structalign_t sa;
sa.setDefault();
return sa;
}
}

/**********************************
Expand Down
4 changes: 2 additions & 2 deletions dmd/dstruct.d
Original file line number Diff line number Diff line change
Expand Up @@ -343,10 +343,10 @@ version (IN_LLVM) {} else
// Round struct size up to next alignsize boundary.
// This will ensure that arrays of structs will get their internals
// aligned properly.
if (alignment == STRUCTALIGN_DEFAULT)
if (alignment.isDefault() || alignment.isPack())
structsize = (structsize + alignsize - 1) & ~(alignsize - 1);
else
structsize = (structsize + alignment - 1) & ~(alignment - 1);
structsize = (structsize + alignment.get() - 1) & ~(alignment.get() - 1);

sizeok = Sizeok.done;

Expand Down
Loading

0 comments on commit 6a240b6

Please sign in to comment.