changeset 76:9e74acfe8c42

fix bug. compiler does not emit unnecessary warning no more.
author Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
date Mon, 05 May 2014 03:18:03 +0900
parents 90677c4a880a
children 67baa08a3894
files lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp tools/clang/lib/CodeGen/CGCall.cpp
diffstat 2 files changed, 20 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp	Sun May 04 02:24:57 2014 +0900
+++ b/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp	Mon May 05 03:18:03 2014 +0900
@@ -5448,6 +5448,24 @@
   TargetLowering::
   CallLoweringInfo CLI(getRoot(), RetTy, FTy, isTailCall, Callee, Args, DAG,
                        getCurSDLoc(), CS);
+#ifndef noCbC
+  // variable arguments check.
+  if (CLI.RetTy->is__CodeTy() && CS.getCaller()->getReturnType()->is__CodeTy() && CLI.IsVarArg) {
+    CLI.CallConv = CallingConv::C;
+    errs().changeColor(raw_ostream::MAGENTA, true);
+    if (CS.getCalledFunction()) {// if this codesegment call is a direct access; ex)  goto codesegment();
+      errs() << "warning: ";
+      errs().resetColor();
+      errs() << CS.getCaller()->getName() + " : Tail call elimination was failed on goto"
+	+ CS.getCalledFunction()->getName() + ". Write a exactly prototype declaration.\n";
+    }
+    else if (CS.getCalledValue()->getType()->isPointerTy()) {// if it is a pointer access; ex) goto codesegmentPointer;
+      errs() << "warning: ";
+      errs().resetColor();
+      errs() << CS.getCaller()->getName() + " : Tail call elimination was failed on pointer accessed goto. Write a exactly prototype declaration.\n";
+    }
+  }
+#endif
   std::pair<SDValue,SDValue> Result = TLI->LowerCallTo(CLI);
   assert((isTailCall || Result.second.getNode()) &&
          "Non-null chain expected with non-tail call!");
@@ -5455,7 +5473,7 @@
          "Null value expected with tail call!");
 #ifndef noCbC
   // if code segment's tail call flag was changed false , we report it on error.
-  if (CLI.RetTy->is__CodeTy() && CS.getCaller()->getReturnType()->is__CodeTy() && !isTailCall) {
+  if (CLI.RetTy->is__CodeTy() && CS.getCaller()->getReturnType()->is__CodeTy() && !isTailCall && !CLI.IsVarArg) {
     if (CS.getCalledFunction()) // if this codesegment call is a direct access; ex)  goto codesegment();
       DAG.getContext()->emitError(CS.getInstruction(), CS.getCaller()->getName() + " : Tail call elimination was failed on goto "
 				  + CS.getCalledFunction()->getName() + " !");
--- a/tools/clang/lib/CodeGen/CGCall.cpp	Sun May 04 02:24:57 2014 +0900
+++ b/tools/clang/lib/CodeGen/CGCall.cpp	Mon May 05 03:18:03 2014 +0900
@@ -450,17 +450,7 @@
 #ifndef noCbC
   // if the function is a code segment , set fastcall calling convention.
   if(resultType.getTypePtr()->is__CodeType()){
-    if(!required.allowsOptionalArgs()) // If the code segment is a variadic function , LLVM can't do TCE.
-      CC = llvm::CallingConv::Fast;
-    else { // emit warning
-      DiagnosticsEngine &Diags = CGM.getDiags();
-      unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Warning, "code segment's function pointer arguments must be written exactly prototype");
-      Diags.Report(DiagID);
-      // how to bring current function name and location here?
-      // todo : do not emit warning when this function declaration is arguments' argument.
-      //      ex) __code (__code(*aua)(int, void*, __code(*)( )))
-      //                                           ^^^^^^^^^^^^ we have not check its argument.          
-    }
+    CC = llvm::CallingConv::Fast;
   }
 #endif