[LLVMdev] instruction sequence

Jerry Hom jhom at cs.rutgers.edu
Fri Jun 30 15:50:13 PDT 2006


I'm trying to insert a call to fprintf(stderr, ...).  I've looked at
the emitted assembly from llvm-gcc, and it consists of a LoadInst (of
stderr) and CallInst.  It looks like this:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	%tmp.1 = load %struct._IO_FILE** %stderr		 ; ty=%struct._IO_FILE*
	%tmp.0 = call int (%struct._IO_FILE*, sbyte*, ...)* %fprintf(%struct._IO_FILE* %tmp.1, sbyte* getelementptr ([6 x sbyte]* %.str_1, int 0, int 0))		 ; ty=int
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

I essentially modified the code example from Ryan Lefever's post on
May 1, 2006.  Here's a snippet of my code:

****************************************
   Constant* constStr = ConstantArray::get("test\n");
   GlobalVariable* gv = new GlobalVariable
     (constStr->getType(), true, GlobalValue::InternalLinkage, constStr,
      "", MP);
   std::vector<Constant*> geplist;
   geplist.push_back(ConstantUInt::get(Type::UIntTy,0));
   geplist.push_back(ConstantUInt::get(Type::UIntTy,0));
   Constant* gep = ConstantExpr::getGetElementPtr(gv,geplist);

   IP = new LoadInst(GVstderr, "loadstderr", IP);
   IPstderr = IP;

   std::vector<Value*> args;
   args.push_back(IPstderr);
   args.push_back(gep);

   IP = new CallInst(F, args, "", IP);
****************************************

However, I'm getting the following error message:

----------------------------------------
Instruction does not dominate all uses!
        %loadstderr = load %struct._IO_FILE** %stderr           ; <%struct._IO_FILE*> [#uses=1]
        call int (%struct._IO_FILE*, sbyte*, ...)* %fprintf( %struct._IO_FILE* %loadstderr, sbyte* getelementptr ([6 x sbyte]* %0, uint 0, uint 0) )           ; <int>:0 [#uses=0]
Broken module found, compilation aborted!
----------------------------------------

Can someone tell me what I'm doing wrong?  Thanks.

-- 
Jerry Hom




More information about the llvm-dev mailing list