1 //===--- Builtins.h - Builtin function header -------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// \brief Defines enum values for all the target-independent builtin
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_CLANG_BASIC_BUILTINS_H
17 #define LLVM_CLANG_BASIC_BUILTINS_H
19 #include "clang/Basic/LLVM.h"
22 // VC++ defines 'alloca' as an object-like macro, which interferes with our
28 class IdentifierTable;
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 ALL_LANGUAGES = C_LANG | CXX_LANG | OBJC_LANG, // builtin for all languages.
40 ALL_GNU_LANGUAGES = ALL_LANGUAGES | GNU_LANG, // builtin requires GNU mode.
41 ALL_MS_LANGUAGES = ALL_LANGUAGES | MS_LANG // builtin requires MS mode.
46 NotBuiltin = 0, // This is not a builtin function.
47 #define BUILTIN(ID, TYPE, ATTRS) BI##ID,
48 #include "clang/Basic/Builtins.def"
53 const char *Name, *Type, *Attributes, *HeaderName;
54 LanguageID builtin_lang;
56 bool operator==(const Info &RHS) const {
57 return !strcmp(Name, RHS.Name) &&
58 !strcmp(Type, RHS.Type) &&
59 !strcmp(Attributes, RHS.Attributes);
61 bool operator!=(const Info &RHS) const { return !(*this == RHS); }
64 /// \brief Holds information about both target-independent and
65 /// target-specific builtins, allowing easy queries by clients.
67 const Info *TSRecords;
68 unsigned NumTSRecords;
72 /// \brief Perform target-specific initialization
73 void InitializeTarget(const TargetInfo &Target);
75 /// \brief Mark the identifiers for all the builtins with their
76 /// appropriate builtin ID # and mark any non-portable builtin identifiers as
78 void InitializeBuiltins(IdentifierTable &Table, const LangOptions& LangOpts);
80 /// \brief Populate the vector with the names of all of the builtins.
81 void GetBuiltinNames(SmallVectorImpl<const char *> &Names);
83 /// \brief Return the identifier name for the specified builtin,
84 /// e.g. "__builtin_abs".
85 const char *GetName(unsigned ID) const {
86 return GetRecord(ID).Name;
89 /// \brief Get the type descriptor string for the specified builtin.
90 const char *GetTypeString(unsigned ID) const {
91 return GetRecord(ID).Type;
94 /// \brief Return true if this function has no side effects and doesn't
96 bool isConst(unsigned ID) const {
97 return strchr(GetRecord(ID).Attributes, 'c') != 0;
100 /// \brief Return true if we know this builtin never throws an exception.
101 bool isNoThrow(unsigned ID) const {
102 return strchr(GetRecord(ID).Attributes, 'n') != 0;
105 /// \brief Return true if we know this builtin never returns.
106 bool isNoReturn(unsigned ID) const {
107 return strchr(GetRecord(ID).Attributes, 'r') != 0;
110 /// \brief Return true if we know this builtin can return twice.
111 bool isReturnsTwice(unsigned ID) const {
112 return strchr(GetRecord(ID).Attributes, 'j') != 0;
115 /// \brief Returns true if this builtin does not perform the side-effects
116 /// of its arguments.
117 bool isUnevaluated(unsigned ID) const {
118 return strchr(GetRecord(ID).Attributes, 'u') != 0;
121 /// \brief Return true if this is a builtin for a libc/libm function,
122 /// with a "__builtin_" prefix (e.g. __builtin_abs).
123 bool isLibFunction(unsigned ID) const {
124 return strchr(GetRecord(ID).Attributes, 'F') != 0;
127 /// \brief Determines whether this builtin is a predefined libc/libm
128 /// function, such as "malloc", where we know the signature a
130 bool isPredefinedLibFunction(unsigned ID) const {
131 return strchr(GetRecord(ID).Attributes, 'f') != 0;
134 /// \brief Determines whether this builtin is a predefined compiler-rt/libgcc
135 /// function, such as "__clear_cache", where we know the signature a
137 bool isPredefinedRuntimeFunction(unsigned ID) const {
138 return strchr(GetRecord(ID).Attributes, 'i') != 0;
141 /// \brief Determines whether this builtin has custom typechecking.
142 bool hasCustomTypechecking(unsigned ID) const {
143 return strchr(GetRecord(ID).Attributes, 't') != 0;
146 /// \brief Completely forget that the given ID was ever considered a builtin,
147 /// e.g., because the user provided a conflicting signature.
148 void ForgetBuiltin(unsigned ID, IdentifierTable &Table);
150 /// \brief If this is a library function that comes from a specific
151 /// header, retrieve that header name.
152 const char *getHeaderName(unsigned ID) const {
153 return GetRecord(ID).HeaderName;
156 /// \brief Determine whether this builtin is like printf in its
157 /// formatting rules and, if so, set the index to the format string
158 /// argument and whether this function as a va_list argument.
159 bool isPrintfLike(unsigned ID, unsigned &FormatIdx, bool &HasVAListArg);
161 /// \brief Determine whether this builtin is like scanf in its
162 /// formatting rules and, if so, set the index to the format string
163 /// argument and whether this function as a va_list argument.
164 bool isScanfLike(unsigned ID, unsigned &FormatIdx, bool &HasVAListArg);
166 /// \brief Return true if this function has no side effects and doesn't
167 /// read memory, except for possibly errno.
169 /// Such functions can be const when the MathErrno lang option is disabled.
170 bool isConstWithoutErrno(unsigned ID) const {
171 return strchr(GetRecord(ID).Attributes, 'e') != 0;
175 const Info &GetRecord(unsigned ID) const;
177 /// \brief Is this builtin supported according to the given language options?
178 bool BuiltinIsSupported(const Builtin::Info &BuiltinInfo,
179 const LangOptions &LangOpts);
183 } // end namespace clang