Fixed crash in DtoCreateNestedContextType().

In some cases, like the following, DtoDeclareFunction() hasn't already been called when DtoCreateNestedContextType() is invoked. This seems to have been anticipated when the function was originally written, but DtoDeclareFunction() was previously called after the ir func was already accessed in fd->ir.irFunc->nestedContextCreated.

---
void main() {
  mixin({
    string foo() {
      return "";
    }

    string bar()() {
      return foo();
    }

    return bar();
  }());
}
---
This commit is contained in:
David Nadlinger
2011-07-28 23:17:20 +02:00
parent e397b29722
commit 618051022f
+5 -1
View File
@@ -365,12 +365,15 @@ static void DtoCreateNestedContextType(FuncDeclaration* fd) {
Logger::println("DtoCreateNestedContextType for %s", fd->toChars()); Logger::println("DtoCreateNestedContextType for %s", fd->toChars());
LOG_SCOPE LOG_SCOPE
#if DMDV2
DtoDeclareFunction(fd);
#endif
if (fd->ir.irFunc->nestedContextCreated) if (fd->ir.irFunc->nestedContextCreated)
return; return;
fd->ir.irFunc->nestedContextCreated = true; fd->ir.irFunc->nestedContextCreated = true;
#if DMDV2 #if DMDV2
DtoDeclareFunction(fd);
if (fd->nestedVars.empty()) { if (fd->nestedVars.empty()) {
// fill nestedVars // fill nestedVars
size_t nnest = fd->closureVars.dim; size_t nnest = fd->closureVars.dim;
@@ -381,6 +384,7 @@ static void DtoCreateNestedContextType(FuncDeclaration* fd) {
} }
} }
#endif #endif
if (nestedCtx == NCHybrid) { if (nestedCtx == NCHybrid) {
// construct nested variables array // construct nested variables array
if (!fd->nestedVars.empty()) if (!fd->nestedVars.empty())