Skip to content
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
3 changes: 1 addition & 2 deletions compiler/src/dmd/dsymbol.d
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import dmd.arraytypes;
import dmd.attrib;
import dmd.astenums;
import dmd.ast_node;
import dmd.gluelayer;
import dmd.dclass;
import dmd.declaration;
import dmd.denum;
Expand Down Expand Up @@ -334,7 +333,7 @@ extern (C++) class Dsymbol : ASTNode
{
Identifier ident;
Dsymbol parent;
Symbol* csym; // symbol for code generator
void* csym; // symbol for code generator
Scope* _scope; // !=null means context to use for semantic()
private DsymbolAttributes* atts; /// attached attribute declarations
const Loc loc; // where defined
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dmd/frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ struct _d_dynamicArray final

class Visitor;
class Identifier;
struct Symbol;
struct Scope;
struct DsymbolAttributes;
class DeprecatedDeclaration;
Expand Down Expand Up @@ -118,6 +117,7 @@ class ForeachStatement;
class ForeachRangeStatement;
struct OutBuffer;
class TypeInfoClassDeclaration;
struct Symbol;
class TypeTuple;
class Initializer;
struct IntRange;
Expand Down Expand Up @@ -543,7 +543,7 @@ class Dsymbol : public ASTNode
public:
Identifier* ident;
Dsymbol* parent;
Symbol* csym;
void* csym;
Scope* _scope;
private:
DsymbolAttributes* atts;
Expand Down
19 changes: 11 additions & 8 deletions compiler/src/dmd/tocsym.d
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ Symbol* toSymbol(Dsymbol s)
/* Use the C symbol for the previously generated function
*/
fd.csym = Csymtab.lookup(fd.ident).csym;
result = fd.csym;
result = cast(Symbol*)fd.csym;

fd.skipCodegen = true;
return;
Expand Down Expand Up @@ -532,15 +532,18 @@ Symbol* toSymbol(Dsymbol s)
}
}

if (s.csym)
return s.csym;
if (auto csym = cast(Symbol*)s.csym)
return csym;

scope ToSymbol v = new ToSymbol();
s.accept(v);
s.csym = v.result;

if (isDllImported(s))
s.csym.Sisym = createImport(s.csym, s.loc);
{
auto csym = cast(Symbol*) s.csym;
csym.Sisym = createImport(csym, s.loc);
}

return v.result;
}
Expand Down Expand Up @@ -606,7 +609,7 @@ Symbol* toImport(Dsymbol ds)
{
if (!ds.csym)
toSymbol(ds);
return ds.csym.Sisym;
return (cast(Symbol*)(ds.csym)).Sisym;
}

/*************************************
Expand All @@ -629,10 +632,10 @@ Symbol* toThunkSymbol(FuncDeclaration fd, int offset)
char[nameLen] name = void;

const len = snprintf(name.ptr,nameLen,"_THUNK%d",tmpnum++);
auto sthunk = symbol_name(name[0 .. len],SC.static_,fd.csym.Stype);
auto sthunk = symbol_name(name[0 .. len],SC.static_,(cast(Symbol*)(fd.csym)).Stype);
sthunk.Sflags |= SFLnodebug | SFLartifical;
sthunk.Sflags |= SFLimplem;
outthunk(sthunk, fd.csym, 0, TYnptr, -offset, -1, 0);
outthunk(sthunk, cast(Symbol*)fd.csym, 0, TYnptr, -offset, -1, 0);
return sthunk;
}

Expand Down Expand Up @@ -675,7 +678,7 @@ Symbol* toVtblSymbol(ClassDeclaration cd, bool genCsymbol = true)
auto vtbl = cd.vtblSymbol();
vtbl.csym = s;
}
return cd.vtblsym.csym;
return cast(Symbol*)cd.vtblsym.csym;
}

/**********************************
Expand Down
8 changes: 4 additions & 4 deletions compiler/src/dmd/todt.d
Original file line number Diff line number Diff line change
Expand Up @@ -1265,7 +1265,7 @@ private extern (C++) class TypeInfoDtVisitor : Visitor
const(char)* name = sd.toPrettyChars();
size_t namelen = strlen(name);
dtb.size(namelen);
dtb.xoff(d.csym, Type.typeinfoenum.structsize);
dtb.xoff(cast(Symbol*)d.csym, Type.typeinfoenum.structsize);

// void[] init;
if (!sd.members || d.tinfo.isZeroInit(Loc.initial))
Expand Down Expand Up @@ -1385,7 +1385,7 @@ private extern (C++) class TypeInfoDtVisitor : Visitor
assert(name);
const namelen = strlen(name);
dtb.size(namelen);
dtb.xoff(d.csym, Type.typeinfofunction.structsize);
dtb.xoff(cast(Symbol*)d.csym, Type.typeinfofunction.structsize);

// Put out name[] immediately following TypeInfo_Function
dtb.nbytes(name[0 .. namelen + 1]);
Expand All @@ -1409,7 +1409,7 @@ private extern (C++) class TypeInfoDtVisitor : Visitor
assert(name);
const namelen = strlen(name);
dtb.size(namelen);
dtb.xoff(d.csym, Type.typeinfodelegate.structsize);
dtb.xoff(cast(Symbol*)d.csym, Type.typeinfodelegate.structsize);

// Put out name[] immediately following TypeInfo_Delegate
dtb.nbytes(name[0 .. namelen + 1]);
Expand Down Expand Up @@ -1485,7 +1485,7 @@ private extern (C++) class TypeInfoDtVisitor : Visitor
const mangledName = tc.deco;
const mangledNameLen = strlen(mangledName);
dtb.size(mangledNameLen);
dtb.xoff(d.csym, Type.typeinfostruct.structsize);
dtb.xoff(cast(Symbol*)d.csym, Type.typeinfostruct.structsize);

// void[] init;
dtb.size(sd.structsize); // init.length
Expand Down
21 changes: 14 additions & 7 deletions compiler/src/dmd/toir.d
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,10 @@ elem* getEthis(Loc loc, ref IRState irs, Dsymbol fd, Dsymbol fdp = null, Dsymbol
ethis = el_long(TYnptr, 0);
ethis.Eoper = OPframeptr;

thisfd.csym.Sfunc.Fflags &= ~Finline; // inliner breaks with this because the offsets are off
// see runnable/ice10086b.d
auto csym = cast(Symbol*) thisfd.csym;
// inliner breaks with this because the offsets are off
// see runnable/ice10086b.d
csym.Sfunc.Fflags &= ~Finline;
}
else
{
Expand Down Expand Up @@ -681,8 +683,13 @@ TYPE* getParentClosureType(Symbol* sthis, FuncDeclaration fd)
for (Dsymbol sym = fd.toParent2(); sym; sym = sym.toParent2())
{
if (auto fn = sym.isFuncDeclaration())
if (fn.csym && fn.csym.Sscope)
return fn.csym.Sscope.Stype;
{
if (auto csym = cast(Symbol*)fn.csym)
{
if (csym.Sscope)
return csym.Sscope.Stype;
}
}
if (sym.isAggregateDeclaration())
break;
}
Expand Down Expand Up @@ -880,7 +887,7 @@ void buildClosure(FuncDeclaration fd, ref IRState irs)
//printf("structsize = %d\n", cast(uint)structsize);

Closstru.Ttag.Sstruct.Sstructsize = cast(uint)structsize;
fd.csym.Sscope = sclosure;
(cast(Symbol*)fd.csym).Sscope = sclosure;

if (driverParams.symdebug)
toDebugClosure(Closstru.Ttag);
Expand Down Expand Up @@ -1112,7 +1119,7 @@ void buildAlignSection(FuncDeclaration fd, ref IRState irs)
structsize += aggAlignment - stackAlign;

Closstru.Ttag.Sstruct.Sstructsize = cast(uint)structsize;
fd.csym.Sscope = sclosure;
(cast(Symbol*)fd.csym).Sscope = sclosure;

if (driverParams.symdebug)
toDebugClosure(Closstru.Ttag);
Expand Down Expand Up @@ -1180,7 +1187,7 @@ void buildCapture(FuncDeclaration fd)
Symbol* scapture = symbol_name("__captureptr", SC.alias_, type_pointer(capturestru));
scapture.Sflags |= SFLtrue | SFLfree;
//symbol_add(scapture);
fd.csym.Sscope = scapture;
(cast(Symbol*)fd.csym).Sscope = scapture;

toDebugClosure(capturestru.Ttag);
}
Expand Down
64 changes: 35 additions & 29 deletions compiler/src/dmd/toobj.d
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@

//////////////////////////////////////////////

m.csym.Sclass = SC.global;
m.csym.Sfl = FL.data;
auto csym = cast(Symbol*)m.csym;
csym.Sclass = SC.global;
csym.Sfl = FL.data;

auto dtb = DtBuilder(0);

Expand Down Expand Up @@ -210,9 +211,9 @@
}

objc.generateModuleInfo(m);
m.csym.Sdt = dtb.finish();
out_readonly(m.csym);
outdata(m.csym);
csym.Sdt = dtb.finish();
out_readonly(csym);
outdata(csym);

//////////////////////////////////////////////

Expand Down Expand Up @@ -420,7 +421,7 @@
//printf("putting out %s.vtbl[]\n", toChars());
auto dtbv = DtBuilder(0);
if (cd.vtblOffset())
dtbv.xoff(cd.csym, 0, TYnptr); // first entry is ClassInfo reference
dtbv.xoff(cast(Symbol*)cd.csym, 0, TYnptr); // first entry is ClassInfo reference
foreach (i; cd.vtblOffset() .. cd.vtbl.length)
{
FuncDeclaration fd = cd.vtbl[i].isFuncDeclaration();
Expand All @@ -441,13 +442,14 @@
*/
dtbv.size(0);
}
cd.vtblsym.csym.Sdt = dtbv.finish();
cd.vtblsym.csym.Sclass = scclass;
cd.vtblsym.csym.Sfl = FL.data;
out_readonly(cd.vtblsym.csym);
outdata(cd.vtblsym.csym);
auto csym = cast(Symbol*) cd.vtblsym.csym;
csym.Sdt = dtbv.finish();
csym.Sclass = scclass;
csym.Sfl = FL.data;
out_readonly(csym);
outdata(csym);
if (cd.isExport() || driverParams.exportVisibility == ExpVis.public_)
objmod.export_symbol(cd.vtblsym.csym, 0);
objmod.export_symbol(csym, 0);

Check warning on line 452 in compiler/src/dmd/toobj.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/toobj.d#L452

Added line #L452 was not covered by tests
}

override void visit(InterfaceDeclaration id)
Expand Down Expand Up @@ -1227,18 +1229,19 @@

// Put out the ClassInfo, which will be the __ClassZ symbol in the object file
SC scclass = SC.comdat;
cd.csym.Sclass = scclass;
cd.csym.Sfl = FL.data;
auto csym = cast(Symbol*) cd.csym;
csym.Sclass = scclass;
csym.Sfl = FL.data;

auto dtb = DtBuilder(0);

ClassInfoToDt(dtb, cd, sinit);

cd.csym.Sdt = dtb.finish();
csym.Sdt = dtb.finish();
// ClassInfo cannot be const data, because we use the monitor on it
outdata(cd.csym);
outdata(csym);
if (cd.isExport() || driverParams.exportVisibility == ExpVis.public_)
objmod.export_symbol(cd.csym, 0);
objmod.export_symbol(csym, 0);

Check warning on line 1244 in compiler/src/dmd/toobj.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/toobj.d#L1244

Added line #L1244 was not covered by tests
}

private void ClassInfoToDt(ref DtBuilder dtb, ClassDeclaration cd, Symbol* sinit)
Expand Down Expand Up @@ -1293,19 +1296,20 @@
namelen = strlen(name);
}
dtb.size(namelen);
dt_t* pdtname = dtb.xoffpatch(cd.csym, 0, TYnptr);
auto csym = cast(Symbol*) cd.csym;
dt_t* pdtname = dtb.xoffpatch(csym, 0, TYnptr);

// vtbl[]
dtb.size(cd.vtbl.length);
if (cd.vtbl.length)
dtb.xoff(cd.vtblsym.csym, 0, TYnptr);
dtb.xoff(cast(Symbol*)cd.vtblsym.csym, 0, TYnptr);
else
dtb.size(0);

// interfaces[]
dtb.size(cd.vtblInterfaces.length);
if (cd.vtblInterfaces.length)
dtb.xoff(cd.csym, offset, TYnptr); // (*)
dtb.xoff(csym, offset, TYnptr); // (*)
else
dtb.size(0);

Expand Down Expand Up @@ -1432,7 +1436,7 @@

// vtbl[]
dtb.size(id.vtbl.length);
dtb.xoff(cd.csym, offset, TYnptr);
dtb.xoff(cast(Symbol*)cd.csym, offset, TYnptr);

// offset
dtb.size(b.offset);
Expand Down Expand Up @@ -1483,18 +1487,19 @@
SC scclass = SC.comdat;

// Put out the ClassInfo
id.csym.Sclass = scclass;
id.csym.Sfl = FL.data;
auto csym = cast(Symbol*) id.csym;
csym.Sclass = scclass;
csym.Sfl = FL.data;

auto dtb = DtBuilder(0);

InterfaceInfoToDt(dtb, id);

id.csym.Sdt = dtb.finish();
out_readonly(id.csym);
outdata(id.csym);
csym.Sdt = dtb.finish();
out_readonly(csym);
outdata(csym);
if (id.isExport() || driverParams.exportVisibility == ExpVis.public_)
objmod.export_symbol(id.csym, 0);
objmod.export_symbol(csym, 0);

Check warning on line 1502 in compiler/src/dmd/toobj.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/toobj.d#L1502

Added line #L1502 was not covered by tests
}

private void InterfaceInfoToDt(ref DtBuilder dtb, InterfaceDeclaration id)
Expand Down Expand Up @@ -1541,7 +1546,8 @@
const(char) *name = id.toPrettyChars(/*QualifyTypes=*/ true);
size_t namelen = strlen(name);
dtb.size(namelen);
dt_t* pdtname = dtb.xoffpatch(id.csym, 0, TYnptr);
auto csym = cast(Symbol*)id.csym;
dt_t* pdtname = dtb.xoffpatch(csym, 0, TYnptr);

// vtbl[]
dtb.size(0);
Expand All @@ -1562,7 +1568,7 @@
fatal();
}
}
dtb.xoff(id.csym, offset, TYnptr); // (*)
dtb.xoff(csym, offset, TYnptr); // (*)
}
else
{
Expand Down
Loading