<div dir="ltr">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.</div><br><div class="gmail_quote"><div dir="ltr">On Fri, 14 Dec 2018 at 14:25, Erich Keane 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">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" rel="noreferrer" 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" rel="noreferrer" 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" rel="noreferrer" 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" rel="noreferrer" 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" rel="noreferrer" 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" rel="noreferrer" 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" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
</blockquote></div>