jtbandes updated this revision to Diff 151771. jtbandes added a comment. Added `-fdigraphs`. I kept it as a cc1 option because it seemed awkward to "check whether the last arg was -fno-digraphs and pass only that arg to cc1" (if just directly forwarding all args, there would be an unrecognized argument error if it's not a cc1 option).
Repository: rC Clang https://reviews.llvm.org/D48266 Files: include/clang/Driver/Options.td lib/Driver/ToolChains/Clang.cpp lib/Frontend/CompilerInvocation.cpp test/Lexer/digraph.c Index: test/Lexer/digraph.c =================================================================== --- test/Lexer/digraph.c +++ test/Lexer/digraph.c @@ -1,6 +1,11 @@ -// RUN: %clang_cc1 -fsyntax-only -verify -ffreestanding %s -// expected-no-diagnostics +// RUN: %clang_cc1 -DDIGRAPHS -fsyntax-only -verify -ffreestanding %s +// RUN: %clang_cc1 -DDIGRAPHS -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 + +#if DIGRAPHS +// expected-no-diagnostics %:include <stdint.h> %:ifndef BUFSIZE @@ -14,3 +19,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 Index: lib/Frontend/CompilerInvocation.cpp =================================================================== --- lib/Frontend/CompilerInvocation.cpp +++ lib/Frontend/CompilerInvocation.cpp @@ -2174,6 +2174,8 @@ 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; Index: lib/Driver/ToolChains/Clang.cpp =================================================================== --- lib/Driver/ToolChains/Clang.cpp +++ lib/Driver/ToolChains/Clang.cpp @@ -3970,6 +3970,7 @@ // 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); Index: include/clang/Driver/Options.td =================================================================== --- include/clang/Driver/Options.td +++ include/clang/Driver/Options.td @@ -1334,6 +1334,10 @@ 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>,
Index: test/Lexer/digraph.c =================================================================== --- test/Lexer/digraph.c +++ test/Lexer/digraph.c @@ -1,6 +1,11 @@ -// RUN: %clang_cc1 -fsyntax-only -verify -ffreestanding %s -// expected-no-diagnostics +// RUN: %clang_cc1 -DDIGRAPHS -fsyntax-only -verify -ffreestanding %s +// RUN: %clang_cc1 -DDIGRAPHS -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 + +#if DIGRAPHS +// expected-no-diagnostics %:include <stdint.h> %:ifndef BUFSIZE @@ -14,3 +19,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 Index: lib/Frontend/CompilerInvocation.cpp =================================================================== --- lib/Frontend/CompilerInvocation.cpp +++ lib/Frontend/CompilerInvocation.cpp @@ -2174,6 +2174,8 @@ 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; Index: lib/Driver/ToolChains/Clang.cpp =================================================================== --- lib/Driver/ToolChains/Clang.cpp +++ lib/Driver/ToolChains/Clang.cpp @@ -3970,6 +3970,7 @@ // 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); Index: include/clang/Driver/Options.td =================================================================== --- include/clang/Driver/Options.td +++ include/clang/Driver/Options.td @@ -1334,6 +1334,10 @@ 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>,
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits