[cfe-commits] r169311 - in /cfe/trunk: lib/CodeGen/CGDebugInfo.cpp test/CodeGenCXX/debug-info-flex-member.cpp test/CodeGenCXX/debug-info-zero-length-arrays.cpp

Bill Wendling isanbard at gmail.com
Tue Dec 4 13:34:00 PST 2012


Author: void
Date: Tue Dec  4 15:33:58 2012
New Revision: 169311

URL: http://llvm.org/viewvc/llvm-project?rev=169311&view=rev
Log:
Use the 'count' attribute to calculate the upper bound of an array.

The count attribute is more accurate with regards to the size of an array. It
also obviates the upper bound attribute in the subrange. We can also better
handle an unbound array by setting the count to -1 instead of the lower bound to
1 and upper bound to 0.

Modified:
    cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
    cfe/trunk/test/CodeGenCXX/debug-info-flex-member.cpp
    cfe/trunk/test/CodeGenCXX/debug-info-zero-length-arrays.cpp

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=169311&r1=169310&r2=169311&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Tue Dec  4 15:33:58 2012
@@ -1473,25 +1473,19 @@
 
 llvm::DIType CGDebugInfo::CreateType(const VectorType *Ty, llvm::DIFile Unit) {
   llvm::DIType ElementTy = getOrCreateType(Ty->getElementType(), Unit);
-  int64_t NumElems = Ty->getNumElements();
-  int64_t LowerBound = 0;
-  int64_t Count = NumElems;
-  if (NumElems == 0)
+  int64_t Count = Ty->getNumElements();
+  if (Count == 0)
     // If number of elements are not known then this is an unbounded array.
-    // Use Low = 1, Hi = 0 to express such arrays.
-    LowerBound = 1;
-  else
-    --NumElems;
+    // Use Count == -1 to express such arrays.
+    Count = -1;
 
-  llvm::Value *Subscript = DBuilder.getOrCreateSubrange(LowerBound, NumElems,
-                                                        Count);
+  llvm::Value *Subscript = DBuilder.getOrCreateSubrange(0, Count);
   llvm::DIArray SubscriptArray = DBuilder.getOrCreateArray(Subscript);
 
   uint64_t Size = CGM.getContext().getTypeSize(Ty);
   uint64_t Align = CGM.getContext().getTypeAlign(Ty);
 
-  return
-    DBuilder.createVectorType(Size, Align, ElementTy, SubscriptArray);
+  return DBuilder.createVectorType(Size, Align, ElementTy, SubscriptArray);
 }
 
 llvm::DIType CGDebugInfo::CreateType(const ArrayType *Ty,
@@ -1532,23 +1526,12 @@
     //   struct foo {
     //     int x[0];
     //   };
-    int64_t UpperBound = 0;
-    int64_t LowerBound = 0;
-    int64_t Count = -1;
-    if (const ConstantArrayType *CAT = dyn_cast<ConstantArrayType>(Ty)) {
+    int64_t Count = -1;         // Count == -1 is an unbounded array.
+    if (const ConstantArrayType *CAT = dyn_cast<ConstantArrayType>(Ty))
       Count = CAT->getSize().getZExtValue();
-      if (Count)
-        UpperBound = Count - 1;
-    } else {
-      // This is an unbounded array. Use Low = 1, Hi = 0 to express such 
-      // arrays.
-      LowerBound = 1;
-    }
     
     // FIXME: Verify this is right for VLAs.
-    Subscripts.push_back(DBuilder.getOrCreateSubrange(LowerBound,
-                                                      UpperBound,
-                                                      Count));
+    Subscripts.push_back(DBuilder.getOrCreateSubrange(0, Count));
     EltTy = Ty->getElementType();
   }
 

Modified: cfe/trunk/test/CodeGenCXX/debug-info-flex-member.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-flex-member.cpp?rev=169311&r1=169310&r2=169311&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/debug-info-flex-member.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/debug-info-flex-member.cpp Tue Dec  4 15:33:58 2012
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 -emit-llvm -g -triple x86_64-apple-darwin %s -o - | FileCheck %s
 
-// CHECK: metadata !{i32 {{.*}}, i64 1, i64 0, i64 -1}        ; [ DW_TAG_subrange_type ]
+// CHECK: metadata !{i32 {{.*}}, i64 0, i64 -1}        ; [ DW_TAG_subrange_type ]
 
 struct StructName {
   int member[];

Modified: cfe/trunk/test/CodeGenCXX/debug-info-zero-length-arrays.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-zero-length-arrays.cpp?rev=169311&r1=169310&r2=169311&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/debug-info-zero-length-arrays.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/debug-info-zero-length-arrays.cpp Tue Dec  4 15:33:58 2012
@@ -10,4 +10,4 @@
 // CHECK: [[ARRAY_TYPE]] = metadata !{i32 {{.*}}, null, metadata !"", null, i32 0, i64 0, i64 32, i32 0, i32 0, metadata [[BASE_TYPE:.*]], metadata [[ELEM_TYPE:.*]], i32 0, i32 0} ; [ DW_TAG_array_type ]
 // CHECK: [[BASE_TYPE]] = metadata !{i32 {{.*}}, null, metadata !"int", null, i32 0, i64 32, i64 32, i64 0, i32 0, i32 5} ; [ DW_TAG_base_type ]
 // CHECK: [[ELEM_TYPE]] = metadata !{metadata [[SUBRANGE:.*]]}
-// CHECK: [[SUBRANGE]] = metadata !{i32 786465, i64 1, i64 0, i64 -1} ; [ DW_TAG_subrange_type ] [1, 0]
+// CHECK: [[SUBRANGE]] = metadata !{i32 786465, i64 0, i64 -1} ; [ DW_TAG_subrange_type ] [unbound]





More information about the cfe-commits mailing list