[cfe-commits] r156117 - /cfe/trunk/lib/Driver/Driver.cpp
Chad Rosier
mcrosier at apple.com
Fri May 4 08:33:14 PDT 2012
On May 3, 2012, at 8:35 PM, Jordy Rose wrote:
>
> On May 3, 2012, at 18:38, Chad Rosier wrote:
>
>> Author: mcrosier
>> Date: Thu May 3 17:38:00 2012
>> New Revision: 156117
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=156117&view=rev
>> Log:
>> [driver - crash diagnostics] Convert the flags back to an array of strings and use
>> array_lengthof. Also, append the new filename with correct preprocessed suffix.
>> Last part of rdar://11285725
>>
>> 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=156117&r1=156116&r2=156117&view=diff
>> ==============================================================================
>> --- cfe/trunk/lib/Driver/Driver.cpp (original)
>> +++ cfe/trunk/lib/Driver/Driver.cpp Thu May 3 17:38:00 2012
>> @@ -521,7 +521,19 @@
>> Cmd.erase(I, E - I + 1);
>> } while(1);
>> }
>> - // FIXME: Append the new filename with correct preprocessed suffix.
>> + // Append the new filename with correct preprocessed suffix.
>> + size_t I, E;
>> + I = Cmd.find("-main-file-name ");
>> + assert (I != std::string::npos && "Expected to find -main-file-name");
>> + 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);
>> ScriptOS << Cmd;
>> Diag(clang::diag::note_drv_command_failed_diag_msg) << Script;
>> }
>
> There's no reason you can't use StringRef here and avoid the copies.
Committed revision 156172. Thanks, Jordy.
> StringRef OldFilename = StringRef(Cmd).slice(I, E);
> StringRef NewFilename = llvm::sys::path::filename(*it);
> I = StringRef(Cmd).rfind(OldFilename);
> E = I + OldFilename.length();
> I = Cmd.rfind(" ", I) + 1;
> Cmd.replace(I, E-I, NewFilename.data(), NewFilename.size());
>
> Not that it's /so/ expensive, but hey, why not?
>
> Jordy
More information about the cfe-commits
mailing list