[cfe-commits] r68558 - in /cfe/trunk: lib/Driver/Tools.cpp test/Driver/std.c tools/clang-cc/clang-cc.cpp
Daniel Dunbar
daniel at zuster.org
Tue Apr 7 15:13:21 PDT 2009
Author: ddunbar
Date: Tue Apr 7 17:13:21 2009
New Revision: 68558
URL: http://llvm.org/viewvc/llvm-project?rev=68558&view=rev
Log:
Driver: Fix forwarding of -{std,ansi,trigraphs} when there are
multiple instances of an option.
Also, removed direct -ansi support from clang-cc.
Added:
cfe/trunk/test/Driver/std.c
Modified:
cfe/trunk/lib/Driver/Tools.cpp
cfe/trunk/tools/clang-cc/clang-cc.cpp
Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=68558&r1=68557&r2=68558&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Tue Apr 7 17:13:21 2009
@@ -350,8 +350,23 @@
Args.AddAllArgs(CmdArgs, options::OPT_clang_W_Group,
options::OPT_pedantic_Group);
Args.AddLastArg(CmdArgs, options::OPT_w);
- Args.AddAllArgs(CmdArgs, options::OPT_std_EQ, options::OPT_ansi,
- options::OPT_trigraphs);
+
+ // Handle -{std, ansi, trigraphs} -- take the last of -{std, ansi}
+ // (-ansi is equivalent to -std=c89).
+ //
+ // If a std is supplied, only add -trigraphs if it follows the
+ // option.
+ if (Arg *Std = Args.getLastArg(options::OPT_std_EQ, options::OPT_ansi)) {
+ if (Std->getOption().matches(options::OPT_ansi))
+ CmdArgs.push_back("-std=c89");
+ else
+ Std->render(Args, CmdArgs);
+
+ if (Arg *A = Args.getLastArg(options::OPT_trigraphs))
+ if (A->getIndex() > Std->getIndex())
+ A->render(Args, CmdArgs);
+ } else
+ Args.AddLastArg(CmdArgs, options::OPT_trigraphs);
if (Arg *A = Args.getLastArg(options::OPT_ftemplate_depth_)) {
CmdArgs.push_back("-ftemplate-depth");
Added: cfe/trunk/test/Driver/std.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/std.c?rev=68558&view=auto
==============================================================================
--- cfe/trunk/test/Driver/std.c (added)
+++ cfe/trunk/test/Driver/std.c Tue Apr 7 17:13:21 2009
@@ -0,0 +1,8 @@
+// RUN: clang -std=c99 -trigraphs -std=gnu99 %s -E -o %t &&
+// RUN: grep '??(??)' %t &&
+// RUN: clang -ansi %s -E -o %t &&
+// RUN: grep -F '[]' %t &&
+// RUN: clang -std=gnu99 -trigraphs %s -E -o %t &&
+// RUN: grep -F '[]' %t
+
+??(??)
Modified: cfe/trunk/tools/clang-cc/clang-cc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/clang-cc.cpp?rev=68558&r1=68557&r2=68558&view=diff
==============================================================================
--- cfe/trunk/tools/clang-cc/clang-cc.cpp (original)
+++ cfe/trunk/tools/clang-cc/clang-cc.cpp Tue Apr 7 17:13:21 2009
@@ -585,9 +585,6 @@
static llvm::cl::opt<bool>
Trigraphs("trigraphs", llvm::cl::desc("Process trigraph sequences."));
-static llvm::cl::opt<bool>
-Ansi("ansi", llvm::cl::desc("Equivalent to specifying -std=c89."));
-
static llvm::cl::list<std::string>
TargetFeatures("mattr", llvm::cl::CommaSeparated,
llvm::cl::desc("Target specific attributes (-mattr=help for details)"));
@@ -653,9 +650,6 @@
}
}
- if (Ansi) // "The -ansi option is equivalent to -std=c89."
- LangStd = lang_c89;
-
if (LangStd == lang_unspecified) {
// Based on the base language, pick one.
switch (LK) {
@@ -719,8 +713,8 @@
else
Options.ImplicitInt = 0;
- // Mimicing gcc's behavior, trigraphs are only enabled if -trigraphs or -ansi
- // is specified, or -std is set to a conforming mode.
+ // Mimicing gcc's behavior, trigraphs are only enabled if -trigraphs
+ // is specified, or -std is set to a conforming mode.
Options.Trigraphs = !Options.GNUMode;
if (Trigraphs.getPosition())
Options.Trigraphs = Trigraphs; // Command line option wins if specified.
More information about the cfe-commits
mailing list