aboutsummaryrefslogtreecommitdiff
path: root/clang
diff options
context:
space:
mode:
authorAaron Ballman <aaron@aaronballman.com>2022-04-08 10:22:09 -0400
committerAaron Ballman <aaron@aaronballman.com>2022-04-08 10:26:16 -0400
commitbe9371659380388a693ec99624e1f3d02f07047f (patch)
tree0e99843eb2b1fbdcbe48bb758c2f9693298adf1a /clang
parentae377575b23b07107c08627357821a131a2ab1e0 (diff)
downloadllvm-be9371659380388a693ec99624e1f3d02f07047f.zip
llvm-be9371659380388a693ec99624e1f3d02f07047f.tar.gz
llvm-be9371659380388a693ec99624e1f3d02f07047f.tar.bz2
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.
Diffstat (limited to 'clang')
-rw-r--r--clang/include/clang/Basic/LangOptions.def12
-rw-r--r--clang/lib/Frontend/CompilerInvocation.cpp2
2 files changed, 10 insertions, 4 deletions
diff --git a/clang/include/clang/Basic/LangOptions.def b/clang/include/clang/Basic/LangOptions.def
index 7556dba..ba89b5a 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 f586f8d..83de27b 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;