Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp =================================================================== --- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp +++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp @@ -4503,7 +4503,13 @@ Value *OpenMPIRBuilder::getOMPCriticalRegionLock(StringRef CriticalName) { std::string Prefix = Twine("gomp_critical_user_", CriticalName).str(); std::string Name = getNameWithSeparators({Prefix, "var"}, ".", "."); - return getOrCreateInternalVariable(KmpCriticalNameTy, Name); + llvm::GlobalVariable *G = + getOrCreateInternalVariable(KmpCriticalNameTy, Name); + llvm::Align PtrAlign = + M.getDataLayout().getPointerABIAlignment(G->getAddressSpace()); + if (PtrAlign > llvm::Align(G->getAlignment())) + G->setAlignment(PtrAlign); + return G; } Value *OpenMPIRBuilder::getSizeInBytes(Value *BasePtr) { Index: llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp =================================================================== --- llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp +++ llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp @@ -2744,7 +2744,14 @@ PointerType *CriticalNamePtrTy = PointerType::getUnqual(ArrayType::get(Type::getInt32Ty(Ctx), 8)); EXPECT_EQ(CriticalEndCI->getArgOperand(2), CriticalEntryCI->getArgOperand(2)); - EXPECT_EQ(CriticalEndCI->getArgOperand(2)->getType(), CriticalNamePtrTy); + GlobalVariable *GV = + dyn_cast(CriticalEndCI->getArgOperand(2)); + ASSERT_NE(GV, nullptr); + EXPECT_EQ(GV->getType(), CriticalNamePtrTy); + llvm::Align PtrAlign = + M->getDataLayout().getPointerABIAlignment(GV->getAddressSpace()); + if (PtrAlign.value() > GV->getAlignment()) + EXPECT_EQ(GV->getAlignment(), PtrAlign.value()); } TEST_F(OpenMPIRBuilderTest, OrderedDirectiveDependSource) {