]> granicus.if.org Git - clang/commitdiff
Debug Info: fix the line location for cleanup code of a block function
authorManman Ren <mren@apple.com>
Fri, 4 Jan 2013 18:51:35 +0000 (18:51 +0000)
committerManman Ren <mren@apple.com>
Fri, 4 Jan 2013 18:51:35 +0000 (18:51 +0000)
The line information was changed when emitting debug information for all the
DeclRefExprs and we should change it back to get ready for PopClenupBlocks
called from FinishFunction.

rdar://11562117

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

lib/CodeGen/CGBlocks.cpp
test/CodeGenObjC/debug-info-block-line.m [new file with mode: 0644]

index 68958522d8f3ec21de89b345aa61b07c3d2e0258..54bcb88ce3816fd7e266495bda143ab1d606105d 100644 (file)
@@ -1176,6 +1176,9 @@ CodeGenFunction::GenerateBlockFunction(GlobalDecl GD,
                                               Builder, blockInfo);
       }
     }
+    // Recover location if it was changed in the above loop.
+    DI->EmitLocation(Builder,
+        cast<CompoundStmt>(blockDecl->getBody())->getRBracLoc());
   }
 
   // And resume where we left off.
diff --git a/test/CodeGenObjC/debug-info-block-line.m b/test/CodeGenObjC/debug-info-block-line.m
new file mode 100644 (file)
index 0000000..f050bb7
--- /dev/null
@@ -0,0 +1,85 @@
+// REQUIRES: x86-64-registered-target
+// RUN: %clang_cc1 -emit-llvm -fblocks -fobjc-default-synthesize-properties -fobjc-arc -O0 -g -triple x86_64-apple-darwin10 %s -o - | FileCheck %s
+
+// rdar://11562117
+typedef unsigned int NSUInteger;
+typedef long NSInteger;
+typedef signed char BOOL;
+
+#define nil ((void*) 0)
+#define YES             ((BOOL)1)
+#define NO              ((BOOL)0)
+
+@interface NSObject
+- (id)init;
+@end
+
+@interface NSError : NSObject
+@end
+
+@interface NSString : NSObject
+@end
+
+@interface NSString (NSStringExtensionMethods)
+- (void)enumerateLinesUsingBlock:(void (^)(NSString *line, BOOL *stop))block;
+@end
+
+@interface NSData : NSObject
+@end
+
+@interface NSData (ASBase64)
+- (NSString *)encodedString:(NSInteger)position;
+- (NSData *)compressedData;
+@end
+
+typedef void (^TDataCompletionBlock)(NSData *data, NSError *error);
+@interface TMap : NSObject
+- (NSString *)identifier;
+- (NSString *)name;
++ (TMap *)mapForID:(NSString *)identifier;
+- (void)dataWithCompletionBlock:(TDataCompletionBlock)block;
+@end
+
+typedef enum : NSUInteger {
+    TOK                = 100,
+    TError = 125,
+} TResponseCode;
+
+@interface TConnection : NSObject
+- (void)sendString:(NSString *)string;
+- (void)sendFormat:(NSString *)format, ...;
+- (void)sendResponseCode:(TResponseCode)responseCode dataFollows:(BOOL)flag
+                         format:(NSString *)format, ...;
+@end
+
+@interface TServer : NSObject
+@end
+
+@implementation TServer
+- (void)serverConnection:(TConnection *)connection getCommand:(NSString *)str
+{
+    NSString    *mapID = nil;
+    TMap       *map = [TMap mapForID:mapID];
+// Make sure we do not map code generated for the block to the above line.
+// CHECK: define internal void @"__39-[TServer serverConnection:getCommand:]_block_invoke"
+// CHECK: if.end:
+// CHECK: call void @objc_storeStrong(i8** [[VAL1:%.*]], i8* null) nounwind, !dbg ![[MD1:.*]]
+// CHECK: call void @objc_storeStrong(i8** [[VAL2:%.*]], i8* null) nounwind, !dbg ![[MD1]]
+// CHECK-NEXT: ret
+// CHECK: ![[MD1]] = metadata !{i32 83
+    [map dataWithCompletionBlock:^(NSData *data, NSError *error) {
+        if (data) {
+            NSString    *encoded = [[data compressedData] encodedString:18];
+            [connection sendResponseCode:TOK dataFollows:YES
+                format:@"Sending \"%@\" (%@)", [map name], [map identifier]];
+            [encoded enumerateLinesUsingBlock:^(NSString *line, BOOL *stop) {
+                [connection sendFormat:@"%@\r\n", line];
+            }];
+            [connection sendString:@".\r\n"];
+        } else {
+            [connection sendResponseCode:TError dataFollows:NO
+                format:@"Failed \"%@\" (%@)", [map name], [map identifier]];
+        }
+    }];
+}
+@end