Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable] Fix Bugzilla 24599 - Wrongly elided TypeInfo emission #15868

Merged
merged 1 commit into from
Jul 2, 2024
Merged
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
12 changes: 1 addition & 11 deletions compiler/src/dmd/expressionsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -7091,17 +7091,7 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
// Handle this in the glue layer
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.flags & SCOPE.compile)
{
genObjCode = false;
}

e.type = getTypeInfoType(exp.loc, ta, sc, genObjCode);
e.type = getTypeInfoType(exp.loc, ta, sc);
semanticTypeInfo(sc, ta);

if (ea)
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dmd/frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -7628,7 +7628,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
{
Expand Down
7 changes: 7 additions & 0 deletions compiler/src/dmd/todt.d
Original file line number Diff line number Diff line change
Expand Up @@ -1443,6 +1443,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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a sensible place to run sema

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are about to emit the functions here, so we need sema3.

}

if (sd.xeq && sd.xeq != StructDeclaration.xerreq)
toObjFile(sd.xeq, global.params.multiobj);
if (sd.xcmp && sd.xcmp != StructDeclaration.xerrcmp)
Expand Down
5 changes: 2 additions & 3 deletions compiler/src/dmd/typinf.d
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dmd/typinf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
2 changes: 1 addition & 1 deletion compiler/src/tests/cxxfrontend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
13 changes: 0 additions & 13 deletions compiler/test/runnable/test23650.d

This file was deleted.

24 changes: 24 additions & 0 deletions compiler/test/runnable/test24599.d
Original file line number Diff line number Diff line change
@@ -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() {}
Loading