diff --git a/gen/toconstelem.cpp b/gen/toconstelem.cpp index 60ba2afe6c..ad2ced3607 100644 --- a/gen/toconstelem.cpp +++ b/gen/toconstelem.cpp @@ -392,40 +392,6 @@ class ToConstElemVisitor : public Visitor { IF_LOG Logger::println("AddrExp::toConstElem: %s @ %s", e->toChars(), e->type->toChars()); LOG_SCOPE; - // FIXME: this should probably be generalized more so we don't - // need to have a case for each thing we can take the address of - - // address of global variable - if (auto vexp = e->e1->isVarExp()) { - result = DtoConstSymbolAddress(e->loc, vexp->var); - return; - } - - // address of indexExp - if (auto iexp = e->e1->isIndexExp()) { - // indexee must be global static array var - VarExp *vexp = iexp->e1->isVarExp(); - assert(vexp); - VarDeclaration *vd = vexp->var->isVarDeclaration(); - assert(vd); - assert(vd->type->toBasetype()->ty == TY::Tsarray); - DtoResolveVariable(vd); - assert(isIrGlobalCreated(vd)); - - // get index - LLConstant *index = toConstElem(iexp->e2, p); - assert(index->getType() == DtoSize_t()); - - // gep - LLConstant *idxs[2] = {DtoConstSize_t(0), index}; - LLConstant *val = isaConstant(getIrGlobal(vd)->value); - LLConstant *gep = llvm::ConstantExpr::getGetElementPtr( - DtoType(vd->type), val, idxs, true); - - assert(e->type->toBasetype()->ty == TY::Tpointer); - result = gep; - return; - } if (auto se = e->e1->isStructLiteralExp()) { result = p->getStructLiteralGlobal(se); @@ -449,12 +415,7 @@ class ToConstElemVisitor : public Visitor { return; } - if (e->e1->op == EXP::slice || e->e1->op == EXP::dotVariable) { - visit(static_cast(e)); - return; - } - - llvm_unreachable("unsupported AddrExp in ToConstElemVisitor"); + visit(static_cast(e)); } ////////////////////////////////////////////////////////////////////////////// diff --git a/tests/fail_compilation/gh4938.d b/tests/fail_compilation/gh4938.d new file mode 100644 index 0000000000..bcbfcba866 --- /dev/null +++ b/tests/fail_compilation/gh4938.d @@ -0,0 +1,4 @@ +// RUN: not %ldc -c %s 2>&1 | FileCheck %s + +// CHECK: gh4938.d(4): Error: expression `&"whoops"w[0]` is not a constant +immutable(wchar)* x = &"whoops"w[0];