aboutsummaryrefslogtreecommitdiff
path: root/gcc/d/typeinfo.cc
diff options
context:
space:
mode:
authorIain Buclaw <ibuclaw@gdcproject.org>2019-04-23 20:08:46 +0000
committerIain Buclaw <ibuclaw@gcc.gnu.org>2019-04-23 20:08:46 +0000
commitc0aebc60b2ac19816f0431241d8f7203e60afb01 (patch)
tree4eec38d1f02e2a59de0dc908c56593c54d0d3960 /gcc/d/typeinfo.cc
parent32efff9f947137bb6f6bf47a846e3bf8a162170a (diff)
downloadgcc-c0aebc60b2ac19816f0431241d8f7203e60afb01.zip
gcc-c0aebc60b2ac19816f0431241d8f7203e60afb01.tar.gz
gcc-c0aebc60b2ac19816f0431241d8f7203e60afb01.tar.bz2
d: Add support for compiling without libphobos library.
Merges upstream dmd 3b3dca8be Reviewed-on: https://github.com/dlang/dmd/pull/9678 gcc/d/ChangeLog: 2019-04-23 Iain Buclaw <ibuclaw@gdcproject.org> * d-builtins.cc (d_init_versions): Add D_BetterC, D_ModuleInfo, D_Exceptions, D_TypeInfo as predefined version conditions. * d-codegen.cc (build_bounds_condition): Generate trap if D asserts are turned off. * d-frontend.cc (getTypeInfoType): Add error when -fno-rtti is set. * d-lang.cc (d_init_options): Initialize new front-end options. (d_handle_option): Handle -fdruntime, -fexceptions, and -frtti. (d_post_options): Turn off D runtime features if -fno-druntime is set. * d-spec.cc (lang_specific_driver): Handle -fdruntime. * d-tree.h (have_typeinfo_p): Add prototype. (build_typeinfo): Update prototype. * decl.cc (DeclVisitor::visit(StructDeclaration)): Create typeinfo only if TypeInfo exists. (DeclVisitor::visit(ClassDeclaration)): Likewise. (DeclVisitor::visit(InterfaceDeclaration)): Likewise. (DeclVisitor::visit(EnumDeclaration)): Likewise. * expr.cc: Update all calls to build_typeinfo. * gdc.texi (Runtime Options): Document -fdruntime and -frtti. * lang.opt: Add -fdruntime and -frtti. * modules.cc (build_module_tree): Create module info only if ModuleInfo exists. * toir.cc (IRVisitor::visit(ThrowStatement)): Update test for -fno-exceptions. * typeinfo.cc (create_tinfo_types): Build internal typeinfo classes only if Object exists. (have_typeinfo_p): New function. (class TypeInfoVisitor): Update all calls to build_typeinfo. (build_typeinfo): Add error when -fno-rtti is set. gcc/testsuite/ChangeLog: 2019-04-23 Iain Buclaw <ibuclaw@gdcproject.org> * gdc.test/fail_compilation/fail2456.d: New test. * gdc.test/fail_compilation/test18312.d: New test. * gdc.test/gdc-test.exp (gdc-convert-args): Handle -betterC. From-SVN: r270518
Diffstat (limited to 'gcc/d/typeinfo.cc')
-rw-r--r--gcc/d/typeinfo.cc78
1 files changed, 60 insertions, 18 deletions
diff --git a/gcc/d/typeinfo.cc b/gcc/d/typeinfo.cc
index dac66ac..ffa7e23 100644
--- a/gcc/d/typeinfo.cc
+++ b/gcc/d/typeinfo.cc
@@ -227,6 +227,10 @@ create_tinfo_types (Module *mod)
ptr_type_node, d_uint_type, ptr_type_node,
array_type_node, ptr_type_node, ptr_type_node, NULL);
+ /* If there's no Object class defined, then neither can TypeInfo be. */
+ if (ClassDeclaration::object == NULL)
+ return;
+
/* Create all frontend TypeInfo classes declarations. We rely on all
existing, even if only just as stubs. */
if (!Type::dtypeinfo)
@@ -289,6 +293,27 @@ create_tinfo_types (Module *mod)
ClassDeclaration::object);
}
+/* Return true if TypeInfo class TINFO is available in the runtime library. */
+
+bool
+have_typeinfo_p (ClassDeclaration *tinfo)
+{
+ /* Run-time typeinfo disabled on command line. */
+ if (!global.params.useTypeInfo)
+ return false;
+
+ /* Can't layout TypeInfo if type is not declared, or is an opaque
+ declaration in the object module. */
+ if (!tinfo || !tinfo->members)
+ return false;
+
+ /* Typeinfo is compiler-generated. */
+ if (tinfo->storage_class & STCtemp)
+ return false;
+
+ return true;
+}
+
/* Implements the visitor interface to build the TypeInfo layout of all
TypeInfoDeclaration AST classes emitted from the D Front-end.
All visit methods accept one parameter D, which holds the frontend AST
@@ -338,7 +363,12 @@ class TypeInfoVisitor : public Visitor
void layout_base (ClassDeclaration *cd)
{
gcc_assert (cd != NULL);
- this->layout_field (build_address (get_vtable_decl (cd)));
+
+ if (have_typeinfo_p (cd))
+ this->layout_field (build_address (get_vtable_decl (cd)));
+ else
+ this->layout_field (null_pointer_node);
+
this->layout_field (null_pointer_node);
}
@@ -490,7 +520,7 @@ public:
this->layout_base (Type::typeinfoconst);
/* TypeInfo for the mutable type. */
- this->layout_field (build_typeinfo (tm));
+ this->layout_field (build_typeinfo (d->loc, tm));
}
/* Layout of TypeInfo_Immutable is:
@@ -507,7 +537,7 @@ public:
this->layout_base (Type::typeinfoinvariant);
/* TypeInfo for the mutable type. */
- this->layout_field (build_typeinfo (tm));
+ this->layout_field (build_typeinfo (d->loc, tm));
}
/* Layout of TypeInfo_Shared is:
@@ -524,7 +554,7 @@ public:
this->layout_base (Type::typeinfoshared);
/* TypeInfo for the unshared type. */
- this->layout_field (build_typeinfo (tm));
+ this->layout_field (build_typeinfo (d->loc, tm));
}
/* Layout of TypeInfo_Inout is:
@@ -541,7 +571,7 @@ public:
this->layout_base (Type::typeinfowild);
/* TypeInfo for the mutable type. */
- this->layout_field (build_typeinfo (tm));
+ this->layout_field (build_typeinfo (d->loc, tm));
}
/* Layout of TypeInfo_Enum is:
@@ -561,7 +591,7 @@ public:
this->layout_base (Type::typeinfoenum);
/* TypeInfo for enum members. */
- tree memtype = (ed->memtype) ? build_typeinfo (ed->memtype)
+ tree memtype = (ed->memtype) ? build_typeinfo (d->loc, ed->memtype)
: null_pointer_node;
this->layout_field (memtype);
@@ -593,7 +623,7 @@ public:
this->layout_base (Type::typeinfopointer);
/* TypeInfo for pointer-to type. */
- this->layout_field (build_typeinfo (ti->next));
+ this->layout_field (build_typeinfo (d->loc, ti->next));
}
/* Layout of TypeInfo_Array is:
@@ -610,7 +640,7 @@ public:
this->layout_base (Type::typeinfoarray);
/* TypeInfo for array of type. */
- this->layout_field (build_typeinfo (ti->next));
+ this->layout_field (build_typeinfo (d->loc, ti->next));
}
/* Layout of TypeInfo_StaticArray is:
@@ -628,7 +658,7 @@ public:
this->layout_base (Type::typeinfostaticarray);
/* TypeInfo for array of type. */
- this->layout_field (build_typeinfo (ti->next));
+ this->layout_field (build_typeinfo (d->loc, ti->next));
/* Static array length. */
this->layout_field (size_int (ti->dim->toInteger ()));
@@ -649,10 +679,10 @@ public:
this->layout_base (Type::typeinfoassociativearray);
/* TypeInfo for value of type. */
- this->layout_field (build_typeinfo (ti->next));
+ this->layout_field (build_typeinfo (d->loc, ti->next));
/* TypeInfo for index of type. */
- this->layout_field (build_typeinfo (ti->index));
+ this->layout_field (build_typeinfo (d->loc, ti->index));
}
/* Layout of TypeInfo_Vector is:
@@ -669,7 +699,7 @@ public:
this->layout_base (Type::typeinfovector);
/* TypeInfo for equivalent static array. */
- this->layout_field (build_typeinfo (ti->basetype));
+ this->layout_field (build_typeinfo (d->loc, ti->basetype));
}
/* Layout of TypeInfo_Function is:
@@ -687,7 +717,7 @@ public:
this->layout_base (Type::typeinfofunction);
/* TypeInfo for function return value. */
- this->layout_field (build_typeinfo (ti->next));
+ this->layout_field (build_typeinfo (d->loc, ti->next));
/* Mangled name of function declaration. */
this->layout_string (d->tinfo->deco);
@@ -708,7 +738,7 @@ public:
this->layout_base (Type::typeinfodelegate);
/* TypeInfo for delegate return value. */
- this->layout_field (build_typeinfo (ti->next));
+ this->layout_field (build_typeinfo (d->loc, ti->next));
/* Mangled name of delegate declaration. */
this->layout_string (d->tinfo->deco);
@@ -1038,12 +1068,12 @@ public:
if (global.params.is64bit)
{
/* TypeInfo m_arg1; */
- tree arg1type = (sd->arg1type) ? build_typeinfo (sd->arg1type)
+ tree arg1type = (sd->arg1type) ? build_typeinfo (d->loc, sd->arg1type)
: null_pointer_node;
this->layout_field (arg1type);
/* TypeInfo m_arg2; */
- tree arg2type = (sd->arg2type) ? build_typeinfo (sd->arg2type)
+ tree arg2type = (sd->arg2type) ? build_typeinfo (d->loc, sd->arg2type)
: null_pointer_node;
this->layout_field (arg2type);
}
@@ -1075,7 +1105,7 @@ public:
{
Parameter *arg = (*ti->arguments)[i];
CONSTRUCTOR_APPEND_ELT (elms, size_int (i),
- build_typeinfo (arg->type));
+ build_typeinfo (d->loc, arg->type));
}
tree ctor = build_constructor (build_ctype (satype), elms);
tree decl = build_artificial_decl (TREE_TYPE (ctor), ctor);
@@ -1311,8 +1341,20 @@ get_classinfo_decl (ClassDeclaration *decl)
/* Returns typeinfo reference for TYPE. */
tree
-build_typeinfo (Type *type)
+build_typeinfo (const Loc &loc, Type *type)
{
+ if (!global.params.useTypeInfo)
+ {
+ static int warned = 0;
+
+ if (!warned)
+ {
+ error_at (make_location_t (loc),
+ "%<object.TypeInfo%> cannot be used with -fno-rtti");
+ warned = 1;
+ }
+ }
+
gcc_assert (type->ty != Terror);
create_typeinfo (type, NULL);
return build_address (get_typeinfo_decl (type->vtinfo));