From: Daniel Dunbar Date: Tue, 7 Apr 2009 22:13:21 +0000 (+0000) Subject: Driver: Fix forwarding of -{std,ansi,trigraphs} when there are X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d573d26e1abcce24c31ece3d6f7af158db569e4c;p=clang Driver: Fix forwarding of -{std,ansi,trigraphs} when there are 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 --- diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index 4e2a7b9939..a3cea95c26 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -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 index 0000000000..ef6d8f1977 --- /dev/null +++ b/test/Driver/std.c @@ -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 + +??(??) diff --git a/tools/clang-cc/clang-cc.cpp b/tools/clang-cc/clang-cc.cpp index 9260afe4b7..2843848f31 100644 --- a/tools/clang-cc/clang-cc.cpp +++ b/tools/clang-cc/clang-cc.cpp @@ -585,9 +585,6 @@ NeXTRuntime("fnext-runtime", static llvm::cl::opt Trigraphs("trigraphs", llvm::cl::desc("Process trigraph sequences.")); -static llvm::cl::opt -Ansi("ansi", llvm::cl::desc("Equivalent to specifying -std=c89.")); - static llvm::cl::list 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.