Skip to content

Commit

Permalink
d: Merge upstream dmd 568496d5b, druntime 178c44ff, phobos 574bf883b.
Browse files Browse the repository at this point in the history
D front-end changes:

    - Import dmd v2.098.0
    - New ImportC module for compiling preprocessed C11 code into D.
    - New -ftransition=in switch.
    - Improved handling of new 'noreturn' type.

Druntime changes:

    - Import druntime v2.098.0
    - Fix broken import in core.sys.linux.perf_event module (PR103558).

Phobos changes:

    - Import phobos v2.098.0
    - All sources are now compiled with -fpreview=fieldwise.

gcc/d/ChangeLog:

	* dmd/MERGE: Merge upstream dmd 568496d5b.
	* Make-lang.in (D_FRONTEND_OBJS): Add d/common-file.o,
	d/common-outbuffer.o, d/common-string.o, d/file_manager.o,
	d/importc.o.  Remove d/root-outbuffer.o.
	(d/common-%.o): New recipe.
	* d-builtins.cc (build_frontend_type): Update for new front-end
	interface.
	(d_build_d_type_nodes): Set noreturn_type_node.
	* d-codegen.cc (d_build_call): Don't call function if one of the
	arguments is type 'noreturn'.
	(build_vthis_function): Propagate TYPE_QUAL_VOLATILE from original
	function type.
	* d-frontend.cc (eval_builtin): Update signature.
	(getTypeInfoType): Likewise.
	(toObjFile): New function.
	* d-gimplify.cc (d_gimplify_call_expr): Always evaluate arguments from
	left to right.
	* d-lang.cc (d_handle_option): Handle OPT_ftransition_in.
	(d_parse_file): Don't generate D main if it is declared in user code.
	* d-tree.h (CALL_EXPR_ARGS_ORDERED): Remove.
	(enum d_tree_index): Add DTI_BOTTOM_TYPE.
	(noreturn_type_node): New.
	* decl.cc (apply_pragma_crt): Remove.
	(DeclVisitor::visit): Update for new front-end interface.
	(DeclVisitor::visit (PragmaDeclaration *)): Don't handle
	crt_constructor and crt_destructor pragmas.
	(DeclVisitor::visit (VarDeclaration *)): Don't generate declarations
	of type 'noreturn'.
	(DeclVisitor::visit (FuncDeclaration *)): Stop adding parameters when
	'noreturn' type has been encountered.
	(get_symbol_decl): Set DECL_STATIC_CONSTRUCTOR and
	DECL_STATIC_DESTRUCTOR on decl node if requested.
	(aggregate_initializer_decl): Update for new front-end interface.
	* expr.cc (ExprVisitor::visit (CallExp *)): Always use the 'this'
	object as the result of calling any constructor function.
	(ExprVisitor::visit): Update for new front-end interface.
	* gdc.texi (Runtime Options): Document -fmain and -ftransition=in.
	* lang.opt (ftransition=in): New option.
	* modules.cc (get_internal_fn): Update for new front-end interface.
	* types.cc (TypeVisitor::visit): Likewise.
	(TypeVisitor::visit (TypeNoreturn *)): Return noreturn_type_node.
	(TypeVisitor::visit (TypeFunction *)): Stop adding parameters when
	'notreturn' type has been encountered.  Qualify function types that
	return 'noreturn' as TYPE_QUAL_VOLATILE.

libphobos/ChangeLog:

	PR d/103558
	* libdruntime/MERGE: Merge upstream druntime 178c44ff.
	* libdruntime/Makefile.am (DRUNTIME_DSOURCES_LINUX): Add
	core/sys/linux/syscalls.d.
	(DRUNTIME_DSOURCES_OPENBSD): Add core/sys/openbsd/pthread_np.d.
	* libdruntime/Makefile.in: Regenerate.
	* src/MERGE: Merge upstream phobos 574bf883b.
	* src/Makefile.am (D_EXTRA_DFLAGS): Add -fpreview=fieldwise.
	* src/Makefile.in: Regenerate.
	* testsuite/libphobos.exceptions/assert_fail.d: Update test.
	* testsuite/libphobos.betterc/test22336.d: New test.
  • Loading branch information
ibuclaw committed Dec 8, 2021
1 parent c15aa46 commit 0fb5703
Show file tree
Hide file tree
Showing 443 changed files with 11,451 additions and 5,082 deletions.
10 changes: 9 additions & 1 deletion gcc/d/Make-lang.in
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ D_FRONTEND_OBJS = \
d/canthrow.o \
d/chkformat.o \
d/clone.o \
d/common-file.o \
d/common-outbuffer.o \
d/common-string.o \
d/compiler.o \
d/complex.o \
d/cond.o \
Expand Down Expand Up @@ -120,6 +123,7 @@ D_FRONTEND_OBJS = \
d/escape.o \
d/expression.o \
d/expressionsem.o \
d/file_manager.o \
d/foreachvar.o \
d/func.o \
d/globals.o \
Expand All @@ -131,6 +135,7 @@ D_FRONTEND_OBJS = \
d/identifier.o \
d/impcnvtab.o \
d/imphint.o \
d/importc.o \
d/init.o \
d/initsem.o \
d/inline.o \
Expand All @@ -157,7 +162,6 @@ D_FRONTEND_OBJS = \
d/root-filename.o \
d/root-hash.o \
d/root-longdouble.o \
d/root-outbuffer.o \
d/root-port.o \
d/root-region.o \
d/root-rmem.o \
Expand Down Expand Up @@ -393,6 +397,10 @@ d/%.o: d/dmd/%.d
$(DCOMPILE) $(D_INCLUDES) $<
$(DPOSTCOMPILE)

d/common-%.o: d/dmd/common/%.d
$(DCOMPILE) $(D_INCLUDES) $<
$(DPOSTCOMPILE)

d/root-%.o: d/dmd/root/%.d
$(DCOMPILE) $(D_INCLUDES) $<
$(DPOSTCOMPILE)
7 changes: 5 additions & 2 deletions gcc/d/d-builtins.cc
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ build_frontend_type (tree type)
sdecl->parent = stubmod;
sdecl->structsize = int_size_in_bytes (type);
sdecl->alignsize = TYPE_ALIGN_UNIT (type);
sdecl->alignment = STRUCTALIGN_DEFAULT;
sdecl->alignment.setDefault ();
sdecl->sizeok = Sizeok::done;
sdecl->type = (TypeStruct::create (sdecl))->addMod (mod);
sdecl->type->ctype = type;
Expand Down Expand Up @@ -275,7 +275,7 @@ build_frontend_type (tree type)
NULL);
vd->parent = sdecl;
vd->offset = tree_to_uhwi (byte_position (field));
vd->semanticRun = PASSsemanticdone;
vd->semanticRun = PASS::semanticdone;
vd->csym = field;
sdecl->members->push (vd);
sdecl->fields.push (vd);
Expand Down Expand Up @@ -856,6 +856,9 @@ d_build_d_type_nodes (void)
ireal_type_node = build_distinct_type_copy (long_double_type_node);
TYPE_IMAGINARY_FLOAT (ireal_type_node) = 1;

/* Noreturn type. */
noreturn_type_node = build_distinct_type_copy (void_type_node);

/* Calling build_ctype() links the front-end Type to the GCC node,
and sets the TYPE_NAME to the D language type. */
for (unsigned ty = 0; ty < (unsigned) TY::TMAX; ty++)
Expand Down
36 changes: 30 additions & 6 deletions gcc/d/d-codegen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2140,6 +2140,7 @@ d_build_call (TypeFunction *tf, tree callable, tree object,
/* Build the argument list for the call. */
vec <tree, va_gc> *args = NULL;
tree saved_args = NULL_TREE;
bool noreturn_call = false;

/* If this is a delegate call or a nested function being called as
a delegate, the object should not be NULL. */
Expand All @@ -2165,9 +2166,9 @@ d_build_call (TypeFunction *tf, tree callable, tree object,
}
}

size_t nparams = tf->parameterList.length ();
const size_t nparams = tf->parameterList.length ();
/* if _arguments[] is the first argument. */
size_t varargs = tf->isDstyleVariadic ();
const size_t varargs = tf->isDstyleVariadic ();

/* Assumes arguments->length <= formal_args->length if (!tf->varargs). */
for (size_t i = 0; i < arguments->length; ++i)
Expand Down Expand Up @@ -2206,6 +2207,11 @@ d_build_call (TypeFunction *tf, tree callable, tree object,
build_address (targ));
}

/* Type `noreturn` is a terminator, as no other arguments can possibly
be evaluated after it. */
if (TREE_TYPE (targ) == noreturn_type_node)
noreturn_call = true;

vec_safe_push (args, targ);
}
}
Expand All @@ -2217,13 +2223,27 @@ d_build_call (TypeFunction *tf, tree callable, tree object,
saved_args = compound_expr (callee, saved_args);
}

/* If we saw a `noreturn` parameter, any unreachable argument evaluations
after it are discarded, as well as the function call itself. */
if (noreturn_call)
{
if (TREE_SIDE_EFFECTS (callee))
saved_args = compound_expr (callee, saved_args);

tree arg;
unsigned int ix;

FOR_EACH_VEC_SAFE_ELT (args, ix, arg)
saved_args = compound_expr (saved_args, arg);

/* Add a stub result type for the expression. */
tree result = build_zero_cst (TREE_TYPE (ctype));
return compound_expr (saved_args, result);
}

tree result = build_call_vec (TREE_TYPE (ctype), callee, args);
SET_EXPR_LOCATION (result, input_location);

/* Enforce left to right evaluation. */
if (tf->linkage == LINK::d)
CALL_EXPR_ARGS_ORDERED (result) = 1;

result = maybe_expand_intrinsic (result);

/* Return the value in a temporary slot so that it can be evaluated
Expand Down Expand Up @@ -2296,6 +2316,10 @@ build_vthis_function (tree basetype, tree type)
TYPE_ARG_TYPES (type));
tree fntype = build_function_type (TREE_TYPE (type), argtypes);

/* Copy volatile qualifiers from the original function type. */
if (TYPE_QUALS (type) & TYPE_QUAL_VOLATILE)
fntype = build_qualified_type (fntype, TYPE_QUAL_VOLATILE);

if (RECORD_OR_UNION_TYPE_P (basetype))
TYPE_METHOD_BASETYPE (fntype) = TYPE_MAIN_VARIANT (basetype);
else
Expand Down
11 changes: 9 additions & 2 deletions gcc/d/d-frontend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ along with GCC; see the file COPYING3. If not see
#include "diagnostic.h"

#include "d-tree.h"
#include "d-frontend.h"

/* Implements back-end specific interfaces used by the frontend. */

Expand All @@ -51,7 +52,7 @@ isBuiltin (FuncDeclaration *fd)
Return result; NULL if cannot evaluate it. */

Expression *
eval_builtin (Loc loc, FuncDeclaration *fd, Expressions *arguments)
eval_builtin (const Loc &loc, FuncDeclaration *fd, Expressions *arguments)
{
if (fd->builtin == BUILTIN::unimp)
return NULL;
Expand All @@ -78,10 +79,16 @@ eval_builtin (Loc loc, FuncDeclaration *fd, Expressions *arguments)
/* Build and return typeinfo type for TYPE. */

Type *
getTypeInfoType (Loc loc, Type *type, Scope *sc)
getTypeInfoType (const Loc &loc, Type *type, Scope *sc)
{
gcc_assert (type->ty != TY::Terror);
check_typeinfo_type (loc, sc);
create_typeinfo (type, sc ? sc->_module->importedFrom : NULL);
return type->vtinfo->type;
}

void
toObjFile (Dsymbol *ds, bool)
{
build_decl_tree (ds);
}
65 changes: 30 additions & 35 deletions gcc/d/d-gimplify.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,52 +120,47 @@ d_gimplify_addr_expr (tree *expr_p)
static gimplify_status
d_gimplify_call_expr (tree *expr_p, gimple_seq *pre_p)
{
if (CALL_EXPR_ARGS_ORDERED (*expr_p))
{
/* Strictly evaluate all arguments from left to right. */
int nargs = call_expr_nargs (*expr_p);
location_t loc = EXPR_LOC_OR_LOC (*expr_p, input_location);
/* Strictly evaluate all arguments from left to right. */
int nargs = call_expr_nargs (*expr_p);
location_t loc = EXPR_LOC_OR_LOC (*expr_p, input_location);

/* No need to enforce evaluation order if only one argument. */
if (nargs < 2)
return GS_UNHANDLED;
/* No need to enforce evaluation order if only one argument. */
if (nargs < 2)
return GS_UNHANDLED;

/* Or if all arguments are already free of side-effects. */
bool has_side_effects = false;
for (int i = 0; i < nargs; i++)
/* Or if all arguments are already free of side-effects. */
bool has_side_effects = false;
for (int i = 0; i < nargs; i++)
{
if (TREE_SIDE_EFFECTS (CALL_EXPR_ARG (*expr_p, i)))
{
if (TREE_SIDE_EFFECTS (CALL_EXPR_ARG (*expr_p, i)))
{
has_side_effects = true;
break;
}
has_side_effects = true;
break;
}
}

if (!has_side_effects)
return GS_UNHANDLED;

/* Leave the last argument for gimplify_call_expr. */
for (int i = 0; i < nargs - 1; i++)
{
tree new_arg = CALL_EXPR_ARG (*expr_p, i);
if (!has_side_effects)
return GS_UNHANDLED;

/* If argument has a side-effect, gimplify_arg will handle it. */
if (gimplify_arg (&new_arg, pre_p, loc) == GS_ERROR)
return GS_ERROR;
/* Leave the last argument for gimplify_call_expr. */
for (int i = 0; i < nargs - 1; i++)
{
tree new_arg = CALL_EXPR_ARG (*expr_p, i);

/* Even if an argument itself doesn't have any side-effects, it
might be altered by another argument in the list. */
if (new_arg == CALL_EXPR_ARG (*expr_p, i)
&& !really_constant_p (new_arg))
new_arg = get_formal_tmp_var (new_arg, pre_p);
/* If argument has a side-effect, gimplify_arg will handle it. */
if (gimplify_arg (&new_arg, pre_p, loc) == GS_ERROR)
return GS_ERROR;

CALL_EXPR_ARG (*expr_p, i) = new_arg;
}
/* Even if an argument itself doesn't have any side-effects, it
might be altered by another argument in the list. */
if (new_arg == CALL_EXPR_ARG (*expr_p, i)
&& !really_constant_p (new_arg))
new_arg = get_formal_tmp_var (new_arg, pre_p);

return GS_OK;
CALL_EXPR_ARG (*expr_p, i) = new_arg;
}

return GS_UNHANDLED;
return GS_OK;
}

/* Gimplify an UNSIGNED_RSHIFT_EXPR node. */
Expand Down
16 changes: 16 additions & 0 deletions gcc/d/d-lang.cc
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,7 @@ d_handle_option (size_t scode, const char *arg, HOST_WIDE_INT value,
case OPT_ftransition_all:
global.params.vfield = value;
global.params.vgc = value;
global.params.vin = value;
global.params.vmarkdown= value;
global.params.vtls = value;
break;
Expand All @@ -682,6 +683,10 @@ d_handle_option (size_t scode, const char *arg, HOST_WIDE_INT value,
global.params.vfield = value;
break;

case OPT_ftransition_in:
global.params.vin = value;
break;

case OPT_ftransition_nogc:
global.params.vgc = value;
break;
Expand Down Expand Up @@ -1176,6 +1181,14 @@ d_parse_file (void)
{
Module *m = modules[i];

/* If this is the `__main` module, check that `D main` hasn't already
been declared in user code before running semantic on it. */
if (m == main_module && global.hasMainFunction)
{
modules.remove (i);
continue;
}

if (global.params.verbose)
message ("semantic %s", m->toChars ());

Expand Down Expand Up @@ -1357,6 +1370,9 @@ d_parse_file (void)
for (size_t i = 0; i < modules.length; i++)
{
Module *m = modules[i];

/* Skip generating code for header files, or when the module wasn't
specified by `-fonly=`. */
if ((m->isHdrFile && m != main_module)
|| (d_option.fonly && m != Module::rootModule))
continue;
Expand Down
9 changes: 3 additions & 6 deletions gcc/d/d-tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ typedef Array <Expression *> Expressions;

/* Usage of TREE_LANG_FLAG_?:
0: METHOD_CALL_EXPR
1: CALL_EXPR_ARGS_ORDERED (in CALL_EXPR).
Usage of TYPE_LANG_FLAG_?:
0: TYPE_SHARED
Expand Down Expand Up @@ -351,11 +350,6 @@ lang_tree_node
#define METHOD_CALL_EXPR(NODE) \
(TREE_LANG_FLAG_0 (NODE))

/* True if all arguments in a call expression should be evaluated in the
order they are given (left to right). */
#define CALL_EXPR_ARGS_ORDERED(NODE) \
(TREE_LANG_FLAG_1 (CALL_EXPR_CHECK (NODE)))

/* True if the type was declared 'shared'. */
#define TYPE_SHARED(NODE) \
(TYPE_LANG_FLAG_0 (NODE))
Expand Down Expand Up @@ -430,6 +424,7 @@ enum d_tree_index

DTI_ARRAY_TYPE,
DTI_NULL_ARRAY,
DTI_BOTTOM_TYPE,

DTI_MAX
};
Expand Down Expand Up @@ -465,6 +460,8 @@ extern GTY(()) tree d_global_trees[DTI_MAX];
#define array_type_node d_global_trees[DTI_ARRAY_TYPE]
/* Null initializer for dynamic arrays. */
#define null_array_node d_global_trees[DTI_NULL_ARRAY]
/* The bottom type, referred to as `noreturn` in code. */
#define noreturn_type_node d_global_trees[DTI_BOTTOM_TYPE]

/* A prefix for internal variables, which are not user-visible. */
#if !defined (NO_DOT_IN_LABEL)
Expand Down
Loading

0 comments on commit 0fb5703

Please sign in to comment.