[clang-tidy] Fix altera-struct-pack-align crash for struct fields with incomplete type
We can only use ASTContext::getTypeInfo for complete types.
This fixes bugzilla issue 50313.
Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D102569
diff --git a/clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp b/clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp
index a2178be..ef5fe41 100644
--- a/clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp
+++ b/clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp
@@ -58,9 +58,11 @@
// For each StructField, record how big it is (in bits).
// Would be good to use a pair of <offset, size> to advise a better
// packing order.
+ QualType StructFieldTy = StructField->getType();
+ if (StructFieldTy->isIncompleteType())
+ return;
unsigned int StructFieldWidth =
- (unsigned int)Result.Context
- ->getTypeInfo(StructField->getType().getTypePtr())
+ (unsigned int)Result.Context->getTypeInfo(StructFieldTy.getTypePtr())
.Width;
FieldSizes.emplace_back(StructFieldWidth, StructField->getFieldIndex());
// FIXME: Recommend a reorganization of the struct (sort by StructField