[pkg-d-commits] [ldc] 47/211: Fix issue #1774

Matthias Klumpp mak at moszumanska.debian.org
Sun Apr 23 22:36:08 UTC 2017


This is an automated email from the git hooks/post-receive script.

mak pushed a commit to annotated tag v1.1.0
in repository ldc.

commit 4b72aad8755bc5b6f761813b164656322678aea8
Author: Martin <noone at nowhere.com>
Date:   Sun Oct 2 12:11:05 2016 +0200

    Fix issue #1774
    
    Running a cleanup with a dummy target BB and later replacing all uses of
    that dummy with the actual BB is buggy, as the cleanup keeps track of its
    exit targets (via pointers) which aren't updated.
---
 gen/trycatchfinally.cpp | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/gen/trycatchfinally.cpp b/gen/trycatchfinally.cpp
index 48c9dea..a8c84ba 100644
--- a/gen/trycatchfinally.cpp
+++ b/gen/trycatchfinally.cpp
@@ -486,16 +486,22 @@ void TryCatchFinallyScopes::popCleanups(CleanupCursor targetScope) {
     // Any gotos that are still unresolved necessarily leave this scope.
     // Thus, the cleanup needs to be executed.
     for (const auto &gotoJump : currentUnresolvedGotos()) {
-      // Make the source resp. last cleanup branch to this one.
+      // Replace all branches to the tentative target by branches to the cleanup
+      // and continue with the tentative target (we simply reuse it because
+      // there is no reason not to).
       llvm::BasicBlock *tentative = gotoJump.tentativeTarget;
-      llvm::BasicBlock *afterCleanup = irs.insertBB("");
+      // 1) Replace all branches to the tentative target by branches to a
+      //    temporary placeholder BB.
+      llvm::BasicBlock *dummy = irs.insertBB("");
+      tentative->replaceAllUsesWith(dummy);
+      // 2) We need a cleanup instance which continues execution with the
+      //    tentative target.
       auto startCleanup =
-          cleanupScopes[i].run(irs, gotoJump.sourceBlock, afterCleanup);
-      tentative->replaceAllUsesWith(startCleanup);
-      // And continue execution with the tentative target (we simply reuse
-      // it because there is no reason not to).
-      afterCleanup->replaceAllUsesWith(tentative);
-      afterCleanup->eraseFromParent();
+          cleanupScopes[i].run(irs, gotoJump.sourceBlock, tentative);
+      // 3) Replace all branches to the placeholder BB by branches to the
+      //    cleanup.
+      dummy->replaceAllUsesWith(startCleanup);
+      dummy->eraseFromParent();
     }
 
     Gotos &nextUnresolved = unresolvedGotosPerCleanupScope[i];

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-d/ldc.git



More information about the pkg-d-commits mailing list