This is an archive of the discontinued LLVM Phabricator instance.

[Driver] Add -fno-digraphs
ClosedPublic

Authored by jtbandes on Jun 17 2018, 10:55 PM.

Details

Summary

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

Diff Detail

Repository
rL LLVM

Event Timeline

jtbandes created this revision.Jun 17 2018, 10:55 PM
rsmith added a subscriber: rsmith.Jun 17 2018, 11:22 PM
rsmith added inline comments.
include/clang/Driver/Options.td
1337–1338 ↗(On Diff #151655)

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.

jtbandes updated this revision to Diff 151771.Jun 18 2018, 12:50 PM

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).

jtbandes marked an inline comment as done.Jun 18 2018, 12:52 PM
jtbandes added inline comments.
include/clang/Driver/Options.td
1337–1338 ↗(On Diff #151655)

Didn't find a great place to put this option; I'm not sure what this file's organization scheme is supposed to be.

rsmith added inline comments.Jun 18 2018, 1:29 PM
lib/Driver/ToolChains/Clang.cpp
3973 ↗(On Diff #151771)

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.

jtbandes updated this revision to Diff 151858.Jun 19 2018, 12:42 AM
jtbandes marked an inline comment as done.

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.

jtbandes marked an inline comment as done.

Friendly ping!

rsmith added inline comments.Jul 9 2018, 2:27 PM
include/clang/Driver/Options.td
1337–1340 ↗(On Diff #151858)

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

lib/Frontend/CompilerInvocation.cpp
2181 ↗(On Diff #151858)

* not * , please.

2183–2185 ↗(On Diff #151858)

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.

jtbandes updated this revision to Diff 155115.Jul 11 2018, 10:54 PM
  • remove diagnostic; fix formatting
jtbandes marked 2 inline comments as done.Jul 11 2018, 10:56 PM

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.

jtbandes updated this revision to Diff 155116.Jul 11 2018, 10:58 PM
jtbandes marked an inline comment as done.
  • include %:%: in help text

Ping again 😇

rsmith accepted this revision.Jul 16 2018, 5:19 PM

Looks good with one cleanup.

lib/Frontend/CompilerInvocation.cpp
2177–2178 ↗(On Diff #155116)

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

This revision is now accepted and ready to land.Jul 16 2018, 5:19 PM
This revision was automatically updated to reflect the committed changes.
jtbandes marked an inline comment as done.Jul 16 2018, 10:01 PM
This comment was removed by jtbandes.