From be9371659380388a693ec99624e1f3d02f07047f Mon Sep 17 00:00:00 2001 From: Aaron Ballman Date: Fri, 8 Apr 2022 10:22:09 -0400 Subject: [PATCH] Clarify language option default value behavior; NFC The LANGOPT macro allows you to specify a default value for the langauge option. However, it's expected that these values be constant rather than depending on other language options (because the constructor setting the default values does not know the language mode at the time it's being constructed). Some of our language options were abusing this and passing in other language mode options which were then set correctly by other parts of frontend initialization. This removes the default values for the language options, and then ensures they're consistently set from the same place when setting language standard defaults. --- clang/include/clang/Basic/LangOptions.def | 12 ++++++++---- clang/lib/Frontend/CompilerInvocation.cpp | 2 ++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/clang/include/clang/Basic/LangOptions.def b/clang/include/clang/Basic/LangOptions.def index 7556dba35db1..ba89b5aa2c64 100644 --- a/clang/include/clang/Basic/LangOptions.def +++ b/clang/include/clang/Basic/LangOptions.def @@ -7,7 +7,11 @@ //===----------------------------------------------------------------------===// // // This file defines the language options. Users of this file must -// define the LANGOPT macro to make use of this information. +// define the LANGOPT macro to make use of this information. The arguments to +// the macro are: +// LANGOPT(Name, Bits, DefaultValue, Description) +// Note that the DefaultValue must be a constant value (literal or enumeration); +// it cannot depend on the value of another language option. // // Optionally, the user may also define: // @@ -107,7 +111,7 @@ LANGOPT(Trigraphs , 1, 0,"trigraphs") LANGOPT(LineComment , 1, 0, "'//' comments") LANGOPT(Bool , 1, 0, "bool, true, and false keywords") LANGOPT(Half , 1, 0, "half keyword") -LANGOPT(WChar , 1, CPlusPlus, "wchar_t keyword") +LANGOPT(WChar , 1, 0, "wchar_t keyword") LANGOPT(Char8 , 1, 0, "char8_t keyword") LANGOPT(IEEE128 , 1, 0, "__ieee128 keyword") LANGOPT(DeclSpecKeyword , 1, 0, "__declspec keyword") @@ -116,9 +120,9 @@ BENIGN_LANGOPT(AsmPreprocessor, 1, 0, "preprocessor in asm mode") LANGOPT(GNUMode , 1, 1, "GNU extensions") LANGOPT(GNUKeywords , 1, 1, "GNU keywords") VALUE_LANGOPT(GNUCVersion , 32, 0, "GNU C compatibility version") -BENIGN_LANGOPT(ImplicitInt, 1, !C99 && !CPlusPlus, "C89 implicit 'int'") +BENIGN_LANGOPT(ImplicitInt, 1, 0, "C89 implicit 'int'") LANGOPT(Digraphs , 1, 0, "digraphs") -BENIGN_LANGOPT(HexFloats , 1, C99, "C99 hexadecimal float constants") +BENIGN_LANGOPT(HexFloats , 1, 0, "C99 hexadecimal float constants") LANGOPT(CXXOperatorNames , 1, 0, "C++ operator name keywords") LANGOPT(AppleKext , 1, 0, "Apple kext support") BENIGN_LANGOPT(PascalStrings, 1, 0, "Pascal string support") diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index f586f8d64a7a..83de27b3a4f1 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -3263,6 +3263,8 @@ void CompilerInvocation::setLangDefaults(LangOptions &Opts, InputKind IK, Opts.GNUCVersion = 0; Opts.HexFloats = Std.hasHexFloats(); Opts.ImplicitInt = Std.hasImplicitInt(); + Opts.WChar = Std.isCPlusPlus(); + Opts.Digraphs = Std.hasDigraphs(); Opts.HLSL = IK.getLanguage() == Language::HLSL;