<div dir="ltr">I would like to get this into 3.5 to remove the undefined behavior and also to prevent future versions of Clang warning on this when the undefined pointer to bool conversion warning will eventually get improved to catch this. <br>
<div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Jul 31, 2014 at 6:42 PM, Richard Trieu <span dir="ltr"><<a href="mailto:rtrieu@google.com" target="_blank">rtrieu@google.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: rtrieu<br>
Date: Thu Jul 31 20:42:01 2014<br>
New Revision: 214471<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=214471&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=214471&view=rev</a><br>
Log:<br>
Remove this pointer that is converted to bool.  In well-defined contexts, the<br>
this pointer is always non-null.  If the this pointer is null, it is undefined<br>
and the compiler may optimize it away by assuming it is non-null.  The null<br>
checks are pushed into the callers.<br>
<br>
Modified:<br>
    cfe/trunk/lib/Basic/DiagnosticIDs.cpp<br>
<br>
Modified: cfe/trunk/lib/Basic/DiagnosticIDs.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/DiagnosticIDs.cpp?rev=214471&r1=214470&r2=214471&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/DiagnosticIDs.cpp?rev=214471&r1=214470&r2=214471&view=diff</a><br>



==============================================================================<br>
--- cfe/trunk/lib/Basic/DiagnosticIDs.cpp (original)<br>
+++ cfe/trunk/lib/Basic/DiagnosticIDs.cpp Thu Jul 31 20:42:01 2014<br>
@@ -259,14 +259,14 @@ namespace clang {<br>
       /// getDescription - Return the description of the specified custom<br>
       /// diagnostic.<br>
       StringRef getDescription(unsigned DiagID) const {<br>
-        assert(this && DiagID-DIAG_UPPER_LIMIT < DiagInfo.size() &&<br>
+        assert(DiagID - DIAG_UPPER_LIMIT < DiagInfo.size() &&<br>
                "Invalid diagnostic ID");<br>
         return DiagInfo[DiagID-DIAG_UPPER_LIMIT].second;<br>
       }<br>
<br>
       /// getLevel - Return the level of the specified custom diagnostic.<br>
       DiagnosticIDs::Level getLevel(unsigned DiagID) const {<br>
-        assert(this && DiagID-DIAG_UPPER_LIMIT < DiagInfo.size() &&<br>
+        assert(DiagID - DIAG_UPPER_LIMIT < DiagInfo.size() &&<br>
                "Invalid diagnostic ID");<br>
         return DiagInfo[DiagID-DIAG_UPPER_LIMIT].first;<br>
       }<br>
@@ -358,6 +358,7 @@ bool DiagnosticIDs::isDefaultMappingAsEr<br>
 StringRef DiagnosticIDs::getDescription(unsigned DiagID) const {<br>
   if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID))<br>
     return Info->getDescription();<br>
+  assert(CustomDiagInfo && "Invalid CustomDiagInfo");<br>
   return CustomDiagInfo->getDescription(DiagID);<br>
 }<br>
<br>
@@ -384,8 +385,10 @@ DiagnosticIDs::Level<br>
 DiagnosticIDs::getDiagnosticLevel(unsigned DiagID, SourceLocation Loc,<br>
                                   const DiagnosticsEngine &Diag) const {<br>
   // Handle custom diagnostics, which cannot be mapped.<br>
-  if (DiagID >= diag::DIAG_UPPER_LIMIT)<br>
+  if (DiagID >= diag::DIAG_UPPER_LIMIT) {<br>
+    assert(CustomDiagInfo && "Invalid CustomDiagInfo");<br>
     return CustomDiagInfo->getLevel(DiagID);<br>
+  }<br>
<br>
   unsigned DiagClass = getBuiltinDiagClass(DiagID);<br>
   if (DiagClass == CLASS_NOTE) return DiagnosticIDs::Note;<br>
@@ -669,6 +672,7 @@ void DiagnosticIDs::EmitDiag(Diagnostics<br>
<br>
 bool DiagnosticIDs::isUnrecoverable(unsigned DiagID) const {<br>
   if (DiagID >= diag::DIAG_UPPER_LIMIT) {<br>
+    assert(CustomDiagInfo && "Invalid CustomDiagInfo");<br>
     // Custom diagnostics.<br>
     return CustomDiagInfo->getLevel(DiagID) >= DiagnosticIDs::Error;<br>
   }<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu" target="_blank">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div></div>