Index: include/clang/Frontend/CodeGenOptions.h =================================================================== --- include/clang/Frontend/CodeGenOptions.h +++ include/clang/Frontend/CodeGenOptions.h @@ -151,6 +151,9 @@ /// A list of command-line options to forward to the LLVM backend. std::vector BackendOptions; + /// A list of function attributes to save to the IR. + std::vector> FunctionAttributes; + /// A list of dependent libraries. std::vector DependentLibraries; Index: lib/CodeGen/CGCall.cpp =================================================================== --- lib/CodeGen/CGCall.cpp +++ lib/CodeGen/CGCall.cpp @@ -1455,6 +1455,9 @@ FuncAttrs.addAttribute(llvm::Attribute::NoBuiltin); } else { // Attributes that should go on the function, but not the call site. + for (auto &KV : CodeGenOpts.FunctionAttributes) + FuncAttrs.addAttribute(KV.first, KV.second); + if (!CodeGenOpts.DisableFPElim) { FuncAttrs.addAttribute("no-frame-pointer-elim", "false"); } else if (CodeGenOpts.OmitLeafFramePointer) { Index: lib/Frontend/CompilerInvocation.cpp =================================================================== --- lib/Frontend/CompilerInvocation.cpp +++ lib/Frontend/CompilerInvocation.cpp @@ -340,6 +340,14 @@ } } +static void getFunctionAttributes(CodeGenOptions &Opts) { + StringRef Opt = "-arm-long-calls", Key = Opt.drop_front(1); + + if (std::find(Opts.BackendOptions.begin(), Opts.BackendOptions.end(), + Opt) != Opts.BackendOptions.end()) + Opts.FunctionAttributes.push_back(std::make_pair(Key, "")); +} + static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK, DiagnosticsEngine &Diags, const TargetOptions &TargetOpts) { @@ -643,6 +651,8 @@ Args.getAllArgValues(OPT_fsanitize_recover_EQ), Diags, Opts.SanitizeRecover); + getFunctionAttributes(Opts); + return Success; } Index: test/CodeGen/fn-attr.c =================================================================== --- /dev/null +++ test/CodeGen/fn-attr.c @@ -0,0 +1,7 @@ +// RUN: %clang_cc1 -triple thumbv7-apple-ios5 -backend-option -arm-long-calls -emit-llvm -o - %s | FileCheck -check-prefix=LONGCALL %s +// RUN: %clang_cc1 -triple thumbv7-apple-ios5 -emit-llvm -o - %s | FileCheck -check-prefix=NOLONGCALL %s + +// LONGCALL: attributes #0 = { {{.*}} "arm-long-calls +// NOLONGCALL-NOT: attributes #0 = { {{.*}} "arm-long-calls + +int foo1(int a) { return a; }