[cfe-commits] r46592 - in /cfe/trunk: AST/Expr.cpp include/clang/AST/Expr.h

Steve Naroff snaroff at apple.com
Wed Jan 30 17:07:12 PST 2008


Author: snaroff
Date: Wed Jan 30 19:07:12 2008
New Revision: 46592

URL: http://llvm.org/viewvc/llvm-project?rev=46592&view=rev
Log:

Add support for CallExpr::isBuiltinConstantExpr(). For now, this hook is used to support CFConstantStrings. Can be extended to support other built-in functions.

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")


Modified:
    cfe/trunk/AST/Expr.cpp
    cfe/trunk/include/clang/AST/Expr.h

Modified: cfe/trunk/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/Expr.cpp?rev=46592&r1=46591&r2=46592&view=diff

==============================================================================
--- cfe/trunk/AST/Expr.cpp (original)
+++ cfe/trunk/AST/Expr.cpp Wed Jan 30 19:07:12 2008
@@ -118,6 +118,24 @@
   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 @@
       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;
   }

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=46592&r1=46591&r2=46592&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Wed Jan 30 19:07:12 2008
@@ -620,6 +620,9 @@
   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 { 





More information about the cfe-commits mailing list