Author: Georgy Komarov Date: 2021-05-17T16:50:47+03:00 New Revision: ab92a4c26f54170bf72706ad29c0fb151a177590
URL: https://github.com/llvm/llvm-project/commit/ab92a4c26f54170bf72706ad29c0fb151a177590 DIFF: https://github.com/llvm/llvm-project/commit/ab92a4c26f54170bf72706ad29c0fb151a177590.diff LOG: [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 Added: clang-tools-extra/test/clang-tidy/checkers/altera-struct-pack-align-no-crash.cpp Modified: clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp Removed: ################################################################################ diff --git a/clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp b/clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp index a2178befa9df..ef5fe41fd8c9 100644 --- a/clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp +++ b/clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp @@ -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 diff --git a/clang-tools-extra/test/clang-tidy/checkers/altera-struct-pack-align-no-crash.cpp b/clang-tools-extra/test/clang-tidy/checkers/altera-struct-pack-align-no-crash.cpp new file mode 100644 index 000000000000..660addcbe803 --- /dev/null +++ b/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] +}; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits