From: Alexey Bataev Date: Wed, 11 Mar 2015 04:48:56 +0000 (+0000) Subject: [OPENMP] Fix for ExprWithCleanups in 'omp atomic' constructs. X-Git-Tag: llvmorg-3.7.0-rc1~9570 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=10fec57e5a4508eb0fee4cc76c4cc68e21ddf345;p=platform%2Fupstream%2Fllvm.git [OPENMP] Fix for ExprWithCleanups in 'omp atomic' constructs. This patch allows using of ExprWithCleanups expressions and other complex expressions in 'omp atomic' construct Differential Revision: http://reviews.llvm.org/D8200 llvm-svn: 231905 --- diff --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp b/clang/lib/CodeGen/CGStmtOpenMP.cpp index bd8d10f..ed68155 100644 --- a/clang/lib/CodeGen/CGStmtOpenMP.cpp +++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp @@ -921,7 +921,13 @@ void CodeGenFunction::EmitOMPAtomicDirective(const OMPAtomicDirective &S) { break; } } + + const auto *CS = + S.getAssociatedStmt()->IgnoreContainers(/*IgnoreCaptured=*/true); + if (const auto *EWC = dyn_cast(CS)) + enterFullExpression(EWC); InlinedOpenMPRegionScopeRAII Region(*this, S); + EmitOMPAtomicExpr(*this, Kind, IsSeqCst, S.getX(), S.getV(), S.getExpr(), S.getLocStart()); } diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp index 38fdf7c..9b66d2f 100644 --- a/clang/lib/Sema/SemaOpenMP.cpp +++ b/clang/lib/Sema/SemaOpenMP.cpp @@ -3267,6 +3267,9 @@ StmtResult Sema::ActOnOpenMPAtomicDirective(ArrayRef Clauses, } auto Body = CS->getCapturedStmt(); + if (auto *EWC = dyn_cast(Body)) + Body = EWC->getSubExpr(); + Expr *X = nullptr; Expr *V = nullptr; Expr *E = nullptr; diff --git a/clang/test/OpenMP/atomic_codegen.cpp b/clang/test/OpenMP/atomic_codegen.cpp index b80726f..e78720d 100644 --- a/clang/test/OpenMP/atomic_codegen.cpp +++ b/clang/test/OpenMP/atomic_codegen.cpp @@ -1,7 +1,37 @@ +// RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp=libiomp5 -fexceptions -fcxx-exceptions -x c++ -emit-llvm %s -o - | FileCheck %s // RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp=libiomp5 -fexceptions -fcxx-exceptions -gline-tables-only -x c++ -emit-llvm %s -o - | FileCheck %s --check-prefix=TERM_DEBUG // expected-no-diagnostics int a; +int b; + +struct St { + St() {} + ~St() {} + int &get() { return a; } +}; + +// CHECK-LABEL: parallel_atomic_ewc +void parallel_atomic_ewc() { +#pragma omp parallel + { + // CHECK: invoke void @_ZN2StC1Ev(%struct.St* [[TEMP_ST_ADDR:%.+]]) + // CHECK: [[SCALAR_ADDR:%.+]] = invoke dereferenceable(4) i32* @_ZN2St3getEv(%struct.St* [[TEMP_ST_ADDR]]) + // CHECK: [[SCALAR_VAL:%.+]] = load atomic i32, i32* [[SCALAR_ADDR]] monotonic + // CHECK: store i32 [[SCALAR_VAL]], i32* @b + // CHECK: invoke void @_ZN2StD1Ev(%struct.St* [[TEMP_ST_ADDR]]) +#pragma omp atomic read + b = St().get(); + // CHECK: invoke void @_ZN2StC1Ev(%struct.St* [[TEMP_ST_ADDR:%.+]]) + // CHECK: [[SCALAR_ADDR:%.+]] = invoke dereferenceable(4) i32* @_ZN2St3getEv(%struct.St* [[TEMP_ST_ADDR]]) + // CHECK: [[B_VAL:%.+]] = load i32, i32* @b + // CHECK: store atomic i32 [[B_VAL]], i32* [[SCALAR_ADDR]] monotonic + // CHECK: invoke void @_ZN2StD1Ev(%struct.St* [[TEMP_ST_ADDR]]) +#pragma omp atomic write + St().get() = b; + } +} + int &foo() { return a; } // TERM_DEBUG-LABEL: parallel_atomic @@ -12,7 +42,7 @@ void parallel_atomic() { // TERM_DEBUG-NOT: __kmpc_global_thread_num // TERM_DEBUG: invoke {{.*}}foo{{.*}}() // TERM_DEBUG: unwind label %[[TERM_LPAD:.+]], - // TERM_DEBUG: load atomic i32, i32* @{{.+}} monotonic, {{.*}}!dbg [[READ_LOC:![0-9]+]] + // TERM_DEBUG: load atomic i32, i32* @{{.+}} monotonic, {{.*}}!dbg [[READ_LOC:![0-9]+]] foo() = a; #pragma omp atomic write // TERM_DEBUG-NOT: __kmpc_global_thread_num @@ -26,5 +56,5 @@ void parallel_atomic() { a = foo(); } } -// TERM_DEBUG-DAG: [[READ_LOC]] = !MDLocation(line: 11, -// TERM_DEBUG-DAG: [[WRITE_LOC]] = !MDLocation(line: 17, +// TERM_DEBUG-DAG: [[READ_LOC]] = !MDLocation(line: 41, +// TERM_DEBUG-DAG: [[WRITE_LOC]] = !MDLocation(line: 47,