clang 20.0.0git
LangOptions.cpp
Go to the documentation of this file.
1//===- LangOptions.cpp - C Language Family Language Options ---------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines the LangOptions class.
10//
11//===----------------------------------------------------------------------===//
12
14#include "llvm/ADT/SmallString.h"
15#include "llvm/Support/Path.h"
16
17using namespace clang;
18
19LangOptions::LangOptions() : LangStd(LangStandard::lang_unspecified) {
20#define LANGOPT(Name, Bits, Default, Description) Name = Default;
21#define ENUM_LANGOPT(Name, Type, Bits, Default, Description) set##Name(Default);
22#include "clang/Basic/LangOptions.def"
23}
24
26#define LANGOPT(Name, Bits, Default, Description)
27#define BENIGN_LANGOPT(Name, Bits, Default, Description) Name = Default;
28#define BENIGN_ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
29 Name = static_cast<unsigned>(Default);
30#include "clang/Basic/LangOptions.def"
31
32 // Reset "benign" options with implied values (Options.td ImpliedBy relations)
33 // rather than their defaults. This avoids unexpected combinations and
34 // invocations that cannot be round-tripped to arguments.
35 // FIXME: we should derive this automatically from ImpliedBy in tablegen.
36 AllowFPReassoc = UnsafeFPMath;
37 NoHonorInfs = FastMath;
38 NoHonorNaNs = FastMath;
39
40 // These options do not affect AST generation.
41 NoSanitizeFiles.clear();
44
45 CurrentModule.clear();
46 IsHeaderFile = false;
47}
48
49bool LangOptions::isNoBuiltinFunc(StringRef FuncName) const {
50 for (unsigned i = 0, e = NoBuiltinFuncs.size(); i != e; ++i)
51 if (FuncName == NoBuiltinFuncs[i])
52 return true;
53 return false;
54}
55
57 const int Ver = OpenCLCPlusPlus ? OpenCLCPlusPlusVersion : OpenCLVersion;
58 if (OpenCLCPlusPlus && Ver != 100)
59 return VersionTuple(Ver / 100);
60 return VersionTuple(Ver / 100, (Ver % 100) / 10);
61}
62
64 if (!OpenCLCPlusPlus)
65 return OpenCLVersion;
66 if (OpenCLCPlusPlusVersion == 100)
67 return 200;
68 if (OpenCLCPlusPlusVersion == 202100)
69 return 300;
70 llvm_unreachable("Unknown OpenCL version");
71}
72
74 for (const auto &Entry : MacroPrefixMap)
75 if (llvm::sys::path::replace_path_prefix(Path, Entry.first, Entry.second))
76 break;
77}
78
80 std::string Result;
81 {
82 llvm::raw_string_ostream Out(Result);
83 Out << (OpenCLCPlusPlus ? "C++ for OpenCL" : "OpenCL C") << " version "
84 << getOpenCLVersionTuple().getAsString();
85 }
86 return Result;
87}
88