[PATCH] D71042: WIP: [DebugInfo] Ensure fallback artificial location is available for cleanups

Vedant Kumar via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 4 19:29:02 PST 2019


vsk created this revision.
vsk added reviewers: aprantl, dblaikie.

When `CodeGenFunction::FinishFunction()` is passed an empty end location the function does not only contain 'simple' return statements, a cleanup which involves a call may be popped. As there is no debug location set (due to the empty end location), this triggers a verifier failure ("inlinable function without debug location...").

I'm working on producing a reduced test case, but thought I'd share this for review early to check that the proposed patch is reasonable.

rdar://57630879


https://reviews.llvm.org/D71042

Files:
  clang/lib/CodeGen/CGDebugInfo.h
  clang/lib/CodeGen/CodeGenFunction.cpp


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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D71042.232252.patch
Type: text/x-patch
Size: 1231 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191205/98b62f26/attachment.bin>


More information about the cfe-commits mailing list