Fix problems with programs that prototype printf to something unusual
[oota-llvm.git] / lib / Target / CBackend / CBackend.cpp
index 0a9c8d1d017edd1bd4a2ffb1db39a8ccbf9845b0..65919e8c48d9cc6423f9dff589312003c6410ff1 100644 (file)
@@ -869,12 +869,12 @@ void CWriter::printFunction(Function *F) {
         if (FPC->getType() == Type::DoubleTy)
           Out << "  const ConstantDoubleTy FloatConstant" << FPCounter++
               << " = 0x" << std::hex << *(unsigned long long*)&Val << std::dec
-              << ";    /* " << Val << " */\n";
+              << "ULL;    /* " << Val << " */\n";
         else if (FPC->getType() == Type::FloatTy) {
           float fVal = Val;
           Out << "  const ConstantFloatTy FloatConstant" << FPCounter++
               << " = 0x" << std::hex << *(unsigned*)&fVal << std::dec
-              << ";    /* " << Val << " */\n";
+              << "U;    /* " << Val << " */\n";
         } else
           assert(0 && "Unknown float type!");
       }
@@ -886,7 +886,7 @@ void CWriter::printFunction(Function *F) {
     BasicBlock *Prev = BB->getPrev();
 
     // Don't print the label for the basic block if there are no uses, or if the
-    // only terminator use is the precessor basic block's terminator.  We have
+    // only terminator use is the predecessor basic block's terminator.  We have
     // to scan the use list because PHI nodes use basic blocks too but do not
     // require a label to be generated.
     //
@@ -987,8 +987,10 @@ void CWriter::visitUnwindInst(UnwindInst &I) {
   // instruction is found.  In this context, we code generated the invoke
   // instruction to add an entry to the top of the jmpbuf_list.  Thus, here we
   // just have to longjmp to the specified handler.
-  Out << "  if (__llvm_jmpbuf_list == 0) {  /* llvm.unwind */\n"
-      << "    printf(\"throw found with no handler!\\n\"); abort();\n"
+  Out << "  if (__llvm_jmpbuf_list == 0) {  /* unwind */\n"
+      << "    extern write();\n"
+      << "    ((void (*)(int, void*, unsigned))write)(2,\n"
+      << "           \"throw found with no handler!\\n\", 31); abort();\n"
       << "  }\n"
       << "  longjmp(__llvm_jmpbuf_list->buf, 1);\n";
   emittedInvoke = true;
@@ -1022,8 +1024,8 @@ void CWriter::printBranchToBlock(BasicBlock *CurBB, BasicBlock *Succ,
   }
 }
 
-// Brach instruction printing - Avoid printing out a brach to a basic block that
-// immediately succeeds the current one.
+// Branch instruction printing - Avoid printing out a branch to a basic block
+// that immediately succeeds the current one.
 //
 void CWriter::visitBranchInst(BranchInst &I) {
   if (I.isConditional()) {
@@ -1133,7 +1135,7 @@ void CWriter::visitCallInst(CallInst &I) {
       switch (ID) {
       default:  assert(0 && "Unknown LLVM intrinsic!");
       case LLVMIntrinsic::va_start: 
-        Out << "va_start((va_list)*";
+        Out << "va_start(*(va_list*)";
         writeOperand(I.getOperand(1));
         Out << ", ";
         // Output the last argument to the enclosing function...
@@ -1141,12 +1143,12 @@ void CWriter::visitCallInst(CallInst &I) {
         Out << ")";
         return;
       case LLVMIntrinsic::va_end:
-        Out << "va_end((va_list)*";
+        Out << "va_end(*(va_list*)";
         writeOperand(I.getOperand(1));
         Out << ")";
         return;
       case LLVMIntrinsic::va_copy:
-        Out << "va_copy((va_list)*";
+        Out << "va_copy(*(va_list*)";
         writeOperand(I.getOperand(1));
         Out << ", (va_list)";
         writeOperand(I.getOperand(2));
@@ -1155,7 +1157,7 @@ void CWriter::visitCallInst(CallInst &I) {
 
       case LLVMIntrinsic::setjmp:
       case LLVMIntrinsic::sigsetjmp:
-        // This instrinsic should never exist in the program, but until we get
+        // This intrinsic should never exist in the program, but until we get
         // setjmp/longjmp transformations going on, we should codegen it to
         // something reasonable.  This will allow code that never calls longjmp
         // to work.