]> granicus.if.org Git - clang/commitdiff
Don't crash generating debug info for VLA in function prototype.
authorEli Friedman <efriedma@codeaurora.org>
Wed, 19 Oct 2016 22:16:32 +0000 (22:16 +0000)
committerEli Friedman <efriedma@codeaurora.org>
Wed, 19 Oct 2016 22:16:32 +0000 (22:16 +0000)
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

lib/CodeGen/CGDebugInfo.cpp
test/CodeGenCXX/debug-info-vla.cpp

index ef8f31e574d354fc8c2077d5e655b2058aa41158..1d80a1bf9da1b0a6d8cb7cc351fb3f1095e7a532 100644 (file)
@@ -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.
index 024ee3a6f9ae7be18414d7d2492f8db0a8f526b6..cd9b7f6c4575a38c93d0d7332bd03e3966161bdb 100644 (file)
@@ -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)