r214471 - Remove this pointer that is converted to bool. In well-defined contexts, the
Richard Trieu
rtrieu at google.com
Fri Aug 1 15:06:40 PDT 2014
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.
On Thu, Jul 31, 2014 at 6:42 PM, Richard Trieu <rtrieu at google.com> wrote:
> Author: rtrieu
> Date: Thu Jul 31 20:42:01 2014
> New Revision: 214471
>
> URL: http://llvm.org/viewvc/llvm-project?rev=214471&view=rev
> Log:
> Remove this pointer that is converted to bool. In well-defined contexts,
> the
> this pointer is always non-null. If the this pointer is null, it is
> undefined
> and the compiler may optimize it away by assuming it is non-null. The null
> checks are pushed into the callers.
>
> Modified:
> cfe/trunk/lib/Basic/DiagnosticIDs.cpp
>
> Modified: cfe/trunk/lib/Basic/DiagnosticIDs.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/DiagnosticIDs.cpp?rev=214471&r1=214470&r2=214471&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Basic/DiagnosticIDs.cpp (original)
> +++ cfe/trunk/lib/Basic/DiagnosticIDs.cpp Thu Jul 31 20:42:01 2014
> @@ -259,14 +259,14 @@ namespace clang {
> /// getDescription - Return the description of the specified custom
> /// diagnostic.
> StringRef getDescription(unsigned DiagID) const {
> - assert(this && DiagID-DIAG_UPPER_LIMIT < DiagInfo.size() &&
> + assert(DiagID - DIAG_UPPER_LIMIT < DiagInfo.size() &&
> "Invalid diagnostic ID");
> return DiagInfo[DiagID-DIAG_UPPER_LIMIT].second;
> }
>
> /// getLevel - Return the level of the specified custom diagnostic.
> DiagnosticIDs::Level getLevel(unsigned DiagID) const {
> - assert(this && DiagID-DIAG_UPPER_LIMIT < DiagInfo.size() &&
> + assert(DiagID - DIAG_UPPER_LIMIT < DiagInfo.size() &&
> "Invalid diagnostic ID");
> return DiagInfo[DiagID-DIAG_UPPER_LIMIT].first;
> }
> @@ -358,6 +358,7 @@ bool DiagnosticIDs::isDefaultMappingAsEr
> StringRef DiagnosticIDs::getDescription(unsigned DiagID) const {
> if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID))
> return Info->getDescription();
> + assert(CustomDiagInfo && "Invalid CustomDiagInfo");
> return CustomDiagInfo->getDescription(DiagID);
> }
>
> @@ -384,8 +385,10 @@ DiagnosticIDs::Level
> DiagnosticIDs::getDiagnosticLevel(unsigned DiagID, SourceLocation Loc,
> const DiagnosticsEngine &Diag) const {
> // Handle custom diagnostics, which cannot be mapped.
> - if (DiagID >= diag::DIAG_UPPER_LIMIT)
> + if (DiagID >= diag::DIAG_UPPER_LIMIT) {
> + assert(CustomDiagInfo && "Invalid CustomDiagInfo");
> return CustomDiagInfo->getLevel(DiagID);
> + }
>
> unsigned DiagClass = getBuiltinDiagClass(DiagID);
> if (DiagClass == CLASS_NOTE) return DiagnosticIDs::Note;
> @@ -669,6 +672,7 @@ void DiagnosticIDs::EmitDiag(Diagnostics
>
> bool DiagnosticIDs::isUnrecoverable(unsigned DiagID) const {
> if (DiagID >= diag::DIAG_UPPER_LIMIT) {
> + assert(CustomDiagInfo && "Invalid CustomDiagInfo");
> // Custom diagnostics.
> return CustomDiagInfo->getLevel(DiagID) >= DiagnosticIDs::Error;
> }
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140801/f21d2628/attachment.html>
More information about the cfe-commits
mailing list