[llvm] [llvm][mustache] Fix UB in ASTNode::render() (PR #142249)

via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 5 09:35:10 PDT 2025


================
@@ -560,68 +566,71 @@ void toMustacheString(const json::Value &Data, raw_ostream &OS) {
   }
 }
 
-void ASTNode::render(const json::Value &Data, raw_ostream &OS) {
-  ParentContext = &Data;
+void ASTNode::render(const json::Value &CurrentCtx, raw_ostream &OS) {
+  // Set the parent context to the incoming context so that we
+  // can walk up the context tree correctly in findContext().
+  ParentContext = &CurrentCtx;
----------------
PeterChou1 wrote:

The ASTNode is a tree of nodes with the parentContext originally set to null. As we render the moustache template we set the parent context from the incoming parent node. We don't need to reset the parentContext when leaving because its was null originally 

https://github.com/llvm/llvm-project/pull/142249


More information about the llvm-commits mailing list