[PATCH] D102569: [clang-tidy] Fix altera-struct-pack-align crash for struct fields with incomplete type
Georgy Komarov via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat May 15 22:50:42 PDT 2021
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D102569.345672.patch
Type: text/x-patch
Size: 1460 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210516/2f955923/attachment.bin>
More information about the cfe-commits
mailing list