llvm.org GIT mirror llvm / 64cfcef
Fixed more best practices, and explicit/implicit style guide issues. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129245 91177308-0d34-0410-b5e6-96231b3b80d8 Garrison Venn 8 years ago
1 changed file(s) with 131 addition(s) and 134 deletion(s). Raw diff Collapse all Expand all
112112 } __attribute__((__aligned__));
113113
114114 struct _Unwind_Context;
115 typedef struct _Unwind_Context* _Unwind_Context_t;
116
117 extern const uint8_t* _Unwind_GetLanguageSpecificData (_Unwind_Context_t c);
115 typedef struct _Unwind_Context *_Unwind_Context_t;
116
117 extern const uint8_t *_Unwind_GetLanguageSpecificData (_Unwind_Context_t c);
118118 extern uintptr_t _Unwind_GetGR (_Unwind_Context_t c, int i);
119119 extern void _Unwind_SetGR (_Unwind_Context_t c, int i, uintptr_t n);
120120 extern void _Unwind_SetIP (_Unwind_Context_t, uintptr_t new_value);
170170 static std::vector ourTypeInfoNames;
171171 static std::map ourTypeInfoNamesIndex;
172172
173 static llvm::StructType* ourTypeInfoType;
174 static llvm::StructType* ourExceptionType;
175 static llvm::StructType* ourUnwindExceptionType;
176
177 static llvm::ConstantInt* ourExceptionNotThrownState;
178 static llvm::ConstantInt* ourExceptionThrownState;
179 static llvm::ConstantInt* ourExceptionCaughtState;
173 static llvm::StructType *ourTypeInfoType;
174 static llvm::StructType *ourExceptionType;
175 static llvm::StructType *ourUnwindExceptionType;
176
177 static llvm::ConstantInt *ourExceptionNotThrownState;
178 static llvm::ConstantInt *ourExceptionThrownState;
179 static llvm::ConstantInt *ourExceptionCaughtState;
180180
181181 typedef std::vector ArgNames;
182182 typedef std::vector ArgTypes;
197197 /// @param declarationOnly for function declarations
198198 /// @param isVarArg function uses vararg arguments
199199 /// @returns function instance
200 llvm::Function *createFunction(llvm::Module& module,
201 const llvm::Type* retType,
202 const ArgTypes& theArgTypes,
203 const ArgNames& theArgNames,
204 const std::string& functName,
200 llvm::Function *createFunction(llvm::Module &module,
201 const llvm::Type *retType,
202 const ArgTypes &theArgTypes,
203 const ArgNames &theArgNames,
204 const std::string &functName,
205205 llvm::GlobalValue::LinkageTypes linkage,
206206 bool declarationOnly,
207207 bool isVarArg) {
233233 /// @param type stack variable type
234234 /// @param initWith optional constant initialization value
235235 /// @returns AllocaInst instance
236 static llvm::AllocaInst *createEntryBlockAlloca(llvm::Function& function,
236 static llvm::AllocaInst *createEntryBlockAlloca(llvm::Function &function,
237237 const std::string &varName,
238 const llvm::Type* type,
239 llvm::Constant* initWith = 0) {
240 llvm::BasicBlock& block = function.getEntryBlock();
238 const llvm::Type *type,
239 llvm::Constant *initWith = 0) {
240 llvm::BasicBlock &block = function.getEntryBlock();
241241 llvm::IRBuilder<> tmp(&block, block.begin());
242 llvm::AllocaInst* ret = tmp.CreateAlloca(type, 0, varName.c_str());
242 llvm::AllocaInst *ret = tmp.CreateAlloca(type, 0, varName.c_str());
243243
244244 if (initWith)
245245 tmp.CreateStore(initWith, ret);
264264 /// Prints a 32 bit number, according to the format, to stderr.
265265 /// @param intToPrint integer to print
266266 /// @param format printf like format to use when printing
267 void print32Int(int intToPrint, const char* format) {
267 void print32Int(int intToPrint, const char *format) {
268268 if (format) {
269269 // Note: No NULL check
270270 fprintf(stderr, format, intToPrint);
281281 /// Prints a 64 bit number, according to the format, to stderr.
282282 /// @param intToPrint integer to print
283283 /// @param format printf like format to use when printing
284 void print64Int(long int intToPrint, const char* format) {
284 void print64Int(long int intToPrint, const char *format) {
285285 if (format) {
286286 // Note: No NULL check
287287 fprintf(stderr, format, intToPrint);
295295
296296 /// Prints a C string to stderr
297297 /// @param toPrint string to print
298 void printStr(char* toPrint) {
298 void printStr(char *toPrint) {
299299 if (toPrint) {
300300 fprintf(stderr, "%s", toPrint);
301301 }
309309 /// is calculated from the supplied OurBaseException_t::unwindException
310310 /// member address. Handles (ignores), NULL pointers.
311311 /// @param expToDelete exception to delete
312 void deleteOurException(OurUnwindException* expToDelete) {
312 void deleteOurException(OurUnwindException *expToDelete) {
313313 #ifdef DEBUG
314314 fprintf(stderr,
315315 "deleteOurException(...).\n");
330330 /// @unlink
331331 /// @param expToDelete exception instance to delete
332332 void deleteFromUnwindOurException(_Unwind_Reason_Code reason,
333 OurUnwindException* expToDelete) {
333 OurUnwindException *expToDelete) {
334334 #ifdef DEBUG
335335 fprintf(stderr,
336336 "deleteFromUnwindOurException(...).\n");
343343 /// Creates (allocates on the heap), an exception (OurException instance),
344344 /// of the supplied type info type.
345345 /// @param type type info type
346 OurUnwindException* createOurException(int type) {
346 OurUnwindException *createOurException(int type) {
347347 size_t size = sizeof(OurException);
348 OurException* ret = (OurException*) memset(malloc(size), 0, size);
348 OurException *ret = (OurException*) memset(malloc(size), 0, size);
349349 (ret->type).type = type;
350350 (ret->unwindException).exception_class = ourBaseExceptionClass;
351351 (ret->unwindException).exception_cleanup = deleteFromUnwindOurException;
359359 /// @link http://dwarfstd.org/Dwarf3.pdf @unlink
360360 /// @param data reference variable holding memory pointer to decode from
361361 /// @returns decoded value
362 static uintptr_t readULEB128(const uint8_t** data) {
362 static uintptr_t readULEB128(const uint8_t **data) {
363363 uintptr_t result = 0;
364364 uintptr_t shift = 0;
365365 unsigned char byte;
366 const uint8_t* p = *data;
366 const uint8_t *p = *data;
367367
368368 do {
369369 byte = *p++;
383383 /// @link http://dwarfstd.org/Dwarf3.pdf @unlink
384384 /// @param data reference variable holding memory pointer to decode from
385385 /// @returns decoded value
386 static uintptr_t readSLEB128(const uint8_t** data) {
386 static uintptr_t readSLEB128(const uint8_t **data) {
387387 uintptr_t result = 0;
388388 uintptr_t shift = 0;
389389 unsigned char byte;
390 const uint8_t* p = *data;
390 const uint8_t *p = *data;
391391
392392 do {
393393 byte = *p++;
412412 /// @param data reference variable holding memory pointer to decode from
413413 /// @param encoding dwarf encoding type
414414 /// @returns decoded value
415 static uintptr_t readEncodedPointer(const uint8_t** data, uint8_t encoding) {
415 static uintptr_t readEncodedPointer(const uint8_t **data, uint8_t encoding) {
416416 uintptr_t result = 0;
417 const uint8_t* p = *data;
417 const uint8_t *p = *data;
418418
419419 if (encoding == llvm::dwarf::DW_EH_PE_omit)
420420 return(result);
521521 (exceptionClass != ourBaseExceptionClass))
522522 return(ret);
523523
524 struct OurBaseException_t* excp = (struct OurBaseException_t*)
524 struct OurBaseException_t *excp = (struct OurBaseException_t*)
525525 (((char*) exceptionObject) + ourBaseFromUnwindOffset);
526526 struct OurExceptionType_t *excpType = &(excp->type);
527527 int type = excpType->type;
597597 /// @param context unwind system context
598598 /// @returns minimally supported unwinding control indicator
599599 static _Unwind_Reason_Code handleLsda(int version,
600 const uint8_t* lsda,
600 const uint8_t *lsda,
601601 _Unwind_Action actions,
602602 uint64_t exceptionClass,
603 struct _Unwind_Exception* exceptionObject,
603 struct _Unwind_Exception *exceptionObject,
604604 _Unwind_Context_t context) {
605605 _Unwind_Reason_Code ret = _URC_CONTINUE_UNWIND;
606606
620620 // emitted dwarf code)
621621 uintptr_t funcStart = _Unwind_GetRegionStart(context);
622622 uintptr_t pcOffset = pc - funcStart;
623 struct OurExceptionType_t** classInfo = NULL;
623 struct OurExceptionType_t **classInfo = NULL;
624624
625625 // Note: See JITDwarfEmitter::EmitExceptionTable(...) for corresponding
626626 // dwarf emission
648648
649649 uint8_t callSiteEncoding = *lsda++;
650650 uint32_t callSiteTableLength = readULEB128(&lsda);
651 const uint8_t* callSiteTableStart = lsda;
652 const uint8_t* callSiteTableEnd = callSiteTableStart +
651 const uint8_t *callSiteTableStart = lsda;
652 const uint8_t *callSiteTableEnd = callSiteTableStart +
653653 callSiteTableLength;
654 const uint8_t* actionTableStart = callSiteTableEnd;
655 const uint8_t* callSitePtr = callSiteTableStart;
654 const uint8_t *actionTableStart = callSiteTableEnd;
655 const uint8_t *callSitePtr = callSiteTableStart;
656656
657657 bool foreignException = false;
658658
703703 int64_t actionValue = 0;
704704
705705 if (actionEntry) {
706 exceptionMatched = handleActionValue
707 (
708 &actionValue,
709 classInfo,
710 actionEntry,
711 exceptionClass,
712 exceptionObject
713 );
706 exceptionMatched = handleActionValue(&actionValue,
707 classInfo,
708 actionEntry,
709 exceptionClass,
710 exceptionObject);
714711 }
715712
716713 if (!(actions & _UA_SEARCH_PHASE)) {
788785 _Unwind_Reason_Code ourPersonality(int version,
789786 _Unwind_Action actions,
790787 uint64_t exceptionClass,
791 struct _Unwind_Exception* exceptionObject,
788 struct _Unwind_Exception *exceptionObject,
792789 _Unwind_Context_t context) {
793790 #ifdef DEBUG
794791 fprintf(stderr,
803800 }
804801 #endif
805802
806 const uint8_t* lsda = _Unwind_GetLanguageSpecificData(context);
803 const uint8_t *lsda = _Unwind_GetLanguageSpecificData(context);
807804
808805 #ifdef DEBUG
809806 fprintf(stderr,
859856 /// generated, and is used to hold the constant string. A value of
860857 /// false indicates that the constant string will be stored on the
861858 /// stack.
862 void generateStringPrint(llvm::LLVMContext& context,
863 llvm::Module& module,
864 llvm::IRBuilder<>& builder,
859 void generateStringPrint(llvm::LLVMContext &context,
860 llvm::Module &module,
861 llvm::IRBuilder<> &builder,
865862 std::string toPrint,
866863 bool useGlobal = true) {
867864 llvm::Function *printFunct = module.getFunction("printStr");
868865
869866 llvm::Value *stringVar;
870 llvm::Constant* stringConstant =
867 llvm::Constant *stringConstant =
871868 llvm::ConstantArray::get(context, toPrint);
872869
873870 if (useGlobal) {
885882 builder.CreateStore(stringConstant, stringVar);
886883 }
887884
888 llvm::Value* cast =
885 llvm::Value *cast =
889886 builder.CreatePointerCast(stringVar,
890887 builder.getInt8Ty()->getPointerTo());
891888 builder.CreateCall(printFunct, cast);
904901 /// generated, and is used to hold the constant string. A value of
905902 /// false indicates that the constant string will be stored on the
906903 /// stack.
907 void generateIntegerPrint(llvm::LLVMContext& context,
908 llvm::Module& module,
909 llvm::IRBuilder<>& builder,
910 llvm::Function& printFunct,
911 llvm::Value& toPrint,
904 void generateIntegerPrint(llvm::LLVMContext &context,
905 llvm::Module &module,
906 llvm::IRBuilder<> &builder,
907 llvm::Function &printFunct,
908 llvm::Value &toPrint,
912909 std::string format,
913910 bool useGlobal = true) {
914911 llvm::Constant *stringConstant = llvm::ConstantArray::get(context, format);
929926 builder.CreateStore(stringConstant, stringVar);
930927 }
931928
932 llvm::Value* cast =
929 llvm::Value *cast =
933930 builder.CreateBitCast(stringVar,
934931 builder.getInt8Ty()->getPointerTo());
935932 builder.CreateCall2(&printFunct, &toPrint, cast);
955952 /// @param exceptionCaughtFlag reference exception caught/thrown status storage
956953 /// @param exceptionStorage reference to exception pointer storage
957954 /// @returns newly created block
958 static llvm::BasicBlock* createFinallyBlock(llvm::LLVMContext& context,
959 llvm::Module& module,
960 llvm::IRBuilder<>& builder,
961 llvm::Function& toAddTo,
962 std::string& blockName,
963 std::string& functionId,
964 llvm::BasicBlock& terminatorBlock,
965 llvm::BasicBlock& unwindResumeBlock,
966 llvm::Value** exceptionCaughtFlag,
967 llvm::Value** exceptionStorage) {
955 static llvm::BasicBlock *createFinallyBlock(llvm::LLVMContext &context,
956 llvm::Module &module,
957 llvm::IRBuilder<> &builder,
958 llvm::Function &toAddTo,
959 std::string &blockName,
960 std::string &functionId,
961 llvm::BasicBlock &terminatorBlock,
962 llvm::BasicBlock &unwindResumeBlock,
963 llvm::Value **exceptionCaughtFlag,
964 llvm::Value **exceptionStorage) {
968965 assert(exceptionCaughtFlag &&
969966 "ExceptionDemo::createFinallyBlock(...):exceptionCaughtFlag "
970967 "is NULL");
978975 ourExceptionNotThrownState->getType(),
979976 ourExceptionNotThrownState);
980977
981 const llvm::PointerType* exceptionStorageType =
978 const llvm::PointerType *exceptionStorageType =
982979 builder.getInt8Ty()->getPointerTo();
983980 *exceptionStorage =
984981 createEntryBlockAlloca(toAddTo,
1002999 bufferToPrint.str(),
10031000 USE_GLOBAL_STR_CONSTS);
10041001
1005 llvm::SwitchInst* theSwitch =
1002 llvm::SwitchInst *theSwitch =
10061003 builder.CreateSwitch(builder.CreateLoad(*exceptionCaughtFlag),
10071004 &terminatorBlock,
10081005 2);
10251022 /// @param terminatorBlock terminator "end" block
10261023 /// @param exceptionCaughtFlag exception caught/thrown status
10271024 /// @returns newly created block
1028 static llvm::BasicBlock* createCatchBlock(llvm::LLVMContext& context,
1029 llvm::Module& module,
1030 llvm::IRBuilder<>& builder,
1031 llvm::Function& toAddTo,
1032 std::string& blockName,
1033 std::string& functionId,
1034 llvm::BasicBlock& terminatorBlock,
1035 llvm::Value& exceptionCaughtFlag) {
1025 static llvm::BasicBlock *createCatchBlock(llvm::LLVMContext &context,
1026 llvm::Module &module,
1027 llvm::IRBuilder<> &builder,
1028 llvm::Function &toAddTo,
1029 std::string &blockName,
1030 std::string &functionId,
1031 llvm::BasicBlock &terminatorBlock,
1032 llvm::Value &exceptionCaughtFlag) {
10361033
10371034 llvm::BasicBlock *ret = llvm::BasicBlock::Create(context,
10381035 blockName,
10781075 /// @param exceptionTypesToCatch array of type info types to "catch"
10791076 /// @returns generated function
10801077 static
1081 llvm::Function* createCatchWrappedInvokeFunction(llvm::Module& module,
1082 llvm::IRBuilder<>& builder,
1083 llvm::FunctionPassManager& fpm,
1084 llvm::Function& toInvoke,
1085 std::string ourId,
1086 unsigned numExceptionsToCatch,
1087 unsigned exceptionTypesToCatch[]) {
1088
1089 llvm::LLVMContext& context = module.getContext();
1078 llvm::Function *createCatchWrappedInvokeFunction(llvm::Module &module,
1079 llvm::IRBuilder<> &builder,
1080 llvm::FunctionPassManager &fpm,
1081 llvm::Function &toInvoke,
1082 std::string ourId,
1083 unsigned numExceptionsToCatch,
1084 unsigned exceptionTypesToCatch[]) {
1085
1086 llvm::LLVMContext &context = module.getContext();
10901087 llvm::Function *toPrint32Int = module.getFunction("print32Int");
10911088
10921089 ArgTypes argTypes;
10951092 ArgNames argNames;
10961093 argNames.push_back("exceptTypeToThrow");
10971094
1098 llvm::Function* ret = createFunction(module,
1095 llvm::Function *ret = createFunction(module,
10991096 builder.getVoidTy(),
11001097 argTypes,
11011098 argNames,
11341131
11351132 std::string nextName;
11361133 std::vector catchBlocks(numExceptionsToCatch);
1137 llvm::Value* exceptionCaughtFlag = NULL;
1138 llvm::Value* exceptionStorage = NULL;
1134 llvm::Value *exceptionCaughtFlag = NULL;
1135 llvm::Value *exceptionStorage = NULL;
11391136
11401137 // Finally block which will branch to unwindResumeBlock if
11411138 // exception is not caught. Initializes/allocates stack locations.
1142 llvm::BasicBlock* finallyBlock = createFinallyBlock(context,
1139 llvm::BasicBlock *finallyBlock = createFinallyBlock(context,
11431140 module,
11441141 builder,
11451142 *ret,
12231220 llvm::Function *ehException = module.getFunction("llvm.eh.exception");
12241221
12251222 // Retrieve thrown exception
1226 llvm::Value* unwindException = builder.CreateCall(ehException);
1223 llvm::Value *unwindException = builder.CreateCall(ehException);
12271224
12281225 // Store exception and flag
12291226 builder.CreateStore(unwindException, exceptionStorage);
12301227 builder.CreateStore(ourExceptionThrownState, exceptionCaughtFlag);
12311228 llvm::Function *personality = module.getFunction("ourPersonality");
1232 llvm::Value* functPtr =
1229 llvm::Value *functPtr =
12331230 builder.CreatePointerCast(personality,
12341231 builder.getInt8Ty()->getPointerTo());
12351232
12551252 // handles this call. This landing pad (this exception block), will be
12561253 // called either because it nees to cleanup (call finally) or a type
12571254 // info was found which matched the thrown exception.
1258 llvm::Value* retTypeInfoIndex = builder.CreateCall(ehSelector,
1255 llvm::Value *retTypeInfoIndex = builder.CreateCall(ehSelector,
12591256 args.begin(),
12601257 args.end());
12611258
12621259 // Retrieve exception_class member from thrown exception
12631260 // (_Unwind_Exception instance). This member tells us whether or not
12641261 // the exception is foreign.
1265 llvm::Value* unwindExceptionClass =
1262 llvm::Value *unwindExceptionClass =
12661263 builder.CreateLoad(builder.CreateStructGEP(
12671264 builder.CreatePointerCast(unwindException,
12681265 ourUnwindExceptionType->getPointerTo()),
12971294 // (OurException instance).
12981295 //
12991296 // Note: ourBaseFromUnwindOffset is usually negative
1300 llvm::Value* typeInfoThrown =
1297 llvm::Value *typeInfoThrown =
13011298 builder.CreatePointerCast(builder.CreateConstGEP1_64(unwindException,
13021299 ourBaseFromUnwindOffset),
13031300 ourExceptionType->getPointerTo());
13081305 // unlike a true getelementptr (GEP) instruction
13091306 typeInfoThrown = builder.CreateStructGEP(typeInfoThrown, 0);
13101307
1311 llvm::Value* typeInfoThrownType =
1308 llvm::Value *typeInfoThrownType =
13121309 builder.CreateStructGEP(typeInfoThrown, 0);
13131310
13141311 generateIntegerPrint(context,
13231320 USE_GLOBAL_STR_CONSTS);
13241321
13251322 // Route to matched type info catch block or run cleanup finally block
1326 llvm::SwitchInst* switchToCatchBlock =
1323 llvm::SwitchInst *switchToCatchBlock =
13271324 builder.CreateSwitch(retTypeInfoIndex,
13281325 finallyBlock,
13291326 numExceptionsToCatch);
13591356 /// if the above nativeThrowType matches generated function's arg.
13601357 /// @returns generated function
13611358 static
1362 llvm::Function* createThrowExceptionFunction(llvm::Module& module,
1363 llvm::IRBuilder<>& builder,
1364 llvm::FunctionPassManager& fpm,
1359 llvm::Function *createThrowExceptionFunction(llvm::Module &module,
1360 llvm::IRBuilder<> &builder,
1361 llvm::FunctionPassManager &fpm,
13651362 std::string ourId,
13661363 int32_t nativeThrowType,
1367 llvm::Function& nativeThrowFunct) {
1368 llvm::LLVMContext& context = module.getContext();
1364 llvm::Function &nativeThrowFunct) {
1365 llvm::LLVMContext &context = module.getContext();
13691366 namedValues.clear();
13701367 ArgTypes unwindArgTypes;
13711368 unwindArgTypes.push_back(builder.getInt32Ty());
13971394 "generatedThrow",
13981395 ret);
13991396 // Retrieved runtime type info type to throw
1400 llvm::Value* exceptionType = namedValues["exceptTypeToThrow"];
1397 llvm::Value *exceptionType = namedValues["exceptTypeToThrow"];
14011398
14021399 // nativeThrowBlock block
14031400
14251422 // Switches on runtime type info type value to determine whether or not
14261423 // a foreign exception is thrown. Defaults to throwing one of our
14271424 // generated exceptions.
1428 llvm::SwitchInst* theSwitch = builder.CreateSwitch(exceptionType,
1425 llvm::SwitchInst *theSwitch = builder.CreateSwitch(exceptionType,
14291426 generatedThrowBlock,
14301427 1);
14311428
14431440 module.getFunction("_Unwind_RaiseException");
14441441
14451442 // Creates exception to throw with runtime type info type.
1446 llvm::Value* exception =
1443 llvm::Value *exception =
14471444 builder.CreateCall(createOurException,
14481445 namedValues["exceptTypeToThrow"]);
14491446
14581455 }
14591456
14601457 static void createStandardUtilityFunctions(unsigned numTypeInfos,
1461 llvm::Module& module,
1462 llvm::IRBuilder<>& builder);
1458 llvm::Module &module,
1459 llvm::IRBuilder<> &builder);
14631460
14641461 /// Creates test code by generating and organizing these functions into the
14651462 /// test case. The test case consists of an outer function setup to invoke
14811478 /// @param nativeThrowFunctName name of external function which will throw
14821479 /// a foreign exception
14831480 /// @returns outermost generated test function.
1484 llvm::Function* createUnwindExceptionTest(llvm::Module& module,
1485 llvm::IRBuilder<>& builder,
1486 llvm::FunctionPassManager& fpm,
1481 llvm::Function *createUnwindExceptionTest(llvm::Module &module,
1482 llvm::IRBuilder<> &builder,
1483 llvm::FunctionPassManager &fpm,
14871484 std::string nativeThrowFunctName) {
14881485 // Number of type infos to generate
14891486 unsigned numTypeInfos = 6;
14981495
14991496 // Create exception throw function using the value ~0 to cause
15001497 // foreign exceptions to be thrown.
1501 llvm::Function* throwFunct =
1498 llvm::Function *throwFunct =
15021499 createThrowExceptionFunction(module,
15031500 builder,
15041501 fpm,
15111508 sizeof(unsigned);
15121509
15131510 // Generate inner function.
1514 llvm::Function* innerCatchFunct =
1511 llvm::Function *innerCatchFunct =
15151512 createCatchWrappedInvokeFunction(module,
15161513 builder,
15171514 fpm,
15261523 sizeof(unsigned);
15271524
15281525 // Generate outer function
1529 llvm::Function* outerCatchFunct =
1526 llvm::Function *outerCatchFunct =
15301527 createCatchWrappedInvokeFunction(module,
15311528 builder,
15321529 fpm,
15461543 OurCppRunException(const std::string reason) :
15471544 std::runtime_error(reason) {}
15481545
1549 OurCppRunException (const OurCppRunException& toCopy) :
1546 OurCppRunException (const OurCppRunException &toCopy) :
15501547 std::runtime_error(toCopy) {}
15511548
1552 OurCppRunException& operator = (const OurCppRunException& toCopy) {
1549 OurCppRunException &operator = (const OurCppRunException &toCopy) {
15531550 return(reinterpret_cast(
15541551 std::runtime_error::operator=(toCopy)));
15551552 }
15781575 /// @param typeToThrow type info type of generated exception to throw, or
15791576 /// indicator to cause foreign exception to be thrown.
15801577 static
1581 void runExceptionThrow(llvm::ExecutionEngine* engine,
1582 llvm::Function* function,
1578 void runExceptionThrow(llvm::ExecutionEngine *engine,
1579 llvm::Function *function,
15831580 int32_t typeToThrow) {
15841581
15851582 // Find test's function pointer
16231620 /// @param module code for module instance
16241621 /// @param builder builder instance
16251622 static void createStandardUtilityFunctions(unsigned numTypeInfos,
1626 llvm::Module& module,
1627 llvm::IRBuilder<>& builder) {
1628
1629 llvm::LLVMContext& context = module.getContext();
1623 llvm::Module &module,
1624 llvm::IRBuilder<> &builder) {
1625
1626 llvm::LLVMContext &context = module.getContext();
16301627
16311628 // Exception initializations
16321629
16821679 std::vector structVals;
16831680
16841681 llvm::Constant *nextStruct;
1685 llvm::GlobalVariable* nextGlobal = NULL;
1682 llvm::GlobalVariable *nextGlobal = NULL;
16861683
16871684 // Generate each type info
16881685 //
17111708
17121709 ArgNames argNames;
17131710 ArgTypes argTypes;
1714 llvm::Function* funct = NULL;
1711 llvm::Function *funct = NULL;
17151712
17161713 // print32Int
17171714
1718 const llvm::Type* retType = builder.getVoidTy();
1715 const llvm::Type *retType = builder.getVoidTy();
17191716
17201717 argTypes.clear();
17211718 argTypes.push_back(builder.getInt32Ty());
19091906 /// <= 6 and >= 1 will be caught by test functions; and type info types > 6
19101907 /// will result in exceptions which pass through to the test harness. All other
19111908 /// type info types are not supported and could cause a crash.
1912 int main(int argc, char* argv[]) {
1909 int main(int argc, char *argv[]) {
19131910 if (argc == 1) {
19141911 fprintf(stderr,
19151912 "\nUsage: ExceptionDemo "
19281925 llvm::JITExceptionHandling = true;
19291926
19301927 llvm::InitializeNativeTarget();
1931 llvm::LLVMContext& context = llvm::getGlobalContext();
1928 llvm::LLVMContext &context = llvm::getGlobalContext();
19321929 llvm::IRBuilder<> theBuilder(context);
19331930
19341931 // Make the module, which holds all the code.
1935 llvm::Module* module = new llvm::Module("my cool jit", context);
1932 llvm::Module *module = new llvm::Module("my cool jit", context);
19361933
19371934 // Build engine with JIT
19381935 llvm::EngineBuilder factory(module);
19391936 factory.setEngineKind(llvm::EngineKind::JIT);
19401937 factory.setAllocateGVsWithCode(false);
1941 llvm::ExecutionEngine* executionEngine = factory.create();
1938 llvm::ExecutionEngine *executionEngine = factory.create();
19421939
19431940 {
19441941 llvm::FunctionPassManager fpm(module);
19751972
19761973 // Generate test code using function throwCppException(...) as
19771974 // the function which throws foreign exceptions.
1978 llvm::Function* toRun =
1975 llvm::Function *toRun =
19791976 createUnwindExceptionTest(*module,
19801977 theBuilder,
19811978 fpm,