]> granicus.if.org Git - clang/commitdiff
Add support for CallExpr::isBuiltinConstantExpr(). For now, this hook is used to...
authorSteve Naroff <snaroff@apple.com>
Thu, 31 Jan 2008 01:07:12 +0000 (01:07 +0000)
committerSteve Naroff <snaroff@apple.com>
Thu, 31 Jan 2008 01:07:12 +0000 (01:07 +0000)
This allows the following code to compile without error...

#include <CoreFoundation/CoreFoundation.h>

#define CONST_STRING_DECL(S, V) const CFStringRef S = (const CFStringRef)__builtin___CFStringMakeConstantString(V);

CONST_STRING_DECL(kCFTimeZoneSystemTimeZoneDidChangeNotification, "kCFTimeZoneSystemTimeZoneDidChangeNotification")

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46592 91177308-0d34-0410-b5e6-96231b3b80d8

AST/Expr.cpp
include/clang/AST/Expr.h

index e209db35ffb9a71c671ea40314736c5272260b9f..88c1b236e8ece58bcc27e9b62283ee363654c62c 100644 (file)
@@ -118,6 +118,24 @@ void CallExpr::setNumArgs(unsigned NumArgs) {
   this->NumArgs = NumArgs;
 }
 
+bool CallExpr::isBuiltinConstantExpr() const {
+  // All simple function calls (e.g. func()) are implicitly cast to pointer to
+  // function. As a result, we try and obtain the DeclRefExpr from the 
+  // ImplicitCastExpr.
+  const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(getCallee());
+  if (!ICE) // FIXME: deal with more complex calls (e.g. (func)(), (*func)()).
+    return false;
+    
+  const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(ICE->getSubExpr());
+  if (!DRE)
+    return false;
+
+  // We have a DeclRefExpr.
+  if (strcmp(DRE->getDecl()->getName(), 
+             "__builtin___CFStringMakeConstantString") == 0)
+    return true;
+  return false;
+}
 
 bool CallExpr::isBuiltinClassifyType(llvm::APSInt &Result) const {
   // The following enum mimics gcc's internal "typeclass.h" file.
@@ -471,6 +489,8 @@ bool Expr::isConstantExpr(ASTContext &Ctx, SourceLocation *Loc) const {
       static_cast<uint32_t>(Ctx.getTypeSize(getType(), CE->getLocStart())));
     if (CE->isBuiltinClassifyType(Result))
       return true;
+    if (CE->isBuiltinConstantExpr())
+      return true;
     if (Loc) *Loc = getLocStart();
     return false;
   }
index 820289976d7ebe4afc0f47ef5adb45bd6c2ac2ff..6e8c7c6e91d26532c02d53627482296e4e8155f4 100644 (file)
@@ -620,6 +620,9 @@ public:
   unsigned getNumCommas() const { return NumArgs ? NumArgs - 1 : 0; }
 
   bool isBuiltinClassifyType(llvm::APSInt &Result) const;
+
+  /// isBuiltinConstantExpr - Return true if this built-in call is constant.
+  bool isBuiltinConstantExpr() const;
   
   SourceLocation getRParenLoc() const { return RParenLoc; }
   SourceRange getSourceRange() const {