changeset 143:7859b39d8905

merge
author mir3636
date Tue, 03 Apr 2018 19:13:30 +0900
parents e2d230961781 (current diff) 3c911905a0e9 (diff)
children 488dcfcac50b
files
diffstat 6 files changed, 39 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/lib/CodeGen/CodeGenPrepare.cpp	Tue Apr 03 19:11:29 2018 +0900
+++ b/lib/CodeGen/CodeGenPrepare.cpp	Tue Apr 03 19:13:30 2018 +0900
@@ -343,7 +343,7 @@
 FunctionPass *llvm::createCodeGenPreparePass() { return new CodeGenPrepare(); }
 
 bool CodeGenPrepare::runOnFunction(Function &F) {
-  if (skipFunction(F))
+  if ( (! F.getReturnType()->is__CodeTy()) && skipFunction(F))
     return false;
 
   DL = &F.getParent()->getDataLayout();
--- a/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp	Tue Apr 03 19:11:29 2018 +0900
+++ b/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp	Tue Apr 03 19:13:30 2018 +0900
@@ -6276,6 +6276,33 @@
       .setCallee(RetTy, FTy, Callee, std::move(Args), CS)
       .setTailCall(isTailCall)
       .setConvergent(CS.isConvergent());
+#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";
+    }
+  }
+  // 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 && !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() + " !");
+    else if (CS.getCalledValue()->getType()->isPointerTy()) // if it is a pointer access; ex) goto codesegmentPointer;
+      DAG.getContext()->emitError(CS.getInstruction(), CS.getCaller()->getName() + 
+                                  " : Tail call elimination was failed on codesegment which is accessed by pointer!"); // we can't get name from Type...
+  }
+#endif
   std::pair<SDValue, SDValue> Result = lowerInvokable(CLI, EHPadBB);
 
   if (Result.first.getNode()) {
--- a/lib/CodeGen/TargetPassConfig.cpp	Tue Apr 03 19:11:29 2018 +0900
+++ b/lib/CodeGen/TargetPassConfig.cpp	Tue Apr 03 19:13:30 2018 +0900
@@ -671,7 +671,9 @@
 /// Add pass to prepare the LLVM IR for code generation. This should be done
 /// before exception handling preparation passes.
 void TargetPassConfig::addCodeGenPrepare() {
+#ifdef noCbC
   if (getOptLevel() != CodeGenOpt::None && !DisableCGP)
+#endif
     addPass(createCodeGenPreparePass());
   addPass(createRewriteSymbolsPass());
 }
--- a/tools/clang/include/clang/Basic/TokenKinds.def	Tue Apr 03 19:11:29 2018 +0900
+++ b/tools/clang/include/clang/Basic/TokenKinds.def	Tue Apr 03 19:13:30 2018 +0900
@@ -311,8 +311,8 @@
 
 #ifndef noCbC // CbC Keywords.
 KEYWORD(__code                      , KEYALL)
-KEYWORD(__return                    , KEYALL)
-KEYWORD(__environment               , KEYALL)
+KEYWORD(_CbC_return                    , KEYALL)
+KEYWORD(_CbC_environment               , KEYALL)
 #endif
 
 // C++ 2.11p1: Keywords.
--- a/tools/clang/lib/Parse/ParseCbC.cpp	Tue Apr 03 19:11:29 2018 +0900
+++ b/tools/clang/lib/Parse/ParseCbC.cpp	Tue Apr 03 19:13:30 2018 +0900
@@ -421,7 +421,6 @@
   return New;
 }
 
-
 /// CreateSjForContinuationWithEnv - Create statements of setjmp for continuation with the environment.
 ///   code example:
 ///         if (setjmp(__CbC_environment.env)){
@@ -444,7 +443,8 @@
 
   ArgExprs.push_back(__envExprRes.get());
   CondExp = Actions.ActOnCallExpr(getCurScope(), CondExp.get(), Loc, ArgExprs, Loc, 0);
-  CondExp = Actions.CheckBooleanCondition(Loc, CondExp.get());
+  Cond    = Actions.ActOnCondition(getCurScope(), Loc, CondExp.get(), Sema::ConditionKind::Boolean);
+
 
   ParseScope InnerScope(this, Scope::DeclScope,false);
   SourceLocation InnerStatementTrailingElseLoc;
@@ -464,8 +464,7 @@
   InnerScope.Exit();
   IfScope.Exit();
   StmtResult ElseStmt;
-  bool IsConstexpr = false;
-  IfRes = Actions.ActOnIfStmt(Loc, IsConstexpr, InitStmt.get(), Cond, ThenStmt.get(),Loc, ElseStmt.get());
+  IfRes = Actions.ActOnIfStmt(Loc, false, CondExp.get(), Cond, ThenStmt.get(),Loc, ElseStmt.get());
   return IfRes;
 }
 
--- a/tools/clang/lib/Parse/ParseExpr.cpp	Tue Apr 03 19:11:29 2018 +0900
+++ b/tools/clang/lib/Parse/ParseExpr.cpp	Tue Apr 03 19:13:30 2018 +0900
@@ -1436,10 +1436,10 @@
       break;
     }
 #ifndef noCbC
-  case tok::kw___return:
+  case tok::kw__CbC_return:
     Res = Prepare__retForGotoWithTheEnvExpr();
     break;
-  case tok::kw___environment:
+  case tok::kw__CbC_environment:
     Res = Prepare__envForGotoWithTheEnvExpr();
     break;
 #endif    
@@ -2808,10 +2808,10 @@
       Expr = ParseBraceInitializer();
     } 
 #ifndef noCbC
-    else if (Tok.is(tok::kw___return)){
+    else if (Tok.is(tok::kw__CbC_return)){
       Expr = Prepare__retForGotoWithTheEnvExpr();
     }
-    else if (Tok.is(tok::kw___environment)){
+    else if (Tok.is(tok::kw__CbC_environment)){
       Expr = Prepare__envForGotoWithTheEnvExpr();
     }
     else if (Tok.is(tok::identifier) && NeedPrototypeDeclaration(Tok)){ // check code segment declaration.