[clang] 58c9480 - [CodeGen] Consider MangleCtx when move lazy emission States

Jun Zhang via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 25 21:44:40 PDT 2022


Author: Jun Zhang
Date: 2022-07-26T12:34:03+08:00
New Revision: 58c94808450d0ec73bed38d1661314c1a3d56e2f

URL: https://github.com/llvm/llvm-project/commit/58c94808450d0ec73bed38d1661314c1a3d56e2f
DIFF: https://github.com/llvm/llvm-project/commit/58c94808450d0ec73bed38d1661314c1a3d56e2f.diff

LOG: [CodeGen] Consider MangleCtx when move lazy emission States

Also move MangleCtx when moving some lazy emission states in
CodeGenModule. Without this patch clang-repl hits an invalid address
access when passing `-Xcc -O2` flag.

Signed-off-by: Jun Zhang <jun at junz.org>

Differential Revision: https://reviews.llvm.org/D130420

Added: 
    

Modified: 
    clang/lib/CodeGen/CGCXXABI.h
    clang/lib/CodeGen/CodeGenModule.cpp
    clang/test/Interpreter/execute.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/CodeGen/CGCXXABI.h b/clang/lib/CodeGen/CGCXXABI.h
index a46f7f37141f0..0768e6581acb8 100644
--- a/clang/lib/CodeGen/CGCXXABI.h
+++ b/clang/lib/CodeGen/CGCXXABI.h
@@ -41,6 +41,8 @@ struct CatchTypeInfo;
 
 /// Implements C++ ABI-specific code generation functions.
 class CGCXXABI {
+  friend class CodeGenModule;
+
 protected:
   CodeGenModule &CGM;
   std::unique_ptr<MangleContext> MangleCtx;

diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index 101080b6fe132..29713a5d2b3b3 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -7000,4 +7000,6 @@ void CodeGenModule::moveLazyEmissionStates(CodeGenModule *NewBuilder) {
          "Still have (unmerged) EmittedDeferredDecls deferred decls");
 
   NewBuilder->EmittedDeferredDecls = std::move(EmittedDeferredDecls);
+
+  NewBuilder->ABI->MangleCtx = std::move(ABI->MangleCtx);
 }

diff  --git a/clang/test/Interpreter/execute.cpp b/clang/test/Interpreter/execute.cpp
index f5c70c21ac507..0396ad82e9b36 100644
--- a/clang/test/Interpreter/execute.cpp
+++ b/clang/test/Interpreter/execute.cpp
@@ -5,6 +5,7 @@
 // UNSUPPORTED: system-aix
 // CHECK-DRIVER: i = 10
 // RUN: cat %s | clang-repl | FileCheck %s
+// RUN: cat %s | clang-repl -Xcc -O2 | FileCheck %s
 extern "C" int printf(const char *, ...);
 int i = 42;
 auto r1 = printf("i = %d\n", i);


        


More information about the cfe-commits mailing list