[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
Mon May 17 06:58:52 PDT 2021


This revision was automatically updated to reflect the committed changes.
Closed by commit rGab92a4c26f54: [clang-tidy] Fix altera-struct-pack-align crash for struct fields with… (authored by jubnzv).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D102569/new/

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.345865.patch
Type: text/x-patch
Size: 1460 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210517/11cc8303/attachment.bin>


More information about the cfe-commits mailing list