jubnzv created this revision. jubnzv added reviewers: aaron.ballman, njames93. jubnzv added a project: clang-tools-extra. Herald added a subscriber: xazax.hun. jubnzv requested review of this revision.
We can only use `ASTContext::getTypeInfo` for complete types. This fixes the following bugzilla issue: https://bugs.llvm.org/show_bug.cgi?id=50313. https://reviews.llvm.org/D102569 Files: clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp clang-tools-extra/test/clang-tidy/checkers/altera-struct-pack-align-no-crash.cpp Index: clang-tools-extra/test/clang-tidy/checkers/altera-struct-pack-align-no-crash.cpp =================================================================== --- /dev/null +++ clang-tools-extra/test/clang-tidy/checkers/altera-struct-pack-align-no-crash.cpp @@ -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] +}; Index: clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp +++ 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
Index: clang-tools-extra/test/clang-tidy/checkers/altera-struct-pack-align-no-crash.cpp =================================================================== --- /dev/null +++ clang-tools-extra/test/clang-tidy/checkers/altera-struct-pack-align-no-crash.cpp @@ -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] +}; Index: clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp +++ 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
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits