Driver: Manually translate a number of -f with no- variants options to
clang.
- We will eventually want some more driver infrastructre for this
probably.
- For now, the clang-cc interface stays relatively the same, but we
don't accept multiple instances anymore, or the [no-] variants
directly.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68550 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/Driver/Options.def b/include/clang/Driver/Options.def
index 7e77a1a..bfa5a66 100644
--- a/include/clang/Driver/Options.def
+++ b/include/clang/Driver/Options.def
@@ -424,11 +424,11 @@
OPTION("-fastcp", fastcp, Flag, f_Group, INVALID, "", 0, 0, 0)
OPTION("-fastf", fastf, Flag, f_Group, INVALID, "", 0, 0, 0)
OPTION("-fast", fast, Flag, f_Group, INVALID, "", 0, 0, 0)
-OPTION("-fblocks", fblocks, Flag, clang_f_Group, INVALID, "", 0, 0, 0)
+OPTION("-fblocks", fblocks, Flag, f_Group, INVALID, "", 0, 0, 0)
OPTION("-fbootclasspath=", fbootclasspath_EQ, Joined, f_Group, INVALID, "", 0, 0, 0)
-OPTION("-fbuiltin", fbuiltin, Flag, clang_f_Group, INVALID, "", 0, 0, 0)
+OPTION("-fbuiltin", fbuiltin, Flag, f_Group, INVALID, "", 0, 0, 0)
OPTION("-fclasspath=", fclasspath_EQ, Joined, f_Group, INVALID, "", 0, 0, 0)
-OPTION("-fcommon", fcommon, Flag, clang_f_Group, INVALID, "", 0, 0, 0)
+OPTION("-fcommon", fcommon, Flag, f_Group, INVALID, "", 0, 0, 0)
OPTION("-fcompile-resource=", fcompile_resource_EQ, Joined, f_Group, INVALID, "", 0, 0, 0)
OPTION("-fconstant-cfstrings", fconstant_cfstrings, Flag, clang_ignored_f_Group, INVALID, "", 0, 0, 0)
OPTION("-fcreate-profile", fcreate_profile, Flag, f_Group, INVALID, "", 0, 0, 0)
@@ -459,10 +459,10 @@
OPTION("-fmudflap", fmudflap, Flag, f_Group, INVALID, "", 0, 0, 0)
OPTION("-fnested-functions", fnested_functions, Flag, f_Group, INVALID, "", 0, 0, 0)
OPTION("-fnext-runtime", fnext_runtime, Flag, clang_f_Group, INVALID, "", 0, 0, 0)
-OPTION("-fno-blocks", fno_blocks, Flag, clang_f_Group, INVALID, "", 0, 0, 0)
-OPTION("-fno-builtin", fno_builtin, Flag, clang_f_Group, INVALID, "", 0, 0, 0)
+OPTION("-fno-blocks", fno_blocks, Flag, f_Group, INVALID, "", 0, 0, 0)
+OPTION("-fno-builtin", fno_builtin, Flag, f_Group, INVALID, "", 0, 0, 0)
OPTION("-fno-caret-diagnostics", fno_caret_diagnostics, Flag, clang_f_Group, INVALID, "", 0, 0, 0)
-OPTION("-fno-common", fno_common, Flag, clang_f_Group, INVALID, "", 0, 0, 0)
+OPTION("-fno-common", fno_common, Flag, f_Group, INVALID, "", 0, 0, 0)
OPTION("-fno-constant-cfstrings", fno_constant_cfstrings, Flag, f_Group, INVALID, "", 0, 0, 0)
OPTION("-fno-eliminate-unused-debug-symbols", fno_eliminate_unused_debug_symbols, Flag, f_Group, INVALID, "", 0, 0, 0)
OPTION("-fno-inline-functions", fno_inline_functions, Flag, clang_ignored_f_Group, INVALID, "", 0, 0, 0)
@@ -488,7 +488,7 @@
OPTION("-force_cpusubtype_ALL", force__cpusubtype__ALL, Flag, INVALID, INVALID, "", 0, 0, 0)
OPTION("-force_flat_namespace", force__flat__namespace, Flag, INVALID, INVALID, "", 0, 0, 0)
OPTION("-foutput-class-dir=", foutput_class_dir_EQ, Joined, f_Group, INVALID, "", 0, 0, 0)
-OPTION("-fpascal-strings", fpascal_strings, Flag, clang_f_Group, INVALID, "", 0, 0, 0)
+OPTION("-fpascal-strings", fpascal_strings, Flag, f_Group, INVALID, "", 0, 0, 0)
OPTION("-fpch-preprocess", fpch_preprocess, Flag, f_Group, INVALID, "", 0, 0, 0)
OPTION("-fpic", fpic, Flag, f_Group, INVALID, "", 0, 0, 0)
OPTION("-fpie", fpie, Flag, f_Group, INVALID, "", 0, 0, 0)
diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp
index e26bb9e..dd3a00e 100644
--- a/lib/Driver/Tools.cpp
+++ b/lib/Driver/Tools.cpp
@@ -357,8 +357,34 @@
CmdArgs.push_back(A->getValue(Args));
}
+ // Forward -f options which we can pass directly.
Args.AddAllArgs(CmdArgs, options::OPT_clang_f_Group);
+ // Forward -f options with positive and negative forms; we translate
+ // these by hand.
+
+ // -fbuiltin is default, only pass non-default.
+ if (!Args.hasFlag(options::OPT_fbuiltin, options::OPT_fno_builtin))
+ CmdArgs.push_back("-fbuiltin=0");
+
+ // -fblocks default varies depending on platform and language;
+ // -always 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");
+ }
+
+ // -fno-pascal-strings is default, only pass non-default.
+ if (Args.hasFlag(options::OPT_fpascal_strings,
+ options::OPT_fno_pascal_strings))
+ CmdArgs.push_back("-fpascal-strings");
+
+ // -fcommon is default, only pass non-default.
+ if (!Args.hasFlag(options::OPT_fcommon, options::OPT_fno_common))
+ CmdArgs.push_back("-fno-common");
+
// If tool chain translates fpascal-strings, we want to back
// translate here.
// FIXME: This is gross; that translation should be pulled from the
diff --git a/test/Sema/exprs.c b/test/Sema/exprs.c
index ae4c37c..9db8c92 100644
--- a/test/Sema/exprs.c
+++ b/test/Sema/exprs.c
@@ -1,4 +1,4 @@
-// RUN: clang-cc %s -verify -pedantic -fsyntax-only -fno-blocks
+// RUN: clang-cc %s -verify -pedantic -fsyntax-only -fblocks=0
// PR1966
_Complex double test1() {
diff --git a/test/Sema/unused-expr.c b/test/Sema/unused-expr.c
index b3d6efb..9c231e9 100644
--- a/test/Sema/unused-expr.c
+++ b/test/Sema/unused-expr.c
@@ -1,4 +1,4 @@
-// RUN: clang-cc -fsyntax-only -verify -fno-math-errno %s
+// RUN: clang-cc -fsyntax-only -verify -fmath-errno=0 %s
int foo(int X, int Y);
diff --git a/tools/clang-cc/clang-cc.cpp b/tools/clang-cc/clang-cc.cpp
index d257c43..9260afe 100644
--- a/tools/clang-cc/clang-cc.cpp
+++ b/tools/clang-cc/clang-cc.cpp
@@ -323,15 +323,13 @@
"freestanding environment"));
static llvm::cl::opt<bool>
-AllowBuiltins("fbuiltin",
- llvm::cl::desc("Disable implicit builtin knowledge of functions"),
- llvm::cl::init(true), llvm::cl::AllowInverse);
+AllowBuiltins("fbuiltin", llvm::cl::init(true),
+ llvm::cl::desc("Disable implicit builtin knowledge of functions"));
static llvm::cl::opt<bool>
-MathErrno("fmath-errno",
- llvm::cl::desc("Require math functions to respect errno"),
- llvm::cl::init(true), llvm::cl::AllowInverse);
+MathErrno("fmath-errno", llvm::cl::init(true),
+ llvm::cl::desc("Require math functions to respect errno"));
//===----------------------------------------------------------------------===//
// Language Options
@@ -546,9 +544,7 @@
"elements or different element types"));
static llvm::cl::opt<bool>
-EnableBlocks("fblocks", llvm::cl::desc("enable the 'blocks' language feature"),
- llvm::cl::ValueDisallowed, llvm::cl::AllowInverse,
- llvm::cl::ZeroOrMore);
+EnableBlocks("fblocks", llvm::cl::desc("enable the 'blocks' language feature"));
static llvm::cl::opt<bool>
EnableHeinousExtensions("fheinous-gnu-extensions",