forked from OSchip/llvm-project
[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
This commit is contained in:
parent
2c9688d201
commit
ab92a4c26f
|
@ -58,9 +58,11 @@ void StructPackAlignCheck::check(const MatchFinder::MatchResult &Result) {
|
|||
// 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
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
// RUN: %check_clang_tidy -expect-clang-tidy-error %s altera-struct-pack-align %t -- -header-filter=.*
|
||||
|
||||
struct A;
|
||||
struct B {
|
||||
A a;
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:5: error: field has incomplete type 'A' [clang-diagnostic-error]
|
||||
};
|
Loading…
Reference in New Issue