<div dir="ltr">I have a patch I put together a while back as an attempt to fix a different bug, that creates a new CastKind for this operation (didn't work out there, but it might do so here). I'll dig it out and mail it to you in case it's a useful starting point.</div><br><div class="gmail_quote"><div dir="ltr">On Fri, 14 Dec 2018 at 14:42, Keane, Erich via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">





<div lang="EN-US" link="blue" vlink="purple">
<div class="m_2001087958823220955WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">Alright, no problem.  I’ll push a revert in a few minutes and give it another try.  Perhaps I can suppress the creation of a CK_LValueToRValue in the case where
 it’s a read from nullptr_t<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><a name="m_2001087958823220955__MailEndCompose"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><u></u> <u></u></span></a></p>
<p class="MsoNormal"><a name="m_2001087958823220955______replyseparator"></a><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"> Richard Smith [mailto:<a href="mailto:richard@metafoo.co.uk" target="_blank">richard@metafoo.co.uk</a>]
<br>
<b>Sent:</b> Friday, December 14, 2018 2:41 PM<br>
<b>To:</b> Keane, Erich <<a href="mailto:erich.keane@intel.com" target="_blank">erich.keane@intel.com</a>><br>
<b>Cc:</b> cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>><br>
<b>Subject:</b> Re: r349201 - Add extension to always default-initialize nullptr_t.<u></u><u></u></span></p>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<p class="MsoNormal">Sorry, I was late with my review comment. I think this is the wrong way to approach this problem. This does not "fix all situations where nullptr_t would seem uninitialized", and it makes our AST representation lose source fidelity.<u></u><u></u></p>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal">On Fri, 14 Dec 2018 at 14:25, Erich Keane via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>> wrote:<u></u><u></u></p>
</div>
<blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<p class="MsoNormal">Author: erichkeane<br>
Date: Fri Dec 14 14:22:29 2018<br>
New Revision: 349201<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=349201&view=rev" target="_blank">
http://llvm.org/viewvc/llvm-project?rev=349201&view=rev</a><br>
Log:<br>
Add extension to always default-initialize nullptr_t.<br>
<br>
Core issue 1013 suggests that having an uninitialied std::nullptr_t be<br>
UB is a bit foolish, since there is only a single valid value. This DR<br>
reports that DR616 fixes it, which does so by making lvalue-to-rvalue<br>
conversions from nullptr_t be equal to nullptr.<br>
<br>
However, just implementing that results in warnings/etc in many places.<br>
In order to fix all situations where nullptr_t would seem uninitialized,<br>
this patch instead (as an otherwise transparent extension) default<br>
initializes uninitialized VarDecls of nullptr_t.<br>
<br>
Differential Revision: <a href="https://reviews.llvm.org/D53713" target="_blank">
https://reviews.llvm.org/D53713</a><br>
<br>
Change-Id: I84d72a9290054fa55341e8cbdac43c8e7f25b885<br>
<br>
Added:<br>
    cfe/trunk/test/SemaCXX/nullptr_t-init.cpp   (with props)<br>
Modified:<br>
    cfe/trunk/lib/Sema/SemaInit.cpp<br>
    cfe/trunk/test/Analysis/nullptr.cpp<br>
    cfe/trunk/test/SemaCXX/ast-print-crash.cpp<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaInit.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=349201&r1=349200&r2=349201&view=diff" target="_blank">
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=349201&r1=349200&r2=349201&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaInit.cpp Fri Dec 14 14:22:29 2018<br>
@@ -4881,6 +4881,13 @@ static void TryDefaultInitialization(Sem<br>
     return;<br>
   }<br>
<br>
+  // As an extension, and to fix Core issue 1013, zero initialize nullptr_t.<br>
+  // Since there is only 1 valid value of nullptr_t, we can just use that.<br>
+  if (DestType->isNullPtrType()) {<br>
+    Sequence.AddZeroInitializationStep(Entity.getType());<br>
+    return;<br>
+  }<br>
+<br>
   //     - otherwise, no initialization is performed.<br>
<br>
   //   If a program calls for the default initialization of an object of<br>
<br>
Modified: cfe/trunk/test/Analysis/nullptr.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/nullptr.cpp?rev=349201&r1=349200&r2=349201&view=diff" target="_blank">
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/nullptr.cpp?rev=349201&r1=349200&r2=349201&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/Analysis/nullptr.cpp (original)<br>
+++ cfe/trunk/test/Analysis/nullptr.cpp Fri Dec 14 14:22:29 2018<br>
@@ -125,21 +125,16 @@ struct Type {<br>
 };<br>
<br>
 void shouldNotCrash() {<br>
-  decltype(nullptr) p; // expected-note{{'p' declared without an initial value}}<br>
-  if (getSymbol()) // expected-note   {{Assuming the condition is false}}<br>
-                   // expected-note@-1{{Taking false branch}}<br>
-                   // expected-note@-2{{Assuming the condition is false}}<br>
-                   // expected-note@-3{{Taking false branch}}<br>
-                   // expected-note@-4{{Assuming the condition is true}}<br>
-                   // expected-note@-5{{Taking true branch}}<br>
-    invokeF(p); // expected-warning{{1st function call argument is an uninitialized value}}<br>
-                // expected-note@-1{{1st function call argument is an uninitialized value}}<br>
+  decltype(nullptr) p; // expected-note{{'p' initialized to a null pointer value}}<br>
   if (getSymbol()) // expected-note   {{Assuming the condition is false}}<br>
                    // expected-note@-1{{Taking false branch}}<br>
                    // expected-note@-2{{Assuming the condition is true}}<br>
                    // expected-note@-3{{Taking true branch}}<br>
-    invokeF(nullptr); // expected-note   {{Calling 'invokeF'}}<br>
-                      // expected-note@-1{{Passing null pointer value via 1st parameter 'x'}}<br>
+    invokeF(p); // expected-note{{Passing null pointer value via 1st parameter 'x'}}<br>
+                // expected-note@-1{{Calling 'invokeF'}}<br>
+  if (getSymbol()) // expected-note   {{Assuming the condition is false}}<br>
+                   // expected-note@-1{{Taking false branch}}<br>
+    invokeF(nullptr);<br>
   if (getSymbol()) {  // expected-note  {{Assuming the condition is true}}<br>
                       // expected-note@-1{{Taking true branch}}<br>
     X *xx = Type().x; // expected-note   {{Null pointer value stored to field 'x'}}<br>
<br>
Modified: cfe/trunk/test/SemaCXX/ast-print-crash.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/ast-print-crash.cpp?rev=349201&r1=349200&r2=349201&view=diff" target="_blank">
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/ast-print-crash.cpp?rev=349201&r1=349200&r2=349201&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/SemaCXX/ast-print-crash.cpp (original)<br>
+++ cfe/trunk/test/SemaCXX/ast-print-crash.cpp Fri Dec 14 14:22:29 2018<br>
@@ -7,6 +7,6 @@<br>
<br>
 // CHECK:      struct {<br>
 // CHECK-NEXT: } dont_crash_on_syntax_error;<br>
-// CHECK-NEXT: decltype(nullptr) p;<br>
+// CHECK-NEXT: decltype(nullptr) p(/*implicit*/(decltype(nullptr))0);<br>
 struct {<br>
 } dont_crash_on_syntax_error /* missing ; */ decltype(nullptr) p;<br>
<br>
Added: cfe/trunk/test/SemaCXX/nullptr_t-init.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/nullptr_t-init.cpp?rev=349201&view=auto" target="_blank">
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/nullptr_t-init.cpp?rev=349201&view=auto</a><br>
==============================================================================<br>
--- cfe/trunk/test/SemaCXX/nullptr_t-init.cpp (added)<br>
+++ cfe/trunk/test/SemaCXX/nullptr_t-init.cpp Fri Dec 14 14:22:29 2018<br>
@@ -0,0 +1,10 @@<br>
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -ffreestanding -Wuninitialized %s<br>
+// expected-no-diagnostics<br>
+typedef decltype(nullptr) nullptr_t;<br>
+<br>
+// Ensure no 'uninitialized when used here' warnings (Wuninitialized), for <br>
+// nullptr_t always-initialized extension.<br>
+nullptr_t default_init() {<br>
+  nullptr_t a;<br>
+  return a;<br>
+}<br>
<br>
Propchange: cfe/trunk/test/SemaCXX/nullptr_t-init.cpp<br>
------------------------------------------------------------------------------<br>
    svn:eol-style = native<br>
<br>
Propchange: cfe/trunk/test/SemaCXX/nullptr_t-init.cpp<br>
------------------------------------------------------------------------------<br>
    svn:keywords = "Author Date Id Rev URL"<br>
<br>
Propchange: cfe/trunk/test/SemaCXX/nullptr_t-init.cpp<br>
------------------------------------------------------------------------------<br>
    svn:mime-type = text/plain<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><u></u><u></u></p>
</blockquote>
</div>
</div>
</div>

_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
</blockquote></div>