comparison gen/llvmhelpers.cpp @ 357:82af71383b8a trunk

[svn r378] Make some errors fatal to prevent segfaults. Error instead of assert on missing label. Fixes: nocompile/ finally_02, 03, 07, 08 goto_16_A, 16_B, 12, 13, 14
author ChristianK
date Mon, 14 Jul 2008 12:11:30 +0200
parents 44daf304421c
children 051f5b550d9c
comparison
equal deleted inserted replaced
356:44daf304421c 357:82af71383b8a
159 { 159 {
160 FuncDeclaration* fd = gIR->func()->decl; 160 FuncDeclaration* fd = gIR->func()->decl;
161 FuncDeclaration::LabelMap::iterator iter = fd->labmap.find(ident->toChars()); 161 FuncDeclaration::LabelMap::iterator iter = fd->labmap.find(ident->toChars());
162 if (iter == fd->labmap.end()) 162 if (iter == fd->labmap.end())
163 { 163 {
164 if (fd->returnLabel->ident->equals(ident)) 164 if (fd->returnLabel && fd->returnLabel->ident->equals(ident))
165 { 165 {
166 assert(fd->returnLabel->statement); 166 assert(fd->returnLabel->statement);
167 return fd->returnLabel->statement; 167 return fd->returnLabel->statement;
168 } 168 }
169 return NULL; 169 return NULL;
178 void DtoGoto(Loc* loc, Identifier* target, EnclosingHandler* enclosinghandler, TryFinallyStatement* sourcetf) 178 void DtoGoto(Loc* loc, Identifier* target, EnclosingHandler* enclosinghandler, TryFinallyStatement* sourcetf)
179 { 179 {
180 assert(!gIR->scopereturned()); 180 assert(!gIR->scopereturned());
181 181
182 LabelStatement* lblstmt = DtoLabelStatement(target); 182 LabelStatement* lblstmt = DtoLabelStatement(target);
183 assert(lblstmt != NULL); 183 if(!lblstmt) {
184 error(*loc, "the label %s does not exist", target->toChars());
185 fatal();
186 }
184 187
185 // if the target label is inside inline asm, error 188 // if the target label is inside inline asm, error
186 if(lblstmt->asmLabel) 189 if(lblstmt->asmLabel) {
187 error(*loc, "cannot goto into inline asm block"); 190 error(*loc, "cannot goto to label %s inside an inline asm block", target->toChars());
191 fatal();
192 }
188 193
189 // find target basic block 194 // find target basic block
190 std::string labelname = gIR->func()->getScopedLabelName(target->toChars()); 195 std::string labelname = gIR->func()->getScopedLabelName(target->toChars());
191 llvm::BasicBlock*& targetBB = gIR->func()->labelToBB[labelname]; 196 llvm::BasicBlock*& targetBB = gIR->func()->labelToBB[labelname];
192 if (targetBB == NULL) 197 if (targetBB == NULL)
202 if(endfinally != lblstmt->enclosinghandler) 207 if(endfinally != lblstmt->enclosinghandler)
203 error(*loc, "cannot goto into try block"); 208 error(*loc, "cannot goto into try block");
204 209
205 // goto into finally blocks is forbidden by the spec 210 // goto into finally blocks is forbidden by the spec
206 // though it should not be problematic to implement 211 // though it should not be problematic to implement
207 if(lblstmt->tf != sourcetf) 212 if(lblstmt->tf != sourcetf) {
208 error(*loc, "spec disallows goto into finally block"); 213 error(*loc, "spec disallows goto into finally block");
214 fatal();
215 }
209 216
210 // emit code for finallys between goto and label 217 // emit code for finallys between goto and label
211 DtoEnclosingHandlers(enclosinghandler, endfinally); 218 DtoEnclosingHandlers(enclosinghandler, endfinally);
212 219
213 llvm::BranchInst::Create(targetBB, gIR->scopebb()); 220 llvm::BranchInst::Create(targetBB, gIR->scopebb());