[PATCH] D12011: Logically Dead Code

Chakshu Grover via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 13 09:28:06 PDT 2015


chakshugrover created this revision.
chakshugrover added a subscriber: llvm-commits.

Removed Logically Dead Code

```
3373	  const unsigned MaxEditDistance = 1;
3374	  unsigned BestEditDistance = MaxEditDistance + 1;
```
assigns BestEditDistance=2U

```
3382	  if (EditDistance > MaxEditDistance)
3383	    return;
```
As we take false branch after it, so EditDistance is atmost 1U after this check.
```
3384	  if (EditDistance == BestEditDistance)
3385	    BestMethod.push_back(Method);
```
As EditDistance is atmost 1U and BestEditDistance is 2U, So this condition can never be true and can be removed
```
3386	  else if (EditDistance < BestEditDistance) {
```
And this condition is always true so check can be removed.
So in fact BestEditDistance can essentially be completely removed from the code.


http://reviews.llvm.org/D12011

Files:
  lib/Sema/SemaDeclObjC.cpp

Index: lib/Sema/SemaDeclObjC.cpp
===================================================================
--- lib/Sema/SemaDeclObjC.cpp
+++ lib/Sema/SemaDeclObjC.cpp
@@ -3371,7 +3371,6 @@
                       SmallVectorImpl<const ObjCMethodDecl *> &BestMethod,
                       StringRef Typo, const ObjCMethodDecl * Method) {
   const unsigned MaxEditDistance = 1;
-  unsigned BestEditDistance = MaxEditDistance + 1;
   std::string MethodName = Method->getSelector().getAsString();
   
   unsigned MinPossibleEditDistance = abs((int)MethodName.size() - (int)Typo.size());
@@ -3381,12 +3380,8 @@
   unsigned EditDistance = Typo.edit_distance(MethodName, true, MaxEditDistance);
   if (EditDistance > MaxEditDistance)
     return;
-  if (EditDistance == BestEditDistance)
-    BestMethod.push_back(Method);
-  else if (EditDistance < BestEditDistance) {
-    BestMethod.clear();
-    BestMethod.push_back(Method);
-  }
+  BestMethod.clear();
+  BestMethod.push_back(Method);
 }
 
 static bool HelperIsMethodInObjCType(Sema &S, Selector Sel,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D12011.32068.patch
Type: text/x-patch
Size: 1044 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150813/ff1a9c1e/attachment.bin>


More information about the llvm-commits mailing list