[LLVMdev] Help with replacing instructions via function pass

Shivam Bhagi shivam.bhagi at outlook.com
Thu Dec 5 12:13:01 PST 2013


Hi,

In my IR code, I have the following:

%arr = alloca [30 x i8], align 1
%arraydecay = getelementptr inbounds [16 x i8]* %arr, i32 0, i32 0
%arraydecay1 = getelementptr inbounds [16 x i8]* %arr, i32 0, i32 0

I'm trying to change the capacity of arr via a function pass. I've written the following code in my function pass:

ArrayType* b = ArrayType::get(IntegerType::get(getGlobalContext(), 8), 10);
AllocaInst* pa = new AllocaInst(b, "arr");
//I  is an instruction pointer currently pointing to %arr = alloca [30 x i8], align 1
I->replaceAllUsesWith(pa);        
I->eraseFromParent();
I->getParent()->getInstList().insert(*I, pa);

When I run the pass, I run into the following error:

Stack dump:

Return code not zero; aborting
void llvm::Value::replaceAllUsesWith(llvm::Value*): Assertion `New->getType() == getType() && "replaceAllUses of value with new value of different type!"' failed.
0  opt           0x08fc4996 llvm::sys::PrintStackTrace(_IO_FILE*) + 50
1  opt           0x08fc4be9
2  opt           0x08fc45f0
3                0xb77c4400 __kernel_sigreturn + 0
4                0xb77c4422 __kernel_vsyscall + 2
5  libc.so.6     0xb751f941 gsignal + 81
6  libc.so.6     0xb7522d72 abort + 386
7  libc.so.6     0xb7518b58 __assert_fail + 248
8  opt           0x08edfb85 llvm::Value::replaceAllUsesWith(llvm::Value*) + 187
9  CS6265Pass.so 0xb77bdee4
10 opt           0x08ec5317 llvm::FPPassManager::runOnFunction(llvm::Function&) + 301
11 opt           0x08ec54b8 llvm::FPPassManager::runOnModule(llvm::Module&) + 92
12 opt           0x08ec57bc llvm::MPPassManager::runOnModule(llvm::Module&) + 496
13 opt           0x08ec5d4d llvm::PassManagerImpl::run(llvm::Module&) + 229
14 opt           0x08ec5f41 llvm::PassManager::run(llvm::Module&) + 39
15 opt           0x0849c28b main + 5835
16 libc.so.6     0xb750be46 __libc_start_main + 230
17 opt           0x0848e4b1

How can I fix it?

Thanks,
Shivam
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20131205/95e68986/attachment.html>


More information about the llvm-dev mailing list