diff options
author | Jacob Bandes-Storch <jacob@bandes-stor.ch> | 2018-07-17 04:56:22 +0000 |
---|---|---|
committer | Jacob Bandes-Storch <jacob@bandes-stor.ch> | 2018-07-17 04:56:22 +0000 |
commit | 33f3e630b47384db957481f7f7aca99b6f37b3a6 (patch) | |
tree | c49e1f5f0c07ddbdeda1335017ce65284807652f | |
parent | fec4c1a101996f203388d19160cc279b1bc5618f (diff) | |
download | bcm5719-llvm-33f3e630b47384db957481f7f7aca99b6f37b3a6.tar.gz bcm5719-llvm-33f3e630b47384db957481f7f7aca99b6f37b3a6.zip |
[Driver] Add -fno-digraphs
Summary: Add a flag `-fno-digraphs` to disable digraphs in the lexer, similar to `-fno-operator-names` which disables alternative names for C++ operators.
Reviewers: rsmith
Reviewed By: rsmith
Subscribers: rsmith, cfe-commits
Differential Revision: https://reviews.llvm.org/D48266
llvm-svn: 337232
-rw-r--r-- | clang/include/clang/Driver/Options.td | 4 | ||||
-rw-r--r-- | clang/lib/Driver/ToolChains/Clang.cpp | 1 | ||||
-rw-r--r-- | clang/lib/Frontend/CompilerInvocation.cpp | 2 | ||||
-rw-r--r-- | clang/test/Lexer/digraph.c | 23 |
4 files changed, 28 insertions, 2 deletions
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 5a7e5c9e4e5..9035a91ce21 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -1335,6 +1335,10 @@ def fno_diagnostics_show_hotness : Flag<["-"], "fno-diagnostics-show-hotness">, def fno_diagnostics_show_option : Flag<["-"], "fno-diagnostics-show-option">, Group<f_Group>; def fno_diagnostics_show_note_include_stack : Flag<["-"], "fno-diagnostics-show-note-include-stack">, Flags<[CC1Option]>, Group<f_Group>; +def fdigraphs : Flag<["-"], "fdigraphs">, Group<f_Group>, Flags<[CC1Option]>, + HelpText<"Enable alternative token representations '<:', ':>', '<%', '%>', '%:', '%:%:' (default)">; +def fno_digraphs : Flag<["-"], "fno-digraphs">, Group<f_Group>, Flags<[CC1Option]>, + HelpText<"Disallow alternative token representations '<:', ':>', '<%', '%>', '%:', '%:%:'">; def fno_declspec : Flag<["-"], "fno-declspec">, Group<f_clang_Group>, HelpText<"Disallow __declspec as a keyword">, Flags<[CC1Option]>; def fno_dollars_in_identifiers : Flag<["-"], "fno-dollars-in-identifiers">, Group<f_Group>, diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 472a4163e55..853f9a422f1 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -3925,6 +3925,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, // Forward -f (flag) options which we can pass directly. Args.AddLastArg(CmdArgs, options::OPT_femit_all_decls); Args.AddLastArg(CmdArgs, options::OPT_fheinous_gnu_extensions); + Args.AddLastArg(CmdArgs, options::OPT_fdigraphs, options::OPT_fno_digraphs); Args.AddLastArg(CmdArgs, options::OPT_fno_operator_names); Args.AddLastArg(CmdArgs, options::OPT_femulated_tls, options::OPT_fno_emulated_tls); diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index f57f23a0d4c..d62429dc788 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -2173,6 +2173,8 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK, Opts.GNUKeywords = Args.hasFlag(OPT_fgnu_keywords, OPT_fno_gnu_keywords, Opts.GNUKeywords); + Opts.Digraphs = Args.hasFlag(OPT_fdigraphs, OPT_fno_digraphs, Opts.Digraphs); + if (Args.hasArg(OPT_fno_operator_names)) Opts.CXXOperatorNames = 0; diff --git a/clang/test/Lexer/digraph.c b/clang/test/Lexer/digraph.c index e940caf44f4..5d8a77d5395 100644 --- a/clang/test/Lexer/digraph.c +++ b/clang/test/Lexer/digraph.c @@ -1,6 +1,13 @@ -// RUN: %clang_cc1 -fsyntax-only -verify -ffreestanding %s -// expected-no-diagnostics +// RUN: %clang_cc1 -DDIGRAPHS=1 -fsyntax-only -verify -ffreestanding %s +// RUN: %clang_cc1 -DDIGRAPHS=1 -fno-digraphs -fdigraphs -fsyntax-only -verify -ffreestanding %s +// RUN: %clang_cc1 -fno-digraphs -fsyntax-only -verify -ffreestanding %s +// RUN: %clang_cc1 -fdigraphs -fno-digraphs -fsyntax-only -verify -ffreestanding %s +// RUN: %clang_cc1 -std=c89 -DDIGRAPHS=1 -fdigraphs -fsyntax-only -verify -ffreestanding %s +// RUN: %clang_cc1 -std=c89 -fno-digraphs -fsyntax-only -verify -ffreestanding %s + +#if DIGRAPHS +// expected-no-diagnostics %:include <stdint.h> %:ifndef BUFSIZE @@ -14,3 +21,15 @@ d<:len:> = s<:len:>; %> %> +#else + +// expected-error@+1 {{expected identifier or '('}} +%:include <stdint.h> +; +// expected-error@+1 {{expected ')'}} expected-note@+1{{to match this '('}} +void copy(char d<::>); + +// expected-error@+1 {{expected function body}} +void copy() <% %> + +#endif |