[PATCH] D48266: [Driver] Add -fno-digraphs

2018-07-16 Thread Jacob Bandes-Storch via Phabricator via cfe-commits
jtbandes marked an inline comment as done.
jtbandes added a comment.

Ping again 


Repository:
  rL LLVM

https://reviews.llvm.org/D48266



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D48266: [Driver] Add -fno-digraphs

2018-07-16 Thread Jacob Bandes-Storch via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL337232: [Driver] Add -fno-digraphs (authored by jtbandes, 
committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D48266?vs=155116=155809#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D48266

Files:
  cfe/trunk/include/clang/Driver/Options.td
  cfe/trunk/lib/Driver/ToolChains/Clang.cpp
  cfe/trunk/lib/Frontend/CompilerInvocation.cpp
  cfe/trunk/test/Lexer/digraph.c


Index: cfe/trunk/include/clang/Driver/Options.td
===
--- cfe/trunk/include/clang/Driver/Options.td
+++ cfe/trunk/include/clang/Driver/Options.td
@@ -1335,6 +1335,10 @@
 def fno_diagnostics_show_option : Flag<["-"], "fno-diagnostics-show-option">, 
Group;
 def fno_diagnostics_show_note_include_stack : Flag<["-"], 
"fno-diagnostics-show-note-include-stack">,
 Flags<[CC1Option]>, Group;
+def fdigraphs : Flag<["-"], "fdigraphs">, Group, Flags<[CC1Option]>,
+  HelpText<"Enable alternative token representations '<:', ':>', '<%', '%>', 
'%:', '%:%:' (default)">;
+def fno_digraphs : Flag<["-"], "fno-digraphs">, Group, 
Flags<[CC1Option]>,
+  HelpText<"Disallow alternative token representations '<:', ':>', '<%', '%>', 
'%:', '%:%:'">;
 def fno_declspec : Flag<["-"], "fno-declspec">, Group,
   HelpText<"Disallow __declspec as a keyword">, Flags<[CC1Option]>;
 def fno_dollars_in_identifiers : Flag<["-"], "fno-dollars-in-identifiers">, 
Group,
Index: cfe/trunk/test/Lexer/digraph.c
===
--- cfe/trunk/test/Lexer/digraph.c
+++ cfe/trunk/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 
 
 %:ifndef BUFSIZE
@@ -14,3 +21,15 @@
 d<:len:> = s<:len:>;
 %>
 %>
+#else
+
+// expected-error@+1 {{expected identifier or '('}}
+%:include 
+;
+// expected-error@+1 {{expected ')'}} expected-note@+1{{to match this '('}}
+void copy(char d<::>);
+
+// expected-error@+1 {{expected function body}}
+void copy() <% %>
+
+#endif
Index: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp
@@ -3925,6 +3925,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: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
===
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp
@@ -2173,6 +2173,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: cfe/trunk/include/clang/Driver/Options.td
===
--- cfe/trunk/include/clang/Driver/Options.td
+++ cfe/trunk/include/clang/Driver/Options.td
@@ -1335,6 +1335,10 @@
 def fno_diagnostics_show_option : Flag<["-"], "fno-diagnostics-show-option">, Group;
 def fno_diagnostics_show_note_include_stack : Flag<["-"], "fno-diagnostics-show-note-include-stack">,
 Flags<[CC1Option]>, Group;
+def fdigraphs : Flag<["-"], "fdigraphs">, Group, Flags<[CC1Option]>,
+  HelpText<"Enable alternative token representations '<:', ':>', '<%', '%>', '%:', '%:%:' (default)">;
+def fno_digraphs : Flag<["-"], "fno-digraphs">, Group, Flags<[CC1Option]>,
+  HelpText<"Disallow alternative token representations '<:', ':>', '<%', '%>', '%:', '%:%:'">;
 def fno_declspec : Flag<["-"], "fno-declspec">, Group,
   HelpText<"Disallow __declspec as a keyword">, Flags<[CC1Option]>;
 def fno_dollars_in_identifiers : Flag<["-"], "fno-dollars-in-identifiers">, Group,
Index: cfe/trunk/test/Lexer/digraph.c

[PATCH] D48266: [Driver] Add -fno-digraphs

2018-07-16 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith accepted this revision.
rsmith added a comment.
This revision is now accepted and ready to land.

Looks good with one cleanup.




Comment at: lib/Frontend/CompilerInvocation.cpp:2177-2178
 
+  if (const Arg *A = Args.getLastArg(OPT_fdigraphs, OPT_fno_digraphs))
+Opts.Digraphs = A->getOption().matches(OPT_fdigraphs) ? 1 : 0;
+

Simplify this to `Opts.Digraphs = Args.hasFlag(OPT_fdigraphs, 
OPT_fno_diagraphs, Opts.Digraphs);`


Repository:
  rC Clang

https://reviews.llvm.org/D48266



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D48266: [Driver] Add -fno-digraphs

2018-07-16 Thread Jacob Bandes-Storch via Phabricator via cfe-commits
jtbandes added a comment.

Ping again 


Repository:
  rC Clang

https://reviews.llvm.org/D48266



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D48266: [Driver] Add -fno-digraphs

2018-07-11 Thread Jacob Bandes-Storch via Phabricator via cfe-commits
jtbandes updated this revision to Diff 155116.
jtbandes marked an inline comment as done.
jtbandes added a comment.

- include %:%: in help text


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,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 
 
 %:ifndef BUFSIZE
@@ -14,3 +21,15 @@
 d<:len:> = s<:len:>;
 %>
 %>
+#else
+
+// expected-error@+1 {{expected identifier or '('}}
+%:include 
+;
+// 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,9 @@
   Opts.GNUKeywords = Args.hasFlag(OPT_fgnu_keywords, OPT_fno_gnu_keywords,
   Opts.GNUKeywords);
 
+  if (const Arg *A = Args.getLastArg(OPT_fdigraphs, OPT_fno_digraphs))
+Opts.Digraphs = A->getOption().matches(OPT_fdigraphs) ? 1 : 0;
+
   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;
 def fno_diagnostics_show_note_include_stack : Flag<["-"], 
"fno-diagnostics-show-note-include-stack">,
 Flags<[CC1Option]>, Group;
+def fdigraphs : Flag<["-"], "fdigraphs">, Group, Flags<[CC1Option]>,
+  HelpText<"Enable alternative token representations '<:', ':>', '<%', '%>', 
'%:', '%:%:' (default)">;
+def fno_digraphs : Flag<["-"], "fno-digraphs">, Group, 
Flags<[CC1Option]>,
+  HelpText<"Disallow alternative token representations '<:', ':>', '<%', '%>', 
'%:', '%:%:'">;
 def fno_declspec : Flag<["-"], "fno-declspec">, Group,
   HelpText<"Disallow __declspec as a keyword">, Flags<[CC1Option]>;
 def fno_dollars_in_identifiers : Flag<["-"], "fno-dollars-in-identifiers">, 
Group,


Index: test/Lexer/digraph.c
===
--- test/Lexer/digraph.c
+++ 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 
 
 %:ifndef BUFSIZE
@@ -14,3 +21,15 @@
 d<:len:> = s<:len:>;
 %>
 %>
+#else
+
+// expected-error@+1 {{expected identifier or '('}}
+%:include 
+;
+// 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
===
--- 

[PATCH] D48266: [Driver] Add -fno-digraphs

2018-07-11 Thread Jacob Bandes-Storch via Phabricator via cfe-commits
jtbandes marked 2 inline comments as done.
jtbandes added a comment.

If I understood your comment correctly, you meant to remove the diagnostic 
completely (regardless of whether `-fdigraphs` or `-fno-digraphs` is given, and 
regardless of whether digraphs were enabled for the selected language)? I've 
done that, and added a couple `-std=c89` invocations to the test cases.


Repository:
  rC Clang

https://reviews.llvm.org/D48266



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D48266: [Driver] Add -fno-digraphs

2018-07-11 Thread Jacob Bandes-Storch via Phabricator via cfe-commits
jtbandes updated this revision to Diff 155115.
jtbandes added a comment.

- remove diagnostic; fix formatting


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,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 
 
 %:ifndef BUFSIZE
@@ -14,3 +21,15 @@
 d<:len:> = s<:len:>;
 %>
 %>
+#else
+
+// expected-error@+1 {{expected identifier or '('}}
+%:include 
+;
+// 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,9 @@
   Opts.GNUKeywords = Args.hasFlag(OPT_fgnu_keywords, OPT_fno_gnu_keywords,
   Opts.GNUKeywords);
 
+  if (const Arg *A = Args.getLastArg(OPT_fdigraphs, OPT_fno_digraphs))
+Opts.Digraphs = A->getOption().matches(OPT_fdigraphs) ? 1 : 0;
+
   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;
 def fno_diagnostics_show_note_include_stack : Flag<["-"], 
"fno-diagnostics-show-note-include-stack">,
 Flags<[CC1Option]>, Group;
+def fdigraphs : Flag<["-"], "fdigraphs">, Group, Flags<[CC1Option]>,
+  HelpText<"Enable alternative token representations '<:', ':>', '<%', '%>', 
'%:' (default)">;
+def fno_digraphs : Flag<["-"], "fno-digraphs">, Group, 
Flags<[CC1Option]>,
+  HelpText<"Disallow alternative token representations '<:', ':>', '<%', '%>', 
'%:'">;
 def fno_declspec : Flag<["-"], "fno-declspec">, Group,
   HelpText<"Disallow __declspec as a keyword">, Flags<[CC1Option]>;
 def fno_dollars_in_identifiers : Flag<["-"], "fno-dollars-in-identifiers">, 
Group,


Index: test/Lexer/digraph.c
===
--- test/Lexer/digraph.c
+++ 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 
 
 %:ifndef BUFSIZE
@@ -14,3 +21,15 @@
 d<:len:> = s<:len:>;
 %>
 %>
+#else
+
+// expected-error@+1 {{expected identifier or '('}}
+%:include 
+;
+// 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
+++ 

[PATCH] D48266: [Driver] Add -fno-digraphs

2018-07-09 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: include/clang/Driver/Options.td:1337-1340
+def fdigraphs : Flag<["-"], "fdigraphs">, Group, Flags<[CC1Option]>,
+  HelpText<"Enable alternative token representations '<:', ':>', '<%', '%>', 
'%:' (default)">;
+def fno_digraphs : Flag<["-"], "fno-digraphs">, Group, 
Flags<[CC1Option]>,
+  HelpText<"Disallow alternative token representations '<:', ':>', '<%', '%>', 
'%:'">;

It'd make sense to also list `%:%:` here, particularly because it is controlled 
by this flag and isn't technically a digraph.



Comment at: lib/Frontend/CompilerInvocation.cpp:2181
 
+  if (const Arg* A = Args.getLastArg(OPT_fdigraphs, OPT_fno_digraphs)) {
+// Prevent the user from enabling or disabling digraphs when they are not 
supported.

` *` not `* `, please.



Comment at: lib/Frontend/CompilerInvocation.cpp:2183-2185
+if (!Opts.Digraphs && LangStdArg)
+  Diags.Report(diag::err_drv_argument_not_allowed_with)
+  << A->getSpelling() << LangStdArg->getAsString(Args);

Do we have any languages that disable digraphs by default? This won't work in 
such cases.

And actually... there doesn't seem to be a good reason to disallow enabling 
digraphs in C89-like modes, so maybe we should just remove the diagnostic for 
this case entirely? We generally don't prevent the user from arbitrarily 
combining language features.


Repository:
  rC Clang

https://reviews.llvm.org/D48266



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D48266: [Driver] Add -fno-digraphs

2018-07-09 Thread Jacob Bandes-Storch via Phabricator via cfe-commits
jtbandes added a comment.

Friendly ping!


Repository:
  rC Clang

https://reviews.llvm.org/D48266



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D48266: [Driver] Add -fno-digraphs

2018-06-19 Thread Jacob Bandes-Storch via Phabricator via cfe-commits
jtbandes updated this revision to Diff 151858.
jtbandes marked an inline comment as done.
jtbandes added a comment.

Added an error when language standard doesn't support digraphs.

Still keeping `-fdigraphs` as a cc1 option because then I can distinguish 
explicitly-enabled/disabled from the absence of a flag. I can also check 
whether digraphs are supported using the LangStandard/LangOpts in the 
CompilerInstance rather than hard-coding an incompatibility with -std=c89.


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,17 @@
-// 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: not %clang_cc1 -std=c89 -fdigraphs -fsyntax-only -ffreestanding %s 2>&1 | FileCheck -check-prefix=CHECK1 %s
+// RUN: not %clang_cc1 -std=c89 -fno-digraphs -fsyntax-only -ffreestanding %s 2>&1 | FileCheck -check-prefix=CHECK2 %s
+
+// CHECK1: error: invalid argument '-fdigraphs' not allowed with '-std=c89'
+// CHECK2: error: invalid argument '-fno-digraphs' not allowed with '-std=c89'
 
+#if DIGRAPHS
+
+// expected-no-diagnostics
 %:include 
 
 %:ifndef BUFSIZE
@@ -14,3 +25,15 @@
 d<:len:> = s<:len:>;
 %>
 %>
+#else
+
+// expected-error@+1 {{expected identifier or '('}}
+%:include 
+;
+// 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
@@ -2080,6 +2080,7 @@
   DiagnosticsEngine ) {
   // FIXME: Cleanup per-file based stuff.
   LangStandard::Kind LangStd = LangStandard::lang_unspecified;
+  const Arg *LangStdArg;
   if (const Arg *A = Args.getLastArg(OPT_std_EQ)) {
 LangStd = llvm::StringSwitch(A->getValue())
 #define LANGSTANDARD(id, name, lang, desc, features) \
@@ -2117,6 +2118,7 @@
 } else {
   // Valid standard, check to make sure language and standard are
   // compatible.
+  LangStdArg = A;
   const LangStandard  = LangStandard::getLangStandardForKind(LangStd);
   if (!IsInputCompatibleWithStandard(IK, Std)) {
 Diags.Report(diag::err_drv_argument_not_allowed_with)
@@ -2147,8 +2149,10 @@
   Diags.Report(diag::err_drv_invalid_value)
 << A->getAsString(Args) << A->getValue();
 }
-else
+else {
   LangStd = OpenCLLangStd;
+  LangStdArg = A;
+}
   }
 
   Opts.IncludeDefaultHeader = Args.hasArg(OPT_finclude_default_header);
@@ -2174,6 +2178,16 @@
   Opts.GNUKeywords = Args.hasFlag(OPT_fgnu_keywords, OPT_fno_gnu_keywords,
   Opts.GNUKeywords);
 
+  if (const Arg* A = Args.getLastArg(OPT_fdigraphs, OPT_fno_digraphs)) {
+// Prevent the user from enabling or disabling digraphs when they are not supported.
+if (!Opts.Digraphs && LangStdArg)
+  Diags.Report(diag::err_drv_argument_not_allowed_with)
+  << A->getSpelling() << LangStdArg->getAsString(Args);
+
+if (A->getOption().matches(OPT_fno_digraphs))
+  Opts.Digraphs = 0;
+  }
+
   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;
 def fno_diagnostics_show_note_include_stack : Flag<["-"], "fno-diagnostics-show-note-include-stack">,
 Flags<[CC1Option]>, Group;
+def fdigraphs : Flag<["-"], 

[PATCH] D48266: [Driver] Add -fno-digraphs

2018-06-18 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: lib/Driver/ToolChains/Clang.cpp:3973
   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);

Use `Args.hasFlag` to determine if `-fdigraphs` or `-fno-digraphs` was 
specified last, then `CmdArgs.push_back("-fno-digraphs")` if digraphs are 
disabled. (There are lots of examples of that in this file that you can follow.)

What should `-fdigraphs` do under `-std=c89`? I think produing a "this flag is 
not compatible with that flag" diagnostic would make sense for that case.


Repository:
  rC Clang

https://reviews.llvm.org/D48266



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D48266: [Driver] Add -fno-digraphs

2018-06-18 Thread Jacob Bandes-Storch via Phabricator via cfe-commits
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 
 
 %:ifndef BUFSIZE
@@ -14,3 +19,15 @@
 d<:len:> = s<:len:>;
 %>
 %>
+#else
+
+// expected-error@+1 {{expected identifier or '('}}
+%:include 
+;
+// 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;
 def fno_diagnostics_show_note_include_stack : Flag<["-"], 
"fno-diagnostics-show-note-include-stack">,
 Flags<[CC1Option]>, Group;
+def fdigraphs : Flag<["-"], "fdigraphs">, Group, Flags<[CC1Option]>,
+  HelpText<"Enable alternative token representations '<:', ':>', '<%', '%>', 
'%:' (default)">;
+def fno_digraphs : Flag<["-"], "fno-digraphs">, Group, 
Flags<[CC1Option]>,
+  HelpText<"Disallow alternative token representations '<:', ':>', '<%', '%>', 
'%:'">;
 def fno_declspec : Flag<["-"], "fno-declspec">, Group,
   HelpText<"Disallow __declspec as a keyword">, Flags<[CC1Option]>;
 def fno_dollars_in_identifiers : Flag<["-"], "fno-dollars-in-identifiers">, 
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 
 
 %:ifndef BUFSIZE
@@ -14,3 +19,15 @@
 d<:len:> = s<:len:>;
 %>
 %>
+#else
+
+// expected-error@+1 {{expected identifier or '('}}
+%:include 
+;
+// 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 = 

[PATCH] D48266: [Driver] Add -fno-digraphs

2018-06-18 Thread Jacob Bandes-Storch via Phabricator via cfe-commits
jtbandes marked an inline comment as done.
jtbandes added inline comments.



Comment at: include/clang/Driver/Options.td:1337-1338
 Flags<[CC1Option]>, Group;
+def fno_digraphs : Flag<["-"], "fno-digraphs">, Group, 
Flags<[CC1Option]>,
+  HelpText<"Disallow alternative token representations '<:', ':>', '<%', '%>', 
'%:'">;
 def fno_declspec : Flag<["-"], "fno-declspec">, Group,

rsmith wrote:
> In the driver, we generally want a `-ffoo` option matching `-fno-foo`. That 
> is, the driver (but not `-cc1`) should support a matching `-fdigraphs` option 
> to undo the effect of `-fno-digraphs`, unless there's a good reason not to do 
> so.
Didn't find a great place to put this option; I'm not sure what this file's 
organization scheme is supposed to be.


Repository:
  rC Clang

https://reviews.llvm.org/D48266



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D48266: [Driver] Add -fno-digraphs

2018-06-18 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: include/clang/Driver/Options.td:1337-1338
 Flags<[CC1Option]>, Group;
+def fno_digraphs : Flag<["-"], "fno-digraphs">, Group, 
Flags<[CC1Option]>,
+  HelpText<"Disallow alternative token representations '<:', ':>', '<%', '%>', 
'%:'">;
 def fno_declspec : Flag<["-"], "fno-declspec">, Group,

In the driver, we generally want a `-ffoo` option matching `-fno-foo`. That is, 
the driver (but not `-cc1`) should support a matching `-fdigraphs` option to 
undo the effect of `-fno-digraphs`, unless there's a good reason not to do so.


Repository:
  rC Clang

https://reviews.llvm.org/D48266



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D48266: [Driver] Add -fno-digraphs

2018-06-17 Thread Jacob Bandes-Storch via Phabricator via cfe-commits
jtbandes created this revision.

Add a flag `-fno-digraphs` to disable digraphs in the lexer, similar to 
`-fno-operator-names` which disables alternative names for C++ operators.


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,9 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -ffreestanding %s
-// expected-no-diagnostics
+// RUN: %clang_cc1 -DDIGRAPHS -fsyntax-only -verify -ffreestanding %s
+// RUN: %clang_cc1 -fno-digraphs -fsyntax-only -verify -ffreestanding %s
+
+#if DIGRAPHS
 
+// expected-no-diagnostics
 %:include 
 
 %:ifndef BUFSIZE
@@ -14,3 +17,15 @@
 d<:len:> = s<:len:>;
 %>
 %>
+#else
+
+// expected-error@+1 {{expected identifier or '('}}
+%:include 
+;
+// 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,9 @@
   Opts.GNUKeywords = Args.hasFlag(OPT_fgnu_keywords, OPT_fno_gnu_keywords,
   Opts.GNUKeywords);
 
+  if (Args.hasArg(OPT_fno_digraphs))
+Opts.Digraphs = 0;
+
   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_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,8 @@
 def fno_diagnostics_show_option : Flag<["-"], "fno-diagnostics-show-option">, 
Group;
 def fno_diagnostics_show_note_include_stack : Flag<["-"], 
"fno-diagnostics-show-note-include-stack">,
 Flags<[CC1Option]>, Group;
+def fno_digraphs : Flag<["-"], "fno-digraphs">, Group, 
Flags<[CC1Option]>,
+  HelpText<"Disallow alternative token representations '<:', ':>', '<%', '%>', 
'%:'">;
 def fno_declspec : Flag<["-"], "fno-declspec">, Group,
   HelpText<"Disallow __declspec as a keyword">, Flags<[CC1Option]>;
 def fno_dollars_in_identifiers : Flag<["-"], "fno-dollars-in-identifiers">, 
Group,


Index: test/Lexer/digraph.c
===
--- test/Lexer/digraph.c
+++ test/Lexer/digraph.c
@@ -1,6 +1,9 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -ffreestanding %s
-// expected-no-diagnostics
+// RUN: %clang_cc1 -DDIGRAPHS -fsyntax-only -verify -ffreestanding %s
+// RUN: %clang_cc1 -fno-digraphs -fsyntax-only -verify -ffreestanding %s
+
+#if DIGRAPHS
 
+// expected-no-diagnostics
 %:include 
 
 %:ifndef BUFSIZE
@@ -14,3 +17,15 @@
 d<:len:> = s<:len:>;
 %>
 %>
+#else
+
+// expected-error@+1 {{expected identifier or '('}}
+%:include 
+;
+// 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,9 @@
   Opts.GNUKeywords = Args.hasFlag(OPT_fgnu_keywords, OPT_fno_gnu_keywords,
   Opts.GNUKeywords);
 
+  if (Args.hasArg(OPT_fno_digraphs))
+Opts.Digraphs = 0;
+
   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_fno_digraphs);
   Args.AddLastArg(CmdArgs, options::OPT_fno_operator_names);
   Args.AddLastArg(CmdArgs, options::OPT_femulated_tls,
   options::OPT_fno_emulated_tls);