r285982 - Add an assert to further check the invariant that a null pointer

Chandler Carruth via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 3 23:11:55 PDT 2016


Author: chandlerc
Date: Fri Nov  4 01:11:54 2016
New Revision: 285982

URL: http://llvm.org/viewvc/llvm-project?rev=285982&view=rev
Log:
Add an assert to further check the invariant that a null pointer
corresponds to another argument being valid.

This makes it clear that the code is correct despite the PVS-Studio
report that a pointer might be dereferenced prior to being checked for
whether it is null. It likely is also enough for static analyzers to not
flag the code.

Modified:
    cfe/trunk/lib/Sema/SemaExprObjC.cpp

Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=285982&r1=285981&r2=285982&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Fri Nov  4 01:11:54 2016
@@ -2539,6 +2539,10 @@ ExprResult Sema::BuildInstanceMessage(Ex
                                       SourceLocation RBracLoc,
                                       MultiExprArg ArgsIn,
                                       bool isImplicit) {
+  assert((Receiver || SuperLoc.isValid()) && "If the Receiver is null, the "
+                                             "SuperLoc must be valid so we can "
+                                             "use it instead.");
+
   // The location of the receiver.
   SourceLocation Loc = SuperLoc.isValid()? SuperLoc : Receiver->getLocStart();
   SourceRange RecRange =




More information about the cfe-commits mailing list