Skip to content

Commit 4c8f020

Browse files
committed
handle macro symbol redecl
1 parent 2b54b5c commit 4c8f020

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

compiler/src/dmd/backend/var.d

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ int controlc_saw = 0; /* a control C was seen */
164164
symtab_t globsym; /* global symbol table */
165165
Pstate pstate; // parser state
166166
Cstate cstate; // compiler state
167+
const(char)[][] gCsym; // hash table for C symbol lookup
167168

168169
uint numcse; // number of common subexpressions
169170

compiler/src/dmd/glue/toobj.d

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ import dmd.backend.obj;
8181
import dmd.backend.oper;
8282
import dmd.backend.ty;
8383
import dmd.backend.type;
84+
import dmd.backend.var;
8485

8586
package(dmd.glue):
8687

@@ -439,6 +440,19 @@ void toObjFile(Dsymbol ds, bool multiobj)
439440

440441
override void visit(VarDeclaration vd)
441442
{
443+
static bool symbol_search(VarDeclaration vd)
444+
{
445+
auto id = vd.ident.toString();
446+
447+
auto length = gCsym.length;
448+
foreach(ident; gCsym)
449+
{
450+
if (id == ident)
451+
return true;
452+
}
453+
gCsym ~= id;
454+
return false;
455+
}
442456

443457
//printf("VarDeclaration.toObjFile(%p '%s' type=%s) visibility %d\n", vd, vd.toChars(), vd.type.toChars(), vd.visibility);
444458
//printf("\talign = %d\n", vd.alignment);
@@ -464,6 +478,9 @@ void toObjFile(Dsymbol ds, bool multiobj)
464478
if (!vd.isDataseg() || vd.storage_class & STC.extern_)
465479
return;
466480

481+
if (vd.isCmacro && symbol_search(vd)) // true ==> symbol exists
482+
return;
483+
467484
Symbol* s = toSymbol(vd);
468485
const sz64 = vd.type.size(vd.loc);
469486
if (sz64 == SIZE_INVALID)

0 commit comments

Comments
 (0)