Add driver flags -ftrigraphs, -fno-trigraphs.

-trigraphs is now an alias for -ftrigraphs.  -fno-trigraphs makes it possible
to explicitly disable trigraphs, which couldn't be done before.

  clang -std=c++11 -fno-trigraphs

now builds without GNU extensions, but with trigraphs disabled.  Previously,
trigraphs were only disabled in GNU modes or with -std=c++1z.

Make the new -f flags the cc1 interface too.  This requires changing -trigraphs
to -ftrigraphs in a few cc1 tests.

Related to PR21974.

llvm-svn: 224790
This commit is contained in:
Nico Weber 2014-12-23 22:32:37 +00:00
parent 9fdeb37bd3
commit 007215044b
13 changed files with 42 additions and 25 deletions

View File

@ -940,6 +940,10 @@ def freroll_loops : Flag<["-"], "freroll-loops">, Group<f_Group>,
HelpText<"Turn on loop reroller">, Flags<[CC1Option]>;
def fno_reroll_loops : Flag<["-"], "fno-reroll-loops">, Group<f_Group>,
HelpText<"Turn off loop reroller">;
def ftrigraphs : Flag<["-"], "ftrigraphs">, Group<f_Group>,
HelpText<"Process trigraph sequences">, Flags<[CC1Option]>;
def fno_trigraphs : Flag<["-"], "fno-trigraphs">, Group<f_Group>,
HelpText<"Do not process trigraph sequences">, Flags<[CC1Option]>;
def funsigned_bitfields : Flag<["-"], "funsigned-bitfields">, Group<f_Group>;
def funsigned_char : Flag<["-"], "funsigned-char">, Group<f_Group>;
def fno_unsigned_char : Flag<["-"], "fno-unsigned-char">, Group<clang_ignored_f_Group>;
@ -1471,7 +1475,7 @@ def time : Flag<["-"], "time">,
def traditional_cpp : Flag<["-", "--"], "traditional-cpp">, Flags<[CC1Option]>,
HelpText<"Enable some traditional CPP emulation">;
def traditional : Flag<["-", "--"], "traditional">;
def trigraphs : Flag<["-", "--"], "trigraphs">, Flags<[CC1Option]>,
def trigraphs : Flag<["-", "--"], "trigraphs">, Alias<ftrigraphs>,
HelpText<"Process trigraph sequences">;
def twolevel__namespace__hints : Flag<["-"], "twolevel_namespace_hints">;
def twolevel__namespace : Flag<["-"], "twolevel_namespace">;

View File

@ -3412,8 +3412,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
else
Std->render(Args, CmdArgs);
// If -f(no-)trigraphs appears after the language standard flag, honor it.
if (Arg *A = Args.getLastArg(options::OPT_std_EQ, options::OPT_ansi,
options::OPT_trigraphs))
options::OPT_ftrigraphs,
options::OPT_fno_trigraphs))
if (A != Std)
A->render(Args, CmdArgs);
} else {
@ -3429,7 +3431,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
else if (IsWindowsMSVC)
CmdArgs.push_back("-std=c++11");
Args.AddLastArg(CmdArgs, options::OPT_trigraphs);
Args.AddLastArg(CmdArgs, options::OPT_ftrigraphs,
options::OPT_fno_trigraphs);
}
// GCC's behavior for -Wwrite-strings is a bit strange:

View File

@ -1440,8 +1440,8 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
// is specified, or -std is set to a conforming mode.
// Trigraphs are disabled by default in c++1z onwards.
Opts.Trigraphs = !Opts.GNUMode && !Opts.MSVCCompat && !Opts.CPlusPlus1z;
if (Args.hasArg(OPT_trigraphs))
Opts.Trigraphs = 1;
Opts.Trigraphs =
Args.hasFlag(OPT_ftrigraphs, OPT_fno_trigraphs, Opts.Trigraphs);
Opts.DollarIdents = Args.hasFlag(OPT_fdollars_in_identifiers,
OPT_fno_dollars_in_identifiers,

View File

@ -1,4 +1,4 @@
// RUN: %clang_cc1 -fsyntax-only -trigraphs -Wtrigraphs -verify %s
// RUN: %clang_cc1 -fsyntax-only -ftrigraphs -Wtrigraphs -verify %s
??=pragma // expected-warning {{trigraph converted to '#' character}}

View File

@ -1,3 +1,3 @@
// RUN: %clang_cc1 -fsyntax-only -trigraphs -Wtrigraphs -verify %s
// RUN: %clang_cc1 -fsyntax-only -ftrigraphs -Wtrigraphs -verify %s
??=define arraycheck(a,b) a??(b??) ??!??! b??(a??) // expected-warning {{trigraph converted to '#' character}} expected-warning {{trigraph converted to '[' character}} expected-warning {{trigraph converted to ']' character}} expected-warning {{trigraph converted to '|' character}} expected-warning {{trigraph converted to '|' character}} expected-warning {{trigraph converted to '[' character}} expected-warning {{trigraph converted to ']' character}}

View File

@ -1,4 +1,4 @@
// RUN: %clang_cc1 -fsyntax-only -trigraphs -Wtrigraphs -verify %s
// RUN: %clang_cc1 -fsyntax-only -ftrigraphs -Wtrigraphs -verify %s
// expected-no-diagnostics
char a[] =

View File

@ -1,8 +1,18 @@
// RUN: %clang -std=c99 -trigraphs -std=gnu99 %s -E -o - | FileCheck -check-prefix=OVERRIDE %s
// RUN: %clang -w -std=c99 -trigraphs -std=gnu99 %s -E -o - | FileCheck -check-prefix=OVERRIDE %s
// OVERRIDE: ??(??)
// RUN: %clang -ansi %s -E -o - | FileCheck -check-prefix=ANSI %s
// RUN: %clang -w -std=c99 -trigraphs -std=gnu99 %s -E -o - | FileCheck -check-prefix=FOVERRIDE %s
// FOVERRIDE: ??(??)
// RUN: %clang -w -ansi %s -E -o - | FileCheck -check-prefix=ANSI %s
// ANSI: []
// RUN: %clang -std=gnu99 -trigraphs %s -E -o - | FileCheck -check-prefix=EXPLICIT %s
// RUN: %clang -w -ansi %s -fno-trigraphs -E -o - | FileCheck -check-prefix=ANSI-OVERRIDE %s
// ANSI-OVERRIDE: ??(??)
// RUN: %clang -w -std=gnu99 -trigraphs %s -E -o - | FileCheck -check-prefix=EXPLICIT %s
// EXPLICIT: []
// RUN: %clang -w -std=gnu99 -ftrigraphs %s -E -o - | FileCheck -check-prefix=FEXPLICIT %s
// FEXPLICIT: []
// RUN: %clang -w -ftrigraphs -fno-trigraphs %s -E -o - | FileCheck -check-prefix=ONOFF %s
// ONOFF: ??(??)
// RUN: %clang -w -fno-trigraphs -trigraphs %s -E -o - | FileCheck -check-prefix=OFFFON %s
// OFFFON: []
??(??)

View File

@ -1,8 +1,8 @@
// RUN: %clang_cc1 -DSTDCPP11 -std=c++11 -verify -fsyntax-only %s
// RUN: %clang_cc1 -DSTDGNU11 -std=gnu++11 -verify -fsyntax-only %s
// RUN: %clang_cc1 -DSTDGNU11TRI -trigraphs -std=gnu++11 -verify -fsyntax-only %s
// RUN: %clang_cc1 -DSTDGNU11TRI -ftrigraphs -std=gnu++11 -verify -fsyntax-only %s
// RUN: %clang_cc1 -DSTDCPP17 -std=c++1z -verify -fsyntax-only %s
// RUN: %clang_cc1 -DSTDCPP17TRI -trigraphs -std=c++1z -verify -fsyntax-only %s
// RUN: %clang_cc1 -DSTDCPP17TRI -ftrigraphs -std=c++1z -verify -fsyntax-only %s
// RUN: %clang_cc1 -DMSCOMPAT -fms-compatibility -std=c++11 -verify -fsyntax-only %s
void foo() {

View File

@ -1,4 +1,4 @@
// RUN: %clang_cc1 -Eonly -trigraphs %s
// RUN: %clang_cc1 -Eonly -ftrigraphs %s
// RUN: %clang_cc1 -Eonly -verify %s
//\

View File

@ -1,9 +1,9 @@
/*
RUN: %clang_cc1 -E -trigraphs %s | grep bar
RUN: %clang_cc1 -E -trigraphs %s | grep foo
RUN: %clang_cc1 -E -trigraphs %s | not grep qux
RUN: %clang_cc1 -E -trigraphs %s | not grep xyz
RUN: %clang_cc1 -fsyntax-only -trigraphs -verify %s
RUN: %clang_cc1 -E -ftrigraphs %s | grep bar
RUN: %clang_cc1 -E -ftrigraphs %s | grep foo
RUN: %clang_cc1 -E -ftrigraphs %s | not grep qux
RUN: %clang_cc1 -E -ftrigraphs %s | not grep xyz
RUN: %clang_cc1 -fsyntax-only -ftrigraphs -verify %s
*/
// This is a simple comment, /*/ does not end a comment, the trailing */ does.

View File

@ -1,4 +1,4 @@
// RUN: %clang_cc1 -fsyntax-only -verify -pedantic -trigraphs %s
// RUN: %clang_cc1 -fsyntax-only -verify -pedantic -ftrigraphs %s
int x = 000000080; // expected-error {{invalid digit}}

View File

@ -1,5 +1,5 @@
// RUN: %clang_cc1 -std=c++1z %s -verify
// RUN: %clang_cc1 -std=c++1z %s -trigraphs -fsyntax-only
// RUN: %clang_cc1 -std=c++1z %s -ftrigraphs -fsyntax-only
??= define foo ; // expected-error {{}} expected-warning {{trigraph ignored}}

View File

@ -1,7 +1,7 @@
// RUN: %clang_cc1 -E -trigraphs %s | grep -- ' ->'
// RUN: %clang_cc1 -E -trigraphs %s 2>&1 | grep 'backslash and newline separated by space'
// RUN: %clang_cc1 -E -trigraphs %s 2>&1 | grep 'trigraph converted'
// RUN: %clang_cc1 -E -CC -trigraphs %s
// RUN: %clang_cc1 -E -ftrigraphs %s | grep -- ' ->'
// RUN: %clang_cc1 -E -ftrigraphs %s 2>&1 | grep 'backslash and newline separated by space'
// RUN: %clang_cc1 -E -ftrigraphs %s 2>&1 | grep 'trigraph converted'
// RUN: %clang_cc1 -E -CC -ftrigraphs %s
// This is an ugly way to spell a -> token.
-??/