From 70b21560106ab562830bb9b6d602533e7687cb99 Mon Sep 17 00:00:00 2001 From: Robert Clipsham Date: Sat, 19 Sep 2009 13:05:10 +0100 Subject: [PATCH] Fixed a segfault in ldc2 when compiling synchronized{} blocks. --- dmd2/statement.c | 17 +++++++++++------ gen/tollvm.cpp | 7 ++----- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/dmd2/statement.c b/dmd2/statement.c index e191d3b2..0e6c391f 100644 --- a/dmd2/statement.c +++ b/dmd2/statement.c @@ -30,7 +30,16 @@ #include "attrib.h" #if IN_LLVM -#include "gen/tollvm.h" +// sizes based on those from tollvm.cpp:DtoMutexType() +int os_critsecsize() +{ + if (global.params.os == OSWindows) + return 68; + else if (global.params.os == OSFreeBSD) + return sizeof(size_t); + else + return sizeof(pthread_mutex_t); +} #elif IN_DMD extern int os_critsecsize(); #endif @@ -3869,7 +3878,7 @@ Statement *SynchronizedStatement::semantic(Scope *sc) #if IN_LLVM FuncDeclaration *fdexit = FuncDeclaration::genCfunc(args, Type::tvoid, Id::monitorexit); #else - FuncDeclaration *fdexit = FuncDeclaration::genCfunc(args, Type::tvoid, Id::monitorexit); + FuncDeclaration *fdexit = FuncDeclaration::genCfunc(Type::tvoid, Id::monitorexit); #endif e = new CallExp(loc, new VarExp(loc, fdexit), new VarExp(loc, tmp)); e->type = Type::tvoid; // do not run semantic on e @@ -3889,11 +3898,7 @@ Statement *SynchronizedStatement::semantic(Scope *sc) * try { body } finally { _d_criticalexit(critsec.ptr); } */ Identifier *id = Lexer::uniqueId("__critsec"); -#if IN_LLVM - Type *t = new TypeSArray(Type::tint8, new IntegerExp(PTRSIZE + getTypePaddedSize(DtoMutexType()))); -#elif IN_DMD Type *t = new TypeSArray(Type::tint8, new IntegerExp(PTRSIZE + os_critsecsize())); -#endif VarDeclaration *tmp = new VarDeclaration(loc, t, id, NULL); tmp->storage_class |= STCgshared | STCstatic; diff --git a/gen/tollvm.cpp b/gen/tollvm.cpp index f2f7b6d9..0f0be292 100644 --- a/gen/tollvm.cpp +++ b/gen/tollvm.cpp @@ -874,11 +874,8 @@ const LLStructType* DtoMutexType() opaque->refineAbstractTypeTo(pa.get()); pmutex = isaStruct(pa.get()); - if (gIR->module != NULL) - { - gIR->mutexType = pmutex; - gIR->module->addTypeName("D_CRITICAL_SECTION", pmutex); - } + gIR->mutexType = pmutex; + gIR->module->addTypeName("D_CRITICAL_SECTION", pmutex); return pmutex; }