mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-07-10 09:24:09 +02:00
Re-enable SymOffExp and remove associated LLVM-only modifications.
This commit is contained in:
64
dmd2/cast.c
64
dmd2/cast.c
@@ -686,13 +686,11 @@ MATCH AddrExp::implicitConvTo(Type *t)
|
||||
t->ty == Tpointer && t->nextOf()->ty == Tfunction &&
|
||||
e1->op == TOKvar)
|
||||
{
|
||||
#if !IN_LLVM
|
||||
/* I don't think this can ever happen -
|
||||
* it should have been
|
||||
* converted to a SymOffExp.
|
||||
*/
|
||||
assert(0);
|
||||
#endif
|
||||
VarExp *ve = (VarExp *)e1;
|
||||
FuncDeclaration *f = ve->var->isFuncDeclaration();
|
||||
if (f && f->overloadExactMatch(t->nextOf()))
|
||||
@@ -991,7 +989,6 @@ Expression *Expression::castTo(Scope *sc, Type *t)
|
||||
Type *typeb = type->toBasetype();
|
||||
if (tb != typeb)
|
||||
{
|
||||
#if !IN_LLVM
|
||||
// Do (type *) cast of (type [dim])
|
||||
if (tb->ty == Tpointer &&
|
||||
typeb->ty == Tsarray
|
||||
@@ -1004,17 +1001,15 @@ Expression *Expression::castTo(Scope *sc, Type *t)
|
||||
else
|
||||
e = new AddrExp(loc, e);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
#if 0
|
||||
if (tb->ty == Tdelegate && type->ty != Tdelegate)
|
||||
else if (tb->ty == Tdelegate && type->ty != Tdelegate)
|
||||
{
|
||||
TypeDelegate *td = (TypeDelegate *)tb;
|
||||
TypeFunction *tf = (TypeFunction *)td->nextOf();
|
||||
return toDelegate(sc, tf->nextOf());
|
||||
}
|
||||
else
|
||||
#endif
|
||||
else
|
||||
{
|
||||
if (typeb->ty == Tstruct)
|
||||
{ TypeStruct *ts = (TypeStruct *)typeb;
|
||||
@@ -1432,48 +1427,6 @@ Expression *AddrExp::castTo(Scope *sc, Type *t)
|
||||
f = f2;
|
||||
}
|
||||
}
|
||||
#if IN_LLVM
|
||||
if (f)
|
||||
{
|
||||
f = f->overloadExactMatch(tb->nextOf());
|
||||
if (f)
|
||||
{
|
||||
if (tb->ty == Tdelegate)
|
||||
{
|
||||
if (f->needThis() && hasThis(sc))
|
||||
{
|
||||
e = new DelegateExp(loc, new ThisExp(loc), f);
|
||||
e = e->semantic(sc);
|
||||
}
|
||||
else if (f->isNested())
|
||||
{
|
||||
e = new DelegateExp(loc, new IntegerExp(0), f);
|
||||
e = e->semantic(sc);
|
||||
}
|
||||
else if (f->needThis())
|
||||
{ error("no 'this' to create delegate for %s", f->toChars());
|
||||
return new ErrorExp();
|
||||
}
|
||||
else
|
||||
{ error("cannot cast from function pointer to delegate");
|
||||
return new ErrorExp();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
e = new VarExp(loc, f);
|
||||
e->type = f->type;
|
||||
e = new AddrExp(loc, e);
|
||||
e->type = t;
|
||||
return e;
|
||||
}
|
||||
#if DMDV2
|
||||
f->tookAddressOf++;
|
||||
#endif
|
||||
return e;
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (f)
|
||||
{ f->tookAddressOf++;
|
||||
SymOffExp *se = new SymOffExp(loc, f, 0, 0);
|
||||
@@ -1481,9 +1434,9 @@ Expression *AddrExp::castTo(Scope *sc, Type *t)
|
||||
// Let SymOffExp::castTo() do the heavy lifting
|
||||
return se->castTo(sc, t);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
if (type->ty == Tpointer && type->nextOf()->ty == Tfunction &&
|
||||
tb->ty == Tpointer && tb->nextOf()->ty == Tfunction &&
|
||||
e1->op == TOKvar)
|
||||
@@ -1492,9 +1445,7 @@ Expression *AddrExp::castTo(Scope *sc, Type *t)
|
||||
FuncDeclaration *f = ve->var->isFuncDeclaration();
|
||||
if (f)
|
||||
{
|
||||
#if !IN_LLVM
|
||||
assert(0); // should be SymOffExp instead
|
||||
#endif
|
||||
f = f->overloadExactMatch(tb->nextOf());
|
||||
if (f)
|
||||
{
|
||||
@@ -1506,17 +1457,8 @@ Expression *AddrExp::castTo(Scope *sc, Type *t)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
e = Expression::castTo(sc, t);
|
||||
}
|
||||
#if IN_LLVM
|
||||
else if (e1->op == TOKvar)
|
||||
{
|
||||
VarExp *ve = (VarExp*)e1->copy();
|
||||
ve->hasOverloads = 0;
|
||||
e1 = ve;
|
||||
}
|
||||
#endif
|
||||
e->type = t;
|
||||
return e;
|
||||
}
|
||||
|
||||
@@ -1896,15 +1896,6 @@ bool isCtfeValueValid(Expression *newval)
|
||||
if (((SymOffExp *)newval)->var->isFuncDeclaration())
|
||||
return true;
|
||||
}
|
||||
#if IN_LLVM
|
||||
if (newval->op == TOKaddress) { // function pointer
|
||||
AddrExp *ae = (AddrExp *)newval;
|
||||
if (ae->e1->op == TOKvar) {
|
||||
if (((VarExp *)ae->e1)->var->isFuncDeclaration())
|
||||
return true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (newval->op == TOKint64 || newval->op == TOKfloat64 ||
|
||||
newval->op == TOKchar || newval->op == TOKcomplex80)
|
||||
|
||||
@@ -2229,11 +2229,7 @@ Expression *VarDeclaration::callScopeDtor(Scope *sc)
|
||||
if (array)
|
||||
{
|
||||
// Typeinfo.destroy(cast(void*)&v);
|
||||
#if IN_LLVM
|
||||
Expression *ea = new AddrExp(loc, new DsymbolExp(loc, this));
|
||||
#else
|
||||
Expression *ea = new SymOffExp(loc, this, 0, 0);
|
||||
#endif
|
||||
ea = new CastExp(loc, ea, Type::tvoid->pointerTo());
|
||||
Expressions *args = new Expressions();
|
||||
args->push(ea);
|
||||
|
||||
@@ -1278,23 +1278,6 @@ Type *functionParameters(Loc loc, Scope *sc, TypeFunction *tf,
|
||||
#endif
|
||||
|
||||
// Give error for overloaded function addresses
|
||||
#if IN_LLVM
|
||||
if (arg->op == TOKaddress)
|
||||
{ AddrExp *ae = (AddrExp *)arg;
|
||||
if (ae->e1->op == TOKvar) {
|
||||
VarExp *ve = (VarExp*)ae->e1;
|
||||
FuncDeclaration *fd = ve->var->isFuncDeclaration();
|
||||
if (fd &&
|
||||
#if DMDV2
|
||||
ve->hasOverloads &&
|
||||
#endif
|
||||
!fd->isUnique())
|
||||
{
|
||||
arg->error("function %s is overloaded", arg->toChars());
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (arg->op == TOKsymoff)
|
||||
{ SymOffExp *se = (SymOffExp *)arg;
|
||||
if (
|
||||
@@ -1306,7 +1289,6 @@ Type *functionParameters(Loc loc, Scope *sc, TypeFunction *tf,
|
||||
arg = new ErrorExp();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
arg->rvalue();
|
||||
arg = arg->optimize(WANTvalue);
|
||||
}
|
||||
@@ -7882,27 +7864,12 @@ Lagain:
|
||||
e1 = new DsymbolExp(loc, se->sds);
|
||||
e1 = e1->semantic(sc);
|
||||
}
|
||||
#if IN_LLVM
|
||||
else if (e1->op == TOKaddress)
|
||||
{
|
||||
AddrExp *ae = (AddrExp *)e1;
|
||||
if (ae->e1->op == TOKvar) {
|
||||
VarExp *ve = (VarExp*)ae->e1;
|
||||
if (!ve->var->isOut() && !ve->var->isRef() &&
|
||||
!ve->var->isImportedSymbol() && ve->hasOverloads)
|
||||
{
|
||||
e1 = ve;
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
else if (e1->op == TOKsymoff && ((SymOffExp *)e1)->hasOverloads)
|
||||
{
|
||||
SymOffExp *se = (SymOffExp *)e1;
|
||||
e1 = new VarExp(se->loc, se->var, 1);
|
||||
e1 = e1->semantic(sc);
|
||||
}
|
||||
#endif
|
||||
else if (e1->op == TOKdotexp)
|
||||
{
|
||||
DotExp *de = (DotExp *) e1;
|
||||
@@ -9283,20 +9250,6 @@ Lsafe:
|
||||
void CastExp::checkEscape()
|
||||
{ Type *tb = type->toBasetype();
|
||||
|
||||
#if IN_LLVM
|
||||
if (e1->op == TOKvar &&
|
||||
tb->ty == Tpointer &&
|
||||
e1->type->toBasetype()->ty == Tsarray)
|
||||
{
|
||||
VarDeclaration *v = ((VarExp*)e1)->var->isVarDeclaration();
|
||||
if (v)
|
||||
{
|
||||
if (!v->isDataseg() && !(v->storage_class & (STCref | STCout)))
|
||||
error("escaping reference to local variable %s", v->toChars());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (tb->ty == Tarray && e1->op == TOKvar &&
|
||||
e1->type->toBasetype()->ty == Tsarray)
|
||||
{ VarExp *ve = (VarExp *)e1;
|
||||
|
||||
@@ -753,12 +753,11 @@ struct SymOffExp : SymbolExp
|
||||
MATCH implicitConvTo(Type *t);
|
||||
Expression *castTo(Scope *sc, Type *t);
|
||||
|
||||
#if IN_DMD
|
||||
dt_t **toDt(dt_t **pdt);
|
||||
#endif
|
||||
|
||||
#if IN_LLVM
|
||||
DValue* toElem(IRState* irs);
|
||||
llvm::Constant* toConstElem(IRState* irs);
|
||||
#else
|
||||
dt_t **toDt(dt_t **pdt);
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
11
dmd2/init.c
11
dmd2/init.c
@@ -847,19 +847,8 @@ bool hasNonConstPointers(Expression *e)
|
||||
}
|
||||
if (e->type->ty== Tpointer && e->type->nextOf()->ty != Tfunction)
|
||||
{
|
||||
#if IN_LLVM
|
||||
// address of a global is OK
|
||||
if (e->op == TOKaddress || e->op == TOKcast)
|
||||
return false;
|
||||
if (e->op == TOKadd || e->op == TOKmin) {
|
||||
BinExp *be = (BinExp*)e;
|
||||
if (be->e1->type->ty == Tpointer || be->e2->type->ty == Tpointer)
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
if (e->op == TOKsymoff) // address of a global is OK
|
||||
return false;
|
||||
#endif
|
||||
if (e->op == TOKint64) // cast(void *)int is OK
|
||||
return false;
|
||||
if (e->op == TOKstring) // "abc".ptr is OK
|
||||
|
||||
@@ -1509,59 +1509,6 @@ Expression *AddrExp::interpret(InterState *istate, CtfeGoal goal)
|
||||
#if LOG
|
||||
printf("%s AddrExp::interpret() %s\n", loc.toChars(), toChars());
|
||||
#endif
|
||||
#if IN_LLVM
|
||||
if (e1->op == TOKvar)
|
||||
{ VarExp *ve = (VarExp *)e1;
|
||||
if (ve->var->isFuncDeclaration())
|
||||
return this;
|
||||
if (!ve->var->isOut() && !ve->var->isRef() &&
|
||||
!ve->var->isImportedSymbol())
|
||||
{
|
||||
if (type->ty != Tpointer)
|
||||
{ // Probably impossible
|
||||
error("Cannot interpret %s at compile time", toChars());
|
||||
return EXP_CANT_INTERPRET;
|
||||
}
|
||||
Type *pointee = ((TypePointer *)type)->next;
|
||||
if (isSafePointerCast(ve->var->type, pointee))
|
||||
{
|
||||
ve = new VarExp(loc, ve->var);
|
||||
ve->type = type;
|
||||
return ve;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (e1->op == TOKindex)
|
||||
{
|
||||
IndexExp *ae = (IndexExp *)e1;
|
||||
if (ae->e2->op == TOKint64 && ae->e1->op == TOKvar) {
|
||||
dinteger_t indx = ae->e2->toInteger();
|
||||
VarExp *ve = (VarExp *)ae->e1;
|
||||
if (/*ve->type->ty == Tarray || */ve->type->ty == Tsarray)
|
||||
{
|
||||
Expression *val = getVarExp(loc, istate, ve->var, goal);
|
||||
|
||||
Expression *aggregate = NULL;
|
||||
if (val->op == TOKarrayliteral || val->op == TOKstring)
|
||||
aggregate = val;
|
||||
else if (val->op == TOKslice)
|
||||
{
|
||||
aggregate = ((SliceExp *)val)->e1;
|
||||
Expression *lwr = ((SliceExp *)val)->lwr->interpret(istate);
|
||||
indx += lwr->toInteger();
|
||||
}
|
||||
if (aggregate)
|
||||
{
|
||||
IntegerExp *ofs = new IntegerExp(loc, indx, Type::tsize_t);
|
||||
IndexExp *ie = new IndexExp(loc, aggregate, ofs);
|
||||
ie->type = type;
|
||||
return ie;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// For reference types, we need to return an lvalue ref.
|
||||
TY tb = e1->type->toBasetype()->ty;
|
||||
bool needRef = (tb == Tarray || tb == Taarray || tb == Tclass);
|
||||
@@ -3958,16 +3905,8 @@ Expression *CallExp::interpret(InterState *istate, CtfeGoal goal)
|
||||
if (exceptionOrCantInterpret(ecall))
|
||||
return ecall;
|
||||
|
||||
#if IN_LLVM
|
||||
if (ecall->op == TOKaddress) {
|
||||
AddrExp *e = (AddrExp*)ecall;
|
||||
if (e->e1->op == TOKvar)
|
||||
fd = ((VarExp *)e->e1)->var->isFuncDeclaration();
|
||||
}
|
||||
#else
|
||||
if (ecall->op == TOKsymoff)
|
||||
fd = ((SymOffExp *)ecall)->var->isFuncDeclaration();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else if (pe->op == TOKsymoff)
|
||||
|
||||
@@ -320,8 +320,6 @@ Expression *AddrExp::optimize(int result, bool keepLvalue)
|
||||
{ Expression *e;
|
||||
|
||||
//printf("AddrExp::optimize(result = %d) %s\n", result, toChars());
|
||||
// LDC never try to interpret: it could change the semantics by turning
|
||||
// const p = &s; into an something like const p = &(Struct());
|
||||
|
||||
/* Rewrite &(a,b) as (a,&b)
|
||||
*/
|
||||
@@ -331,35 +329,13 @@ Expression *AddrExp::optimize(int result, bool keepLvalue)
|
||||
ae->type = type;
|
||||
e = new CommaExp(ce->loc, ce->e1, ae);
|
||||
e->type = type;
|
||||
return e->optimize(result & ~WANTinterpret);
|
||||
return e->optimize(result);
|
||||
}
|
||||
|
||||
#if IN_LLVM
|
||||
if (e1->op == TOKindex)
|
||||
{
|
||||
IndexExp *ae = (IndexExp *)e1;
|
||||
|
||||
if (ae->e2->op == TOKint64 && ae->e1->op == TOKvar)
|
||||
{
|
||||
dinteger_t index = ae->e2->toInteger();
|
||||
VarExp *ve = (VarExp *)ae->e1;
|
||||
if (ve->type->ty == Tsarray
|
||||
&& !ve->var->isImportedSymbol())
|
||||
{
|
||||
TypeSArray *ts = (TypeSArray *)ve->type;
|
||||
dinteger_t dim = ts->dim->toInteger();
|
||||
if (index < 0 || index >= dim)
|
||||
error("array index %jd is out of bounds [0..%jd]", index, dim);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (e1->op == TOKvar)
|
||||
{ VarExp *ve = (VarExp *)e1;
|
||||
if (ve->var->storage_class & STCmanifest)
|
||||
e1 = e1->optimize(result & ~WANTinterpret);
|
||||
e1 = e1->optimize(result);
|
||||
}
|
||||
else
|
||||
e1 = e1->optimize(result);
|
||||
@@ -378,7 +354,6 @@ Expression *AddrExp::optimize(int result, bool keepLvalue)
|
||||
}
|
||||
return e;
|
||||
}
|
||||
#if !IN_LLVM
|
||||
if (e1->op == TOKvar)
|
||||
{ VarExp *ve = (VarExp *)e1;
|
||||
if (!ve->var->isOut() && !ve->var->isRef() &&
|
||||
@@ -410,7 +385,6 @@ Expression *AddrExp::optimize(int result, bool keepLvalue)
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -617,13 +591,6 @@ Expression *CastExp::optimize(int result, bool keepLvalue)
|
||||
enum TOK op1 = e1->op;
|
||||
#define X 0
|
||||
|
||||
#if IN_LLVM
|
||||
if (type->toBasetype()->ty == Tpointer &&
|
||||
e1->type->toBasetype()->ty == Tsarray)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
#endif
|
||||
Expression *e1old = e1;
|
||||
e1 = e1->optimize(result);
|
||||
e1 = fromConstInitializer(result, e1);
|
||||
|
||||
Reference in New Issue
Block a user