[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@junz.org>

Differential Revision: https://reviews.llvm.org/D130420
This commit is contained in:
Jun Zhang 2022-07-23 13:55:10 +08:00
parent cd953e4ffc
commit 58c9480845
No known key found for this signature in database
GPG Key ID: E19904830B621534
3 changed files with 5 additions and 0 deletions

View File

@ -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;

View File

@ -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);
}

View File

@ -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);