From 19fa2c3b66332d45125cd5df111db1aa47c5a8b5 Mon Sep 17 00:00:00 2001 From: Alexey Bataev Date: Wed, 29 Apr 2015 05:21:03 +0000 Subject: [PATCH] [OPENMP] Fix crash on reductions codegen for short circuit reduction operations. llvm-svn: 236084 --- clang/lib/CodeGen/CGAtomic.cpp | 4 ++-- clang/test/OpenMP/for_reduction_codegen.cpp | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/clang/lib/CodeGen/CGAtomic.cpp b/clang/lib/CodeGen/CGAtomic.cpp index 2de9cb2..edcc09d 100644 --- a/clang/lib/CodeGen/CGAtomic.cpp +++ b/clang/lib/CodeGen/CGAtomic.cpp @@ -1502,7 +1502,7 @@ void CodeGenFunction::EmitAtomicStore(RValue rvalue, LValue dest, atomics.getAtomicType(), SourceLocation())); // Try to write new value using cmpxchg operation auto Pair = atomics.EmitAtomicCompareExchange(OriginalRValue, NewRValue, AO); - PHI->addIncoming(Pair.first.getScalarVal(), ContBB); + PHI->addIncoming(Pair.first.getScalarVal(), Builder.GetInsertBlock()); Builder.CreateCondBr(Pair.second, ExitBB, ContBB); EmitBlock(ExitBB, /*IsFinished=*/true); } @@ -1592,7 +1592,7 @@ void CodeGenFunction::EmitAtomicUpdate( auto Pair = Atomics.EmitAtomicCompareExchange(OriginalRValue, NewRVal, AO); OldVal = IsScalar ? Pair.first.getScalarVal() : Atomics.convertRValueToInt(Pair.first); - PHI->addIncoming(OldVal, ContBB); + PHI->addIncoming(OldVal, Builder.GetInsertBlock()); Builder.CreateCondBr(Pair.second, ExitBB, ContBB); EmitBlock(ExitBB, /*IsFinished=*/true); } diff --git a/clang/test/OpenMP/for_reduction_codegen.cpp b/clang/test/OpenMP/for_reduction_codegen.cpp index c7a8a6b..c26961b 100644 --- a/clang/test/OpenMP/for_reduction_codegen.cpp +++ b/clang/test/OpenMP/for_reduction_codegen.cpp @@ -42,6 +42,12 @@ T tmain() { vec[i] = t_var; s_arr[i] = var; } +#pragma omp parallel +#pragma omp for reduction(&& : t_var) + for (int i = 0; i < 2; ++i) { + vec[i] = t_var; + s_arr[i] = var; + } return T(); } -- 2.7.4