Skip to content

Commit

Permalink
d: Merge upstream dmd 3b808e838, druntime 483bc129, phobos f89dc217a
Browse files Browse the repository at this point in the history
D front-end changes:

 - Explicit package visibility attribute is now always applied to
   introducing scopes.

 - Added `__traits(totype, string)' to convert mangled type string to an
   existing type.

 - Printf-like and scanf-like functions are now detected by prefixing
   them with `pragma(printf)' for printf-like functions or
   `pragma(scanf)' for scanf-like functions.

 - Added `__c_wchar_t', `__c_complex_float', `__c_complex_double', and
   `__c_complex_real' types for interfacing with C and C++.

 - Template alias parameters can now be instantiated with basic types,
   such as `int` or `void function()`.

 - Mixins can now be used as types in the form `mixin(string) var'.

 - Mixin expressions can take an argument list, same as `pragma(msg)'.

 - Implement DIP1034, add `typeof(*null)' types to represent `noreturn'.

 - `pragma(msg)' can print expressions of type `void'.

 - It is now an error to use private variables selectively imported from
   other modules.  Due to a bug, some imported private members were
   visible from other modules, violating the specification.

 - Added new syntax to declare an alias to a function type using the
   `alias' syntax based on the assignment operator.

 - Function literals can now return a value by reference.

Phobos changes:

 - Synchronize C bindings with the latest port fixes in upstream druntime.

 - Added alias for a `noreturn' type in object.d

 - Make use of the new `pragma(printf)' and `pragma(scanf)' pragmas, fix
   all code that got flagged as being incorrect.

 - Fixed code that relied on bugs in the D import package system.

Reviewed-on: dlang/dmd#12339
	     dlang/druntime#3422
	     dlang/phobos#7932

gcc/d/ChangeLog:

	* dmd/MERGE: Merge upstream dmd 3b808e838.
	* Make-lang.in (D_FRONTEND_OBJS): Add d/chkformat.o.
	* d-codegen.cc (build_struct_literal): Handle special enums.
	* d-convert.cc (convert_expr): Handle noreturn type.
	(convert_for_condition): Likewise.
	* d-target.cc (Target::_init): Set type for wchar_t.
	(TargetCPP::derivedClassOffset): New method.
	(Target::libraryObjectMonitors): New method.
	* decl.cc (get_symbol_decl): Set TREE_THIS_VOLATILE for functions of
	type noreturn.
	* toir.cc (IRVisitor::visit (ReturnStatement *)): Handle returning
	noreturn types.
	* types.cc (TypeVisitor::visit (TypeNoreturn *)): New method.
	(TypeVisitor::visit (TypeEnum *)): Handle special enums.

libphobos/ChangeLog:

	* libdruntime/MERGE: Merge upstream druntime 483bc129.
	* libdruntime/Makefile.am (DRUNTIME_DSOURCES_DARWIN): Add
	core/sys/darwin/fcntl.d.
	(DRUNTIME_DSOURCES_OPENBSD): Add core/sys/openbsd/unistd.d.
	(DRUNTIME_DSOURCES_WINDOWS): Add core/sys/windows/stdc/malloc.d.
	* libdruntime/Makefile.in: Regenerate.
	* src/MERGE: Merge upstream phobos f89dc217a.
	* src/Makefile.am (PHOBOS_DSOURCES): Add std/regex/internal/tests2.d.
	* src/Makefile.in: Regenerate.
	* testsuite/libphobos.exceptions/chain.d: Fix format arguments.
	* testsuite/libphobos.exceptions/line_trace.d: Likewise.
  • Loading branch information
ibuclaw committed Apr 3, 2021
1 parent ba0f690 commit 5a0aa60
Show file tree
Hide file tree
Showing 191 changed files with 7,657 additions and 4,100 deletions.
1 change: 1 addition & 0 deletions gcc/d/Make-lang.in
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ D_FRONTEND_OBJS = \
d/blockexit.o \
d/canthrow.o \
d/checkedint.o \
d/chkformat.o \
d/clone.o \
d/cond.o \
d/constfold.o \
Expand Down
8 changes: 8 additions & 0 deletions gcc/d/d-codegen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1153,6 +1153,14 @@ build_struct_literal (tree type, vec <constructor_elt, va_gc> *init)
if (vec_safe_is_empty (init))
return build_constructor (type, NULL);

/* Struct literals can be seen for special enums representing `_Complex',
make sure to reinterpret the literal as the correct type. */
if (COMPLEX_FLOAT_TYPE_P (type))
{
gcc_assert (vec_safe_length (init) == 2);
return build_complex (type, (*init)[0].value, (*init)[1].value);
}

vec <constructor_elt, va_gc> *ve = NULL;
HOST_WIDE_INT offset = 0;
bool constant_p = true;
Expand Down
14 changes: 13 additions & 1 deletion gcc/d/d-convert.cc
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,9 @@ convert_expr (tree exp, Type *etype, Type *totype)
break;

case Tnull:
/* Casting from typeof(null) is represented as all zeros. */
case Tnoreturn:
/* Casting from `typeof(null)' for `null' expressions, or `typeof(*null)'
for `noreturn' expressions is represented as all zeros. */
result = build_typeof_null_value (totype);

/* Make sure the expression is still evaluated if necessary. */
Expand Down Expand Up @@ -742,6 +744,16 @@ convert_for_condition (tree expr, Type *type)
break;
}

case Tnoreturn:
/* Front-end allows conditionals that never return, represent the
conditional result value as all zeros. */
result = build_zero_cst (d_bool_type);

/* Make sure the expression is still evaluated if necessary. */
if (TREE_SIDE_EFFECTS (expr))
result = compound_expr (expr, result);
break;

default:
result = expr;
break;
Expand Down
28 changes: 28 additions & 0 deletions gcc/d/d-target.cc
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,15 @@ Target::_init (const Param &)
this->c.longsize = int_size_in_bytes (long_integer_type_node);
this->c.long_doublesize = int_size_in_bytes (long_double_type_node);

/* Define what type to use for wchar_t. We don't want to support wide
characters less than "short" in D. */
if (WCHAR_TYPE_SIZE == 32)
this->c.twchar_t = Type::basic[Tdchar];
else if (WCHAR_TYPE_SIZE == 16)
this->c.twchar_t = Type::basic[Twchar];
else
sorry ("D does not support wide characters on this target.");

/* Set-up target C++ ABI. */
this->cpp.reverseOverloads = false;
this->cpp.exceptions = true;
Expand Down Expand Up @@ -417,6 +426,15 @@ TargetCPP::fundamentalType (const Type *, bool &)
return false;
}

/* Get the starting offset position for fields of an `extern(C++)` class
that is derived from the given BASE_CLASS. */

unsigned
TargetCPP::derivedClassOffset(ClassDeclaration *base_class)
{
return base_class->structsize;
}

/* Return the default system linkage for the target. */

LINK
Expand Down Expand Up @@ -517,3 +535,13 @@ Target::getTargetInfo (const char *key, const Loc &loc)

return NULL;
}

/**
* Returns true if the implementation for object monitors is always defined
* in the D runtime library (rt/monitor_.d). */

bool
Target::libraryObjectMonitors (FuncDeclaration *, Statement *)
{
return true;
}
4 changes: 4 additions & 0 deletions gcc/d/decl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1277,6 +1277,10 @@ get_symbol_decl (Declaration *decl)
if (decl->storage_class & STCfinal)
DECL_FINAL_P (decl->csym) = 1;

/* Function is of type `noreturn' or `typeof(*null)'. */
if (fd->type->nextOf ()->ty == Tnoreturn)
TREE_THIS_VOLATILE (decl->csym) = 1;

/* Check whether this function is expanded by the frontend. */
DECL_INTRINSIC_CODE (decl->csym) = INTRINSIC_NONE;
maybe_set_intrinsic (fd);
Expand Down
2 changes: 1 addition & 1 deletion gcc/d/dmd/MERGE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
a3c9bf422e7ff54d45846b8c577ee82da4234db1
3b808e838bb00f527eb4ed5281cd985756237b8f

The first line of this file holds the git revision number of the last
merge done from the dlang/dmd repository.
39 changes: 31 additions & 8 deletions gcc/d/dmd/attrib.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ Scope *AttribDeclaration::createNewScope(Scope *sc,
if (stc != sc->stc ||
linkage != sc->linkage ||
cppmangle != sc->cppmangle ||
!protection.isSubsetOf(sc->protection) ||
explicitProtection != sc->explicitProtection ||
!(protection == sc->protection) ||
aligndecl != sc->aligndecl ||
inlining != sc->inlining)
{
Expand Down Expand Up @@ -552,10 +552,21 @@ void ProtDeclaration::addMember(Scope *sc, ScopeDsymbol *sds)
if (protection.kind == Prot::package_ && protection.pkg && sc->_module)
{
Module *m = sc->_module;
Package* pkg = m->parent ? m->parent->isPackage() : NULL;
if (!pkg || !protection.pkg->isAncestorPackageOf(pkg))
error("does not bind to one of ancestor packages of module `%s`",
m->toPrettyChars(true));

// While isAncestorPackageOf does an equality check, the fix for issue 17441 adds a check to see if
// each package's .isModule() properites are equal.
//
// Properties generated from `package(foo)` i.e. protection.pkg have .isModule() == null.
// This breaks package declarations of the package in question if they are declared in
// the same package.d file, which _do_ have a module associated with them, and hence a non-null
// isModule()
if (!m->isPackage() || !protection.pkg->ident->equals(m->isPackage()->ident))
{
Package* pkg = m->parent ? m->parent->isPackage() : NULL;
if (!pkg || !protection.pkg->isAncestorPackageOf(pkg))
error("does not bind to one of ancestor packages of module `%s`",
m->toPrettyChars(true));
}
}

return AttribDeclaration::addMember(sc, sds);
Expand Down Expand Up @@ -795,6 +806,18 @@ Scope *PragmaDeclaration::newScope(Scope *sc)
sc->protection, sc->explicitProtection, sc->aligndecl,
inlining);
}
if (ident == Id::printf || ident == Id::scanf)
{
Scope *sc2 = sc->push();

if (ident == Id::printf)
// Override previous setting, never let both be set
sc2->flags = (sc2->flags & ~SCOPEscanf) | SCOPEprintf;
else
sc2->flags = (sc2->flags & ~SCOPEprintf) | SCOPEscanf;

return sc2;
}
return sc;
}

Expand Down Expand Up @@ -1164,20 +1187,20 @@ void ForwardingAttribDeclaration::addMember(Scope *sc, ScopeDsymbol *sds)

// These are mixin declarations, like mixin("int x");

CompileDeclaration::CompileDeclaration(Loc loc, Expression *exp)
CompileDeclaration::CompileDeclaration(Loc loc, Expressions *exps)
: AttribDeclaration(NULL)
{
//printf("CompileDeclaration(loc = %d)\n", loc.linnum);
this->loc = loc;
this->exp = exp;
this->exps = exps;
this->scopesym = NULL;
this->compiled = false;
}

Dsymbol *CompileDeclaration::syntaxCopy(Dsymbol *)
{
//printf("CompileDeclaration::syntaxCopy('%s')\n", toChars());
return new CompileDeclaration(loc, exp->syntaxCopy());
return new CompileDeclaration(loc, Expression::arraySyntaxCopy(exps));
}

void CompileDeclaration::addMember(Scope *, ScopeDsymbol *sds)
Expand Down
4 changes: 2 additions & 2 deletions gcc/d/dmd/attrib.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,12 @@ class ForwardingAttribDeclaration : public AttribDeclaration
class CompileDeclaration : public AttribDeclaration
{
public:
Expression *exp;
Expressions *exps;

ScopeDsymbol *scopesym;
bool compiled;

CompileDeclaration(Loc loc, Expression *exp);
CompileDeclaration(Loc loc, Expressions *exps);
Dsymbol *syntaxCopy(Dsymbol *s);
void addMember(Scope *sc, ScopeDsymbol *sds);
void setScope(Scope *sc);
Expand Down
2 changes: 2 additions & 0 deletions gcc/d/dmd/blockexit.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ int blockExit(Statement *s, FuncDeclaration *func, bool mustNotThrow)
return;
}
}
if (s->exp->type->toBasetype()->isTypeNoreturn())
result = BEhalt;
if (canThrow(s->exp, func, mustNotThrow))
result |= BEthrow;
}
Expand Down
Loading

0 comments on commit 5a0aa60

Please sign in to comment.