[cfe-commits] r138662 - in /cfe/trunk: include/clang/Driver/Driver.h lib/Driver/Driver.cpp lib/Driver/Tools.cpp
Benjamin Kramer
benny.kra at googlemail.com
Fri Aug 26 14:52:20 PDT 2011
On Fri, Aug 26, 2011 at 14:28, Chad Rosier <mcrosier at apple.com> wrote:
> Author: mcrosier
> Date: Fri Aug 26 16:28:44 2011
> New Revision: 138662
>
> URL: http://llvm.org/viewvc/llvm-project?rev=138662&view=rev
> Log:
> [driver] When generating temporary files allow a prefix to be added. In many
> cases we want the prefix to be the original file name less the suffix. For an
> input such as test.c to named temporary would be something like test-3O4Clq.o
> Part of <rdar://problem/8314451>
>
> Modified:
> cfe/trunk/include/clang/Driver/Driver.h
> cfe/trunk/lib/Driver/Driver.cpp
> cfe/trunk/lib/Driver/Tools.cpp
>
> Modified: cfe/trunk/include/clang/Driver/Driver.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Driver.h?rev=138662&r1=138661&r2=138662&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Driver/Driver.h (original)
> +++ cfe/trunk/include/clang/Driver/Driver.h Fri Aug 26 16:28:44 2011
> @@ -373,11 +373,11 @@
> const char *BaseInput,
> bool AtTopLevel) const;
>
> - /// GetTemporaryPath - Return the pathname of a temporary file to
> - /// use as part of compilation; the file will have the given suffix.
> + /// GetTemporaryPath - Return the pathname of a temporary file to use
> + /// as part of compilation; the file will have the given prefix and suffix.
> ///
> /// GCC goes to extra lengths here to be a bit more robust.
> - std::string GetTemporaryPath(const char *Suffix) const;
> + std::string GetTemporaryPath(const char *Prefix, const char *Suffix) const;
>
> /// GetHostInfo - Construct a new host info object for the given
> /// host triple.
>
> Modified: cfe/trunk/lib/Driver/Driver.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=138662&r1=138661&r2=138662&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Driver/Driver.cpp (original)
> +++ cfe/trunk/lib/Driver/Driver.cpp Fri Aug 26 16:28:44 2011
> @@ -1335,6 +1335,15 @@
> }
> }
>
> +// Strip the directory and suffix from BaseInput.
> +static const char *getBaseName (const char *BaseInput) {
> + std::pair<StringRef, StringRef> Split = StringRef(BaseInput).rsplit('/');
> + if (Split.second != "")
> + return Split.second.split('.').first.str().c_str();
> + else
> + return Split.first.split('.').first.str().c_str();
> +}
This is a bug, the temporary from str() is free'd before the function
returns, so it will return a dangling pointer.
Please change this to return a StringRef is possible, which makes
slicing strings cheap and safer. I also think we already have a
function that does this somewhere in llvm::sys::path (see
llvm/include/llvm/Support/PathV2.h)
- Ben
More information about the cfe-commits
mailing list