r213265 - Using a std::string instead of a StringRef because the Default case synthesizes a temporary std::string from a Twine. Assigning that into a StringRef causes the StringRef to refer to a temporary, and bad things happen.

Alp Toker alp at nuanti.com
Thu Jul 17 07:03:35 PDT 2014


On 17/07/2014 16:28, Aaron Ballman wrote:
> Author: aaronballman
> Date: Thu Jul 17 08:28:50 2014
> New Revision: 213265
>
> URL: http://llvm.org/viewvc/llvm-project?rev=213265&view=rev
> Log:
> Using a std::string instead of a StringRef because the Default case synthesizes a temporary std::string from a Twine. Assigning that into a StringRef causes the StringRef to refer to a temporary, and bad things happen.
>
> This fixes a failing test case on Windows.
>
> Modified:
>      cfe/trunk/lib/Driver/Tools.cpp
>
> Modified: cfe/trunk/lib/Driver/Tools.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=213265&r1=213264&r2=213265&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Driver/Tools.cpp (original)
> +++ cfe/trunk/lib/Driver/Tools.cpp Thu Jul 17 08:28:50 2014
> @@ -1037,12 +1037,12 @@ static void getMIPSTargetFeatures(const
>     ABIName = getGnuCompatibleMipsABIName(ABIName);
>   
>     // Always override the backend's default ABI.
> -  StringRef ABIFeature = llvm::StringSwitch<StringRef>(ABIName)
> -                              .Case("32", "+o32")
> -                              .Case("n32", "+n32")
> -                              .Case("64", "+n64")
> -                              .Case("eabi", "+eabi")
> -                              .Default(("+" + ABIName).str());
> +  std::string ABIFeature = llvm::StringSwitch<StringRef>(ABIName)
> +                               .Case("32", "+o32")
> +                               .Case("n32", "+n32")
> +                               .Case("64", "+n64")
> +                               .Case("eabi", "+eabi")
> +                               .Default(("+" + ABIName).str());

Is the optimizer smart enough to eliminate the evaluation of that str() 
call or will the string be built and discarded every time the 
StringSwitch is run?


>     Features.push_back("-o32");
>     Features.push_back("-n64");
>     Features.push_back(Args.MakeArgString(ABIFeature));
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

-- 
http://www.nuanti.com
the browser experts




More information about the cfe-commits mailing list