]> granicus.if.org Git - clang/commitdiff
Driver: Fix forwarding of -{std,ansi,trigraphs} when there are
authorDaniel Dunbar <daniel@zuster.org>
Tue, 7 Apr 2009 22:13:21 +0000 (22:13 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Tue, 7 Apr 2009 22:13:21 +0000 (22:13 +0000)
multiple instances of an option.

Also, removed direct -ansi support from clang-cc.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68558 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Driver/Tools.cpp
test/Driver/std.c [new file with mode: 0644]
tools/clang-cc/clang-cc.cpp

index 4e2a7b9939777abe0fec9686282fd9f132e8b25c..a3cea95c26853d5c78741be203eb9b2a8b06af66 100644 (file)
@@ -350,8 +350,23 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
   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");
diff --git a/test/Driver/std.c b/test/Driver/std.c
new file mode 100644 (file)
index 0000000..ef6d8f1
--- /dev/null
@@ -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
+
+??(??)
index 9260afe4b7dbe6d4aa68d9a4dbae005e9420595e..2843848f313cd608dc3dae45e5d441c6d6decaec 100644 (file)
@@ -585,9 +585,6 @@ NeXTRuntime("fnext-runtime",
 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 @@ static void InitializeLanguageStandard(LangOptions &Options, LangKind LK,
     }
   }
   
-  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 @@ static void InitializeLanguageStandard(LangOptions &Options, LangKind LK,
   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.