r279445 - PR29086: DebugInfo: Improve support for fixed array dimensions in variable length arrays

David Blaikie via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 22 10:49:57 PDT 2016


Author: dblaikie
Date: Mon Aug 22 12:49:56 2016
New Revision: 279445

URL: http://llvm.org/viewvc/llvm-project?rev=279445&view=rev
Log:
PR29086: DebugInfo: Improve support for fixed array dimensions in variable length arrays

Added:
    cfe/trunk/test/CodeGenCXX/debug-info-vla.cpp
Modified:
    cfe/trunk/lib/CodeGen/CGDebugInfo.cpp

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=279445&r1=279444&r2=279445&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Mon Aug 22 12:49:56 2016
@@ -2122,6 +2122,11 @@ llvm::DIType *CGDebugInfo::CreateType(co
     int64_t Count = -1; // Count == -1 is an unbounded array.
     if (const auto *CAT = dyn_cast<ConstantArrayType>(Ty))
       Count = CAT->getSize().getZExtValue();
+    else if (const auto *VAT = dyn_cast<VariableArrayType>(Ty)) {
+      llvm::APSInt V;
+      if (VAT->getSizeExpr()->EvaluateAsInt(V, CGM.getContext()))
+        Count = V.getExtValue();
+    }
 
     // FIXME: Verify this is right for VLAs.
     Subscripts.push_back(DBuilder.getOrCreateSubrange(0, Count));

Added: cfe/trunk/test/CodeGenCXX/debug-info-vla.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-vla.cpp?rev=279445&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/debug-info-vla.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/debug-info-vla.cpp Mon Aug 22 12:49:56 2016
@@ -0,0 +1,14 @@
+// RUN: %clang -target x86_64-unknown-unknown -fverbose-asm -g -O0 -S -emit-llvm %s -o - | FileCheck %s
+
+
+void f(int m) {
+  int x[3][m];
+}
+
+// CHECK: !DICompositeType(tag: DW_TAG_array_type,
+// CHECK-NOT:                               size:
+// CHECK-SAME:                              align: 32
+// CHECK-SAME:                              elements: [[ELEM_TYPE:![0-9]+]]
+// CHECK: [[ELEM_TYPE]] = !{[[SUB1:.*]], [[SUB2:.*]]}
+// CHECK: [[SUB1]] = !DISubrange(count: 3)
+// CHECK: [[SUB2]] = !DISubrange(count: -1)




More information about the cfe-commits mailing list