/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/tools/clang/include/clang/Basic/Builtins.h
Line | Count | Source |
1 | | //===--- Builtins.h - Builtin function header -------------------*- C++ -*-===// |
2 | | // |
3 | | // The LLVM Compiler Infrastructure |
4 | | // |
5 | | // This file is distributed under the University of Illinois Open Source |
6 | | // License. See LICENSE.TXT for details. |
7 | | // |
8 | | //===----------------------------------------------------------------------===// |
9 | | /// |
10 | | /// \file |
11 | | /// \brief Defines enum values for all the target-independent builtin |
12 | | /// functions. |
13 | | /// |
14 | | //===----------------------------------------------------------------------===// |
15 | | |
16 | | #ifndef LLVM_CLANG_BASIC_BUILTINS_H |
17 | | #define LLVM_CLANG_BASIC_BUILTINS_H |
18 | | |
19 | | #include "llvm/ADT/ArrayRef.h" |
20 | | #include <cstring> |
21 | | |
22 | | // VC++ defines 'alloca' as an object-like macro, which interferes with our |
23 | | // builtins. |
24 | | #undef alloca |
25 | | |
26 | | namespace clang { |
27 | | class TargetInfo; |
28 | | class IdentifierTable; |
29 | | class ASTContext; |
30 | | class QualType; |
31 | | class LangOptions; |
32 | | |
33 | | enum LanguageID { |
34 | | GNU_LANG = 0x1, // builtin requires GNU mode. |
35 | | C_LANG = 0x2, // builtin for c only. |
36 | | CXX_LANG = 0x4, // builtin for cplusplus only. |
37 | | OBJC_LANG = 0x8, // builtin for objective-c and objective-c++ |
38 | | MS_LANG = 0x10, // builtin requires MS mode. |
39 | | OCLC20_LANG = 0x20, // builtin for OpenCL C 2.0 only. |
40 | | OCLC1X_LANG = 0x40, // builtin for OpenCL C 1.x only. |
41 | | ALL_LANGUAGES = C_LANG | CXX_LANG | OBJC_LANG, // builtin for all languages. |
42 | | ALL_GNU_LANGUAGES = ALL_LANGUAGES | GNU_LANG, // builtin requires GNU mode. |
43 | | ALL_MS_LANGUAGES = ALL_LANGUAGES | MS_LANG, // builtin requires MS mode. |
44 | | ALL_OCLC_LANGUAGES = OCLC1X_LANG | OCLC20_LANG // builtin for OCLC languages. |
45 | | }; |
46 | | |
47 | | namespace Builtin { |
48 | | enum ID { |
49 | | NotBuiltin = 0, // This is not a builtin function. |
50 | | #define BUILTIN(ID, TYPE, ATTRS) BI##ID, |
51 | | #include "clang/Basic/Builtins.def" |
52 | | FirstTSBuiltin |
53 | | }; |
54 | | |
55 | | struct Info { |
56 | | const char *Name, *Type, *Attributes, *HeaderName; |
57 | | LanguageID Langs; |
58 | | const char *Features; |
59 | | }; |
60 | | |
61 | | /// \brief Holds information about both target-independent and |
62 | | /// target-specific builtins, allowing easy queries by clients. |
63 | | /// |
64 | | /// Builtins from an optional auxiliary target are stored in |
65 | | /// AuxTSRecords. Their IDs are shifted up by TSRecords.size() and need to |
66 | | /// be translated back with getAuxBuiltinID() before use. |
67 | | class Context { |
68 | | llvm::ArrayRef<Info> TSRecords; |
69 | | llvm::ArrayRef<Info> AuxTSRecords; |
70 | | |
71 | | public: |
72 | 31.8k | Context() {} |
73 | | |
74 | | /// \brief Perform target-specific initialization |
75 | | /// \param AuxTarget Target info to incorporate builtins from. May be nullptr. |
76 | | void InitializeTarget(const TargetInfo &Target, const TargetInfo *AuxTarget); |
77 | | |
78 | | /// \brief Mark the identifiers for all the builtins with their |
79 | | /// appropriate builtin ID # and mark any non-portable builtin identifiers as |
80 | | /// such. |
81 | | void initializeBuiltins(IdentifierTable &Table, const LangOptions& LangOpts); |
82 | | |
83 | | /// \brief Return the identifier name for the specified builtin, |
84 | | /// e.g. "__builtin_abs". |
85 | 70.3k | const char *getName(unsigned ID) const { |
86 | 70.3k | return getRecord(ID).Name; |
87 | 70.3k | } |
88 | | |
89 | | /// \brief Get the type descriptor string for the specified builtin. |
90 | 1.51M | const char *getTypeString(unsigned ID) const { |
91 | 1.51M | return getRecord(ID).Type; |
92 | 1.51M | } |
93 | | |
94 | | /// \brief Return true if this function is a target-specific builtin. |
95 | 667k | bool isTSBuiltin(unsigned ID) const { |
96 | 667k | return ID >= Builtin::FirstTSBuiltin; |
97 | 667k | } |
98 | | |
99 | | /// \brief Return true if this function has no side effects. |
100 | 1.09M | bool isPure(unsigned ID) const { |
101 | 1.09M | return strchr(getRecord(ID).Attributes, 'U') != nullptr; |
102 | 1.09M | } |
103 | | |
104 | | /// \brief Return true if this function has no side effects and doesn't |
105 | | /// read memory. |
106 | 1.09M | bool isConst(unsigned ID) const { |
107 | 1.09M | return strchr(getRecord(ID).Attributes, 'c') != nullptr; |
108 | 1.09M | } |
109 | | |
110 | | /// \brief Return true if we know this builtin never throws an exception. |
111 | 1.37M | bool isNoThrow(unsigned ID) const { |
112 | 1.37M | return strchr(getRecord(ID).Attributes, 'n') != nullptr; |
113 | 1.37M | } |
114 | | |
115 | | /// \brief Return true if we know this builtin never returns. |
116 | 1.51M | bool isNoReturn(unsigned ID) const { |
117 | 1.51M | return strchr(getRecord(ID).Attributes, 'r') != nullptr; |
118 | 1.51M | } |
119 | | |
120 | | /// \brief Return true if we know this builtin can return twice. |
121 | 1.09M | bool isReturnsTwice(unsigned ID) const { |
122 | 1.09M | return strchr(getRecord(ID).Attributes, 'j') != nullptr; |
123 | 1.09M | } |
124 | | |
125 | | /// \brief Returns true if this builtin does not perform the side-effects |
126 | | /// of its arguments. |
127 | 670k | bool isUnevaluated(unsigned ID) const { |
128 | 670k | return strchr(getRecord(ID).Attributes, 'u') != nullptr; |
129 | 670k | } |
130 | | |
131 | | /// \brief Return true if this is a builtin for a libc/libm function, |
132 | | /// with a "__builtin_" prefix (e.g. __builtin_abs). |
133 | 132k | bool isLibFunction(unsigned ID) const { |
134 | 132k | return strchr(getRecord(ID).Attributes, 'F') != nullptr; |
135 | 132k | } |
136 | | |
137 | | /// \brief Determines whether this builtin is a predefined libc/libm |
138 | | /// function, such as "malloc", where we know the signature a |
139 | | /// priori. |
140 | 10.3M | bool isPredefinedLibFunction(unsigned ID) const { |
141 | 10.3M | return strchr(getRecord(ID).Attributes, 'f') != nullptr; |
142 | 10.3M | } |
143 | | |
144 | | /// \brief Returns true if this builtin requires appropriate header in other |
145 | | /// compilers. In Clang it will work even without including it, but we can emit |
146 | | /// a warning about missing header. |
147 | 207k | bool isHeaderDependentFunction(unsigned ID) const { |
148 | 207k | return strchr(getRecord(ID).Attributes, 'h') != nullptr; |
149 | 207k | } |
150 | | |
151 | | /// \brief Determines whether this builtin is a predefined compiler-rt/libgcc |
152 | | /// function, such as "__clear_cache", where we know the signature a |
153 | | /// priori. |
154 | 11 | bool isPredefinedRuntimeFunction(unsigned ID) const { |
155 | 11 | return strchr(getRecord(ID).Attributes, 'i') != nullptr; |
156 | 11 | } |
157 | | |
158 | | /// \brief Determines whether this builtin has custom typechecking. |
159 | 1.41M | bool hasCustomTypechecking(unsigned ID) const { |
160 | 1.41M | return strchr(getRecord(ID).Attributes, 't') != nullptr; |
161 | 1.41M | } |
162 | | |
163 | | /// \brief Determines whether this builtin has a result or any arguments which |
164 | | /// are pointer types. |
165 | 745k | bool hasPtrArgsOrResult(unsigned ID) const { |
166 | 745k | return strchr(getRecord(ID).Type, '*') != nullptr; |
167 | 745k | } |
168 | | |
169 | | /// \brief Completely forget that the given ID was ever considered a builtin, |
170 | | /// e.g., because the user provided a conflicting signature. |
171 | | void forgetBuiltin(unsigned ID, IdentifierTable &Table); |
172 | | |
173 | | /// \brief If this is a library function that comes from a specific |
174 | | /// header, retrieve that header name. |
175 | 858 | const char *getHeaderName(unsigned ID) const { |
176 | 858 | return getRecord(ID).HeaderName; |
177 | 858 | } |
178 | | |
179 | | /// \brief Determine whether this builtin is like printf in its |
180 | | /// formatting rules and, if so, set the index to the format string |
181 | | /// argument and whether this function as a va_list argument. |
182 | | bool isPrintfLike(unsigned ID, unsigned &FormatIdx, bool &HasVAListArg); |
183 | | |
184 | | /// \brief Determine whether this builtin is like scanf in its |
185 | | /// formatting rules and, if so, set the index to the format string |
186 | | /// argument and whether this function as a va_list argument. |
187 | | bool isScanfLike(unsigned ID, unsigned &FormatIdx, bool &HasVAListArg); |
188 | | |
189 | | /// \brief Return true if this function has no side effects and doesn't |
190 | | /// read memory, except for possibly errno. |
191 | | /// |
192 | | /// Such functions can be const when the MathErrno lang option is disabled. |
193 | 1.08M | bool isConstWithoutErrno(unsigned ID) const { |
194 | 1.08M | return strchr(getRecord(ID).Attributes, 'e') != nullptr; |
195 | 1.08M | } |
196 | | |
197 | 34.2k | const char *getRequiredFeatures(unsigned ID) const { |
198 | 34.2k | return getRecord(ID).Features; |
199 | 34.2k | } |
200 | | |
201 | | /// \brief Return true if builtin ID belongs to AuxTarget. |
202 | 9.34M | bool isAuxBuiltinID(unsigned ID) const { |
203 | 9.34M | return ID >= (Builtin::FirstTSBuiltin + TSRecords.size()); |
204 | 9.34M | } |
205 | | |
206 | | /// Return real buitin ID (i.e. ID it would have furing compilation |
207 | | /// for AuxTarget). |
208 | 74 | unsigned getAuxBuiltinID(unsigned ID) const { return ID - TSRecords.size(); } |
209 | | |
210 | | /// Returns true if this is a libc/libm function without the '__builtin_' |
211 | | /// prefix. |
212 | | static bool isBuiltinFunc(const char *Name); |
213 | | |
214 | | private: |
215 | | const Info &getRecord(unsigned ID) const; |
216 | | |
217 | | /// \brief Is this builtin supported according to the given language options? |
218 | | bool builtinIsSupported(const Builtin::Info &BuiltinInfo, |
219 | | const LangOptions &LangOpts); |
220 | | |
221 | | /// \brief Helper function for isPrintfLike and isScanfLike. |
222 | | bool isLike(unsigned ID, unsigned &FormatIdx, bool &HasVAListArg, |
223 | | const char *Fmt) const; |
224 | | }; |
225 | | |
226 | | } |
227 | | |
228 | | /// \brief Kinds of BuiltinTemplateDecl. |
229 | | enum BuiltinTemplateKind : int { |
230 | | /// \brief This names the __make_integer_seq BuiltinTemplateDecl. |
231 | | BTK__make_integer_seq, |
232 | | |
233 | | /// \brief This names the __type_pack_element BuiltinTemplateDecl. |
234 | | BTK__type_pack_element |
235 | | }; |
236 | | |
237 | | } // end namespace clang |
238 | | #endif |