From 6f5ad4e7e66876271c4f80ace6af8e9495d365df Mon Sep 17 00:00:00 2001 From: Evgeny Mankov Date: Wed, 15 Feb 2017 19:48:31 +0300 Subject: [PATCH] [HIPIFY] [Fix] Crash on thrust example fallback_allocator.cu. https://github.com/GPUOpen-ProfessionalCompute-Tools/HIP/issues/65 [Bug] Access violation in cudaStructVar matcher. StringRef name = structVar->getType() ->getAsStructureType() ->getDecl() // <--- Access Violation ->getNameAsString(); [Solution] Add isStructureType() check before getting type as Struct. [ToDo] Find case-studies for that StructVar matcher with types other than Struct. [ROCm/hip commit: 950434f4af34387993f5d92c0a39a4179de82932] --- projects/hip/hipify-clang/src/Cuda2Hip.cpp | 38 ++++++++++++---------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/projects/hip/hipify-clang/src/Cuda2Hip.cpp b/projects/hip/hipify-clang/src/Cuda2Hip.cpp index 1bcd03feca..3ed9af148c 100644 --- a/projects/hip/hipify-clang/src/Cuda2Hip.cpp +++ b/projects/hip/hipify-clang/src/Cuda2Hip.cpp @@ -2282,25 +2282,27 @@ private: bool cudaStructVar(const MatchFinder::MatchResult &Result) { if (const VarDecl *structVar = Result.Nodes.getNodeAs("cudaStructVar")) { - StringRef name = structVar->getType() - ->getAsStructureType() - ->getDecl() - ->getNameAsString(); - TypeLoc TL = structVar->getTypeSourceInfo()->getTypeLoc(); - SourceLocation sl = TL.getUnqualifiedLoc().getLocStart(); - SourceManager *SM = Result.SourceManager; - const auto found = N.cuda2hipRename.find(name); - if (found != N.cuda2hipRename.end()) { - updateCounters(found->second, name.str()); - if (!found->second.unsupported) { - StringRef repName = found->second.hipName; - Replacement Rep(*SM, sl, name.size(), repName); - FullSourceLoc fullSL(sl, *SM); - insertReplacement(Rep, fullSL); + QualType QT = structVar->getType(); + // ToDo: find case-studies with types other than Struct. + if (QT->isStructureType()) { + StringRef name = QT.getTypePtr()->getAsStructureType()->getDecl()->getNameAsString(); + TypeLoc TL = structVar->getTypeSourceInfo()->getTypeLoc(); + SourceLocation sl = TL.getUnqualifiedLoc().getLocStart(); + SourceManager *SM = Result.SourceManager; + const auto found = N.cuda2hipRename.find(name); + if (found != N.cuda2hipRename.end()) { + updateCounters(found->second, name.str()); + if (!found->second.unsupported) { + StringRef repName = found->second.hipName; + Replacement Rep(*SM, sl, name.size(), repName); + FullSourceLoc fullSL(sl, *SM); + insertReplacement(Rep, fullSL); + } + } + else { + std::string msg = "the following reference is not handled: '" + name.str() + "' [struct var]."; + printHipifyMessage(*SM, sl, msg); } - } else { - std::string msg = "the following reference is not handled: '" + name.str() + "' [struct var]."; - printHipifyMessage(*SM, sl, msg); } return true; }