[Polly][PATCH] Use reference to clarify pointer can never be null

Johannes Doerfert doerfert at cs.uni-saarland.de
Sat Apr 18 07:59:30 PDT 2015


On 04/18, Tobias Grosser wrote:
> On 04/18/2015 03:58 PM, Johannes Doerfert wrote:
> >>-const ScopDetection::BoxedLoopsSetTy *
> >>+const ScopDetection::BoxedLoopsSetTy &
> >>  ScopDetection::getBoxedLoops(const Region *R) const {
> >>-  auto BLMIt = BoxedLoopsMap.find(R);
> >>-  if (BLMIt == BoxedLoopsMap.end())
> >>-    return nullptr;
> >>-  return &BLMIt->second;
> >>+  return BoxedLoopsMap.find(R)->second;
> >>  }
> >Are you sure the access of ->second is actually legal if find returns
> >BoxedLoopsMap.end() ?
> 
> My understanding is that we will have such a map for each region that we
> detect. Hence, .find(R) should always be successful.
If called with a region that run through ScopDetect it will be
successful. However, if for whatever reason a valid region that was
skipped or ignored by the ScopDetection is passed to that method it
will most certainly crash.

I do not see the benefit on the reference but only the possible problem
of an undocumented precondition that cannot even be checked.

-- 

Johannes Doerfert
Researcher / PhD Student

Compiler Design Lab (Prof. Hack)
Saarland University, Computer Science
Building E1.3, Room 4.31

Tel. +49 (0)681 302-57521 : doerfert at cs.uni-saarland.de
Fax. +49 (0)681 302-3065  : http://www.cdl.uni-saarland.de/people/doerfert
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 213 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150418/ef4def38/attachment.sig>


More information about the llvm-commits mailing list