From d74c15fc0a492fe3ca32cd1865d84911dd0d6e99 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Fri, 31 Aug 2007 03:44:20 +0000 Subject: [PATCH] add some accessors for querying attributes of builtins. Add the new 'F' attribute. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41631 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/Builtins.def | 16 +++++++++------- include/clang/AST/Builtins.h | 17 +++++++++++++++++ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/include/clang/AST/Builtins.def b/include/clang/AST/Builtins.def index 4ab98e8ad5..a5e3138c85 100644 --- a/include/clang/AST/Builtins.def +++ b/include/clang/AST/Builtins.def @@ -43,16 +43,18 @@ // C -> const // The third value provided to the macro specifies information about attributes -// of the function. Currently we have: +// of the function. These must be kept in sync with the predicates in the +// Builtin::Context class. Currently we have: // n -> nothrow // c -> const +// F -> this is a libc/libm function with a '__builtin_' prefix added. -BUILTIN(__builtin_inf , "d" , "nc") -BUILTIN(__builtin_inff , "f" , "nc") -BUILTIN(__builtin_infl , "Ld" , "nc") -BUILTIN(__builtin_fabs , "dd" , "nc") -BUILTIN(__builtin_fabsf, "ff" , "nc") -BUILTIN(__builtin_fabsl, "LdLd", "nc") +BUILTIN(__builtin_inf , "d" , "ncF") +BUILTIN(__builtin_inff , "f" , "ncF") +BUILTIN(__builtin_infl , "Ld" , "ncF") +BUILTIN(__builtin_fabs , "dd" , "ncF") +BUILTIN(__builtin_fabsf, "ff" , "ncF") +BUILTIN(__builtin_fabsl, "LdLd", "ncF") BUILTIN(__builtin_constant_p, "UsUs", "nc") BUILTIN(__builtin_classify_type, "i.", "nc") BUILTIN(__builtin___CFStringMakeConstantString, "FC*cC*", "nc") diff --git a/include/clang/AST/Builtins.h b/include/clang/AST/Builtins.h index 682031f7be..8f808306a6 100644 --- a/include/clang/AST/Builtins.h +++ b/include/clang/AST/Builtins.h @@ -61,6 +61,23 @@ public: return GetRecord(ID).Name; } + /// isConst - Return true if this function has no side effects and doesn't + /// read memory. + bool isConst(unsigned ID) const { + return strchr(GetRecord(ID).Attributes, 'c') != 0; + } + + /// isNoThrow - Return true if we know this builtin never throws an exception. + bool isNoThrow(unsigned ID) const { + return strchr(GetRecord(ID).Attributes, 'n') != 0; + } + + /// isLibFunction - Return true if this is a builtin for a libc/libm function, + /// with a "__builtin_" prefix (e.g. __builtin_inf). + bool isLibFunction(unsigned ID) const { + return strchr(GetRecord(ID).Attributes, 'F') != 0; + } + /// GetBuiltinType - Return the type for the specified builtin. QualType GetBuiltinType(unsigned ID, ASTContext &Context) const; private: -- 2.40.0