vsk updated this revision to Diff 232373.
vsk retitled this revision from "WIP: [DebugInfo] Ensure fallback artificial 
location is available for cleanups" to "[DebugInfo] Ensure fallback artificial 
location is available for cleanups".
vsk edited the summary of this revision.
vsk added a comment.

Added a test.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71042/new/

https://reviews.llvm.org/D71042

Files:
  clang/lib/CodeGen/CGDebugInfo.h
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/test/CodeGenObjCXX/property-object-cleanup.mm


Index: clang/test/CodeGenObjCXX/property-object-cleanup.mm
===================================================================
--- /dev/null
+++ clang/test/CodeGenObjCXX/property-object-cleanup.mm
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -triple arm64e-apple-ios13.4.0 -debug-info-kind=standalone 
-fobjc-arc \
+// RUN:   %s -emit-llvm -o - | FileCheck %s
+
+@interface NSObject
++ (id)alloc;
+@end
+
+@interface NSString : NSObject
+@end
+
+// CHECK: define {{.*}}@"\01-[MyData setData:]"
+// CHECK: [[DATA:%.*]] = alloca %struct.Data
+// CHECK: call %struct.Data* @_ZN4DataD1Ev(%struct.Data* [[DATA]]){{.*}}, !dbg 
[[LOC:![0-9]+]]
+// CHECK-NEXT: ret void
+
+// [[LOC]] = !DILocation(line: 0
+
+@interface MyData : NSObject
+struct Data {
+    NSString *name;
+};
+@property struct Data data;
+@end
+@implementation MyData
+@end
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===================================================================
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -329,9 +329,15 @@
   if (HasCleanups) {
     // Make sure the line table doesn't jump back into the body for
     // the ret after it's been at EndLoc.
-    if (CGDebugInfo *DI = getDebugInfo())
+    Optional<ApplyDebugLocation> AL;
+    if (CGDebugInfo *DI = getDebugInfo()) {
       if (OnlySimpleReturnStmts)
         DI->EmitLocation(Builder, EndLoc);
+      else
+        // We may not have a valid end location. Try to apply it anyway, and
+        // fall back to an artificial location if needed.
+        AL = ApplyDebugLocation::CreateDefaultArtificial(*this, EndLoc);
+    }
 
     PopCleanupBlocks(PrologueCleanupDepth);
   }
Index: clang/lib/CodeGen/CGDebugInfo.h
===================================================================
--- clang/lib/CodeGen/CGDebugInfo.h
+++ clang/lib/CodeGen/CGDebugInfo.h
@@ -749,6 +749,8 @@
     Other.CGF = nullptr;
   }
 
+  ApplyDebugLocation &operator=(ApplyDebugLocation &&) = default;
+
   ~ApplyDebugLocation();
 
   /// Apply TemporaryLocation if it is valid. Otherwise switch


Index: clang/test/CodeGenObjCXX/property-object-cleanup.mm
===================================================================
--- /dev/null
+++ clang/test/CodeGenObjCXX/property-object-cleanup.mm
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -triple arm64e-apple-ios13.4.0 -debug-info-kind=standalone -fobjc-arc \
+// RUN:   %s -emit-llvm -o - | FileCheck %s
+
+@interface NSObject
++ (id)alloc;
+@end
+
+@interface NSString : NSObject
+@end
+
+// CHECK: define {{.*}}@"\01-[MyData setData:]"
+// CHECK: [[DATA:%.*]] = alloca %struct.Data
+// CHECK: call %struct.Data* @_ZN4DataD1Ev(%struct.Data* [[DATA]]){{.*}}, !dbg [[LOC:![0-9]+]]
+// CHECK-NEXT: ret void
+
+// [[LOC]] = !DILocation(line: 0
+
+@interface MyData : NSObject
+struct Data {
+    NSString *name;
+};
+@property struct Data data;
+@end
+@implementation MyData
+@end
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===================================================================
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -329,9 +329,15 @@
   if (HasCleanups) {
     // Make sure the line table doesn't jump back into the body for
     // the ret after it's been at EndLoc.
-    if (CGDebugInfo *DI = getDebugInfo())
+    Optional<ApplyDebugLocation> AL;
+    if (CGDebugInfo *DI = getDebugInfo()) {
       if (OnlySimpleReturnStmts)
         DI->EmitLocation(Builder, EndLoc);
+      else
+        // We may not have a valid end location. Try to apply it anyway, and
+        // fall back to an artificial location if needed.
+        AL = ApplyDebugLocation::CreateDefaultArtificial(*this, EndLoc);
+    }
 
     PopCleanupBlocks(PrologueCleanupDepth);
   }
Index: clang/lib/CodeGen/CGDebugInfo.h
===================================================================
--- clang/lib/CodeGen/CGDebugInfo.h
+++ clang/lib/CodeGen/CGDebugInfo.h
@@ -749,6 +749,8 @@
     Other.CGF = nullptr;
   }
 
+  ApplyDebugLocation &operator=(ApplyDebugLocation &&) = default;
+
   ~ApplyDebugLocation();
 
   /// Apply TemporaryLocation if it is valid. Otherwise switch
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to