diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp --- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp +++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp @@ -1104,7 +1104,8 @@ // Add the barrier if requested. if (NeedsBarrier) - createBarrier(Loc, omp::Directive::OMPD_for, /* ForceSimpleCall */ false, + createBarrier(LocationDescription(Builder.saveIP(), Loc.DL), + omp::Directive::OMPD_for, /* ForceSimpleCall */ false, /* CheckCancelFlag */ false); CLI->assertOK(); diff --git a/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp b/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp --- a/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp +++ b/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp @@ -1155,6 +1155,11 @@ // increment and in the statement that adds the lower bound to it. Value *IV = CLI->getIndVar(); EXPECT_EQ(std::distance(IV->use_begin(), IV->use_end()), 3); + + // The exit block should contain the "fini" call and the barrier call. + BasicBlock *ExitBlock = CLI->getExitBlock(); + EXPECT_EQ( + count_if(*ExitBlock, [](Instruction *I) { return isa(I); }), 2); } TEST_F(OpenMPIRBuilderTest, MasterDirective) {