comparison dmd2/statement.c @ 1582:d8e558087001

Fixed a segfault in ldc2 when compiling synchronized{} blocks.
author Robert Clipsham <robert@octarineparrot.com>
date Sat, 19 Sep 2009 13:05:10 +0100
parents 1dee66f6ec0b
children
comparison
equal deleted inserted replaced
1581:f4421c81398f 1582:d8e558087001
28 #include "parse.h" 28 #include "parse.h"
29 #include "template.h" 29 #include "template.h"
30 #include "attrib.h" 30 #include "attrib.h"
31 31
32 #if IN_LLVM 32 #if IN_LLVM
33 #include "gen/tollvm.h" 33 // sizes based on those from tollvm.cpp:DtoMutexType()
34 int os_critsecsize()
35 {
36 if (global.params.os == OSWindows)
37 return 68;
38 else if (global.params.os == OSFreeBSD)
39 return sizeof(size_t);
40 else
41 return sizeof(pthread_mutex_t);
42 }
34 #elif IN_DMD 43 #elif IN_DMD
35 extern int os_critsecsize(); 44 extern int os_critsecsize();
36 #endif 45 #endif
37 46
38 /******************************** Statement ***************************/ 47 /******************************** Statement ***************************/
3867 cs->push(new ExpStatement(loc, e)); 3876 cs->push(new ExpStatement(loc, e));
3868 3877
3869 #if IN_LLVM 3878 #if IN_LLVM
3870 FuncDeclaration *fdexit = FuncDeclaration::genCfunc(args, Type::tvoid, Id::monitorexit); 3879 FuncDeclaration *fdexit = FuncDeclaration::genCfunc(args, Type::tvoid, Id::monitorexit);
3871 #else 3880 #else
3872 FuncDeclaration *fdexit = FuncDeclaration::genCfunc(args, Type::tvoid, Id::monitorexit); 3881 FuncDeclaration *fdexit = FuncDeclaration::genCfunc(Type::tvoid, Id::monitorexit);
3873 #endif 3882 #endif
3874 e = new CallExp(loc, new VarExp(loc, fdexit), new VarExp(loc, tmp)); 3883 e = new CallExp(loc, new VarExp(loc, fdexit), new VarExp(loc, tmp));
3875 e->type = Type::tvoid; // do not run semantic on e 3884 e->type = Type::tvoid; // do not run semantic on e
3876 Statement *s = new ExpStatement(loc, e); 3885 Statement *s = new ExpStatement(loc, e);
3877 s = new TryFinallyStatement(loc, body, s); 3886 s = new TryFinallyStatement(loc, body, s);
3887 * __gshared byte[CriticalSection.sizeof] critsec; 3896 * __gshared byte[CriticalSection.sizeof] critsec;
3888 * _d_criticalenter(critsec.ptr); 3897 * _d_criticalenter(critsec.ptr);
3889 * try { body } finally { _d_criticalexit(critsec.ptr); } 3898 * try { body } finally { _d_criticalexit(critsec.ptr); }
3890 */ 3899 */
3891 Identifier *id = Lexer::uniqueId("__critsec"); 3900 Identifier *id = Lexer::uniqueId("__critsec");
3892 #if IN_LLVM
3893 Type *t = new TypeSArray(Type::tint8, new IntegerExp(PTRSIZE + getTypePaddedSize(DtoMutexType())));
3894 #elif IN_DMD
3895 Type *t = new TypeSArray(Type::tint8, new IntegerExp(PTRSIZE + os_critsecsize())); 3901 Type *t = new TypeSArray(Type::tint8, new IntegerExp(PTRSIZE + os_critsecsize()));
3896 #endif
3897 VarDeclaration *tmp = new VarDeclaration(loc, t, id, NULL); 3902 VarDeclaration *tmp = new VarDeclaration(loc, t, id, NULL);
3898 tmp->storage_class |= STCgshared | STCstatic; 3903 tmp->storage_class |= STCgshared | STCstatic;
3899 3904
3900 Statements *cs = new Statements(); 3905 Statements *cs = new Statements();
3901 cs->push(new DeclarationStatement(loc, new DeclarationExp(loc, tmp))); 3906 cs->push(new DeclarationStatement(loc, new DeclarationExp(loc, tmp)));