From 16862dcd5fbb326943653a71f0b20ea7e2606473 Mon Sep 17 00:00:00 2001 From: Martin Kinkelin Date: Tue, 2 Jul 2024 19:31:34 +0200 Subject: [PATCH] Fix Bugzilla 24599 - Wrongly elided TypeInfo emission (#15868) Reverting #14844, which caused such missing TypeInfos, *and* making sure the special TypeInfo members are fully analyzed and ready for codegen (otherwise hitting an assertion for the real-world project). --- compiler/src/dmd/expressionsem.d | 12 +----------- compiler/src/dmd/frontend.h | 2 +- compiler/src/dmd/todt.d | 7 +++++++ compiler/src/dmd/typinf.d | 5 ++--- compiler/src/dmd/typinf.h | 2 +- compiler/src/tests/cxxfrontend.cc | 2 +- compiler/test/runnable/test23650.d | 13 ------------- compiler/test/runnable/test24599.d | 24 ++++++++++++++++++++++++ 8 files changed, 37 insertions(+), 30 deletions(-) delete mode 100644 compiler/test/runnable/test23650.d create mode 100644 compiler/test/runnable/test24599.d diff --git a/compiler/src/dmd/expressionsem.d b/compiler/src/dmd/expressionsem.d index ad702dc2c6b3..f1e30ad825f9 100644 --- a/compiler/src/dmd/expressionsem.d +++ b/compiler/src/dmd/expressionsem.d @@ -7194,17 +7194,7 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor // Handle this in the glue layer Expression e = new TypeidExp(exp.loc, ta); - bool genObjCode = true; - - // https://issues.dlang.org/show_bug.cgi?id=23650 - // We generate object code for typeinfo, required - // by typeid, only if in non-speculative context - if (sc.traitsCompiles) - { - genObjCode = false; - } - - e.type = getTypeInfoType(exp.loc, ta, sc, genObjCode); + e.type = getTypeInfoType(exp.loc, ta, sc); semanticTypeInfo(sc, ta); if (ea) diff --git a/compiler/src/dmd/frontend.h b/compiler/src/dmd/frontend.h index 0c6b01d91b49..677373f461f7 100644 --- a/compiler/src/dmd/frontend.h +++ b/compiler/src/dmd/frontend.h @@ -7596,7 +7596,7 @@ struct Target final extern Target target; -extern Type* getTypeInfoType(const Loc& loc, Type* t, Scope* sc, bool genObjCode = true); +extern Type* getTypeInfoType(const Loc& loc, Type* t, Scope* sc); class SemanticTimeTransitiveVisitor : public SemanticTimePermissiveVisitor { diff --git a/compiler/src/dmd/todt.d b/compiler/src/dmd/todt.d index 4bfa0f1b88cc..667cd198cac5 100644 --- a/compiler/src/dmd/todt.d +++ b/compiler/src/dmd/todt.d @@ -1441,6 +1441,13 @@ private extern (C++) class TypeInfoDtVisitor : Visitor /* ti.toObjFile() won't get called. So, store these * member functions into object file in here. */ + + if (sd.semanticRun < PASS.semantic3done) + { + import dmd.semantic3 : semanticTypeInfoMembers; + semanticTypeInfoMembers(sd); + } + if (sd.xeq && sd.xeq != StructDeclaration.xerreq) toObjFile(sd.xeq, global.params.multiobj); if (sd.xcmp && sd.xcmp != StructDeclaration.xerrcmp) diff --git a/compiler/src/dmd/typinf.d b/compiler/src/dmd/typinf.d index 201ea9602663..98d4287b8db5 100644 --- a/compiler/src/dmd/typinf.d +++ b/compiler/src/dmd/typinf.d @@ -100,14 +100,13 @@ bool genTypeInfo(Expression e, const ref Loc loc, Type torig, Scope* sc) * loc = the location for reporting line nunbers in errors * t = the type to get the type of the `TypeInfo` object for * sc = the scope - * genObjCode = if true, object code will be generated for the obtained TypeInfo * Returns: * The type of the `TypeInfo` object associated with `t` */ -extern (C++) Type getTypeInfoType(const ref Loc loc, Type t, Scope* sc, bool genObjCode = true) +extern (C++) Type getTypeInfoType(const ref Loc loc, Type t, Scope* sc) { assert(t.ty != Terror); - if (genTypeInfo(null, loc, t, sc) && genObjCode) + if (genTypeInfo(null, loc, t, sc)) { // Find module that will go all the way to an object file Module m = sc._module.importedFrom; diff --git a/compiler/src/dmd/typinf.h b/compiler/src/dmd/typinf.h index dd9572aab42f..6414ecdd36ac 100644 --- a/compiler/src/dmd/typinf.h +++ b/compiler/src/dmd/typinf.h @@ -22,4 +22,4 @@ namespace dmd bool isSpeculativeType(Type *t); bool builtinTypeInfo(Type *t); } -Type *getTypeInfoType(const Loc &loc, Type *t, Scope *sc, bool genObjCode = true); +Type *getTypeInfoType(const Loc &loc, Type *t, Scope *sc); diff --git a/compiler/src/tests/cxxfrontend.cc b/compiler/src/tests/cxxfrontend.cc index 532a6297425d..eaf4a36936d3 100644 --- a/compiler/src/tests/cxxfrontend.cc +++ b/compiler/src/tests/cxxfrontend.cc @@ -1865,7 +1865,7 @@ void template_h(TemplateParameter *tp, Scope *sc, TemplateParameters *tps, void typinf_h(Expression *e, const Loc &loc, Type *t, Scope *sc) { dmd::genTypeInfo(e, loc, t, sc); - ::getTypeInfoType(loc, t, sc, false); + ::getTypeInfoType(loc, t, sc); dmd::isSpeculativeType(t); dmd::builtinTypeInfo(t); } diff --git a/compiler/test/runnable/test23650.d b/compiler/test/runnable/test23650.d deleted file mode 100644 index 3ce8f5f0759b..000000000000 --- a/compiler/test/runnable/test23650.d +++ /dev/null @@ -1,13 +0,0 @@ -// https://issues.dlang.org/show_bug.cgi?id=23650 - -__gshared int x; - -void main() -{ - - static assert(__traits(compiles, - { - struct S { int *p = &x; } - auto t = typeid(S); - })); -} diff --git a/compiler/test/runnable/test24599.d b/compiler/test/runnable/test24599.d new file mode 100644 index 000000000000..257773846ebf --- /dev/null +++ b/compiler/test/runnable/test24599.d @@ -0,0 +1,24 @@ +module mod; + +struct Variable +{ + size_t toHash() const { return 0; } +} + +enum hasInoutConstruction(T) = __traits(compiles, { struct S { T a; } }); + +struct Algebraic(T) +{ + static if (hasInoutConstruction!T) + { + } +} + +Algebraic!Variable foo(); + +struct S +{ + Variable[] symbols; +} + +void main() {}