Skip to content

Commit 6b73a0a

Browse files
committed
fix arg2
1 parent 49ddfbe commit 6b73a0a

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

lab6/llvm-pass.so.cc

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,20 @@ PreservedAnalyses LLVMPass::run(Module &M, ModuleAnalysisManager &MAM) {
3030
Value *argcArg = &*args++;
3131
Value *argvArg = &*args;
3232

33-
// argv[1] = "hayaku... motohayaku!"
34-
Value *idxs[] = {
35-
ConstantInt::get(Int32Ty, 1)
36-
};
37-
Value *argv1Ptr = Builder.CreateInBoundsGEP(argvArg, idxs, "argv1_ptr");
33+
// 正確計算 argv[1] 的位址並存入字串
34+
Value *argv1Ptr = Builder.CreateInBoundsGEP(
35+
PointerType::getUnqual(Type::getInt8PtrTy(Ctx)),
36+
argvArg,
37+
{ConstantInt::get(Int32Ty, 1)},
38+
"argv1_ptr"
39+
);
3840
Builder.CreateStore(StrConstant, argv1Ptr);
3941

40-
// 3. 將 argc 改為 48763
41-
argcArg->replaceAllUsesWith(debug_arg); // 把 argc 的所有使用都替換成 48763
42+
// 3. 將所有 argc 的用法替換為常數 48763
43+
for (auto it = argcArg->use_begin(), et = argcArg->use_end(); it != et;) {
44+
Use &use = *it++;
45+
use.set(debug_arg);
46+
}
4247
}
4348

4449
}

0 commit comments

Comments
 (0)