@@ -203,7 +203,7 @@ CodeGen_Posix::Allocation CodeGen_Posix::create_allocation(const std::string &na
203203 // allocation that occurs conditionally. TODO: Why not
204204 // just register the destructor at entry?
205205
206- builder->CreateStore (builder-> CreatePointerCast ( slot, PointerType::get ( i8_t , 0 )) , allocation.destructor );
206+ builder->CreateStore (slot, allocation.destructor );
207207 free_stack_allocs.erase (it);
208208 } else {
209209 // Stack allocation with a dynamic size
@@ -220,14 +220,11 @@ CodeGen_Posix::Allocation CodeGen_Posix::create_allocation(const std::string &na
220220
221221 llvm::Function::arg_iterator arg_iter = alloc_fn->arg_begin ();
222222 ++arg_iter; // skip the user context *
223- slot = builder->CreatePointerCast (slot, arg_iter->getType ());
224223 ++arg_iter; // skip the pointer to the stack slot
225224 llvm::Type *size_type = arg_iter->getType ();
226225 llvm_size = builder->CreateIntCast (llvm_size, size_type, false );
227226 Value *args[3 ] = {get_user_context (), slot, llvm_size};
228227 Value *call = builder->CreateCall (alloc_fn, args);
229- llvm::Type *ptr_type = PointerType::get (llvm_type_of (type), 0 );
230- call = builder->CreatePointerCast (call, ptr_type);
231228
232229 // Figure out how much we need to allocate on the real stack
233230 Value *returned_non_null = builder->CreateIsNotNull (call);
@@ -240,21 +237,19 @@ CodeGen_Posix::Allocation CodeGen_Posix::create_allocation(const std::string &na
240237 builder->SetInsertPoint (need_alloca_bb);
241238
242239 // Allocate it. It's zero most of the time.
243- AllocaInst *alloca_inst = builder->CreateAlloca (PointerType::get ( i8_t , 0 ) , llvm_size);
240+ AllocaInst *alloca_inst = builder->CreateAlloca (ptr_t , llvm_size);
244241 // Give it the right alignment
245242 alloca_inst->setAlignment (llvm::Align (native_vector_bits () / 8 ));
246243
247244 // Set the pseudostack slot ptr to the right thing so we reuse
248245 // this pointer next time around.
249- Value *stack_ptr = builder->CreatePointerCast (alloca_inst, ptr_type);
250- Value *slot_ptr_ptr = builder->CreatePointerCast (slot, PointerType::get (ptr_type, 0 ));
251- builder->CreateStore (stack_ptr, slot_ptr_ptr);
246+ builder->CreateStore (alloca_inst, slot);
252247
253248 builder->CreateBr (after_bb);
254249 builder->SetInsertPoint (after_bb);
255250
256- PHINode *phi = builder->CreatePHI (ptr_type , 2 );
257- phi->addIncoming (stack_ptr , need_alloca_bb);
251+ PHINode *phi = builder->CreatePHI (ptr_t , 2 );
252+ phi->addIncoming (alloca_inst , need_alloca_bb);
258253 phi->addIncoming (call, here_bb);
259254
260255 allocation.ptr = phi;
@@ -282,9 +277,6 @@ CodeGen_Posix::Allocation CodeGen_Posix::create_allocation(const std::string &na
282277
283278 Value *call = builder->CreateCall (malloc_fn, args);
284279
285- // Fix the type to avoid pointless bitcasts later
286- call = builder->CreatePointerCast (call, PointerType::get (llvm_type_of (type), 0 ));
287-
288280 allocation.ptr = call;
289281 }
290282
0 commit comments