]> granicus.if.org Git - clang/commitdiff
Driver: Fix use of dangling std::string temporary
authorBenjamin Kramer <benny.kra@googlemail.com>
Wed, 18 Feb 2015 18:45:54 +0000 (18:45 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Wed, 18 Feb 2015 18:45:54 +0000 (18:45 +0000)
What's going on here is that the ternary operator produces a std::string rvalue
that the StringRef points to. I'd hoped bugs like this were a thing of the past
with our asan testing but apparently this code path is only used when LLVM is
configured with a custom --with-c-include-dirs setting.

Unbreaks bootstrapping with GCC5 on Fedora (PR22625), patch by Jonathan Wakely!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@229719 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Driver/ToolChains.cpp

index 845500bf98f5cf2d077f41599833a7e7d7b50eca..579759e77721f8b49c9d277f181d33b6eac31074 100644 (file)
@@ -3154,7 +3154,8 @@ void Linux::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
     SmallVector<StringRef, 5> dirs;
     CIncludeDirs.split(dirs, ":");
     for (StringRef dir : dirs) {
-      StringRef Prefix = llvm::sys::path::is_absolute(dir) ? SysRoot : "";
+      StringRef Prefix =
+          llvm::sys::path::is_absolute(dir) ? StringRef(SysRoot) : "";
       addExternCSystemInclude(DriverArgs, CC1Args, Prefix + dir);
     }
     return;