clang: lib/Basic/LangOptions.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

15#include "llvm/Support/Path.h"

16

17using namespace clang;

18

20#define LANGOPT(Name, Bits, Default, Compatibility, Description) Name = Default;

21#define ENUM_LANGOPT(Name, Type, Bits, Default, Compatibility, Description) \

22 set##Name(Default);

23#include "clang/Basic/LangOptions.def"

24}

25

27#define LANGOPT(Name, Bits, Default, Compatibility, Description) \

28 if constexpr (CompatibilityKind::Compatibility == CompatibilityKind::Benign) \

29 Name = Default;

30#define ENUM_LANGOPT(Name, Type, Bits, Default, Compatibility, Description) \

31 if constexpr (CompatibilityKind::Compatibility == CompatibilityKind::Benign) \

32 Name = static_cast(Default);

33#include "clang/Basic/LangOptions.def"

34

35

36

37

38

39 AllowFPReassoc = UnsafeFPMath;

40 NoHonorInfs = FastMath;

41 NoHonorNaNs = FastMath;

42

43

47

50}

51

53 for (unsigned i = 0, e = NoBuiltinFuncs.size(); i != e; ++i)

55 return true;

56 return false;

57}

58

60 const int Ver = OpenCLCPlusPlus ? OpenCLCPlusPlusVersion : OpenCLVersion;

61 if (OpenCLCPlusPlus && Ver != 100)

62 return VersionTuple(Ver / 100);

63 return VersionTuple(Ver / 100, (Ver % 100) / 10);

64}

65

67 if (!OpenCLCPlusPlus)

68 return OpenCLVersion;

69 if (OpenCLCPlusPlusVersion == 100)

70 return 200;

71 if (OpenCLCPlusPlusVersion == 202100)

72 return 300;

73 llvm_unreachable("Unknown OpenCL version");

74}

75

78 if (llvm::sys::path::replace_path_prefix(Path, Entry.first, Entry.second))

79 break;

80}

81

84 {

85 llvm::raw_string_ostream Out(Result);

86 Out << (OpenCLCPlusPlus ? "C++ for OpenCL" : "OpenCL C") << " version "

88 }

90}

91

93 const llvm::Triple &T,

94 std::vectorstd::string &Includes,

96

97

98

99

100

101

102

104 Opts.AsmPreprocessor = 1;

106 Opts.ObjC = 1;

107 }

108

114 Opts.C99 = Std.isC99();

115 Opts.C11 = Std.isC11();

116 Opts.C17 = Std.isC17();

117 Opts.C23 = Std.isC23();

118 Opts.C2y = Std.isC2y();

127 Opts.GNUCVersion = 0;

132 Opts.NamedLoops = Std.isC2y();

133

135 if (Opts.HLSL) {

136 if (Opts.IncludeDefaultHeader)

137 Includes.push_back("hlsl.h");

138

139 Opts.MaxMatrixDimension = 4;

140 }

141

142

143 Opts.OpenCL = Std.isOpenCL();

144 if (LangStd == LangStandard::lang_opencl10)

145 Opts.OpenCLVersion = 100;

146 else if (LangStd == LangStandard::lang_opencl11)

147 Opts.OpenCLVersion = 110;

148 else if (LangStd == LangStandard::lang_opencl12)

149 Opts.OpenCLVersion = 120;

150 else if (LangStd == LangStandard::lang_opencl20)

151 Opts.OpenCLVersion = 200;

152 else if (LangStd == LangStandard::lang_opencl30)

153 Opts.OpenCLVersion = 300;

154 else if (LangStd == LangStandard::lang_openclcpp10)

155 Opts.OpenCLCPlusPlusVersion = 100;

156 else if (LangStd == LangStandard::lang_openclcpp2021)

157 Opts.OpenCLCPlusPlusVersion = 202100;

158 else if (LangStd == LangStandard::lang_hlsl2015)

160 else if (LangStd == LangStandard::lang_hlsl2016)

162 else if (LangStd == LangStandard::lang_hlsl2017)

164 else if (LangStd == LangStandard::lang_hlsl2018)

166 else if (LangStd == LangStandard::lang_hlsl2021)

168 else if (LangStd == LangStandard::lang_hlsl202x)

170 else if (LangStd == LangStandard::lang_hlsl202y)

172

173

174 if (Opts.OpenCL) {

175 Opts.AltiVec = 0;

176 Opts.ZVector = 0;

178 Opts.OpenCLCPlusPlus = Opts.CPlusPlus;

181

182

183 if (Opts.IncludeDefaultHeader) {

184 if (Opts.DeclareOpenCLBuiltins) {

185

186 Includes.push_back("opencl-c-base.h");

187 } else {

188 Includes.push_back("opencl-c.h");

189 }

190 }

191 }

192

195 if (Opts.HIP) {

196

197

198

199

200

201

202

203

205 } else if (Opts.CUDA) {

206 if (T.isSPIRV()) {

207

208 Opts.OpenCLVersion = 200;

209 }

210

212 }

213

214

215 Opts.Bool = Opts.OpenCL || Opts.CPlusPlus || Opts.C23;

216

217

218 Opts.Half = Opts.OpenCL || Opts.HLSL;

219

220 Opts.PreserveVec3Type = Opts.HLSL;

221}

222

227

230#define FP_OPTION(NAME, TYPE, WIDTH, PREVIOUS) \

231 if (get##NAME() != Base.get##NAME()) \

232 OverrideMask |= NAME##Mask;

233#include "clang/Basic/FPOptions.def"

235}

236

238#define FP_OPTION(NAME, TYPE, WIDTH, PREVIOUS) \

239 llvm::errs() << "\n " #NAME " " << get##NAME();

240#include "clang/Basic/FPOptions.def"

241 llvm::errs() << "\n";

242}

243

245#define FP_OPTION(NAME, TYPE, WIDTH, PREVIOUS) \

246 if (has##NAME##Override()) \

247 llvm::errs() << "\n " #NAME " Override is " << get##NAME##Override();

248#include "clang/Basic/FPOptions.def"

249 llvm::errs() << "\n";

250}

251

254 return std::nullopt;

255

258 Std = LangStandard::lang_cxx26;

260 Std = LangStandard::lang_cxx23;

262 Std = LangStandard::lang_cxx20;

264 Std = LangStandard::lang_cxx17;

266 Std = LangStandard::lang_cxx14;

268 Std = LangStandard::lang_cxx11;

269 else

270 Std = LangStandard::lang_cxx98;

271

273}

274

278 Std = LangStandard::lang_c2y;

279 else if (C23)

280 Std = LangStandard::lang_c23;

281 else if (C17)

282 Std = LangStandard::lang_c17;

283 else if (C11)

284 Std = LangStandard::lang_c11;

285 else if (C99)

286 Std = LangStandard::lang_c99;

288 Std = LangStandard::lang_c94;

289 else

290 return std::nullopt;

291

293}

Defines the clang::LangOptions interface.

Represents difference between two FPOptions values.

LLVM_DUMP_METHOD void dump()

Definition LangOptions.cpp:244

static FPOptions defaultWithoutTrailingStorage(const LangOptions &LO)

Return the default value of FPOptions that's used when trailing storage isn't required.

Definition LangOptions.cpp:223

LLVM_DUMP_METHOD void dump()

Definition LangOptions.cpp:237

Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...

void resetNonModularOptions()

Reset all of the options that are not considered when building a module.

Definition LangOptions.cpp:26

std::vector< std::string > NoBuiltinFuncs

A list of all -fno-builtin-* function names (e.g., memset).

std::vector< std::string > XRayNeverInstrumentFiles

Paths to the XRay "never instrument" files specifying which objects (files, functions,...

bool isNoBuiltinFunc(StringRef Name) const

Is this a libc/libm function that is no longer recognized as a builtin because a -fno-builtin-* optio...

Definition LangOptions.cpp:52

std::string getOpenCLVersionString() const

Return the OpenCL C or C++ for OpenCL language name and version as a string.

Definition LangOptions.cpp:82

bool IsHeaderFile

Indicates whether the front-end is explicitly told that the input is a header file (i....

std::vector< std::string > XRayAlwaysInstrumentFiles

Paths to the XRay "always instrument" files specifying which objects (files, functions,...

VersionTuple getOpenCLVersionTuple() const

Return the OpenCL C or C++ version as a VersionTuple.

Definition LangOptions.cpp:59

static void setLangDefaults(LangOptions &Opts, Language Lang, const llvm::Triple &T, std::vector< std::string > &Includes, LangStandard::Kind LangStd=LangStandard::lang_unspecified)

Set language defaults for the given input language and language standard in the given LangOptions obj...

Definition LangOptions.cpp:92

std::map< std::string, std::string, std::greater< std::string > > MacroPrefixMap

A prefix map for FILE, BASE_FILE and __builtin_FILE().

void remapPathPrefix(SmallVectorImpl< char > &Path) const

Remap path prefix according to -fmacro-prefix-path option.

Definition LangOptions.cpp:76

std::optional< uint32_t > getCPlusPlusLangStd() const

Returns the most applicable C++ standard-compliant language version code.

Definition LangOptions.cpp:252

LangStandard::Kind LangStd

The used language standard.

std::optional< uint32_t > getCLangStd() const

Returns the most applicable C standard-compliant language version code.

Definition LangOptions.cpp:275

unsigned getOpenCLCompatibleVersion() const

Return the OpenCL version that kernel language is compatible with.

Definition LangOptions.cpp:66

LangOptions()

Definition LangOptions.cpp:19

std::vector< std::string > NoSanitizeFiles

Paths to files specifying which objects (files, functions, variables) should not be instrumented.

std::string CurrentModule

The name of the current module, of which the main source file is a part.

The JSON file list parser is used to communicate input to InstallAPI.

LangStandard::Kind getDefaultLanguageStandard(clang::Language Lang, const llvm::Triple &T)

Language

The language for the input, used to select and validate the language standard and possible actions.

@ Asm

Assembly: we accept this only so that we can preprocess it.

@ Result

The result type of a method or function.

const FunctionProtoType * T

LangStandard - Information about the properties of a particular language standard.

bool isCPlusPlus20() const

isCPlusPlus20 - Language is a C++20 variant (or later).

bool isCPlusPlus() const

isCPlusPlus - Language is a C++ variant.

bool hasRawStringLiterals() const

hasRawStringLiterals - Language supports R"()" raw string literals.

bool hasHexFloats() const

hasHexFloats - Language supports hexadecimal float constants.

bool isC11() const

isC11 - Language is a superset of C11.

bool isCPlusPlus17() const

isCPlusPlus17 - Language is a C++17 variant (or later).

bool hasDigraphs() const

hasDigraphs - Language supports digraphs.

bool isCPlusPlus14() const

isCPlusPlus14 - Language is a C++14 variant (or later).

bool isC17() const

isC17 - Language is a superset of C17.

bool isCPlusPlus26() const

isCPlusPlus26 - Language is a post-C++26 variant (or later).

bool isC2y() const

isC2y - Language is a superset of C2y.

bool isCPlusPlus11() const

isCPlusPlus11 - Language is a C++11 variant (or later).

std::optional< uint32_t > getVersion() const

Get the version code for this language standard.

bool isC23() const

isC23 - Language is a superset of C23.

static const LangStandard & getLangStandardForKind(Kind K)

bool isOpenCL() const

isOpenCL - Language is a OpenCL variant.

bool hasLineComments() const

Language supports '//' comments.

bool isCPlusPlus23() const

isCPlusPlus23 - Language is a post-C++23 variant (or later).

bool isGNUMode() const

isGNUMode - Language includes GNU extensions.

bool isC99() const

isC99 - Language is a superset of C99.