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 C_LANG = 0x1, // builtin for c only.
35 CXX_LANG = 0x2, // builtin for cplusplus only.
36 OBJC_LANG = 0x4, // builtin for objective-c and objective-c++
37 ALL_LANGUAGES = (C_LANG|CXX_LANG|OBJC_LANG) //builtin is for all languages.
42 NotBuiltin = 0, // This is not a builtin function.
43 #define BUILTIN(ID, TYPE, ATTRS) BI##ID,
44 #include "clang/Basic/Builtins.def"
49 const char *Name, *Type, *Attributes, *HeaderName;
50 LanguageID builtin_lang;
52 bool operator==(const Info &RHS) const {
53 return !strcmp(Name, RHS.Name) &&
54 !strcmp(Type, RHS.Type) &&
55 !strcmp(Attributes, RHS.Attributes);
57 bool operator!=(const Info &RHS) const { return !(*this == RHS); }
60 /// \brief Holds information about both target-independent and
61 /// target-specific builtins, allowing easy queries by clients.
63 const Info *TSRecords;
64 unsigned NumTSRecords;
68 /// \brief Perform target-specific initialization
69 void InitializeTarget(const TargetInfo &Target);
71 /// \brief Mark the identifiers for all the builtins with their
72 /// appropriate builtin ID # and mark any non-portable builtin identifiers as
74 void InitializeBuiltins(IdentifierTable &Table, const LangOptions& LangOpts);
76 /// \brief Popular the vector with the names of all of the builtins.
77 void GetBuiltinNames(SmallVectorImpl<const char *> &Names,
80 /// \brief Return the identifier name for the specified builtin,
81 /// e.g. "__builtin_abs".
82 const char *GetName(unsigned ID) const {
83 return GetRecord(ID).Name;
86 /// \brief Get the type descriptor string for the specified builtin.
87 const char *GetTypeString(unsigned ID) const {
88 return GetRecord(ID).Type;
91 /// \brief Return true if this function has no side effects and doesn't
93 bool isConst(unsigned ID) const {
94 return strchr(GetRecord(ID).Attributes, 'c') != 0;
97 /// \brief Return true if we know this builtin never throws an exception.
98 bool isNoThrow(unsigned ID) const {
99 return strchr(GetRecord(ID).Attributes, 'n') != 0;
102 /// \brief Return true if we know this builtin never returns.
103 bool isNoReturn(unsigned ID) const {
104 return strchr(GetRecord(ID).Attributes, 'r') != 0;
107 /// \brief Return true if we know this builtin can return twice.
108 bool isReturnsTwice(unsigned ID) const {
109 return strchr(GetRecord(ID).Attributes, 'j') != 0;
112 /// \brief Returns true if this builtin does not perform the side-effects
113 /// of its arguments.
114 bool isUnevaluated(unsigned ID) const {
115 return strchr(GetRecord(ID).Attributes, 'u') != 0;
118 /// \brief Return true if this is a builtin for a libc/libm function,
119 /// with a "__builtin_" prefix (e.g. __builtin_abs).
120 bool isLibFunction(unsigned ID) const {
121 return strchr(GetRecord(ID).Attributes, 'F') != 0;
124 /// \brief Determines whether this builtin is a predefined libc/libm
125 /// function, such as "malloc", where we know the signature a
127 bool isPredefinedLibFunction(unsigned ID) const {
128 return strchr(GetRecord(ID).Attributes, 'f') != 0;
131 /// \brief Determines whether this builtin is a predefined compiler-rt/libgcc
132 /// function, such as "__clear_cache", where we know the signature a
134 bool isPredefinedRuntimeFunction(unsigned ID) const {
135 return strchr(GetRecord(ID).Attributes, 'i') != 0;
138 /// \brief Determines whether this builtin has custom typechecking.
139 bool hasCustomTypechecking(unsigned ID) const {
140 return strchr(GetRecord(ID).Attributes, 't') != 0;
143 /// \brief Completely forget that the given ID was ever considered a builtin,
144 /// e.g., because the user provided a conflicting signature.
145 void ForgetBuiltin(unsigned ID, IdentifierTable &Table);
147 /// \brief If this is a library function that comes from a specific
148 /// header, retrieve that header name.
149 const char *getHeaderName(unsigned ID) const {
150 return GetRecord(ID).HeaderName;
153 /// \brief Determine whether this builtin is like printf in its
154 /// formatting rules and, if so, set the index to the format string
155 /// argument and whether this function as a va_list argument.
156 bool isPrintfLike(unsigned ID, unsigned &FormatIdx, bool &HasVAListArg);
158 /// \brief Determine whether this builtin is like scanf in its
159 /// formatting rules and, if so, set the index to the format string
160 /// argument and whether this function as a va_list argument.
161 bool isScanfLike(unsigned ID, unsigned &FormatIdx, bool &HasVAListArg);
163 /// \brief Return true if this function has no side effects and doesn't
164 /// read memory, except for possibly errno.
166 /// Such functions can be const when the MathErrno lang option is disabled.
167 bool isConstWithoutErrno(unsigned ID) const {
168 return strchr(GetRecord(ID).Attributes, 'e') != 0;
172 const Info &GetRecord(unsigned ID) const;
176 } // end namespace clang