Commit 88ad43b1 by Iain Buclaw Committed by Iain Buclaw

re PR d/90651 (ICE in FuncDeclaration::semantic3, at d/dmd/func.c:1524)

	PR d/90651
d/dmd: Merge upstream dmd 0f6cbbcad

Fixes segmentation fault in FuncDeclaration::semantic3.

Reviewed-on: https://github.com/dlang/dmd/pull/10003

gcc/d/ChangeLog:

2019-06-16  Iain Buclaw  <ibuclaw@gdcproject.org>

	* typeinfo.cc (object_module): New variable.
	(make_frontend_typeinfo): Update signature.  Set temporary on
	generated TypeInfo classes.
	(create_tinfo_types): Set object_module.  Move generation of front-end
	typeinfo into ...
	(create_frontend_tinfo_types): ... New function.
	(layout_typeinfo): Call create_frontend_tinfo_types.
	(layout_classinfo): Likewise.
	(layout_cpp_typeinfo): Likewise.
	(create_typeinfo): Likewise.

From-SVN: r272345
parent a1543fb1
2019-06-16 Iain Buclaw <ibuclaw@gdcproject.org>
PR d/90651
* typeinfo.cc (object_module): New variable.
(make_frontend_typeinfo): Update signature. Set temporary on
generated TypeInfo classes.
(create_tinfo_types): Set object_module. Move generation of front-end
typeinfo into ...
(create_frontend_tinfo_types): ... New function.
(layout_typeinfo): Call create_frontend_tinfo_types.
(layout_classinfo): Likewise.
(layout_cpp_typeinfo): Likewise.
(create_typeinfo): Likewise.
2019-06-11 Richard Biener <rguenthe@suse.de> 2019-06-11 Richard Biener <rguenthe@suse.de>
d/90778 d/90778
......
ab03e2918508d62efcc5ee66c9a912a331b33aa0 3be8a80bb0c4e01c436be970ac3555ceabb3caf8
The first line of this file holds the git revision number of the last The first line of this file holds the git revision number of the last
merge done from the dlang/dmd repository. merge done from the dlang/dmd repository.
...@@ -1806,12 +1806,20 @@ public: ...@@ -1806,12 +1806,20 @@ public:
Expression *e; Expression *e;
if (ea && ta->toBasetype()->ty == Tclass) if (ea && ta->toBasetype()->ty == Tclass)
{ {
if (!Type::typeinfoclass)
{
error(exp->loc, "`object.TypeInfo_Class` could not be found, but is implicitly used");
e = new ErrorExp();
}
else
{
/* Get the dynamic type, which is .classinfo /* Get the dynamic type, which is .classinfo
*/ */
ea = semantic(ea, sc); ea = semantic(ea, sc);
e = new TypeidExp(ea->loc, ea); e = new TypeidExp(ea->loc, ea);
e->type = Type::typeinfoclass->type; e->type = Type::typeinfoclass->type;
} }
}
else if (ta->ty == Terror) else if (ta->ty == Terror)
{ {
e = new ErrorExp(); e = new ErrorExp();
......
...@@ -1520,6 +1520,18 @@ void FuncDeclaration::semantic3(Scope *sc) ...@@ -1520,6 +1520,18 @@ void FuncDeclaration::semantic3(Scope *sc)
{ {
if (f->linkage == LINKd) if (f->linkage == LINKd)
{ {
// Variadic arguments depend on Typeinfo being defined
if (!global.params.useTypeInfo || !Type::dtypeinfo || !Type::typeinfotypelist)
{
if (!global.params.useTypeInfo)
error("D-style variadic functions cannot be used with -betterC");
else if (!Type::typeinfotypelist)
error("`object.TypeInfo_Tuple` could not be found, but is implicitly used in D-style variadic functions");
else
error("`object.TypeInfo` could not be found, but is implicitly used in D-style variadic functions");
fatal();
}
// Declare _arguments[] // Declare _arguments[]
v_arguments = new VarDeclaration(Loc(), Type::typeinfotypelist->type, Id::_arguments_typeinfo, NULL); v_arguments = new VarDeclaration(Loc(), Type::typeinfotypelist->type, Id::_arguments_typeinfo, NULL);
v_arguments->storage_class |= STCtemp | STCparameter; v_arguments->storage_class |= STCtemp | STCparameter;
......
...@@ -8350,7 +8350,12 @@ L1: ...@@ -8350,7 +8350,12 @@ L1:
if (ident == Id::classinfo) if (ident == Id::classinfo)
{ {
assert(Type::typeinfoclass); if (!Type::typeinfoclass)
{
error(e->loc, "`object.TypeInfo_Class` could not be found, but is implicitly used");
return new ErrorExp();
}
Type *t = Type::typeinfoclass->type; Type *t = Type::typeinfoclass->type;
if (e->op == TOKtype || e->op == TOKdottype) if (e->op == TOKtype || e->op == TOKdottype)
{ {
......
...@@ -185,28 +185,36 @@ make_internal_typeinfo (tinfo_kind tk, Identifier *ident, ...) ...@@ -185,28 +185,36 @@ make_internal_typeinfo (tinfo_kind tk, Identifier *ident, ...)
va_end (ap); va_end (ap);
} }
/* Helper for create_tinfo_types. Creates a typeinfo class declaration /* Reference to the `object` module, where all TypeInfo is defined. */
incase one wasn't supplied by reading `object.d'. */
static Module *object_module;
/* Helper for create_frontend_tinfo_types. Creates a typeinfo class
declaration incase one wasn't supplied by reading `object.d'. */
static void static void
make_frontend_typeinfo (Module *mod, Identifier *ident, make_frontend_typeinfo (Identifier *ident, ClassDeclaration *base = NULL)
ClassDeclaration *base = NULL)
{ {
if (!base) if (!base)
base = Type::dtypeinfo; base = Type::dtypeinfo;
gcc_assert (object_module);
/* Create object module in order to complete the semantic. */ /* Create object module in order to complete the semantic. */
if (!mod->_scope) if (!object_module->_scope)
mod->importAll (NULL); object_module->importAll (NULL);
/* Assignment of global typeinfo variables is managed by the ClassDeclaration /* Assignment of global typeinfo variables is managed by the ClassDeclaration
constructor, so only need to new the declaration here. */ constructor, so only need to new the declaration here. */
Loc loc = (mod->md) ? mod->md->loc : mod->loc; Loc loc = (object_module->md) ? object_module->md->loc : object_module->loc;
ClassDeclaration *tinfo = ClassDeclaration::create (loc, ident, NULL, NULL, ClassDeclaration *tinfo = ClassDeclaration::create (loc, ident, NULL, NULL,
true); true);
tinfo->parent = mod; tinfo->parent = object_module;
tinfo->semantic (mod->_scope); tinfo->semantic (object_module->_scope);
tinfo->baseClass = base; tinfo->baseClass = base;
/* This is a compiler generated class, and shouldn't be mistaken for being
the type declared in the runtime library. */
tinfo->storage_class |= STCtemp;
} }
/* Make sure the required builtin types exist for generating the TypeInfo /* Make sure the required builtin types exist for generating the TypeInfo
...@@ -227,69 +235,78 @@ create_tinfo_types (Module *mod) ...@@ -227,69 +235,78 @@ create_tinfo_types (Module *mod)
ptr_type_node, d_uint_type, ptr_type_node, ptr_type_node, d_uint_type, ptr_type_node,
array_type_node, ptr_type_node, ptr_type_node, NULL); array_type_node, ptr_type_node, ptr_type_node, NULL);
object_module = mod;
}
/* Same as create_tinfo_types, but builds all front-end TypeInfo variable
definitions. */
static void
create_frontend_tinfo_types (void)
{
/* If there's no Object class defined, then neither can TypeInfo be. */ /* If there's no Object class defined, then neither can TypeInfo be. */
if (ClassDeclaration::object == NULL) if (object_module == NULL || ClassDeclaration::object == NULL)
return; return;
/* Create all frontend TypeInfo classes declarations. We rely on all /* Create all frontend TypeInfo classes declarations. We rely on all
existing, even if only just as stubs. */ existing, even if only just as stubs. */
if (!Type::dtypeinfo) if (!Type::dtypeinfo)
make_frontend_typeinfo (mod, Identifier::idPool ("TypeInfo"), make_frontend_typeinfo (Identifier::idPool ("TypeInfo"),
ClassDeclaration::object); ClassDeclaration::object);
if (!Type::typeinfoclass) if (!Type::typeinfoclass)
make_frontend_typeinfo (mod, Identifier::idPool ("TypeInfo_Class")); make_frontend_typeinfo (Identifier::idPool ("TypeInfo_Class"));
if (!Type::typeinfointerface) if (!Type::typeinfointerface)
make_frontend_typeinfo (mod, Identifier::idPool ("TypeInfo_Interface")); make_frontend_typeinfo (Identifier::idPool ("TypeInfo_Interface"));
if (!Type::typeinfostruct) if (!Type::typeinfostruct)
make_frontend_typeinfo (mod, Identifier::idPool ("TypeInfo_Struct")); make_frontend_typeinfo (Identifier::idPool ("TypeInfo_Struct"));
if (!Type::typeinfopointer) if (!Type::typeinfopointer)
make_frontend_typeinfo (mod, Identifier::idPool ("TypeInfo_Pointer")); make_frontend_typeinfo (Identifier::idPool ("TypeInfo_Pointer"));
if (!Type::typeinfoarray) if (!Type::typeinfoarray)
make_frontend_typeinfo (mod, Identifier::idPool ("TypeInfo_Array")); make_frontend_typeinfo (Identifier::idPool ("TypeInfo_Array"));
if (!Type::typeinfostaticarray) if (!Type::typeinfostaticarray)
make_frontend_typeinfo (mod, Identifier::idPool ("TypeInfo_StaticArray")); make_frontend_typeinfo (Identifier::idPool ("TypeInfo_StaticArray"));
if (!Type::typeinfoassociativearray) if (!Type::typeinfoassociativearray)
make_frontend_typeinfo (mod, Identifier::idPool ("TypeInfo_AssociativeArray")); make_frontend_typeinfo (Identifier::idPool ("TypeInfo_AssociativeArray"));
if (!Type::typeinfoenum) if (!Type::typeinfoenum)
make_frontend_typeinfo (mod, Identifier::idPool ("TypeInfo_Enum")); make_frontend_typeinfo (Identifier::idPool ("TypeInfo_Enum"));
if (!Type::typeinfofunction) if (!Type::typeinfofunction)
make_frontend_typeinfo (mod, Identifier::idPool ("TypeInfo_Function")); make_frontend_typeinfo (Identifier::idPool ("TypeInfo_Function"));
if (!Type::typeinfodelegate) if (!Type::typeinfodelegate)
make_frontend_typeinfo (mod, Identifier::idPool ("TypeInfo_Delegate")); make_frontend_typeinfo (Identifier::idPool ("TypeInfo_Delegate"));
if (!Type::typeinfotypelist) if (!Type::typeinfotypelist)
make_frontend_typeinfo (mod, Identifier::idPool ("TypeInfo_Tuple")); make_frontend_typeinfo (Identifier::idPool ("TypeInfo_Tuple"));
if (!Type::typeinfoconst) if (!Type::typeinfoconst)
make_frontend_typeinfo (mod, Identifier::idPool ("TypeInfo_Const")); make_frontend_typeinfo (Identifier::idPool ("TypeInfo_Const"));
if (!Type::typeinfoinvariant) if (!Type::typeinfoinvariant)
make_frontend_typeinfo (mod, Identifier::idPool ("TypeInfo_Invariant"), make_frontend_typeinfo (Identifier::idPool ("TypeInfo_Invariant"),
Type::typeinfoconst); Type::typeinfoconst);
if (!Type::typeinfoshared) if (!Type::typeinfoshared)
make_frontend_typeinfo (mod, Identifier::idPool ("TypeInfo_Shared"), make_frontend_typeinfo (Identifier::idPool ("TypeInfo_Shared"),
Type::typeinfoconst); Type::typeinfoconst);
if (!Type::typeinfowild) if (!Type::typeinfowild)
make_frontend_typeinfo (mod, Identifier::idPool ("TypeInfo_Wild"), make_frontend_typeinfo (Identifier::idPool ("TypeInfo_Wild"),
Type::typeinfoconst); Type::typeinfoconst);
if (!Type::typeinfovector) if (!Type::typeinfovector)
make_frontend_typeinfo (mod, Identifier::idPool ("TypeInfo_Vector")); make_frontend_typeinfo (Identifier::idPool ("TypeInfo_Vector"));
if (!ClassDeclaration::cpp_type_info_ptr) if (!ClassDeclaration::cpp_type_info_ptr)
make_frontend_typeinfo (mod, Identifier::idPool ("__cpp_type_info_ptr"), make_frontend_typeinfo (Identifier::idPool ("__cpp_type_info_ptr"),
ClassDeclaration::object); ClassDeclaration::object);
} }
...@@ -1132,6 +1149,9 @@ public: ...@@ -1132,6 +1149,9 @@ public:
tree tree
layout_typeinfo (TypeInfoDeclaration *d) layout_typeinfo (TypeInfoDeclaration *d)
{ {
if (!Type::dtypeinfo)
create_frontend_tinfo_types ();
tree type = TREE_TYPE (get_typeinfo_decl (d)); tree type = TREE_TYPE (get_typeinfo_decl (d));
TypeInfoVisitor v = TypeInfoVisitor (type); TypeInfoVisitor v = TypeInfoVisitor (type);
d->accept (&v); d->accept (&v);
...@@ -1144,6 +1164,9 @@ layout_typeinfo (TypeInfoDeclaration *d) ...@@ -1144,6 +1164,9 @@ layout_typeinfo (TypeInfoDeclaration *d)
tree tree
layout_classinfo (ClassDeclaration *cd) layout_classinfo (ClassDeclaration *cd)
{ {
if (!Type::dtypeinfo)
create_frontend_tinfo_types ();
TypeInfoClassDeclaration *d = TypeInfoClassDeclaration::create (cd->type); TypeInfoClassDeclaration *d = TypeInfoClassDeclaration::create (cd->type);
tree type = TREE_TYPE (get_classinfo_decl (cd)); tree type = TREE_TYPE (get_classinfo_decl (cd));
TypeInfoVisitor v = TypeInfoVisitor (type); TypeInfoVisitor v = TypeInfoVisitor (type);
...@@ -1366,6 +1389,9 @@ build_typeinfo (const Loc &loc, Type *type) ...@@ -1366,6 +1389,9 @@ build_typeinfo (const Loc &loc, Type *type)
void void
layout_cpp_typeinfo (ClassDeclaration *cd) layout_cpp_typeinfo (ClassDeclaration *cd)
{ {
if (!Type::dtypeinfo)
create_frontend_tinfo_types ();
gcc_assert (cd->isCPPclass ()); gcc_assert (cd->isCPPclass ());
tree decl = get_cpp_typeinfo_decl (cd); tree decl = get_cpp_typeinfo_decl (cd);
...@@ -1434,6 +1460,9 @@ get_cpp_typeinfo_decl (ClassDeclaration *decl) ...@@ -1434,6 +1460,9 @@ get_cpp_typeinfo_decl (ClassDeclaration *decl)
void void
create_typeinfo (Type *type, Module *mod) create_typeinfo (Type *type, Module *mod)
{ {
if (!Type::dtypeinfo)
create_frontend_tinfo_types ();
/* Do this since not all Type's are merged. */ /* Do this since not all Type's are merged. */
Type *t = type->merge2 (); Type *t = type->merge2 ();
Identifier *ident; Identifier *ident;
......
/*
REQUIRED_ARGS: -betterC
TEST_OUTPUT:
---
fail_compilation/fail19911a.d(9): Error: function `fail19911a.fun` D-style variadic functions cannot be used with -betterC
---
*/
void fun(...)
{
}
/*
DFLAGS:
REQUIRED_ARGS:
EXTRA_SOURCES: extra-files/minimal/object.d
TEST_OUTPUT:
---
fail_compilation/fail19911b.d(10): Error: function `fail19911b.fun` `object.TypeInfo_Tuple` could not be found, but is implicitly used in D-style variadic functions
---
*/
void fun(...)
{
}
/*
DFLAGS:
REQUIRED_ARGS:
TEST_OUTPUT:
---
fail_compilation/fail19911c.d(15): Error: function `object.fun` `object.TypeInfo` could not be found, but is implicitly used in D-style variadic functions
---
*/
module object;
class Object { }
class TypeInfo_Tuple { }
void fun(...)
{
}
/*
DFLAGS:
REQUIRED_ARGS:
TEST_OUTPUT:
---
fail_compilation/fail19922.d(17): Error: `object.TypeInfo_Class` could not be found, but is implicitly used
---
*/
module object;
class Object {}
void test()
{
Object o;
auto ti = typeid(o);
}
/*
DFLAGS:
REQUIRED_ARGS:
TEST_OUTPUT:
---
fail_compilation/fail19923.d(17): Error: `object.TypeInfo_Class` could not be found, but is implicitly used
---
*/
module object;
class Object {}
void test()
{
Object o;
auto ti = o.classinfo;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment