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).
This commit is contained in:
Martin Kinkelin 2024-07-02 19:31:34 +02:00 committed by GitHub
parent 6a8ce7c32a
commit 7ab98b931a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 37 additions and 30 deletions

View file

@ -7091,17 +7091,7 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
// Handle this in the glue layer // Handle this in the glue layer
e = new TypeidExp(exp.loc, ta); e = new TypeidExp(exp.loc, ta);
bool genObjCode = true; e.type = getTypeInfoType(exp.loc, ta, sc);
// 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.flags & SCOPE.compile)
{
genObjCode = false;
}
e.type = getTypeInfoType(exp.loc, ta, sc, genObjCode);
semanticTypeInfo(sc, ta); semanticTypeInfo(sc, ta);
if (ea) if (ea)

View file

@ -7628,7 +7628,7 @@ public:
extern Target target; 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 class SemanticTimeTransitiveVisitor : public SemanticTimePermissiveVisitor
{ {

View file

@ -1443,6 +1443,13 @@ private extern (C++) class TypeInfoDtVisitor : Visitor
/* ti.toObjFile() won't get called. So, store these /* ti.toObjFile() won't get called. So, store these
* member functions into object file in here. * 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) if (sd.xeq && sd.xeq != StructDeclaration.xerreq)
toObjFile(sd.xeq, global.params.multiobj); toObjFile(sd.xeq, global.params.multiobj);
if (sd.xcmp && sd.xcmp != StructDeclaration.xerrcmp) if (sd.xcmp && sd.xcmp != StructDeclaration.xerrcmp)

View file

@ -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 * loc = the location for reporting line nunbers in errors
* t = the type to get the type of the `TypeInfo` object for * t = the type to get the type of the `TypeInfo` object for
* sc = the scope * sc = the scope
* genObjCode = if true, object code will be generated for the obtained TypeInfo
* Returns: * Returns:
* The type of the `TypeInfo` object associated with `t` * 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); 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 // Find module that will go all the way to an object file
Module m = sc._module.importedFrom; Module m = sc._module.importedFrom;

View file

@ -22,4 +22,4 @@ namespace dmd
bool isSpeculativeType(Type *t); bool isSpeculativeType(Type *t);
bool builtinTypeInfo(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);

View file

@ -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) void typinf_h(Expression *e, const Loc &loc, Type *t, Scope *sc)
{ {
dmd::genTypeInfo(e, loc, t, sc); dmd::genTypeInfo(e, loc, t, sc);
::getTypeInfoType(loc, t, sc, false); ::getTypeInfoType(loc, t, sc);
dmd::isSpeculativeType(t); dmd::isSpeculativeType(t);
dmd::builtinTypeInfo(t); dmd::builtinTypeInfo(t);
} }

View file

@ -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);
}));
}

View file

@ -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() {}