Author: Jordan Rupprecht
Date: 2022-12-15T20:38:32-08:00
New Revision: 5a06334c51aa75d7f044785a495cf2de5bf13a9c

URL: 
https://github.com/llvm/llvm-project/commit/5a06334c51aa75d7f044785a495cf2de5bf13a9c
DIFF: 
https://github.com/llvm/llvm-project/commit/5a06334c51aa75d7f044785a495cf2de5bf13a9c.diff

LOG: [Format] Capture `FormatStyle` by value to avoid use-after-free.

Fixes the test failure in 240e29c5015d246de7fb5e4421aa93042fada59b, reported on 
the D140058 review thread.

Added: 
    

Modified: 
    clang/lib/Format/Format.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index c553a5bf2a3e9..77f6892e5d09a 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -3404,7 +3404,7 @@ reformat(const FormatStyle &Style, StringRef Code,
     if (Style.InsertBraces) {
       FormatStyle S = Expanded;
       S.InsertBraces = true;
-      Passes.emplace_back([&](const Environment &Env) {
+      Passes.emplace_back([&, S](const Environment &Env) {
         return BracesInserter(Env, S).process(/*SkipAnnotation=*/true);
       });
     }
@@ -3412,7 +3412,7 @@ reformat(const FormatStyle &Style, StringRef Code,
     if (Style.RemoveBracesLLVM) {
       FormatStyle S = Expanded;
       S.RemoveBracesLLVM = true;
-      Passes.emplace_back([&](const Environment &Env) {
+      Passes.emplace_back([&, S](const Environment &Env) {
         return BracesRemover(Env, S).process(/*SkipAnnotation=*/true);
       });
     }
@@ -3420,7 +3420,7 @@ reformat(const FormatStyle &Style, StringRef Code,
     if (Style.RemoveSemicolon) {
       FormatStyle S = Expanded;
       S.RemoveSemicolon = true;
-      Passes.emplace_back([&](const Environment &Env) {
+      Passes.emplace_back([&, S](const Environment &Env) {
         return SemiRemover(Env, S).process(/*SkipAnnotation=*/true);
       });
     }


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to