[Driver] Don't pass -fobjc-rumtime= for non-ObjC input

This commit is contained in:
Fangrui Song 2020-03-31 17:37:46 -07:00
parent f93aed66f2
commit 3341dc7339
3 changed files with 15 additions and 3 deletions

View File

@ -5613,7 +5613,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
Args.AddLastArg(CmdArgs, options::OPT_fexperimental_new_pass_manager,
options::OPT_fno_experimental_new_pass_manager);
ObjCRuntime Runtime = AddObjCRuntimeArgs(Args, CmdArgs, rewriteKind);
ObjCRuntime Runtime = AddObjCRuntimeArgs(Args, Inputs, CmdArgs, rewriteKind);
RenderObjCOptions(TC, D, RawTriple, Args, Runtime, rewriteKind != RK_None,
Input, CmdArgs);
@ -6257,6 +6257,7 @@ Clang::~Clang() {}
///
/// Returns true if the runtime is non-fragile.
ObjCRuntime Clang::AddObjCRuntimeArgs(const ArgList &args,
const InputInfoList &inputs,
ArgStringList &cmdArgs,
RewriteKind rewriteKind) const {
// Look for the controlling runtime option.
@ -6380,8 +6381,11 @@ ObjCRuntime Clang::AddObjCRuntimeArgs(const ArgList &args,
runtime = ObjCRuntime(ObjCRuntime::GCC, VersionTuple());
}
cmdArgs.push_back(
args.MakeArgString("-fobjc-runtime=" + runtime.getAsString()));
if (llvm::any_of(inputs, [](const InputInfo &input) {
return types::isObjC(input.getType());
}))
cmdArgs.push_back(
args.MakeArgString("-fobjc-runtime=" + runtime.getAsString()));
return runtime;
}

View File

@ -77,6 +77,7 @@ private:
enum RewriteKind { RK_None, RK_Fragile, RK_NonFragile };
ObjCRuntime AddObjCRuntimeArgs(const llvm::opt::ArgList &args,
const InputInfoList &inputs,
llvm::opt::ArgStringList &cmdArgs,
RewriteKind rewrite) const;

View File

@ -31,5 +31,12 @@
// CHECK-CHECK-I386_IOS-NOT: -fobjc-dispatch-method
// CHECK-CHECK-I386_IOS: darwin-objc-options
/// Don't add -fobjc-runtime for non-ObjC input.
// RUN: touch %t.c
// RUN: %clang -target x86_64-apple-darwin -x objective-c -S -### %t.c 2>&1 | FileCheck --check-prefix=F %s
// RUN: %clang -target x86_64-apple-darwin -S -### %t.c 2>&1 | FileCheck --check-prefix=NO_F %s
// F: -fobjc-runtime=
// NO_F-NOT: -fobjc-runtime=
// Don't crash with an unexpected target triple.
// RUN: %clang -target i386-apple-ios7 -S -### %s