From: Andrew Gozillon Date: Wed, 7 Jun 2023 19:27:42 +0000 (-0500) Subject: [Clang][OpenMP] Rework recently moved getTargetEntryUniqueInfo to fix incorrect error... X-Git-Tag: upstream/17.0.6~5798 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=309023263dba3b02bc885101faa47d110f662f99;p=platform%2Fupstream%2Fllvm.git [Clang][OpenMP] Rework recently moved getTargetEntryUniqueInfo to fix incorrect error breaking sanitizer This move was done by https://reviews.llvm.org/rGcda46cc4f921f6b288c57a68b901ec2f57134606 and may be the issue causing the sanitizer to fail. But in either case, it is an invalid assert that required some changes to function correctly. --- diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp index c7d62fc..a5a5ed1 100644 --- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp +++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp @@ -1646,6 +1646,25 @@ convertCaptureClause(const VarDecl *VD) { } } +static llvm::TargetRegionEntryInfo getEntryInfoFromPresumedLoc( + CodeGenModule &CGM, llvm::OpenMPIRBuilder &OMPBuilder, + SourceLocation BeginLoc, llvm::StringRef ParentName = "") { + + auto FileInfoCallBack = [&]() { + SourceManager &SM = CGM.getContext().getSourceManager(); + PresumedLoc PLoc = SM.getPresumedLoc(BeginLoc); + + llvm::sys::fs::UniqueID ID; + if (auto EC = llvm::sys::fs::getUniqueID(PLoc.getFilename(), ID)) { + PLoc = SM.getPresumedLoc(BeginLoc, /*UseLineDirectives=*/false); + } + + return std::pair(PLoc.getFilename(), PLoc.getLine()); + }; + + return OMPBuilder.getTargetEntryUniqueInfo(FileInfoCallBack, ParentName); +} + Address CGOpenMPRuntime::getAddrOfDeclareTargetVar(const VarDecl *VD) { auto AddrOfGlobal = [&VD, this]() { return CGM.GetAddrOfGlobal(VD); }; @@ -1654,11 +1673,6 @@ Address CGOpenMPRuntime::getAddrOfDeclareTargetVar(const VarDecl *VD) { }; std::vector GeneratedRefs; - auto PLoc = CGM.getContext().getSourceManager().getPresumedLoc( - VD->getCanonicalDecl()->getBeginLoc()); - if (PLoc.isInvalid()) - PLoc = CGM.getContext().getSourceManager().getPresumedLoc( - VD->getCanonicalDecl()->getBeginLoc(), /*UseLineDirectives=*/false); llvm::Type *LlvmPtrTy = CGM.getTypes().ConvertTypeForMem( CGM.getContext().getPointerType(VD->getType())); @@ -1666,7 +1680,8 @@ Address CGOpenMPRuntime::getAddrOfDeclareTargetVar(const VarDecl *VD) { convertCaptureClause(VD), convertDeviceClause(VD), VD->hasDefinition(CGM.getContext()) == VarDecl::DeclarationOnly, VD->isExternallyVisible(), - OMPBuilder.getTargetEntryUniqueInfo(PLoc.getFilename(), PLoc.getLine()), + getEntryInfoFromPresumedLoc(CGM, OMPBuilder, + VD->getCanonicalDecl()->getBeginLoc()), CGM.getMangledName(VD), GeneratedRefs, CGM.getLangOpts().OpenMPSimd, CGM.getLangOpts().OMPTargetTriples, LlvmPtrTy, AddrOfGlobal, LinkageForVariable); @@ -1849,19 +1864,6 @@ llvm::Function *CGOpenMPRuntime::emitThreadPrivateVarDefinition( return nullptr; } -static llvm::TargetRegionEntryInfo getEntryInfoFromPresumedLoc( - CodeGenModule &CGM, llvm::OpenMPIRBuilder &OMPBuilder, - SourceLocation BeginLoc, llvm::StringRef ParentName) { - - auto PLoc = CGM.getContext().getSourceManager().getPresumedLoc(BeginLoc); - if (PLoc.isInvalid()) - PLoc = CGM.getContext().getSourceManager().getPresumedLoc( - BeginLoc, /*UseLineDirectives=*/false); - - return OMPBuilder.getTargetEntryUniqueInfo(PLoc.getFilename(), PLoc.getLine(), - ParentName); -} - bool CGOpenMPRuntime::emitDeclareTargetVarDefinition(const VarDecl *VD, llvm::GlobalVariable *Addr, bool PerformInit) { @@ -10349,16 +10351,12 @@ void CGOpenMPRuntime::registerTargetGlobalVariable(const VarDecl *VD, }; std::vector GeneratedRefs; - auto PLoc = CGM.getContext().getSourceManager().getPresumedLoc( - VD->getCanonicalDecl()->getBeginLoc()); - if (PLoc.isInvalid()) - PLoc = CGM.getContext().getSourceManager().getPresumedLoc( - VD->getCanonicalDecl()->getBeginLoc(), /*UseLineDirectives=*/false); OMPBuilder.registerTargetGlobalVariable( convertCaptureClause(VD), convertDeviceClause(VD), VD->hasDefinition(CGM.getContext()) == VarDecl::DeclarationOnly, VD->isExternallyVisible(), - OMPBuilder.getTargetEntryUniqueInfo(PLoc.getFilename(), PLoc.getLine()), + getEntryInfoFromPresumedLoc(CGM, OMPBuilder, + VD->getCanonicalDecl()->getBeginLoc()), CGM.getMangledName(VD), GeneratedRefs, CGM.getLangOpts().OpenMPSimd, CGM.getLangOpts().OMPTargetTriples, AddrOfGlobal, LinkageForVariable, CGM.getTypes().ConvertTypeForMem( diff --git a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h index 0a55229..4ae9192 100644 --- a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h +++ b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h @@ -1155,15 +1155,18 @@ public: InsertPointTy AllocaIP, BodyGenCallbackTy BodyGenCB); + + using FileIdentifierInfoCallbackTy = std::function()>; + /// Creates a unique info for a target entry when provided a filename and /// line number from. /// - /// \param FileName The name of the file the target entry resides in - /// \param Line The line number where the target entry resides + /// \param CallBack A callback function which should return filename the entry + /// resides in as well as the line number for the target entry /// \param ParentName The name of the parent the target entry resides in, if /// any. static TargetRegionEntryInfo - getTargetEntryUniqueInfo(StringRef FileName, uint64_t Line, + getTargetEntryUniqueInfo(FileIdentifierInfoCallbackTy CallBack, StringRef ParentName = ""); /// Functions used to generate reductions. Such functions take two Values diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp index b2c556b..2e43e6b 100644 --- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp +++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp @@ -5195,14 +5195,17 @@ void OffloadEntriesInfoManager::getTargetRegionEntryFnName( } TargetRegionEntryInfo -OpenMPIRBuilder::getTargetEntryUniqueInfo(StringRef FileName, uint64_t Line, +OpenMPIRBuilder::getTargetEntryUniqueInfo(FileIdentifierInfoCallbackTy CallBack, StringRef ParentName) { sys::fs::UniqueID ID; - if (auto EC = sys::fs::getUniqueID(FileName, ID)) { - assert(EC && - "Unable to get unique ID for file, during getTargetEntryUniqueInfo"); + auto FileIDInfo = CallBack(); + if (auto EC = sys::fs::getUniqueID(std::get<0>(FileIDInfo), ID)) { + llvm_unreachable( + "Unable to get unique ID for file, during getTargetEntryUniqueInfo"); } - return TargetRegionEntryInfo(ParentName, ID.getDevice(), ID.getFile(), Line); + + return TargetRegionEntryInfo(ParentName, ID.getDevice(), ID.getFile(), + std::get<1>(FileIDInfo)); } Constant *OpenMPIRBuilder::getAddrOfDeclareTargetVar(