Skip to content

Commit 3341dc7

Browse files
committed
[Driver] Don't pass -fobjc-rumtime= for non-ObjC input
1 parent f93aed6 commit 3341dc7

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5613,7 +5613,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
56135613
Args.AddLastArg(CmdArgs, options::OPT_fexperimental_new_pass_manager,
56145614
options::OPT_fno_experimental_new_pass_manager);
56155615

5616-
ObjCRuntime Runtime = AddObjCRuntimeArgs(Args, CmdArgs, rewriteKind);
5616+
ObjCRuntime Runtime = AddObjCRuntimeArgs(Args, Inputs, CmdArgs, rewriteKind);
56175617
RenderObjCOptions(TC, D, RawTriple, Args, Runtime, rewriteKind != RK_None,
56185618
Input, CmdArgs);
56195619

@@ -6257,6 +6257,7 @@ Clang::~Clang() {}
62576257
///
62586258
/// Returns true if the runtime is non-fragile.
62596259
ObjCRuntime Clang::AddObjCRuntimeArgs(const ArgList &args,
6260+
const InputInfoList &inputs,
62606261
ArgStringList &cmdArgs,
62616262
RewriteKind rewriteKind) const {
62626263
// Look for the controlling runtime option.
@@ -6380,8 +6381,11 @@ ObjCRuntime Clang::AddObjCRuntimeArgs(const ArgList &args,
63806381
runtime = ObjCRuntime(ObjCRuntime::GCC, VersionTuple());
63816382
}
63826383

6383-
cmdArgs.push_back(
6384-
args.MakeArgString("-fobjc-runtime=" + runtime.getAsString()));
6384+
if (llvm::any_of(inputs, [](const InputInfo &input) {
6385+
return types::isObjC(input.getType());
6386+
}))
6387+
cmdArgs.push_back(
6388+
args.MakeArgString("-fobjc-runtime=" + runtime.getAsString()));
63856389
return runtime;
63866390
}
63876391

clang/lib/Driver/ToolChains/Clang.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class LLVM_LIBRARY_VISIBILITY Clang : public Tool {
7777
enum RewriteKind { RK_None, RK_Fragile, RK_NonFragile };
7878

7979
ObjCRuntime AddObjCRuntimeArgs(const llvm::opt::ArgList &args,
80+
const InputInfoList &inputs,
8081
llvm::opt::ArgStringList &cmdArgs,
8182
RewriteKind rewrite) const;
8283

clang/test/Driver/darwin-objc-options.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,12 @@
3131
// CHECK-CHECK-I386_IOS-NOT: -fobjc-dispatch-method
3232
// CHECK-CHECK-I386_IOS: darwin-objc-options
3333

34+
/// Don't add -fobjc-runtime for non-ObjC input.
35+
// RUN: touch %t.c
36+
// RUN: %clang -target x86_64-apple-darwin -x objective-c -S -### %t.c 2>&1 | FileCheck --check-prefix=F %s
37+
// RUN: %clang -target x86_64-apple-darwin -S -### %t.c 2>&1 | FileCheck --check-prefix=NO_F %s
38+
// F: -fobjc-runtime=
39+
// NO_F-NOT: -fobjc-runtime=
40+
3441
// Don't crash with an unexpected target triple.
3542
// RUN: %clang -target i386-apple-ios7 -S -### %s

0 commit comments

Comments
 (0)