[cfe-commits] r89065 - in /cfe/trunk: include/clang/Driver/Options.def include/clang/Driver/ToolChain.h lib/Driver/ToolChains.h lib/Driver/Tools.cpp test/CodeGen/stack-protector.c test/Driver/clang_f_opts.c

Daniel Dunbar daniel at zuster.org
Tue Nov 17 00:07:36 PST 2009


Author: ddunbar
Date: Tue Nov 17 02:07:36 2009
New Revision: 89065

URL: http://llvm.org/viewvc/llvm-project?rev=89065&view=rev
Log:
Add -fblocks, -stack-protector, and -fobjc-nonfragile-abi defaulting to driver,
instead of using getDefaultLangOptions.
 - Remove unused -fobjc-tight-layout while at it.

Modified:
    cfe/trunk/include/clang/Driver/Options.def
    cfe/trunk/include/clang/Driver/ToolChain.h
    cfe/trunk/lib/Driver/ToolChains.h
    cfe/trunk/lib/Driver/Tools.cpp
    cfe/trunk/test/CodeGen/stack-protector.c
    cfe/trunk/test/Driver/clang_f_opts.c

Modified: cfe/trunk/include/clang/Driver/Options.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.def?rev=89065&r1=89064&r2=89065&view=diff

==============================================================================
--- cfe/trunk/include/clang/Driver/Options.def (original)
+++ cfe/trunk/include/clang/Driver/Options.def Tue Nov 17 02:07:36 2009
@@ -449,7 +449,6 @@
 OPTION("-fobjc-new-property", fobjc_new_property, Flag, clang_ignored_f_Group, INVALID, "", 0, 0, 0)
 OPTION("-fobjc-nonfragile-abi", fobjc_nonfragile_abi, Flag, f_Group, INVALID, "", 0, 0, 0)
 OPTION("-fobjc-sender-dependent-dispatch", fobjc_sender_dependent_dispatch, Flag, f_Group, INVALID, "", 0, 0, 0)
-OPTION("-fobjc-tight-layout", fobjc_tight_layout, Flag, f_Group, INVALID, "", 0, 0, 0)
 OPTION("-fobjc", fobjc, Flag, f_Group, INVALID, "", 0, 0, 0)
 OPTION("-fomit-frame-pointer", fomit_frame_pointer, Flag, f_Group, INVALID, "", 0, 0, 0)
 OPTION("-fopenmp", fopenmp, Flag, f_Group, INVALID, "", 0, 0, 0)

Modified: cfe/trunk/include/clang/Driver/ToolChain.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/ToolChain.h?rev=89065&r1=89064&r2=89065&view=diff

==============================================================================
--- cfe/trunk/include/clang/Driver/ToolChain.h (original)
+++ cfe/trunk/include/clang/Driver/ToolChain.h Tue Nov 17 02:07:36 2009
@@ -90,6 +90,17 @@
   /// default.
   virtual bool IsMathErrnoDefault() const = 0;
 
+  /// IsBlocksDefault - Does this tool chain enable -fblocks by default.
+  virtual bool IsBlocksDefault() const { return false; }
+
+  /// IsObjCNonFragileABIDefault - Does this tool chain set
+  /// -fobjc-nonfragile-abi by default.
+  virtual bool IsObjCNonFragileABIDefault() const { return false; }
+
+  /// GetDefaultStackProtectorLevel - Get the default stack protector level for
+  /// this tool chain (0=off, 1=on, 2=all).
+  virtual unsigned GetDefaultStackProtectorLevel() const { return 0; }
+
   /// IsUnwindTablesDefault - Does this tool chain use -funwind-tables
   /// by default.
   virtual bool IsUnwindTablesDefault() const = 0;

Modified: cfe/trunk/lib/Driver/ToolChains.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.h?rev=89065&r1=89064&r2=89065&view=diff

==============================================================================
--- cfe/trunk/lib/Driver/ToolChains.h (original)
+++ cfe/trunk/lib/Driver/ToolChains.h Tue Nov 17 02:07:36 2009
@@ -137,7 +137,20 @@
   virtual Tool &SelectTool(const Compilation &C, const JobAction &JA) const;
 
   virtual bool IsMathErrnoDefault() const;
+  virtual bool IsBlocksDefault() const {
+    // Blocks default to on for 10.6 (darwin10) and beyond.
+    return (DarwinVersion[0] > 9);
+  }
+  virtual bool IsObjCNonFragileABIDefault() const {
+    // Non-fragile ABI default to on for 10.5 (darwin9) and beyond on x86-64.
+    return (DarwinVersion[0] >= 9 &&
+            getTriple().getArch() == llvm::Triple::x86_64);
+  }
   virtual bool IsUnwindTablesDefault() const;
+  virtual unsigned GetDefaultStackProtectorLevel() const {
+    // Stack protectors default to on for 10.6 (darwin10) and beyond.
+    return (DarwinVersion[0] > 9) ? 1 : 0;
+  }
   virtual const char *GetDefaultRelocationModel() const;
   virtual const char *GetForcedPicModel() const;
 

Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=89065&r1=89064&r2=89065&view=diff

==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Tue Nov 17 02:07:36 2009
@@ -893,9 +893,6 @@
   Args.AddLastArg(CmdArgs, options::OPT_fobjc_gc_only);
   Args.AddLastArg(CmdArgs, options::OPT_fobjc_gc);
   Args.AddLastArg(CmdArgs, options::OPT_fobjc_sender_dependent_dispatch);
-  // FIXME: Should we remove this?
-  Args.AddLastArg(CmdArgs, options::OPT_fobjc_nonfragile_abi);
-  Args.AddLastArg(CmdArgs, options::OPT_fobjc_tight_layout);
   Args.AddLastArg(CmdArgs, options::OPT_fdiagnostics_print_source_range_info);
   Args.AddLastArg(CmdArgs, options::OPT_ftime_report);
   Args.AddLastArg(CmdArgs, options::OPT_ftrapv);
@@ -904,33 +901,33 @@
 
   Args.AddLastArg(CmdArgs, options::OPT_pthread);
 
-  // Forward stack protector flags.
+  // -stack-protector=0 is default.
+  unsigned StackProtectorLevel = 0;
   if (Arg *A = Args.getLastArg(options::OPT_fno_stack_protector,
                                options::OPT_fstack_protector_all,
                                options::OPT_fstack_protector)) {
-    if (A->getOption().matches(options::OPT_fno_stack_protector))
-      CmdArgs.push_back("--stack-protector=0");
-    else if (A->getOption().matches(options::OPT_fstack_protector))
-      CmdArgs.push_back("--stack-protector=1");
-    else
-      CmdArgs.push_back("--stack-protector=2");
+    if (A->getOption().matches(options::OPT_fstack_protector))
+      StackProtectorLevel = 1;
+    else if (A->getOption().matches(options::OPT_fstack_protector_all))
+      StackProtectorLevel = 2;
+  } else
+    StackProtectorLevel = getToolChain().GetDefaultStackProtectorLevel();
+  if (StackProtectorLevel) {
+    CmdArgs.push_back("-stack-protector");
+    CmdArgs.push_back(Args.MakeArgString(llvm::Twine(StackProtectorLevel)));
   }
 
   // Forward -f options with positive and negative forms; we translate
   // these by hand.
 
-  // -fbuiltin is default, only pass non-default.
+  // -fbuiltin is default.
   if (!Args.hasFlag(options::OPT_fbuiltin, options::OPT_fno_builtin))
     CmdArgs.push_back("-fbuiltin=0");
 
-  // -fblocks default varies depending on platform and language; only
-  // pass if specified.
-  if (Arg *A = Args.getLastArg(options::OPT_fblocks, options::OPT_fno_blocks)) {
-    if (A->getOption().matches(options::OPT_fblocks))
-      CmdArgs.push_back("-fblocks");
-    else
-      CmdArgs.push_back("-fblocks=0");
-  }
+  // -fblocks=0 is default.
+  if (Args.hasFlag(options::OPT_fblocks, options::OPT_fno_blocks,
+                   getToolChain().IsBlocksDefault()))
+    CmdArgs.push_back("-fblocks");
 
   if (needsExceptions(Args, InputType, getToolChain().getTriple()))
     CmdArgs.push_back("-fexceptions");
@@ -959,6 +956,13 @@
                     getToolChain().getTriple().getOS() == llvm::Triple::Darwin))
     CmdArgs.push_back("-fgnu-runtime");
 
+  // -fobjc-nonfragile-abi=0 is default.
+  if (types::isObjC(InputType)) {
+    if (Args.hasArg(options::OPT_fobjc_nonfragile_abi) ||
+        getToolChain().IsObjCNonFragileABIDefault())
+      CmdArgs.push_back("-fobjc-nonfragile-abi");
+  }
+
   // -fshort-wchar default varies depending on platform; only
   // pass if specified.
   if (Arg *A = Args.getLastArg(options::OPT_fshort_wchar)) {

Modified: cfe/trunk/test/CodeGen/stack-protector.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/stack-protector.c?rev=89065&r1=89064&r2=89065&view=diff

==============================================================================
--- cfe/trunk/test/CodeGen/stack-protector.c (original)
+++ cfe/trunk/test/CodeGen/stack-protector.c Tue Nov 17 02:07:36 2009
@@ -1,15 +1,9 @@
-// RUN: clang-cc -triple i686-unknown-unknown -emit-llvm -o %t %s
-// RUN: not grep 'ssp' %t
-// RUN: clang-cc -triple i686-apple-darwin9 -emit-llvm -o %t %s
-// RUN: not grep 'ssp' %t
-// RUN: clang-cc -triple i686-apple-darwin10 -emit-llvm -o %t %s
-// RUN: grep 'ssp' %t
-// RUN: clang -fstack-protector-all -emit-llvm -S -o %t %s
-// RUN: grep 'sspreq' %t
-// RUN: clang -fstack-protector -emit-llvm -S -o %t %s
-// RUN: grep 'ssp' %t
-// RUN: clang -fno-stack-protector -emit-llvm -S -o %t %s
-// RUN: not grep 'ssp' %t
+// RUN: clang-cc -emit-llvm -o - %s -stack-protector=0 | FileCheck -check-prefix=NOSSP %s
+// NOSSP: define void @test1(i8* %msg) nounwind {
+// RUN: clang-cc -emit-llvm -o - %s -stack-protector=1 | FileCheck -check-prefix=WITHSSP %s
+// WITHSSP: define void @test1(i8* %msg) nounwind ssp {
+// RUN: clang-cc -emit-llvm -o - %s -stack-protector=2 | FileCheck -check-prefix=SSPREQ %s
+// SSPREQ: define void @test1(i8* %msg) nounwind sspreq {
 
 int printf(const char * _Format, ...);
 

Modified: cfe/trunk/test/Driver/clang_f_opts.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/clang_f_opts.c?rev=89065&r1=89064&r2=89065&view=diff

==============================================================================
--- cfe/trunk/test/Driver/clang_f_opts.c (original)
+++ cfe/trunk/test/Driver/clang_f_opts.c Tue Nov 17 02:07:36 2009
@@ -3,7 +3,6 @@
 // RUN: grep -F '"--fmath-errno=1"' %t
 // RUN: grep -F '"-fpascal-strings"' %t
 // RUN: clang -### -S -x c /dev/null -fblocks -fbuiltin -fmath-errno -fcommon -fpascal-strings -fno-blocks -fno-builtin -fno-math-errno -fno-common -fno-pascal-strings -fno-show-source-location -fshort-wchar %s 2> %t
-// RUN: grep -F '"-fblocks=0"' %t
 // RUN: grep -F '"-fbuiltin=0"' %t
 // RUN: grep -F '"-fno-common"' %t
 // RUN: grep -F '"--fmath-errno=0"' %t





More information about the cfe-commits mailing list