Bladeren bron

[spirv] Use .getAs<>() instead of cast<>() for RecordType (#841)

cast<RecordType>(T.getTypePtr()) cannot handle cases in which
T is typedef of some struct type.
Lei Zhang 7 jaren geleden
bovenliggende
commit
ae9635c56c
2 gewijzigde bestanden met toevoegingen van 3 en 4 verwijderingen
  1. 2 2
      tools/clang/lib/SPIRV/DeclResultIdMapper.cpp
  2. 1 2
      tools/clang/lib/SPIRV/GlPerVertex.cpp

+ 2 - 2
tools/clang/lib/SPIRV/DeclResultIdMapper.cpp

@@ -1102,7 +1102,7 @@ bool DeclResultIdMapper::createStageVars(
     return false;
   }
 
-  const auto *structDecl = cast<RecordType>(type.getTypePtr())->getDecl();
+  const auto *structDecl = type->getAs<RecordType>()->getDecl();
 
   if (asInput) {
     // If this decl translates into multiple stage input variables, we need to
@@ -1226,7 +1226,7 @@ bool DeclResultIdMapper::writeBackOutputStream(const ValueDecl *decl,
     return false;
   }
 
-  const auto *structDecl = cast<RecordType>(type.getTypePtr())->getDecl();
+  const auto *structDecl = type->getAs<RecordType>()->getDecl();
 
   // Write out each field
   for (const auto *field : structDecl->fields()) {

+ 1 - 2
tools/clang/lib/SPIRV/GlPerVertex.cpp

@@ -159,8 +159,7 @@ bool GlPerVertex::doClipCullDistanceDecl(const DeclaratorDecl *decl,
 
   if (!getStageVarSemantic(decl, &semanticStr, &semantic, &semanticIndex)) {
     if (baseType->isStructureType()) {
-      const auto *structDecl =
-          cast<RecordType>(baseType.getTypePtr())->getDecl();
+      const auto *structDecl = baseType->getAs<RecordType>()->getDecl();
       // Go through each field to see if there is any usage of
       // SV_ClipDistance/SV_CullDistance.
       for (const auto *field : structDecl->fields()) {