Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit a32fe92

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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@284652 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 25d6334 commit a32fe92

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

Diff for: lib/CodeGen/CGDebugInfo.cpp

+5-3
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.

Diff for: test/CodeGenCXX/debug-info-vla.cpp

+12-4
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)