Add a flag -fno-digraphs to disable digraphs in the lexer, similar to -fno-operator-names which disables alternative names for C++ operators.
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
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. |
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).
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. |
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. |
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.
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. |
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.
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); |