| OLD | NEW |
| 1 //===- ExpandVarArgs.cpp - Expand out variable argument function calls-----===// | 1 //===- ExpandVarArgs.cpp - Expand out variable argument function calls-----===// |
| 2 // | 2 // |
| 3 // The LLVM Compiler Infrastructure | 3 // The LLVM Compiler Infrastructure |
| 4 // | 4 // |
| 5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
| 6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
| 7 // | 7 // |
| 8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
| 9 // | 9 // |
| 10 // This pass expands out all use of variable argument functions. | 10 // This pass expands out all use of variable argument functions. |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 // This allows va_arg to read an undefined value from the stack | 223 // This allows va_arg to read an undefined value from the stack |
| 224 // rather than crashing by reading from an uninitialized pointer. | 224 // rather than crashing by reading from an uninitialized pointer. |
| 225 // An alternative would be to pass a null pointer to catch the | 225 // An alternative would be to pass a null pointer to catch the |
| 226 // invalid use of va_arg. | 226 // invalid use of va_arg. |
| 227 VarArgsTypes.push_back(Type::getInt32Ty(*Context)); | 227 VarArgsTypes.push_back(Type::getInt32Ty(*Context)); |
| 228 } | 228 } |
| 229 | 229 |
| 230 // Create struct type for packing variable arguments into. We | 230 // Create struct type for packing variable arguments into. We |
| 231 // create this as packed for now and assume that no alignment | 231 // create this as packed for now and assume that no alignment |
| 232 // padding is desired. | 232 // padding is desired. |
| 233 StructType *VarArgsTy = StructType::create(VarArgsTypes, "vararg_call", true); | 233 StructType *VarArgsTy = StructType::get(*Context, VarArgsTypes, true); |
| 234 | 234 |
| 235 // Allocate space for the variable argument buffer. Do this at the | 235 // Allocate space for the variable argument buffer. Do this at the |
| 236 // start of the function so that we don't leak space if the function | 236 // start of the function so that we don't leak space if the function |
| 237 // is called in a loop. | 237 // is called in a loop. |
| 238 Function *Func = Call->getParent()->getParent(); | 238 Function *Func = Call->getParent()->getParent(); |
| 239 Instruction *Buf = new AllocaInst(VarArgsTy, "vararg_buffer"); | 239 Instruction *Buf = new AllocaInst(VarArgsTy, "vararg_buffer"); |
| 240 Func->getEntryBlock().getInstList().push_front(Buf); | 240 Func->getEntryBlock().getInstList().push_front(Buf); |
| 241 | 241 |
| 242 // Call llvm.lifetime.start/end intrinsics to indicate that Buf is | 242 // Call llvm.lifetime.start/end intrinsics to indicate that Buf is |
| 243 // only used for the duration of the function call, so that the | 243 // only used for the duration of the function call, so that the |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 ExpandVarArgFunc(Func); | 330 ExpandVarArgFunc(Func); |
| 331 } | 331 } |
| 332 } | 332 } |
| 333 | 333 |
| 334 return Changed; | 334 return Changed; |
| 335 } | 335 } |
| 336 | 336 |
| 337 ModulePass *llvm::createExpandVarArgsPass() { | 337 ModulePass *llvm::createExpandVarArgsPass() { |
| 338 return new ExpandVarArgs(); | 338 return new ExpandVarArgs(); |
| 339 } | 339 } |
| OLD | NEW |