llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-codegen

@llvm/pr-subscribers-clang

Author: Eric Wright (efwright)

<details>
<summary>Changes</summary>

Clang's CodeGenFunction tracks two insert points for "allocas". One where the 
alloca instructions are placed, and another (immediately following the allocas) 
where any address space casts are placed. For code outlining the two helper 
classes (OutlinedRegionBodyRAII and InlinedRegionBodyRAII) both change the 
first insert point which then causes a desync between the two insert points.

This changes nulls out the PostAllocaInsertPt whenever the AllocaInsertPt is 
changed which will cause those two insert points to sync up again the next time 
the PostAllocaInsertPt is referenced.

---
Full diff: https://github.com/llvm/llvm-project/pull/98668.diff


1 Files Affected:

- (modified) clang/lib/CodeGen/CodeGenFunction.h (+14-4) 


``````````diff
diff --git a/clang/lib/CodeGen/CodeGenFunction.h 
b/clang/lib/CodeGen/CodeGenFunction.h
index cdb5ae6663405..2955949cbacdd 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -428,7 +428,6 @@ class CodeGenFunction : public CodeGenTypeCache {
   /// we prefer to insert allocas.
   llvm::AssertingVH<llvm::Instruction> AllocaInsertPt;
 
-private:
   /// PostAllocaInsertPt - This is a place in the prologue where code can be
   /// inserted that will be dominated by all the static allocas. This helps
   /// achieve two things:
@@ -439,7 +438,6 @@ class CodeGenFunction : public CodeGenTypeCache {
   /// PostAllocaInsertPt will be lazily created when it is *really* required.
   llvm::AssertingVH<llvm::Instruction> PostAllocaInsertPt = nullptr;
 
-public:
   /// Return PostAllocaInsertPt. If it is not yet created, then insert it
   /// immediately after AllocaInsertPt.
   llvm::Instruction *getPostAllocaInsertPoint() {
@@ -2004,11 +2002,17 @@ class CodeGenFunction : public CodeGenTypeCache {
 
         OldReturnBlock = CGF.ReturnBlock;
         CGF.ReturnBlock = CGF.getJumpDestInCurrentScope(&RetBB);
+
+        CGF.PostAllocaInsertPt = nullptr;
+
       }
 
       ~OutlinedRegionBodyRAII() {
         CGF.AllocaInsertPt = OldAllocaIP;
         CGF.ReturnBlock = OldReturnBlock;
+
+        CGF.PostAllocaInsertPt = nullptr;
+
       }
     };
 
@@ -2031,8 +2035,10 @@ class CodeGenFunction : public CodeGenTypeCache {
                "Insertion point should be in the entry block of containing "
                "function!");
         OldAllocaIP = CGF.AllocaInsertPt;
-        if (AllocaIP.isSet())
+        if (AllocaIP.isSet()) {
           CGF.AllocaInsertPt = &*AllocaIP.getPoint();
+          CGF.PostAllocaInsertPt = nullptr;
+        }
 
         // TODO: Remove the call, after making sure the counter is not used by
         //       the EHStack.
@@ -2042,7 +2048,11 @@ class CodeGenFunction : public CodeGenTypeCache {
         (void)CGF.getJumpDestInCurrentScope(&FiniBB);
       }
 
-      ~InlinedRegionBodyRAII() { CGF.AllocaInsertPt = OldAllocaIP; }
+      ~InlinedRegionBodyRAII()
+      {
+        CGF.AllocaInsertPt = OldAllocaIP;
+        CGF.PostAllocaInsertPt = nullptr;
+      }
     };
   };
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/98668
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to