# HG changeset patch # User mir3636 # Date 1520501174 -32400 # Node ID 3c911905a0e9d289e7c05b7808161d31a45e253e # Parent 53f12981605ac7fefb155c33d3593ace8b5fb888 add CodeGenPrepare Pass diff -r 53f12981605a -r 3c911905a0e9 lib/CodeGen/CodeGenPrepare.cpp --- a/lib/CodeGen/CodeGenPrepare.cpp Wed Mar 07 18:36:33 2018 +0900 +++ b/lib/CodeGen/CodeGenPrepare.cpp Thu Mar 08 18:26:14 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(); diff -r 53f12981605a -r 3c911905a0e9 lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp --- a/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp Wed Mar 07 18:36:33 2018 +0900 +++ b/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp Thu Mar 08 18:26:14 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 Result = lowerInvokable(CLI, EHPadBB); if (Result.first.getNode()) { diff -r 53f12981605a -r 3c911905a0e9 lib/CodeGen/TargetPassConfig.cpp --- a/lib/CodeGen/TargetPassConfig.cpp Wed Mar 07 18:36:33 2018 +0900 +++ b/lib/CodeGen/TargetPassConfig.cpp Thu Mar 08 18:26:14 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()); }