[PATCH] D61239: [libclang] Allow field offset lookups in types with incomplete arrays.

Jorn Vernee via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed May 1 06:03:07 PDT 2019


JornVernee updated this revision to Diff 197533.
JornVernee added a comment.

Add forgotten newline


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

https://reviews.llvm.org/D61239

Files:
  test/Index/print-type-size.c
  tools/libclang/CXType.cpp


Index: tools/libclang/CXType.cpp
===================================================================
--- tools/libclang/CXType.cpp
+++ tools/libclang/CXType.cpp
@@ -895,7 +895,7 @@
   // [expr.alignof] p3: if reference type, return size of referenced type
   if (QT->isReferenceType())
     QT = QT.getNonReferenceType();
-  if (QT->isIncompleteType())
+  if (QT->isIncompleteType() && !QT->isIncompleteArrayType())
     return CXTypeLayoutError_Incomplete;
   if (QT->isDependentType())
     return CXTypeLayoutError_Dependent;
@@ -953,7 +953,7 @@
 static long long visitRecordForValidation(const RecordDecl *RD) {
   for (const auto *I : RD->fields()){
     QualType FQT = I->getType();
-    if (FQT->isIncompleteType())
+    if (FQT->isIncompleteType() && !FQT->isIncompleteArrayType())
       return CXTypeLayoutError_Incomplete;
     if (FQT->isDependentType())
       return CXTypeLayoutError_Dependent;
Index: test/Index/print-type-size.c
===================================================================
--- /dev/null
+++ test/Index/print-type-size.c
@@ -0,0 +1,31 @@
+// RUN: c-index-test -test-print-type-size %s | FileCheck %s
+
+struct Foo {
+    int size;
+    // CHECK: FieldDecl=size:4:9 (Definition) [type=int] [typekind=Int] [sizeof=4] [alignof=4] [offsetof=0]
+    void* data[];
+    // CHECK: FieldDecl=data:6:11 (Definition) [type=void *[]] [typekind=IncompleteArray] [sizeof=-2] [alignof=8] [offsetof=64]
+};
+
+struct Bar {
+    int size;
+    // CHECK: FieldDecl=size:11:9 (Definition) [type=int] [typekind=Int] [sizeof=4] [alignof=4] [offsetof=0]
+    struct {
+        int dummy;
+        // CHECK: FieldDecl=dummy:14:13 (Definition) [type=int] [typekind=Int] [sizeof=4] [alignof=4] [offsetof=64/0]
+        void* data[];
+        // CHECK: FieldDecl=data:16:15 (Definition) [type=void *[]] [typekind=IncompleteArray] [sizeof=-2] [alignof=8] [offsetof=128/64]
+    };
+};
+
+struct Baz {
+    int size;
+    // CHECK: FieldDecl=size:22:9 (Definition) [type=int] [typekind=Int] [sizeof=4] [alignof=4] [offsetof=0]
+    union {
+        void* data1[];
+        // CHECK: FieldDecl=data1:25:15 (Definition) [type=void *[]] [typekind=IncompleteArray] [sizeof=-2] [alignof=8] [offsetof=64/0]
+        void* data2[];
+        // CHECK: FieldDecl=data2:27:15 (Definition) [type=void *[]] [typekind=IncompleteArray] [sizeof=-2] [alignof=8] [offsetof=64/0]
+    };
+};
+


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D61239.197533.patch
Type: text/x-patch
Size: 2389 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190501/5f2dfe85/attachment.bin>


More information about the cfe-commits mailing list