<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - Invoke a Function Pass in clang getting: `use_empty() && Uses remain when value is destriyed!"', function ~Value"
href="https://bugs.llvm.org/show_bug.cgi?id=36183">36183</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Invoke a Function Pass in clang getting: `use_empty() && Uses remain when value is destriyed!"', function ~Value
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>-New Bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>golamkayas@temple.edu
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=19784" name="attach_19784" title="LLVM IR file">attachment 19784</a> <a href="attachment.cgi?id=19784&action=edit" title="LLVM IR file">[details]</a></span>
LLVM IR file
Hi,
I build LLVM from the trunk on 30 January 2018.
I write a simple function pass try to instrument a thread-local global
variable. And the value of the variable before instruction.
To build the pass, I put my pass folder under <llvmm_source>/lib/Transform and
made the necessary changes in the CMakeList file
When I try to invoke the pass using "opt" like below:
clang -O0 -emit-llvm test.c -c -o test_unoptimized.bc
opt -load $OBJ_ROOT/lib/SimplePass.so -instrument < test_unoptimized.bc >
test_unoptimized_new.bc
clang -g test_unoptimized_new.bc -o test_unoptimized_new
It works fine. But whenever I tried to invoke the pass without the involvement
of
like below:
clang -Xclang -load -Xclang $LIB/SimplePass.so -O0 s test.c -o test
I got the "use_empty()" error.
My pass looks like below:
#include "llvm/IR/Function.h"
#include "llvm/IR/LegacyPassManager.h"
#include "llvm/Pass.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include <boost/functional/hash.hpp>
#include <tr1/functional>
using namespace llvm;
namespace {
struct SimplePass : public FunctionPass {
public:
static char ID;
SimplePass() : FunctionPass(ID) {}
virtual bool runOnFunction(Function &F) {
static LLVMContext ctx;
Module *parentModule = F.getParent();
GlobalVariable *gPCC;
Type *Int32Type = IntegerType::getInt32Ty(ctx);
BasicBlock &entryBlock = F.getEntryBlock();
Instruction *instPt = &entryBlock.front();
IRBuilder<> B(instPt);
LoadInst *LI;
Constant *value;
Constant *zero = ConstantInt::get(Int32Type, (uint64_t)0, false);
unsigned int callsite_index = 0;
if (!parentModule->getGlobalVariable("t_pcc")) {
gPCC = new GlobalVariable(
*parentModule,
Int32Type,
false,
GlobalValue::CommonLinkage,
zero,
"t_pcc",
0,
GlobalVariable::InitialExecTLSModel);
gPCC->setAlignment(4);
} else {
gPCC = parentModule->getGlobalVariable("t_pcc");
}
LI = B.CreateLoad(gPCC);
for (auto &BB : F) {
for (auto &I : BB) {
callsite_index++;
if (auto *callInst = dyn_cast<CallInst>(&I)) {
IRBuilder<> callSiteBuilder(callInst);
value = ConstantInt::get(Int32Type, 10);
callSiteBuilder.CreateStore(value, gPCC);
}
}
}
errs() << "Instrumented Function: " << F.getName() << "\n";
return true;
}
};
} // namespace
char SimplePass::ID = 0;
namespace{
static RegisterPass<SimplePass> X("instrument", "Instrumentaion Pass", false,
false);
}
static void registerPCCSimple(const PassManagerBuilder &,
legacy::PassManagerBase &PM) {
PM.add(new SimplePass());
}
static RegisterStandardPasses
RegisterMyPass(PassManagerBuilder::EP_EarlyAsPossible,
registerPCCSimple);
//End of the pass
I am attaching my pass and my LLVM IR(.i) file.
Thanks.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>