From 58c94808450d0ec73bed38d1661314c1a3d56e2f Mon Sep 17 00:00:00 2001 From: Jun Zhang Date: Sat, 23 Jul 2022 13:55:10 +0800 Subject: [PATCH] [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 Differential Revision: https://reviews.llvm.org/D130420 --- clang/lib/CodeGen/CGCXXABI.h | 2 ++ clang/lib/CodeGen/CodeGenModule.cpp | 2 ++ clang/test/Interpreter/execute.cpp | 1 + 3 files changed, 5 insertions(+) diff --git a/clang/lib/CodeGen/CGCXXABI.h b/clang/lib/CodeGen/CGCXXABI.h index a46f7f37141f..0768e6581acb 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 MangleCtx; diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 101080b6fe13..29713a5d2b3b 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 f5c70c21ac50..0396ad82e9b3 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);