]> granicus.if.org Git - clang/commitdiff
Fix a block sema bug where result type of initializer
authorFariborz Jahanian <fjahanian@apple.com>
Fri, 11 Feb 2011 18:46:17 +0000 (18:46 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Fri, 11 Feb 2011 18:46:17 +0000 (18:46 +0000)
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

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

lib/AST/ASTContext.cpp
test/Sema/block-call.c
test/Sema/block-return.c
test/SemaObjC/block-return.m [new file with mode: 0644]

index 03c0abd3c624ea320a78f5c90b9f94e6faed2555..dcbfd9deec50c4dfce0f4202f535a46c38e62d2e 100644 (file)
@@ -5076,9 +5076,14 @@ QualType ASTContext::mergeFunctionTypes(QualType lhs, QualType rhs,
 
   // 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);
index fbf0da4eb8b2777d4b080c316cc7741d7cc33c9a..2aa1422dd915637936f2bfb08340d28181b4c9cd 100644 (file)
@@ -13,7 +13,7 @@ int main() {
   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;
 
index 23dbbc2ce66d60106e912f36d0296c08d41bd238..c6e1e9dc54227175b861526b9485c4c7b798f432 100644 (file)
@@ -110,7 +110,7 @@ void foo6() {
 
 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; };
 
diff --git a/test/SemaObjC/block-return.m b/test/SemaObjC/block-return.m
new file mode 100644 (file)
index 0000000..15c3fb6
--- /dev/null
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -fblocks -fobjc-gc-only %s
+// rdar://8979379
+
+@interface NSString
+- (__attribute__((objc_gc(strong))) const char *)UTF8String;
+@end
+
+int main() {
+__attribute__((objc_gc(strong))) char const *(^libraryNameForIndex)() = ^() {
+        NSString *moduleName;
+        return [moduleName UTF8String];
+    };
+}