]> granicus.if.org Git - clang/commitdiff
Rewriteing of gnu extension __typeof in objective-c rewriter.
authorFariborz Jahanian <fjahanian@apple.com>
Tue, 19 Jan 2010 21:48:35 +0000 (21:48 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Tue, 19 Jan 2010 21:48:35 +0000 (21:48 +0000)
Fixes radar 6358225.

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

lib/Frontend/RewriteObjC.cpp
test/Rewriter/rewrite-typeof.mm [new file with mode: 0644]

index 5a5b0eada3ab4a6f8f7d9cc59119d8433873f9b2..2e101f402b7b591d4acc06635f719a2a79e192c5 100644 (file)
@@ -4293,7 +4293,19 @@ void RewriteObjC::RewriteCastExpr(CStyleCastExpr *CE) {
 
   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;
 
diff --git a/test/Rewriter/rewrite-typeof.mm b/test/Rewriter/rewrite-typeof.mm
new file mode 100644 (file)
index 0000000..f95cd9a
--- /dev/null
@@ -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;
+}
+