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

llvm-svn: 279445
This commit is contained in:
David Blaikie 2016-08-22 17:49:56 +00:00
parent c41fcaf8aa
commit 87173f108a
2 changed files with 19 additions and 0 deletions

View File

@ -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<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));

View File

@ -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)