<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:Wingdings;
panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman",serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
span.EmailStyle17
{mso-style-type:personal;
font-family:"Calibri",sans-serif;
color:#1F497D;}
span.EmailStyle18
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:#1F497D;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal" style="margin-left:.5in"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">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.<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in"><a name="_MailEndCompose"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></a></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal" style="margin-left:.5in"><b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> Keane, Erich
<br>
<b>Sent:</b> Friday, October 7, 2016 11:56 AM<br>
<b>To:</b> 'David Blaikie' <dblaikie@gmail.com>; reviews+D25373+public+d8ec2a4bb41b17c6@reviews.llvm.org; cfe-commits@lists.llvm.org; david.majnemer@gmail.com; 'Alexey Bataev' <a.bataev@hotmail.com><br>
<b>Cc:</b> junbuml@codeaurora.org<br>
<b>Subject:</b> RE: [PATCH] D25373: Fix for Bug 30639: CGDebugInfo Null dereference with OpenMP array access<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal" style="margin-left:.5in"><o:p> </o:p></p>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Added Alexey to the list, he’s the OMP Maintainer, so hopefully he knows better
</span><span style="font-size:11.0pt;font-family:Wingdings;color:#1F497D">J</span><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in"><b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> David Blaikie [<a href="mailto:dblaikie@gmail.com">mailto:dblaikie@gmail.com</a>]
<br>
<b>Sent:</b> Friday, October 7, 2016 11:51 AM<br>
<b>To:</b> <a href="mailto:reviews+D25373+public+d8ec2a4bb41b17c6@reviews.llvm.org">
reviews+D25373+public+d8ec2a4bb41b17c6@reviews.llvm.org</a>; Keane, Erich <<a href="mailto:erich.keane@intel.com">erich.keane@intel.com</a>>;
<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a>; <a href="mailto:david.majnemer@gmail.com">
david.majnemer@gmail.com</a>; <a href="mailto:guy.benyei@intel.com">guy.benyei@intel.com</a><br>
<b>Cc:</b> <a href="mailto:junbuml@codeaurora.org">junbuml@codeaurora.org</a><br>
<b>Subject:</b> Re: [PATCH] D25373: Fix for Bug 30639: CGDebugInfo Null dereference with OpenMP array access<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in"><o:p> </o:p></p>
<div>
<p class="MsoNormal" style="margin-left:.5in">Could you explain how/why there's a null size expr? I would've thought it must have /some/ size for code generation purposes...<o:p></o:p></p>
</div>
<p class="MsoNormal" style="margin-left:.5in"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal" style="margin-left:.5in">On Fri, Oct 7, 2016 at 11:33 AM Erich Keane <<a href="mailto:erich.keane@intel.com">erich.keane@intel.com</a>> wrote:<o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0in;margin-bottom:5.0pt">
<p class="MsoNormal" style="mso-margin-top-alt:0in;margin-right:0in;margin-bottom:12.0pt;margin-left:.5in">
erichkeane created this revision.<br>
erichkeane added reviewers: cfe-commits, dblaikie, majnemer, gbenyei.<br>
erichkeane set the repository for this revision to rL LLVM.<br>
<br>
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.<br>
<br>
<br>
Repository:<br>
rL LLVM<br>
<br>
<a href="https://reviews.llvm.org/D25373" target="_blank">https://reviews.llvm.org/D25373</a><br>
<br>
Files:<br>
lib/CodeGen/CGDebugInfo.cpp<br>
test/CodeGenCXX/debug-info-openmp-array.cpp<br>
<br>
<br>
Index: lib/CodeGen/CGDebugInfo.cpp<br>
===================================================================<br>
--- lib/CodeGen/CGDebugInfo.cpp<br>
+++ lib/CodeGen/CGDebugInfo.cpp<br>
@@ -2181,7 +2181,8 @@<br>
Count = CAT->getSize().getZExtValue();<br>
else if (const auto *VAT = dyn_cast<VariableArrayType>(Ty)) {<br>
llvm::APSInt V;<br>
- if (VAT->getSizeExpr()->EvaluateAsInt(V, CGM.getContext()))<br>
+ if (VAT->getSizeExpr() &&<br>
+ VAT->getSizeExpr()->EvaluateAsInt(V, CGM.getContext()))<br>
Count = V.getExtValue();<br>
}<br>
<br>
Index: test/CodeGenCXX/debug-info-openmp-array.cpp<br>
===================================================================<br>
--- test/CodeGenCXX/debug-info-openmp-array.cpp<br>
+++ test/CodeGenCXX/debug-info-openmp-array.cpp<br>
@@ -0,0 +1,17 @@<br>
+// RUN: %clang -target x86_64-unknown-unknown -fverbose-asm -fopenmp -g -O0 -S -emit-llvm %s -o - | FileCheck %s<br>
+<br>
+<br>
+void f(int m) {<br>
+ int i;<br>
+ int cen[m];<br>
+#pragma omp parallel for<br>
+ for (i = 0; i < m; ++i) {<br>
+ cen[i] = i;<br>
+ }<br>
+}<br>
+<br>
+// CHECK: !DICompositeType(tag: DW_TAG_array_type,<br>
+// CHECK-NOT: size:<br>
+// CHECK-SAME: align: 32<br>
+// CHECK-SAME: elements: [[ELEM_TYPE:![0-9]+]]<br>
+// CHECK: !DISubrange(count: -1)<o:p></o:p></p>
</blockquote>
</div>
</div>
</body>
</html>