From a10f4bf393c69adfbf1abf0770b783c0815e4af8 Mon Sep 17 00:00:00 2001 From: Alexey Bataev Date: Wed, 24 Jun 2015 03:35:38 +0000 Subject: [PATCH] Proper changing/restoring for CapturedStmtInfo, NFC. Added special RAII class for proper values changing/restoring in CodeGenFunction::CapturedStmtInfo. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@240517 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGOpenMPRuntime.cpp | 13 +++++-------- lib/CodeGen/CGStmt.cpp | 2 +- lib/CodeGen/CodeGenFunction.h | 14 ++++++++++++++ 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/lib/CodeGen/CGOpenMPRuntime.cpp b/lib/CodeGen/CGOpenMPRuntime.cpp index 3161af36c2..a864c49729 100644 --- a/lib/CodeGen/CGOpenMPRuntime.cpp +++ b/lib/CodeGen/CGOpenMPRuntime.cpp @@ -282,7 +282,7 @@ CGOpenMPRuntime::emitParallelOutlinedFunction(const OMPExecutableDirective &D, const CapturedStmt *CS = cast(D.getAssociatedStmt()); CodeGenFunction CGF(CGM, true); CGOpenMPOutlinedRegionInfo CGInfo(*CS, ThreadIDVar, CodeGen); - CGF.CapturedStmtInfo = &CGInfo; + CodeGenFunction::CGCapturedStmtRAII CapInfoRAII(CGF, &CGInfo); return CGF.GenerateCapturedStmtFunction(*CS); } @@ -295,7 +295,7 @@ CGOpenMPRuntime::emitTaskOutlinedFunction(const OMPExecutableDirective &D, auto *CS = cast(D.getAssociatedStmt()); CodeGenFunction CGF(CGM, true); CGOpenMPTaskOutlinedRegionInfo CGInfo(*CS, ThreadIDVar, CodeGen); - CGF.CapturedStmtInfo = &CGInfo; + CodeGenFunction::CGCapturedStmtRAII CapInfoRAII(CGF, &CGInfo); return CGF.GenerateCapturedStmtFunction(*CS); } @@ -2169,12 +2169,11 @@ void CGOpenMPRuntime::emitTaskCall( }); (void)InitScope.Privatize(); // Emit initialization for single element. - auto *OldCapturedStmtInfo = CGF.CapturedStmtInfo; - CGF.CapturedStmtInfo = &CapturesInfo; + CodeGenFunction::CGCapturedStmtRAII CapInfoRAII( + CGF, &CapturesInfo); CGF.EmitAnyExprToMem(Init, DestElement, Init->getType().getQualifiers(), /*IsInitializer=*/false); - CGF.CapturedStmtInfo = OldCapturedStmtInfo; }); } } else { @@ -2183,11 +2182,9 @@ void CGOpenMPRuntime::emitTaskCall( return SharedRefLValue.getAddress(); }); (void)InitScope.Privatize(); - auto *OldCapturedStmtInfo = CGF.CapturedStmtInfo; - CGF.CapturedStmtInfo = &CapturesInfo; + CodeGenFunction::CGCapturedStmtRAII CapInfoRAII(CGF, &CapturesInfo); CGF.EmitExprAsInit(Init, VD, PrivateLValue, /*capturedByInit=*/false); - CGF.CapturedStmtInfo = OldCapturedStmtInfo; } } else { CGF.EmitExprAsInit(Init, VD, PrivateLValue, /*capturedByInit=*/false); diff --git a/lib/CodeGen/CGStmt.cpp b/lib/CodeGen/CGStmt.cpp index 9286f03589..f10e819ec4 100644 --- a/lib/CodeGen/CGStmt.cpp +++ b/lib/CodeGen/CGStmt.cpp @@ -2149,7 +2149,7 @@ CodeGenFunction::EmitCapturedStmt(const CapturedStmt &S, CapturedRegionKind K) { // Emit the CapturedDecl CodeGenFunction CGF(CGM, true); - CGF.CapturedStmtInfo = new CGCapturedStmtInfo(S, K); + CGCapturedStmtRAII CapInfoRAII(CGF, new CGCapturedStmtInfo(S, K)); llvm::Function *F = CGF.GenerateCapturedStmtFunction(S); delete CGF.CapturedStmtInfo; diff --git a/lib/CodeGen/CodeGenFunction.h b/lib/CodeGen/CodeGenFunction.h index 45475d1af1..8c62829c22 100644 --- a/lib/CodeGen/CodeGenFunction.h +++ b/lib/CodeGen/CodeGenFunction.h @@ -233,6 +233,20 @@ public: }; CGCapturedStmtInfo *CapturedStmtInfo; + /// \brief RAII for correct setting/restoring of CapturedStmtInfo. + class CGCapturedStmtRAII { + private: + CodeGenFunction &CGF; + CGCapturedStmtInfo *PrevCapturedStmtInfo; + public: + CGCapturedStmtRAII(CodeGenFunction &CGF, + CGCapturedStmtInfo *NewCapturedStmtInfo) + : CGF(CGF), PrevCapturedStmtInfo(CGF.CapturedStmtInfo) { + CGF.CapturedStmtInfo = NewCapturedStmtInfo; + } + ~CGCapturedStmtRAII() { CGF.CapturedStmtInfo = PrevCapturedStmtInfo; } + }; + /// BoundsChecking - Emit run-time bounds checks. Higher values mean /// potentially higher performance penalties. unsigned char BoundsChecking; -- 2.40.0