Hello, Everyone. Please find attached patch, which fixes LLVM's behaviour during code emission in LPs.
Currently AddLandingPad() function emits llvm.eh.exception only for TRY_EXCEPT blocks. But sometimes (see, e.g. g++.dg/eh/unexpected1.C) gcc generates code of form: try { throw(); } finally { .... Unwind_Resume(); } so, the exception is rethrown upper. In order to correctly handle this situation we should emit landing pad info for TRY_FINALLY blocks also. Attached patch does this. -- With best regards, Anton Korobeynikov. Faculty of Mathematics & Mechanics, Saint Petersburg State University.
diff -r a0a12058b290 gcc/llvm-convert.cpp --- a/gcc/llvm-convert.cpp Fri May 18 09:02:30 2007 +0000 +++ b/gcc/llvm-convert.cpp Wed May 23 20:11:25 2007 +0400 @@ -1906,38 +1927,44 @@ void TreeToLLVM::AddLandingPad() { break; } } - - if (!TryCatch) return; - - // Gather the typeinfo. - std::vector<Value *> TypeInfos; - tree Catches = TREE_OPERAND(TryCatch, 1); - GatherTypeInfo(Catches, TypeInfos); - - CreateExceptionValues(); - - // Choose type of landing pad type. - Function *F = FuncEHSelector; - - if (TREE_CODE(Catches) == STATEMENT_LIST && - !tsi_end_p(tsi_start(Catches)) && - TREE_CODE(tsi_stmt(tsi_start(Catches))) == EH_FILTER_EXPR) { - F = FuncEHFilter; - } - - // Fetch and store the exception. - Value *Ex = new CallInst(FuncEHException, "eh_ptr", CurBB); - new StoreInst(Ex, ExceptionValue, CurBB); + + if (!TryCatch) { + CreateExceptionValues(); + + // Fetch and store the exception. + Value *Ex = new CallInst(FuncEHException, "eh_ptr", CurBB); + new StoreInst(Ex, ExceptionValue, CurBB); + } else { + // Gather the typeinfo. + std::vector<Value *> TypeInfos; + tree Catches = TREE_OPERAND(TryCatch, 1); + GatherTypeInfo(Catches, TypeInfos); + + CreateExceptionValues(); + + // Choose type of landing pad type. + Function *F = FuncEHSelector; + + if (TREE_CODE(Catches) == STATEMENT_LIST && + !tsi_end_p(tsi_start(Catches)) && + TREE_CODE(tsi_stmt(tsi_start(Catches))) == EH_FILTER_EXPR) { + F = FuncEHFilter; + } + + // Fetch and store the exception. + Value *Ex = new CallInst(FuncEHException, "eh_ptr", CurBB); + new StoreInst(Ex, ExceptionValue, CurBB); - // Fetch and store exception handler. - std::vector<Value*> Args; - Args.push_back(new LoadInst(ExceptionValue, "eh_ptr", CurBB)); - Args.push_back(CastToType(Instruction::BitCast, FuncCPPPersonality, - PointerType::get(Type::Int8Ty))); - for (unsigned i = 0, N = TypeInfos.size(); i < N; ++i) - Args.push_back(TypeInfos[i]); - Value *Select = new CallInst(F, &Args[0], Args.size(), "eh_select", CurBB); - new StoreInst(Select, ExceptionSelectorValue, CurBB); + // Fetch and store exception handler. + std::vector<Value*> Args; + Args.push_back(new LoadInst(ExceptionValue, "eh_ptr", CurBB)); + Args.push_back(CastToType(Instruction::BitCast, FuncCPPPersonality, + PointerType::get(Type::Int8Ty))); + for (unsigned i = 0, N = TypeInfos.size(); i < N; ++i) + Args.push_back(TypeInfos[i]); + Value *Select = new CallInst(F, &Args[0], Args.size(), "eh_select", CurBB); + new StoreInst(Select, ExceptionSelectorValue, CurBB); + } }
_______________________________________________ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits