Skip to content
This repository has been archived by the owner on Jun 20, 2019. It is now read-only.

Set more call attributes and fnspec on all library functions. #617

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
47 changes: 44 additions & 3 deletions gcc/d/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,7 +1,43 @@
2018-02-10 Iain Buclaw <[email protected]>
2018-02-12 Iain Buclaw <[email protected]>

* expr.cc (ExprVisitor::AssertExp): Use builtin expect to mark assert
condition as being likely true.
* runtime.cc (build_libcall_decl): Update signature, handle "fn spec"
attribute.
* runtime.def (DEF_D_RUNTIME): Add fnspec argument. All callers
updated.

2018-02-11 Iain Buclaw <[email protected]>

* runtime.def (DYNAMIC_CAST, INTERFACE_CAST): Set ECF_CONST.
(ARRAYCAST, AAINX, AAGETRVALUEX): Likewise.
(SWITCH_STRING, SWITCH_USTRING, SWITCH_DSTRING): Likewise.

2018-02-11 Iain Buclaw <[email protected]>

* runtime.def (BEGIN_CATCH): Set ECF_NOTHROW.

2018-02-11 Iain Buclaw <[email protected]>

* runtime.def (NEWCLASS): Set ECF_LEAF.
(DYNAMIC_CAST, INTERFACE_CAST): Likewise.
(NEWITEMT, NEWITEMIT, DELMEMORY): Likewise.
(NEWARRAYT, NEWARRAYIT): Likewise.
(NEWARRAYMTX, NEWARRAYMITX): Likewise.
(ARRAYLITERALTX, ARRAYCAST): Likewise.
(ALLOCMEMORY, ARRAYCOPY): Likewise.
(ARRAYAPPENDCD, ARRAYAPPENDWD): Likewise.
(AAINX, AAGETRVALUEX, AADELX): Likewise.
(SWITCH_STRING, SWITCH_USTRING, SWITCH_DSTRING): Likewise.

2018-02-11 Iain Buclaw <[email protected]>

* d-codegen.cc (d_save_expr): Always stabilize CALL_EXPR.
* runtime.def (ALLOCMEMORY): Set ECF_PURE.

2018-02-11 Iain Buclaw <[email protected]>

* runtime.def (ASSERT, ASSERT_MSG): Set ECF_COLD and ECF_LEAF flags.
(UNITTEST, UNITTEST_MSG): Likewise.
(ARRAY_BOUNDS, SWITCH_ERROR): Likewise.

2018-02-11 Iain Buclaw <[email protected]>

Expand All @@ -10,6 +46,11 @@
(fmake-deps, fmake-mdeps): Likewise.
(fin, fout, fXf): Likewise.

2018-02-10 Iain Buclaw <[email protected]>

* expr.cc (ExprVisitor::AssertExp): Use builtin expect to mark assert
condition as being likely true.

2018-01-28 Iain Buclaw <[email protected]>

* gdc.texi (Runtime Options): Remove deprecated -fproperty option.
Expand Down
9 changes: 7 additions & 2 deletions gcc/d/d-codegen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -506,9 +506,14 @@ lvalue_p (tree exp)
tree
d_save_expr (tree exp)
{
if (TREE_SIDE_EFFECTS (exp))
/* Always consider call expressions as a side effect, even if the function
being called is pure. */
tree t = exp;
STRIP_NOPS (t);

if (TREE_SIDE_EFFECTS (t) || TREE_CODE (t) == CALL_EXPR)
{
if (lvalue_p (exp))
if (lvalue_p (t))
return stabilize_reference (exp);

return save_expr (exp);
Expand Down
2 changes: 1 addition & 1 deletion gcc/d/d-tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ extern GTY(()) tree d_global_trees[DTI_MAX];

enum libcall_fn
{
#define DEF_D_RUNTIME(CODE, N, T, P, F) LIBCALL_ ## CODE,
#define DEF_D_RUNTIME(CODE, N, T, P, F, S) LIBCALL_ ## CODE,

#include "runtime.def"

Expand Down
17 changes: 14 additions & 3 deletions gcc/d/runtime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ along with GCC; see the file COPYING3. If not see
#include "tree.h"
#include "fold-const.h"
#include "stringpool.h"
#include "attribs.h"

#include "d-tree.h"
#include "d-frontend.h"
Expand Down Expand Up @@ -214,7 +215,7 @@ get_libcall_type (libcall_type type)

static tree
build_libcall_decl (const char *name, libcall_type return_type,
int flags, int nparams, ...)
int flags, const char *fnspec, int nparams, ...)
{
tree *args = XALLOCAVEC (tree, nparams);
bool varargs = false;
Expand Down Expand Up @@ -248,6 +249,15 @@ build_libcall_decl (const char *name, libcall_type return_type,
else
fntype = build_function_type_array (tret, nparams, args);

if (fnspec)
{
tree attr_args = build_tree_list (NULL_TREE,
build_string (strlen (fnspec), fnspec));
tree attrs = tree_cons (get_identifier ("fn spec"),
attr_args, TYPE_ATTRIBUTES (fntype));
fntype = build_type_attribute_variant (fntype, attrs);
}

tree decl = build_decl (UNKNOWN_LOCATION, FUNCTION_DECL,
get_identifier (name), fntype);
DECL_EXTERNAL (decl) = 1;
Expand Down Expand Up @@ -276,9 +286,10 @@ get_libcall (libcall_fn libcall)

switch (libcall)
{
#define DEF_D_RUNTIME(CODE, NAME, TYPE, PARAMS, FLAGS) \
#define DEF_D_RUNTIME(CODE, NAME, TYPE, PARAMS, FLAGS, FNSPEC) \
case LIBCALL_ ## CODE: \
libcall_decls[libcall] = build_libcall_decl (NAME, TYPE, FLAGS, PARAMS); \
libcall_decls[libcall] = build_libcall_decl (NAME, TYPE, FLAGS, FNSPEC, \
PARAMS); \
break;

#include "runtime.def"
Expand Down
Loading