[cfe-commits] r156172 - /cfe/trunk/lib/Driver/Driver.cpp

Chad Rosier mcrosier at apple.com
Fri May 4 08:32:05 PDT 2012


Author: mcrosier
Date: Fri May  4 10:32:05 2012
New Revision: 156172

URL: http://llvm.org/viewvc/llvm-project?rev=156172&view=rev
Log:
StringRefize code because we're good even when we crash.
Patch by Jordy Rose.


Modified:
    cfe/trunk/lib/Driver/Driver.cpp

Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=156172&r1=156171&r2=156172&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Fri May  4 10:32:05 2012
@@ -528,12 +528,12 @@
         I += 16;
         E = Cmd.find(" ", I);
         assert (E != std::string::npos && "-main-file-name missing argument?");
-        std::string OldFilename = Cmd.substr(I, E - I);
-        std::string NewFilename = llvm::sys::path::filename(*it).str();
-        I = Cmd.rfind(OldFilename);
-        E = I + OldFilename.length() - 1;
-        I = Cmd.rfind(" ", I);
-        Cmd.replace(I + 1, E - I, NewFilename);
+        StringRef OldFilename = StringRef(Cmd).slice(I, E);
+        StringRef NewFilename = llvm::sys::path::filename(*it);
+        I = StringRef(Cmd).rfind(OldFilename);
+        E = I + OldFilename.size();
+        I = Cmd.rfind(" ", I) + 1;
+        Cmd.replace(I, E - I, NewFilename.data(), NewFilename.size());
         ScriptOS << Cmd;
         Diag(clang::diag::note_drv_command_failed_diag_msg) << Script;
       }





More information about the cfe-commits mailing list