LLVM内存损坏

时间:2013-05-29 19:56:40

标签: c++ llvm

我在LLVM传递中遇到了一些C ++内存损坏问题,我不知道如何解决它们。这是我的代码:

在每个基本块的大循环中我有:

std::vector<Value*> values(cnt);

// Value** values=new Value*[cnt];
// for(gy=0;gy<cnt;gy++){
//   values[gy] = new Value;
// }

if(is)
{
    LLVMContext& C = is->getContext();
    errs()<<"\ni: \n";


    for(i=0;i<cnt;i++){
        values[i]=ConstantInt::getSigned(Type::getInt64Ty(C),myArray[i]);
         errs()<<" "<<myArray[i];
     }

    //SmallVector<Value*>* bla = new SmallVector<Value*>(200);
      std::vector<Value*> bla(200);
      //SmallVector<Value*,200> bla;

       for(i=0;i<cnt;i++){
          bla.push_back(values[i]);
       }

       is->setMetadata("path",MDNode::get(C,bla));

       errs()<<"\nmodified instr  "<<*is<<"\n";

       if( (is->getMetadata("path")) ){ 
           for(i=0;i<cnt;i++){
             if(is->getMetadata("path")->getOperand(i)) {
                 errs()<<"\nget instr  "<<*(is->getMetadata("path")->getOperand(i))<<"\n";
              }
           }
        }

    bla.clear();

       //for(i=0;i<cnt;i++)
         //delete values[i];

}
values.clear();

错误是:

opt: malloc.c:3790: _int_malloc: Assertion `(unsigned long)(size) >= (unsigned long)(nb)' failed.

没有从循环中打印出来的东西(只有当我到达第7个基本块时,这与其他块相似)。

我还尝试了在代码中注释//的备选方案。也许堆栈内存会以某种方式损坏,我需要在堆上分配向量/数组(我尝试了一些变体)?我还尝试首先删除向量/数组中的元素,然后删除指向数组/向量的指针。 我必须提到,当我必须添加的元数据不是那么大(只有18个操作数而不是72个)时,它运行良好。 你认为使用Valgrind可能值得吗?它对我有什么帮助?

感谢您的任何建议!

...........

作为更新,我在某些基本块上收到内存损坏错误。以下是调试输出:

  1. 选择 - opt: malloc.c:3801: _int_malloc: Assertion (unsigned long)(size) >= (unsigned long)(nb) failed.

  2. gdb -

    Program received signal SIGABRT, Aborted.
    0xb7fdd424 in __kernel_vsyscall ()
    
  3. valgrind - 它执行所有代码并在有问题的循环迭代中执行:

    == 5134 ==写入大小4无效 == 5134 == at 0x4039280 :(匿名命名空间):: Hello :: runOnModule(llvm :: Module&amp;)(在/home/alex/llvm/Release+Asserts/lib/Hello.so中) == 5134 == by 0x8E33DE3:llvm :: MPPassManager :: runOnModule(llvm :: Module&amp;)(在/ home / alex / llvm / Release + Asserts / bin / opt中) == 5134 == by 0x8E3726F:llvm :: PassManagerImpl :: run(llvm :: Module&amp;)(在/ home / alex / llvm / Release + Asserts / bin / opt中) == 5134 == by 0x8E37385:llvm :: PassManager :: run(llvm :: Module&amp;)(在/ home / alex / llvm / Release + Asserts / bin / opt中) == 5134 == by 0x41AE4D2 :(低于主要)(libc-start.c:226) == 5134 ==地址0x46cfa40在分配大小为200的块后为0字节 == 5134 == at 0x402C454:operator new [](unsigned int)(在/usr/lib/valgrind/vgpreload_memcheck-x86-linux.so中) == 5134 == by 0x4037AE0 :(匿名命名空间):: Hello :: runOnModule(llvm :: Module&amp;)(在/home/alex/llvm/Release+Asserts/lib/Hello.so)

  4. 并重复。

    ==5230== HEAP SUMMARY:
    ==5230==     in use at exit: 95,110 bytes in 317 blocks
    ==5230==   total heap usage: 33,395 allocs, 33,078 frees, 4,484,753 bytes allocated
    ==5230==
    ==5230== LEAK SUMMARY:
    ==5230==    definitely lost: 7,732 bytes in 31 blocks
    ==5230==    indirectly lost: 85,864 bytes in 275 blocks
    ==5230==      possibly lost: 0 bytes in 0 blocks
    ==5230==    still reachable: 1,514 bytes in 11 blocks
    ==5230==         suppressed: 0 bytes in 0 blocks
    ==5230== Rerun with --leak-check=full to see details of leaked memory
    ==5230==
    ==5230== For counts of detected and suppressed errors, rerun with: -v
    ==5230== ERROR SUMMARY: 16432 errors from 15 contexts (suppressed: 0 from 0)
    

    我认为主要问题是: 我没有为价值分配好记忆。或者我可能只为Value *指针分配,而不是为实际值分配。也许我不释放内存。 2.我不能使用数组而不是矢量,因为is-&gt; setMetadata(“path”,MDNode :: get(C,values));不会让我。

    您认为使用Valgrind可能值得吗?它怎么能帮到我?我只想附加一些整数作为元数据,每个操作数一个整数。

    感谢您的任何建议!

0 个答案:

没有答案
相关问题