Skip to content

Commit 01d6b96

Browse files
author
Eli Friedman
committed
Don't crash generating debug info for VLA in function prototype.
Fixes regression from r279445. Differential Revision: https://reviews.llvm.org/D25793 llvm-svn: 284652
1 parent 802e4a5 commit 01d6b96

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2180,9 +2180,11 @@ llvm::DIType *CGDebugInfo::CreateType(const ArrayType *Ty, llvm::DIFile *Unit) {
21802180
if (const auto *CAT = dyn_cast<ConstantArrayType>(Ty))
21812181
Count = CAT->getSize().getZExtValue();
21822182
else if (const auto *VAT = dyn_cast<VariableArrayType>(Ty)) {
2183-
llvm::APSInt V;
2184-
if (VAT->getSizeExpr()->EvaluateAsInt(V, CGM.getContext()))
2185-
Count = V.getExtValue();
2183+
if (Expr *Size = VAT->getSizeExpr()) {
2184+
llvm::APSInt V;
2185+
if (Size->EvaluateAsInt(V, CGM.getContext()))
2186+
Count = V.getExtValue();
2187+
}
21862188
}
21872189

21882190
// FIXME: Verify this is right for VLAs.
Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
1-
// RUN: %clang -target x86_64-unknown-unknown -fverbose-asm -g -O0 -S -emit-llvm %s -o - | FileCheck %s
1+
// RUN: %clang -target x86_64-unknown-unknown -fverbose-asm -g -O0 -S -emit-llvm %s -o - -std=c++11 | FileCheck %s
22

33

44
void f(int m) {
55
int x[3][m];
66
}
77

8+
int (*fp)(int[][*]) = nullptr;
9+
10+
// CHECK: !DICompositeType(tag: DW_TAG_array_type,
11+
// CHECK-NOT: size:
12+
// CHECK-SAME: align: 32
13+
// CHECK-SAME: elements: [[ELEM_TYPE:![0-9]+]]
14+
// CHECK: [[ELEM_TYPE]] = !{[[NOCOUNT:.*]]}
15+
// CHECK: [[NOCOUNT]] = !DISubrange(count: -1)
16+
//
817
// CHECK: !DICompositeType(tag: DW_TAG_array_type,
918
// CHECK-NOT: size:
1019
// CHECK-SAME: align: 32
1120
// CHECK-SAME: elements: [[ELEM_TYPE:![0-9]+]]
12-
// CHECK: [[ELEM_TYPE]] = !{[[SUB1:.*]], [[SUB2:.*]]}
13-
// CHECK: [[SUB1]] = !DISubrange(count: 3)
14-
// CHECK: [[SUB2]] = !DISubrange(count: -1)
21+
// CHECK: [[ELEM_TYPE]] = !{[[THREE:.*]], [[NOCOUNT]]}
22+
// CHECK: [[THREE]] = !DISubrange(count: 3)

0 commit comments

Comments
 (0)