[PATCH] D67979: [BPF] Generate array dimension size properly for zero-size elements

Phabricator via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 24 15:37:08 PDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL372785: [BPF] Generate array dimension size properly for zero-size elements (authored by yhs, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D67979?vs=221581&id=221614#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D67979

Files:
  llvm/trunk/lib/Target/BPF/BTFDebug.cpp
  llvm/trunk/test/CodeGen/BPF/BTF/array-size-0.ll


Index: llvm/trunk/test/CodeGen/BPF/BTF/array-size-0.ll
===================================================================
--- llvm/trunk/test/CodeGen/BPF/BTF/array-size-0.ll
+++ llvm/trunk/test/CodeGen/BPF/BTF/array-size-0.ll
@@ -32,7 +32,7 @@
 ; CHECK-NEXT:        .long   0
 ; CHECK-NEXT:        .long   1
 ; CHECK-NEXT:        .long   3
-; CHECK-NEXT:        .long   0
+; CHECK-NEXT:        .long   10
 ; CHECK-NEXT:        .long   3                       # BTF_KIND_INT(id = 3)
 ; CHECK-NEXT:        .long   16777216                # 0x1000000
 ; CHECK-NEXT:        .long   4
Index: llvm/trunk/lib/Target/BPF/BTFDebug.cpp
===================================================================
--- llvm/trunk/lib/Target/BPF/BTFDebug.cpp
+++ llvm/trunk/lib/Target/BPF/BTFDebug.cpp
@@ -473,35 +473,29 @@
 
 void BTFDebug::visitArrayType(const DICompositeType *CTy, uint32_t &TypeId) {
   // Visit array element type.
-  uint32_t ElemTypeId, ElemSize;
+  uint32_t ElemTypeId;
   const DIType *ElemType = CTy->getBaseType();
   visitTypeEntry(ElemType, ElemTypeId, false, false);
 
-  // Strip qualifiers from element type to get accurate element size.
-  ElemSize = ElemType->getSizeInBits() >> 3;
-
-  if (!CTy->getSizeInBits()) {
-    auto TypeEntry = std::make_unique<BTFTypeArray>(ElemTypeId, 0);
-    ElemTypeId = addType(std::move(TypeEntry), CTy);
-  } else {
-    // Visit array dimensions.
-    DINodeArray Elements = CTy->getElements();
-    for (int I = Elements.size() - 1; I >= 0; --I) {
-      if (auto *Element = dyn_cast_or_null<DINode>(Elements[I]))
-        if (Element->getTag() == dwarf::DW_TAG_subrange_type) {
-          const DISubrange *SR = cast<DISubrange>(Element);
-          auto *CI = SR->getCount().dyn_cast<ConstantInt *>();
-          int64_t Count = CI->getSExtValue();
-
-          auto TypeEntry =
-              std::make_unique<BTFTypeArray>(ElemTypeId, Count);
-          if (I == 0)
-            ElemTypeId = addType(std::move(TypeEntry), CTy);
-          else
-            ElemTypeId = addType(std::move(TypeEntry));
-          ElemSize = ElemSize * Count;
-        }
-    }
+  // Visit array dimensions.
+  DINodeArray Elements = CTy->getElements();
+  for (int I = Elements.size() - 1; I >= 0; --I) {
+    if (auto *Element = dyn_cast_or_null<DINode>(Elements[I]))
+      if (Element->getTag() == dwarf::DW_TAG_subrange_type) {
+        const DISubrange *SR = cast<DISubrange>(Element);
+        auto *CI = SR->getCount().dyn_cast<ConstantInt *>();
+        int64_t Count = CI->getSExtValue();
+
+        // For struct s { int b; char c[]; }, the c[] will be represented
+        // as an array with Count = -1.
+        auto TypeEntry =
+            std::make_unique<BTFTypeArray>(ElemTypeId,
+                Count >= 0 ? Count : 0);
+        if (I == 0)
+          ElemTypeId = addType(std::move(TypeEntry), CTy);
+        else
+          ElemTypeId = addType(std::move(TypeEntry));
+      }
   }
 
   // The array TypeId is the type id of the outermost dimension.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D67979.221614.patch
Type: text/x-patch
Size: 3009 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190924/1009591a/attachment.bin>


More information about the llvm-commits mailing list