[PATCH] D25373: Fix for Bug 30639: CGDebugInfo Null dereference with OpenMP array access

Keane, Erich via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 7 12:37:18 PDT 2016


Ok, I dug into this deeper.  ASTContext.cpp:2811 (getVariableArrayDecayedType) intentionaly sets size to nullptr in this case for the purpose of turning it into a [*] type.  OpenMP.cpp:236 (CodeGenFunction::GenerateOpenMPCapturedStmtFunction) calls this to replace variably modified type with this one.  It definitely looks like this is on purpose as far as I can tell.



From: Keane, Erich
Sent: Friday, October 7, 2016 11:56 AM
To: 'David Blaikie' <dblaikie at gmail.com>; reviews+D25373+public+d8ec2a4bb41b17c6 at reviews.llvm.org; cfe-commits at lists.llvm.org; david.majnemer at gmail.com; 'Alexey Bataev' <a.bataev at hotmail.com>
Cc: junbuml at codeaurora.org
Subject: RE: [PATCH] D25373: Fix for Bug 30639: CGDebugInfo Null dereference with OpenMP array access

Added Alexey to the list, he’s the OMP Maintainer, so hopefully he knows better ☺

From: David Blaikie [mailto:dblaikie at gmail.com]
Sent: Friday, October 7, 2016 11:51 AM
To: reviews+D25373+public+d8ec2a4bb41b17c6 at reviews.llvm.org<mailto:reviews+D25373+public+d8ec2a4bb41b17c6 at reviews.llvm.org>; Keane, Erich <erich.keane at intel.com<mailto:erich.keane at intel.com>>; cfe-commits at lists.llvm.org<mailto:cfe-commits at lists.llvm.org>; david.majnemer at gmail.com<mailto:david.majnemer at gmail.com>; guy.benyei at intel.com<mailto:guy.benyei at intel.com>
Cc: junbuml at codeaurora.org<mailto:junbuml at codeaurora.org>
Subject: Re: [PATCH] D25373: Fix for Bug 30639: CGDebugInfo Null dereference with OpenMP array access

Could you explain how/why there's a null size expr? I would've thought it must have /some/ size for code generation purposes...

On Fri, Oct 7, 2016 at 11:33 AM Erich Keane <erich.keane at intel.com<mailto:erich.keane at intel.com>> wrote:
erichkeane created this revision.
erichkeane added reviewers: cfe-commits, dblaikie, majnemer, gbenyei.
erichkeane set the repository for this revision to rL LLVM.

OpenMP creates a variable array type with a a null size-expr.  The Debug generation failed to properly consider this case.  This patch adds a null check to prevent a null dereference seg-fault in this case, plus adds a test.


Repository:
  rL LLVM

https://reviews.llvm.org/D25373

Files:
  lib/CodeGen/CGDebugInfo.cpp
  test/CodeGenCXX/debug-info-openmp-array.cpp


Index: lib/CodeGen/CGDebugInfo.cpp
===================================================================
--- lib/CodeGen/CGDebugInfo.cpp
+++ lib/CodeGen/CGDebugInfo.cpp
@@ -2181,7 +2181,8 @@
       Count = CAT->getSize().getZExtValue();
     else if (const auto *VAT = dyn_cast<VariableArrayType>(Ty)) {
       llvm::APSInt V;
-      if (VAT->getSizeExpr()->EvaluateAsInt(V, CGM.getContext()))
+      if (VAT->getSizeExpr() &&
+          VAT->getSizeExpr()->EvaluateAsInt(V, CGM.getContext()))
         Count = V.getExtValue();
     }

Index: test/CodeGenCXX/debug-info-openmp-array.cpp
===================================================================
--- test/CodeGenCXX/debug-info-openmp-array.cpp
+++ test/CodeGenCXX/debug-info-openmp-array.cpp
@@ -0,0 +1,17 @@
+// RUN: %clang -target x86_64-unknown-unknown -fverbose-asm -fopenmp -g -O0 -S -emit-llvm %s -o - | FileCheck %s
+
+
+void f(int m) {
+  int i;
+  int cen[m];
+#pragma omp parallel for
+  for (i = 0; i < m; ++i) {
+    cen[i] = i;
+  }
+}
+
+// CHECK: !DICompositeType(tag: DW_TAG_array_type,
+// CHECK-NOT: size:
+// CHECK-SAME: align: 32
+// CHECK-SAME:                              elements: [[ELEM_TYPE:![0-9]+]]
+// CHECK: !DISubrange(count: -1)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161007/e072c808/attachment-0001.html>


More information about the cfe-commits mailing list