From 919d845e814b0bc74cc55191ac1b4257b2e5ce5e Mon Sep 17 00:00:00 2001 From: "Duncan P. N. Exon Smith" Date: Fri, 18 Apr 2014 01:05:25 +0000 Subject: [PATCH] BackendUtil: Pass through -mdisable-tail-calls The frontend option -fno-optimize-sibling-calls resolves to -cc1's -mdisable-tail-calls, which is passed to the TargetMachine in the backend. PassManagerBuilder was adding the -tailcallelim pass anyway. Use a new DisableTailCalls option in PassManagerBuilder to disable tail calls harder. Requires the matching commit in LLVM that adds DisableTailCalls. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@206543 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/BackendUtil.cpp | 1 + test/CodeGen/disable-tail-calls.c | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 test/CodeGen/disable-tail-calls.c diff --git a/lib/CodeGen/BackendUtil.cpp b/lib/CodeGen/BackendUtil.cpp index b75c62a422..2c388ef58e 100644 --- a/lib/CodeGen/BackendUtil.cpp +++ b/lib/CodeGen/BackendUtil.cpp @@ -247,6 +247,7 @@ void EmitAssemblyHelper::CreatePasses() { PMBuilder.SLPVectorize = CodeGenOpts.VectorizeSLP; PMBuilder.LoopVectorize = CodeGenOpts.VectorizeLoop; + PMBuilder.DisableTailCalls = CodeGenOpts.DisableTailCalls; PMBuilder.DisableUnitAtATime = !CodeGenOpts.UnitAtATime; PMBuilder.DisableUnrollLoops = !CodeGenOpts.UnrollLoops; PMBuilder.RerollLoops = CodeGenOpts.RerollLoops; diff --git a/test/CodeGen/disable-tail-calls.c b/test/CodeGen/disable-tail-calls.c new file mode 100644 index 0000000000..b066100226 --- /dev/null +++ b/test/CodeGen/disable-tail-calls.c @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9.0 -emit-llvm -O1 -mdisable-tail-calls -o - < %s | FileCheck %s + +typedef struct List { + struct List *next; + int data; +} List; + +// CHECK-LABEL: define %struct.List* @find +List *find(List *head, int data) { + if (!head) + return 0; + if (head->data == data) + return head; + // CHECK: call %struct.List* @find + return find(head->next, data); +} -- 2.40.0