aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2010-04-10 16:20:23 +0000
committerDaniel Dunbar <daniel@zuster.org>2010-04-10 16:20:23 +0000
commit43a9b3263cb0bcb050cc75c15b3e6a8951e6b97a (patch)
tree8f4c9463f3e2cdf0ffd635db2eaed734dee97ba8
parent35f59b64b497e181f8dbd2a36e35b5e2919e7b1d (diff)
Driver: Ignore -fobjc-gc and -fobjc-gc-only for platforms which don't support them.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@100930 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Basic/DiagnosticDriverKinds.td2
-rw-r--r--include/clang/Driver/ToolChain.h3
-rw-r--r--lib/Driver/ToolChains.cpp5
-rw-r--r--lib/Driver/ToolChains.h2
-rw-r--r--lib/Driver/Tools.cpp17
-rw-r--r--test/Driver/darwin-objc-gc.m19
6 files changed, 46 insertions, 2 deletions
diff --git a/include/clang/Basic/DiagnosticDriverKinds.td b/include/clang/Basic/DiagnosticDriverKinds.td
index 3dbe47f4cf..3b7272e5ac 100644
--- a/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/include/clang/Basic/DiagnosticDriverKinds.td
@@ -94,5 +94,7 @@ def warn_drv_conflicting_deployment_targets : Warning<
def warn_drv_treating_input_as_cxx : Warning<
"treating '%0' input as '%1' when in C++ mode, this behavior is deprecated">,
InGroup<Deprecated>;
+def warn_drv_objc_gc_unsupported : Warning<
+ "Objective-C garbage collection is not supported on this platform, ignoring '%0'">;
}
diff --git a/include/clang/Driver/ToolChain.h b/include/clang/Driver/ToolChain.h
index 9a82973dca..b58205cc4d 100644
--- a/include/clang/Driver/ToolChain.h
+++ b/include/clang/Driver/ToolChain.h
@@ -120,6 +120,9 @@ public:
/// particular PIC mode.
virtual const char *GetForcedPicModel() const = 0;
+ /// Does this tool chain support Objective-C garbage collection.
+ virtual bool SupportsObjCGC() const { return false; }
+
/// UseDwarfDebugFlags - Embed the compile options to clang into the Dwarf
/// compile unit information.
virtual bool UseDwarfDebugFlags() const { return false; }
diff --git a/lib/Driver/ToolChains.cpp b/lib/Driver/ToolChains.cpp
index 4bb3246edd..80dea504a7 100644
--- a/lib/Driver/ToolChains.cpp
+++ b/lib/Driver/ToolChains.cpp
@@ -663,6 +663,11 @@ const char *Darwin::GetForcedPicModel() const {
return 0;
}
+bool Darwin::SupportsObjCGC() const {
+ // Garbage collection is supported everywhere except on iPhone OS.
+ return !isTargetIPhoneOS();
+}
+
/// Generic_GCC - A tool chain using the 'gcc' command to perform
/// all subcommands; this relies on gcc translating the majority of
/// command line options.
diff --git a/lib/Driver/ToolChains.h b/lib/Driver/ToolChains.h
index 0d5b2a3f47..9e61b8972f 100644
--- a/lib/Driver/ToolChains.h
+++ b/lib/Driver/ToolChains.h
@@ -176,6 +176,8 @@ public:
virtual const char *GetDefaultRelocationModel() const;
virtual const char *GetForcedPicModel() const;
+ virtual bool SupportsObjCGC() const;
+
virtual bool UseDwarfDebugFlags() const;
virtual bool UseSjLjExceptions() const;
diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp
index be79e79fd0..6a74ff4743 100644
--- a/lib/Driver/Tools.cpp
+++ b/lib/Driver/Tools.cpp
@@ -1107,10 +1107,23 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
options::OPT_fno_lax_vector_conversions))
CmdArgs.push_back("-fno-lax-vector-conversions");
+ // Handle -fobjc-gc and -fobjc-gc-only. They are exclusive, and -fobjc-gc-only
+ // takes precedence.
+ const Arg *GCArg = Args.getLastArg(options::OPT_fobjc_gc_only);
+ if (!GCArg)
+ GCArg = Args.getLastArg(options::OPT_fobjc_gc);
+ if (GCArg) {
+ if (getToolChain().SupportsObjCGC()) {
+ GCArg->render(Args, CmdArgs);
+ } else {
+ // FIXME: We should move this to a hard error.
+ D.Diag(clang::diag::warn_drv_objc_gc_unsupported)
+ << GCArg->getAsString(Args);
+ }
+ }
+
Args.AddLastArg(CmdArgs, options::OPT_fno_caret_diagnostics);
Args.AddLastArg(CmdArgs, options::OPT_fno_show_column);
- Args.AddLastArg(CmdArgs, options::OPT_fobjc_gc_only);
- Args.AddLastArg(CmdArgs, options::OPT_fobjc_gc);
Args.AddLastArg(CmdArgs, options::OPT_fobjc_sender_dependent_dispatch);
Args.AddLastArg(CmdArgs, options::OPT_fdiagnostics_print_source_range_info);
Args.AddLastArg(CmdArgs, options::OPT_ftime_report);
diff --git a/test/Driver/darwin-objc-gc.m b/test/Driver/darwin-objc-gc.m
new file mode 100644
index 0000000000..aecb9a6b14
--- /dev/null
+++ b/test/Driver/darwin-objc-gc.m
@@ -0,0 +1,19 @@
+// Check that we warn, but accept, -fobjc-gc for iPhone OS.
+
+// RUN: %clang -ccc-host-triple i386-apple-darwin9 -miphoneos-version-min=3.0 -fobjc-gc -flto -S -o %t %s 2> %t.err
+// RUN: FileCheck --check-prefix=IPHONE_OBJC_GC_LL %s < %t
+// RUN: FileCheck --check-prefix=IPHONE_OBJC_GC_STDERR %s < %t.err
+
+// IPHONE_OBJC_GC_LL: define void @f0
+// IPHONE_OBJC_GC_LL-NOT: objc_assign_ivar
+// IPHONE_OBJC_GC_LL: }
+
+// IPHONE_OBJC_GC_STDERR: warning: Objective-C garbage collection is not supported on this platform, ignoring '-fobjc-gc'
+
+@interface A {
+@public
+ id x;
+}
+@end
+
+void f0(A *a, id x) { a->x = x; }