[cfe-commits] r125386 - in /cfe/trunk: lib/AST/ASTContext.cpp test/Sema/block-call.c test/Sema/block-return.c test/SemaObjC/block-return.m

Fariborz Jahanian fjahanian at apple.com
Fri Feb 11 10:46:17 PST 2011


Author: fjahanian
Date: Fri Feb 11 12:46:17 2011
New Revision: 125386

URL: http://llvm.org/viewvc/llvm-project?rev=125386&view=rev
Log:
Fix a block sema bug where result type of initializer
is unqualified but its initialized is qualified.
This is for c only and fixes the imm. problem.
c++ is more involved and is wip.
// rdar://8979379

Added:
    cfe/trunk/test/SemaObjC/block-return.m
Modified:
    cfe/trunk/lib/AST/ASTContext.cpp
    cfe/trunk/test/Sema/block-call.c
    cfe/trunk/test/Sema/block-return.c

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=125386&r1=125385&r2=125386&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Fri Feb 11 12:46:17 2011
@@ -5076,9 +5076,14 @@
 
   // Check return type
   QualType retType;
-  if (OfBlockPointer)
-    retType = mergeTypes(rbase->getResultType(), lbase->getResultType(), true,
-                         Unqualified);
+  if (OfBlockPointer) {
+    QualType RHS = rbase->getResultType();
+    QualType LHS = lbase->getResultType();
+    bool UnqualifiedResult = Unqualified;
+    if (!UnqualifiedResult)
+      UnqualifiedResult = (!RHS.hasQualifiers() && LHS.hasQualifiers());
+    retType = mergeTypes(RHS, LHS, true, UnqualifiedResult);
+  }
   else
     retType = mergeTypes(lbase->getResultType(), rbase->getResultType(), false,
                          Unqualified);

Modified: cfe/trunk/test/Sema/block-call.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/block-call.c?rev=125386&r1=125385&r2=125386&view=diff
==============================================================================
--- cfe/trunk/test/Sema/block-call.c (original)
+++ cfe/trunk/test/Sema/block-call.c Fri Feb 11 12:46:17 2011
@@ -13,7 +13,7 @@
   int (^IFP) () = PFR; // OK
 
 
-  const int (^CIC) () = IFP; // expected-error {{incompatible block pointer types initializing 'const int (^)()' with an expression of type 'int (^)()'}}
+  const int (^CIC) () = IFP; // OK -  initializing 'const int (^)()' with an expression of type 'int (^)()'}}
 
   const int (^CICC) () = CIC;
 

Modified: cfe/trunk/test/Sema/block-return.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/block-return.c?rev=125386&r1=125385&r2=125386&view=diff
==============================================================================
--- cfe/trunk/test/Sema/block-return.c (original)
+++ cfe/trunk/test/Sema/block-return.c Fri Feb 11 12:46:17 2011
@@ -110,7 +110,7 @@
 
 void foo7()
 {
- const int (^BB) (void) = ^{ const int i = 1; return i; }; // expected-error{{incompatible block pointer types initializing 'const int (^)(void)' with an expression of type 'int (^)(void)'}}
+ const int (^BB) (void) = ^{ const int i = 1; return i; }; // OK - initializing 'const int (^)(void)' with an expression of type 'int (^)(void)'
 
  const int (^CC) (void)  = ^const int{ const int i = 1; return i; };
 

Added: cfe/trunk/test/SemaObjC/block-return.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/block-return.m?rev=125386&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjC/block-return.m (added)
+++ cfe/trunk/test/SemaObjC/block-return.m Fri Feb 11 12:46:17 2011
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -fblocks -fobjc-gc-only %s
+// rdar://8979379
+
+ at interface NSString
+- (__attribute__((objc_gc(strong))) const char *)UTF8String;
+ at end
+
+int main() {
+__attribute__((objc_gc(strong))) char const *(^libraryNameForIndex)() = ^() {
+        NSString *moduleName;
+        return [moduleName UTF8String];
+    };
+}





More information about the cfe-commits mailing list