| ... | ... | @@ -43,31 +43,8 @@ |
| 43 | 43 | |
| 44 | 44 | #include <stdlib.h> |
| 45 | 45 | |
| 46 | | #if defined(_MSC_VER) |
| 47 | | #define ATTRIBUTE_RETURNS_NOALIAS __declspec(restrict) |
| 48 | | #else |
| 49 | | #define ATTRIBUTE_RETURNS_NOALIAS __attribute__((__malloc__)) |
| 50 | | #endif |
| 51 | | |
| 52 | 46 | using namespace llvm; |
| 53 | 47 | |
| 54 | | template<typename T, typename... Args> |
| 55 | | ATTRIBUTE_RETURNS_NOALIAS static inline T * create(Args... args) { |
| 56 | | T * ptr = reinterpret_cast<T*>(malloc(sizeof(T))); |
| 57 | | if (ptr == nullptr) |
| 58 | | return nullptr; |
| 59 | | new (ptr) T(args...); |
| 60 | | return ptr; |
| 61 | | } |
| 62 | | |
| 63 | | template<typename T> |
| 64 | | static inline void destroy(T * ptr) { |
| 65 | | if (ptr != nullptr) { |
| 66 | | ptr[0].~T(); |
| 67 | | } |
| 68 | | free(ptr); |
| 69 | | } |
| 70 | | |
| 71 | 48 | void ZigLLVMInitializeLoopStrengthReducePass(LLVMPassRegistryRef R) { |
| 72 | 49 | initializeLoopStrengthReducePass(*unwrap(R)); |
| 73 | 50 | } |
| ... | ... | @@ -116,7 +93,11 @@ bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMM |
| 116 | 93 | |
| 117 | 94 | Module* module = unwrap(module_ref); |
| 118 | 95 | |
| 119 | | PassManagerBuilder *PMBuilder = create<PassManagerBuilder>(); |
| 96 | PassManagerBuilder *PMBuilder = new(std::nothrow) PassManagerBuilder(); |
| 97 | if (PMBuilder == nullptr) { |
| 98 | *error_message = strdup("memory allocation failure"); |
| 99 | return true; |
| 100 | } |
| 120 | 101 | PMBuilder->OptLevel = target_machine->getOptLevel(); |
| 121 | 102 | PMBuilder->SizeLevel = 0; |
| 122 | 103 | |
| ... | ... | @@ -150,7 +131,8 @@ bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMM |
| 150 | 131 | |
| 151 | 132 | // Set up the per-function pass manager. |
| 152 | 133 | legacy::FunctionPassManager FPM = legacy::FunctionPassManager(module); |
| 153 | | FPM.add(create<TargetLibraryInfoWrapperPass>(tlii)); |
| 134 | auto tliwp = new(std::nothrow) TargetLibraryInfoWrapperPass(tlii); |
| 135 | FPM.add(tliwp); |
| 154 | 136 | FPM.add(createTargetTransformInfoWrapperPass(target_machine->getTargetIRAnalysis())); |
| 155 | 137 | if (assertions_on) { |
| 156 | 138 | FPM.add(createVerifierPass()); |
| ... | ... | @@ -446,10 +428,9 @@ unsigned ZigLLVMTag_DW_union_type(void) { |
| 446 | 428 | } |
| 447 | 429 | |
| 448 | 430 | ZigLLVMDIBuilder *ZigLLVMCreateDIBuilder(LLVMModuleRef module, bool allow_unresolved) { |
| 449 | | DIBuilder *di_builder = reinterpret_cast<DIBuilder*>(malloc(sizeof(DIBuilder))); |
| 431 | DIBuilder *di_builder = new(std::nothrow) DIBuilder(*unwrap(module), allow_unresolved); |
| 450 | 432 | if (di_builder == nullptr) |
| 451 | 433 | return nullptr; |
| 452 | | new (di_builder) DIBuilder(*unwrap(module), allow_unresolved); |
| 453 | 434 | return reinterpret_cast<ZigLLVMDIBuilder *>(di_builder); |
| 454 | 435 | } |
| 455 | 436 | |