From b6cce470ec79752d7f4b6d142eba4617eaf2082f Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Mon, 22 Aug 2016 17:49:56 +0000 Subject: [PATCH] PR29086: DebugInfo: Improve support for fixed array dimensions in variable length arrays git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@279445 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGDebugInfo.cpp | 5 +++++ test/CodeGenCXX/debug-info-vla.cpp | 14 ++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 test/CodeGenCXX/debug-info-vla.cpp diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp index fa5f53e459..a153193a53 100644 --- a/lib/CodeGen/CGDebugInfo.cpp +++ b/lib/CodeGen/CGDebugInfo.cpp @@ -2122,6 +2122,11 @@ llvm::DIType *CGDebugInfo::CreateType(const ArrayType *Ty, llvm::DIFile *Unit) { int64_t Count = -1; // Count == -1 is an unbounded array. if (const auto *CAT = dyn_cast(Ty)) Count = CAT->getSize().getZExtValue(); + else if (const auto *VAT = dyn_cast(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)); diff --git a/test/CodeGenCXX/debug-info-vla.cpp b/test/CodeGenCXX/debug-info-vla.cpp new file mode 100644 index 0000000000..024ee3a6f9 --- /dev/null +++ b/test/CodeGenCXX/debug-info-vla.cpp @@ -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) -- 2.40.0