Skip to content

Commit

Permalink
Don't crash generating debug info for VLA in function prototype.
Browse files Browse the repository at this point in the history
Fixes regression from r279445.

Differential Revision: https://reviews.llvm.org/D25793

llvm-svn: 284652
  • Loading branch information
Eli Friedman committed Oct 19, 2016
1 parent 802e4a5 commit 01d6b96
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
8 changes: 5 additions & 3 deletions clang/lib/CodeGen/CGDebugInfo.cpp
Expand Up @@ -2180,9 +2180,11 @@ llvm::DIType *CGDebugInfo::CreateType(const ArrayType *Ty, llvm::DIFile *Unit) {
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();
if (Expr *Size = VAT->getSizeExpr()) {
llvm::APSInt V;
if (Size->EvaluateAsInt(V, CGM.getContext()))
Count = V.getExtValue();
}
}

// FIXME: Verify this is right for VLAs.
Expand Down
16 changes: 12 additions & 4 deletions clang/test/CodeGenCXX/debug-info-vla.cpp
@@ -1,14 +1,22 @@
// RUN: %clang -target x86_64-unknown-unknown -fverbose-asm -g -O0 -S -emit-llvm %s -o - | FileCheck %s
// RUN: %clang -target x86_64-unknown-unknown -fverbose-asm -g -O0 -S -emit-llvm %s -o - -std=c++11 | FileCheck %s


void f(int m) {
int x[3][m];
}

int (*fp)(int[][*]) = nullptr;

// CHECK: !DICompositeType(tag: DW_TAG_array_type,
// CHECK-NOT: size:
// CHECK-SAME: align: 32
// CHECK-SAME: elements: [[ELEM_TYPE:![0-9]+]]
// CHECK: [[ELEM_TYPE]] = !{[[NOCOUNT:.*]]}
// CHECK: [[NOCOUNT]] = !DISubrange(count: -1)
//
// 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)
// CHECK: [[ELEM_TYPE]] = !{[[THREE:.*]], [[NOCOUNT]]}
// CHECK: [[THREE]] = !DISubrange(count: 3)

0 comments on commit 01d6b96

Please sign in to comment.