diff options
author | Nico Weber <nicolasweber@gmx.de> | 2014-12-23 22:32:37 +0000 |
---|---|---|
committer | Nico Weber <nicolasweber@gmx.de> | 2014-12-23 22:32:37 +0000 |
commit | f370b840369678a94800b417db3dd44d6c5bdf69 (patch) | |
tree | 8894d7447419f76eaefbee7e6f77b75dea8848cc | |
parent | 9ef9d72a247fd502071742523c8ffdd7f5056fe2 (diff) |
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@224790 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/Driver/Options.td | 6 | ||||
-rw-r--r-- | lib/Driver/Tools.cpp | 7 | ||||
-rw-r--r-- | lib/Frontend/CompilerInvocation.cpp | 4 | ||||
-rw-r--r-- | test/CXX/lex/lex.trigraph/p1.cpp | 2 | ||||
-rw-r--r-- | test/CXX/lex/lex.trigraph/p2.cpp | 2 | ||||
-rw-r--r-- | test/CXX/lex/lex.trigraph/p3.cpp | 2 | ||||
-rw-r--r-- | test/Driver/std.c | 16 | ||||
-rw-r--r-- | test/Frontend/trigraphs.cpp | 4 | ||||
-rw-r--r-- | test/Lexer/bcpl-escaped-newline.c | 2 | ||||
-rw-r--r-- | test/Lexer/block_cmt_end.c | 10 | ||||
-rw-r--r-- | test/Lexer/constants.c | 2 | ||||
-rw-r--r-- | test/Lexer/cxx1z-trigraphs.cpp | 2 | ||||
-rw-r--r-- | test/Lexer/escape_newline.c | 8 |
13 files changed, 42 insertions, 25 deletions
diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td index 766c964284..4cc3f64dde 100644 --- a/include/clang/Driver/Options.td +++ b/include/clang/Driver/Options.td @@ -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">; diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index 1c5a9aa404..5212d46345 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -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: diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index f44a4fb8ae..8d484a5479 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -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, diff --git a/test/CXX/lex/lex.trigraph/p1.cpp b/test/CXX/lex/lex.trigraph/p1.cpp index aacbc55b28..a80b00eabe 100644 --- a/test/CXX/lex/lex.trigraph/p1.cpp +++ b/test/CXX/lex/lex.trigraph/p1.cpp @@ -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}} diff --git a/test/CXX/lex/lex.trigraph/p2.cpp b/test/CXX/lex/lex.trigraph/p2.cpp index 7d11d5bf5d..6502aa8d79 100644 --- a/test/CXX/lex/lex.trigraph/p2.cpp +++ b/test/CXX/lex/lex.trigraph/p2.cpp @@ -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}} diff --git a/test/CXX/lex/lex.trigraph/p3.cpp b/test/CXX/lex/lex.trigraph/p3.cpp index c74d8f358d..bf935708a2 100644 --- a/test/CXX/lex/lex.trigraph/p3.cpp +++ b/test/CXX/lex/lex.trigraph/p3.cpp @@ -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[] = diff --git a/test/Driver/std.c b/test/Driver/std.c index c82e9f15c7..02dca6698d 100644 --- a/test/Driver/std.c +++ b/test/Driver/std.c @@ -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: [] ??(??) diff --git a/test/Frontend/trigraphs.cpp b/test/Frontend/trigraphs.cpp index 4b04bcbe13..552078951a 100644 --- a/test/Frontend/trigraphs.cpp +++ b/test/Frontend/trigraphs.cpp @@ -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() { diff --git a/test/Lexer/bcpl-escaped-newline.c b/test/Lexer/bcpl-escaped-newline.c index 05d4773b87..0883173b22 100644 --- a/test/Lexer/bcpl-escaped-newline.c +++ b/test/Lexer/bcpl-escaped-newline.c @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -Eonly -trigraphs %s +// RUN: %clang_cc1 -Eonly -ftrigraphs %s // RUN: %clang_cc1 -Eonly -verify %s //\ diff --git a/test/Lexer/block_cmt_end.c b/test/Lexer/block_cmt_end.c index f54b6a4a21..1d00137644 100644 --- a/test/Lexer/block_cmt_end.c +++ b/test/Lexer/block_cmt_end.c @@ -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. diff --git a/test/Lexer/constants.c b/test/Lexer/constants.c index 267e75e64e..9c84ddc019 100644 --- a/test/Lexer/constants.c +++ b/test/Lexer/constants.c @@ -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}} diff --git a/test/Lexer/cxx1z-trigraphs.cpp b/test/Lexer/cxx1z-trigraphs.cpp index 410626fd7b..0ea2adbe1e 100644 --- a/test/Lexer/cxx1z-trigraphs.cpp +++ b/test/Lexer/cxx1z-trigraphs.cpp @@ -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}} diff --git a/test/Lexer/escape_newline.c b/test/Lexer/escape_newline.c index d0f27dffdf..9fc73dc7a4 100644 --- a/test/Lexer/escape_newline.c +++ b/test/Lexer/escape_newline.c @@ -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. -??/ |