<div dir="ltr"><div class="gmail_extra">Why? For more friendly internal error message? Such defensive coding might be good but in this case I feel like they will really never fail (or something seriously wrong is going on in the driver).</div>

<div class="gmail_extra"><br></div><div class="gmail_extra"><div class="gmail_quote">On Tue, Apr 1, 2014 at 11:20 AM, Shankar Easwaran <span dir="ltr"><<a href="mailto:shankare@codeaurora.org" target="_blank">shankare@codeaurora.org</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">We should assert if dyn_cast fails, which would catch issues in the Driver.<div class="HOEnZb"><div class="h5"><br>
<br>
On 4/1/2014 1:04 PM, Rui Ueyama wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Author: ruiu<br>
Date: Tue Apr  1 13:04:56 2014<br>
New Revision: 205332<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=205332&view=rev" target="_blank">http://llvm.org/viewvc/llvm-<u></u>project?rev=205332&view=rev</a><br>
Log:<br>
s/dyn_cast/cast/ where return value should never be null.<br>
<br>
cast<X> asserts the type is correct and does not return null on failure.<br>
So we should use cast<X> rather than dyn_cast<X> at such places where we<br>
don't expect type conversion could fail.<br>
<br>
Modified:<br>
     lld/trunk/lib/Driver/<u></u>GnuLdDriver.cpp<br>
     lld/trunk/lib/Driver/<u></u>WinLinkDriver.cpp<br>
     lld/trunk/unittests/<u></u>DriverTests/DriverTest.h<br>
<br>
Modified: lld/trunk/lib/Driver/<u></u>GnuLdDriver.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/GnuLdDriver.cpp?rev=205332&r1=205331&r2=205332&view=diff" target="_blank">http://llvm.org/viewvc/llvm-<u></u>project/lld/trunk/lib/Driver/<u></u>GnuLdDriver.cpp?rev=205332&r1=<u></u>205331&r2=205332&view=diff</a><br>


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


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


==============================<u></u>==============================<u></u>==================<br>
--- lld/trunk/unittests/<u></u>DriverTests/DriverTest.h (original)<br>
+++ lld/trunk/unittests/<u></u>DriverTests/DriverTest.h Tue Apr  1 13:04:56 2014<br>
@@ -35,7 +35,7 @@ protected:<br>
    std::string inputFile(int index) {<br>
      const InputElement &inputElement = linkingContext()->inputGraph()<u></u>[index];<br>
      if (inputElement.kind() == InputElement::Kind::File)<br>
-      return *dyn_cast<FileNode>(&<u></u>inputElement)->getPath(*<u></u>linkingContext());<br>
+      return *cast<FileNode>(&inputElement)<u></u>->getPath(*linkingContext());<br>
      llvm_unreachable("not handling other types of input files");<br>
    }<br>
  <br>
<br>
______________________________<u></u>_________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/<u></u>mailman/listinfo/llvm-commits</a><br>
<br>
<br>
</blockquote>
<br>
<br></div></div><span class="HOEnZb"><font color="#888888">
-- <br>
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by the Linux Foundation<br>
<br>
</font></span></blockquote></div><br></div></div>