[lld] r205332 - s/dyn_cast/cast/ where return value should never be null.

Rui Ueyama ruiu at google.com
Tue Apr 1 11:04:56 PDT 2014


Author: ruiu
Date: Tue Apr  1 13:04:56 2014
New Revision: 205332

URL: http://llvm.org/viewvc/llvm-project?rev=205332&view=rev
Log:
s/dyn_cast/cast/ where return value should never be null.

cast<X> asserts the type is correct and does not return null on failure.
So we should use cast<X> rather than dyn_cast<X> at such places where we
don't expect type conversion could fail.

Modified:
    lld/trunk/lib/Driver/GnuLdDriver.cpp
    lld/trunk/lib/Driver/WinLinkDriver.cpp
    lld/trunk/unittests/DriverTests/DriverTest.h

Modified: lld/trunk/lib/Driver/GnuLdDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/GnuLdDriver.cpp?rev=205332&r1=205331&r2=205332&view=diff
==============================================================================
--- lld/trunk/lib/Driver/GnuLdDriver.cpp (original)
+++ lld/trunk/lib/Driver/GnuLdDriver.cpp Tue Apr  1 13:04:56 2014
@@ -432,13 +432,13 @@ bool GnuLdDriver::parse(int argc, const
     case OPT_start_group: {
       std::unique_ptr<InputElement> controlStart(new ELFGroup(*ctx, index++));
       controlNodeStack.push(controlStart.get());
-      dyn_cast<ControlNode>(controlNodeStack.top())->processControlEnter();
+      cast<ControlNode>(controlNodeStack.top())->processControlEnter();
       inputGraph->addInputElement(std::move(controlStart));
       break;
     }
 
     case OPT_end_group:
-      dyn_cast<ControlNode>(controlNodeStack.top())->processControlExit();
+      cast<ControlNode>(controlNodeStack.top())->processControlExit();
       controlNodeStack.pop();
       break;
 
@@ -485,11 +485,12 @@ bool GnuLdDriver::parse(int argc, const
         }
       }
       std::unique_ptr<InputElement> inputFile(inputNode);
-      if (controlNodeStack.empty())
+      if (controlNodeStack.empty()) {
         inputGraph->addInputElement(std::move(inputFile));
-      else
-        dyn_cast<ControlNode>(controlNodeStack.top())
+      } else {
+        cast<ControlNode>(controlNodeStack.top())
             ->processInputElement(std::move(inputFile));
+      }
       break;
     }
 

Modified: lld/trunk/lib/Driver/WinLinkDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/WinLinkDriver.cpp?rev=205332&r1=205331&r2=205332&view=diff
==============================================================================
--- lld/trunk/lib/Driver/WinLinkDriver.cpp (original)
+++ lld/trunk/lib/Driver/WinLinkDriver.cpp Tue Apr  1 13:04:56 2014
@@ -1222,7 +1222,7 @@ bool WinLinkDriver::parse(int argc, cons
   // constructed by replacing an extension of the first input file
   // with ".exe".
   if (ctx.outputPath().empty()) {
-    StringRef path = *dyn_cast<FileNode>(&*files[0])->getPath(ctx);
+    StringRef path = *cast<FileNode>(&*files[0])->getPath(ctx);
     ctx.setOutputPath(replaceExtension(ctx, path, ".exe"));
   }
 

Modified: lld/trunk/unittests/DriverTests/DriverTest.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/unittests/DriverTests/DriverTest.h?rev=205332&r1=205331&r2=205332&view=diff
==============================================================================
--- lld/trunk/unittests/DriverTests/DriverTest.h (original)
+++ lld/trunk/unittests/DriverTests/DriverTest.h Tue Apr  1 13:04:56 2014
@@ -35,7 +35,7 @@ protected:
   std::string inputFile(int index) {
     const InputElement &inputElement = linkingContext()->inputGraph()[index];
     if (inputElement.kind() == InputElement::Kind::File)
-      return *dyn_cast<FileNode>(&inputElement)->getPath(*linkingContext());
+      return *cast<FileNode>(&inputElement)->getPath(*linkingContext());
     llvm_unreachable("not handling other types of input files");
   }
 





More information about the llvm-commits mailing list