[cfe-commits] r93917 - in /cfe/trunk: lib/Frontend/RewriteObjC.cpp test/Rewriter/rewrite-typeof.mm

Fariborz Jahanian fjahanian at apple.com
Tue Jan 19 13:48:35 PST 2010


Author: fjahanian
Date: Tue Jan 19 15:48:35 2010
New Revision: 93917

URL: http://llvm.org/viewvc/llvm-project?rev=93917&view=rev
Log:
Rewriteing of gnu extension __typeof in objective-c rewriter.
Fixes radar 6358225.

Added:
    cfe/trunk/test/Rewriter/rewrite-typeof.mm
Modified:
    cfe/trunk/lib/Frontend/RewriteObjC.cpp

Modified: cfe/trunk/lib/Frontend/RewriteObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/RewriteObjC.cpp?rev=93917&r1=93916&r2=93917&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/RewriteObjC.cpp (original)
+++ cfe/trunk/lib/Frontend/RewriteObjC.cpp Tue Jan 19 15:48:35 2010
@@ -4293,7 +4293,19 @@
 
   const char *startBuf = SM->getCharacterData(LocStart);
   const char *endBuf = SM->getCharacterData(LocEnd);
-
+  QualType QT = CE->getType();
+  const Type* TypePtr = QT->getAs<Type>();
+  if (isa<TypeOfExprType>(TypePtr)) {
+    const TypeOfExprType *TypeOfExprTypePtr = cast<TypeOfExprType>(TypePtr);
+    QT = TypeOfExprTypePtr->getUnderlyingExpr()->getType();
+    std::string TypeAsString = "(";
+    TypeAsString += QT.getAsString();
+    TypeAsString += ")";
+    ReplaceText(LocStart, endBuf-startBuf+1, 
+                TypeAsString.c_str(), TypeAsString.size());
+    return;
+  }
+  
   // advance the location to startArgList.
   const char *argPtr = startBuf;
 

Added: cfe/trunk/test/Rewriter/rewrite-typeof.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Rewriter/rewrite-typeof.mm?rev=93917&view=auto

==============================================================================
--- cfe/trunk/test/Rewriter/rewrite-typeof.mm (added)
+++ cfe/trunk/test/Rewriter/rewrite-typeof.mm Tue Jan 19 15:48:35 2010
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc -o - %s
+
+extern "C" {
+extern "C" void *_Block_copy(const void *aBlock);
+extern "C" void _Block_release(const void *aBlock);
+}
+
+int main() {
+    __attribute__((__blocks__(byref))) int a = 42;
+    int save_a = a;
+
+    void (^b)(void) = ^{
+        ((__typeof(^{ a = 2; }))_Block_copy((const void *)(^{ a = 2; })));
+    };
+
+    ((__typeof(b))_Block_copy((const void *)(b)));
+
+    return 0;
+}
+





More information about the cfe-commits mailing list