Skip to content

Commit

Permalink
Merge pull request #4995 from 9rnsr/fix14985
Browse files Browse the repository at this point in the history
[REG2.068.1-b1] Issue 14985 - Link failure for const TypeInfo of speculative instantiated struct
  • Loading branch information
yebblies committed Aug 31, 2015
2 parents 92fcc9d + 7946344 commit ce8e6d1
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 13 deletions.
19 changes: 6 additions & 13 deletions src/typinf.c
Expand Up @@ -167,28 +167,22 @@ bool isSpeculativeType(Type *t)
{
if (!ti->needsCodegen())
{
if (ti->minst || sd->requestTypeInfo)
return;

/* Bugzilla 14425: TypeInfo_Struct would refer the members of
* struct (e.g. opEquals via xopEquals field), so if it's instantiated
* in speculative context, TypeInfo creation should also be
* stopped to avoid 'unresolved symbol' linker errors.
*/
if (!ti->minst)
{
result |= true;
return;
}

/* When -debug/-unittest is specified, all of non-root instances are
* automatically changed to speculative, and here is always reached
* from those instantiated non-root structs.
* Therefore, if the TypeInfo is not auctually requested,
* we have to elide its codegen.
*/
if (!sd->requestTypeInfo)
{
result |= true;
return;
}
result |= true;
return;
}
}
else
Expand Down Expand Up @@ -506,8 +500,7 @@ class TypeInfoDtVisitor : public Visitor
{
if (!ti->needsCodegen())
{
assert(ti->minst);
assert(sd->requestTypeInfo);
assert(ti->minst || sd->requestTypeInfo);

/* ti->toObjFile() won't get called. So, store these
* member functions into object file in here.
Expand Down
33 changes: 33 additions & 0 deletions test/runnable/imports/linktypeinfo_file.d
@@ -0,0 +1,33 @@
module imports.linktypeinfo_file;

auto filter(alias pred, R)(R r)
{
return FilterResult!(pred, R)(r);
}

struct FilterResult(alias pred, R)
{
R r;
bool empty() { return r.empty; }
auto front() { return r.front; }
void popFront()
{
while (!r.empty && pred(r.front))
r.popFront();
}
}

struct DirIterator
{
int[] r;
@property bool empty() { return r.length == 0; }
@property auto front() { return r[0]; }
void popFront() { r = r[1..$]; }

}

auto dirEntries(string path)
{
bool f(int de) { return 1; }
return filter!f(DirIterator());
}
34 changes: 34 additions & 0 deletions test/runnable/linktypeinfo.d
@@ -0,0 +1,34 @@
// EXTRA_SOURCES: imports/linktypeinfo_file.d
// PERMUTE_ARGS: -g -inline -unittest -debug
// COMPILE_SEPARATELY

import imports.linktypeinfo_file;

struct Only(T)
{
private T _val;
}

auto only(V)(V v)
{
return Only!V(v);
}

static struct Chain(R...)
{
R source;
}

auto chain(R...)(R rs)
{
return Chain!R(rs);
}

void main()
{
string docRoot;

const r = dirEntries(docRoot);
typeof(r)[] a;
a.length = 0; // require TypeInfo for const(FilterResult!(DirIterator))
}

0 comments on commit ce8e6d1

Please sign in to comment.