]> granicus.if.org Git - clang/commitdiff
Add an assert to further check the invariant that a null pointer
authorChandler Carruth <chandlerc@gmail.com>
Fri, 4 Nov 2016 06:11:54 +0000 (06:11 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Fri, 4 Nov 2016 06:11:54 +0000 (06:11 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@285982 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExprObjC.cpp

index d208a322c83fc9fc71fbb7796c99d707f8027a93..e7d0d2f6b03d307037df88ed68cdfa714528a04e 100644 (file)
@@ -2539,6 +2539,10 @@ ExprResult Sema::BuildInstanceMessage(Expr *Receiver,
                                       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 =