How to insert inline assembly instruction by using llvm pass

I tried to insert an assembly instruction into each base block using pass in the IR Pass of LLVM.

BasicBlock::iterator IP = BB.getFirstInsertionPt();
            IRBuilder<> IRB(&(*IP));
            StringRef asmString = "int3";
            StringRef constraints = "";
            llvm::InlineAsm *IA = llvm::InlineAsm::get(Ty,asmString,constraints,true,false,InlineAsm::AD_ATT); 
            ArrayRef<Value *> Args = None;
            llvm::CallInst *Ptr = IRB.CreateCall(IA,Args);

However, the following error occurs during execution

Assertion `Verify(getFunctionType(), constraints) && "Function type not 
legal for constraints!"' failed.

But I don’t know why. What can I do about it. Thanks.

What’s Ty? That seems to be the part it’s complaining about.

Ty is the type of the current function.

FunctionType *Ty = F.getFunctionType(); // F is the current function.

Is there a mistake here?

Yes, Ty should be something like void() for no constraints, regardless of what function you’re inserting the asm into.

It’s because you’re trying to produce something like call void asm "int3", ""(), which is a call taking no args and returning nothing (i.e. void()).

Thanks! This error has now been fixed, but even though it compiles, it doesn’t seem to be doing what I wanted, no INT3 statements were inserted into the corresponding file.

LLVMContext *Ctx = nullptr;
Ctx = &M.getContext();
BasicBlock::iterator IP = BB.getFirstInsertionPt();
IRBuilder<> IRB(&(*IP));
StringRef asmString = "int3";
StringRef constraints = "~{dirflag},~{fpsr},~{flags}";
llvm::InlineAsm *IA = llvm::InlineAsm::get(Ty,asmString,constraints,true,false,InlineAsm::AD_ATT); 
ArrayRef<Value *> Args = None;
llvm::CallInst *Ptr = IRB.CreateCall(IA,Args);
Ptr->addAttribute(AttributeList::FunctionIndex, Attribute::NoUnwind); 

I found that no INT3 instructions were inserted into the file.I compared the statement I created with Ptr:

call void asm sideeffect “int3”, “~{dirflag},~{fpsr},~{flags}”() #4

And the real INT3 in IR is:

call void asm sideeffect “int3”, “~{dirflag},~{fpsr},~{flags}”() #2, !srcloc !2

I wonder how can I modify my code to make it work?