[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: 950434f4af]
Этот коммит содержится в:
Evgeny Mankov
2017-02-15 19:48:31 +03:00
родитель 8a8a7bc843
Коммит 6f5ad4e7e6
+20 -18
Просмотреть файл
@@ -2282,25 +2282,27 @@ private:
bool cudaStructVar(const MatchFinder::MatchResult &Result) {
if (const VarDecl *structVar = Result.Nodes.getNodeAs<VarDecl>("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;
}