[lld] r207690 - [ELF] Return result from the function ASAP.

Reid Kleckner rnk at google.com
Wed Apr 30 12:55:33 PDT 2014


On Wed, Apr 30, 2014 at 12:03 PM, Simon Atanasyan <simon at atanasyan.com>wrote:

> Author: atanasyan
> Date: Wed Apr 30 14:03:56 2014
> New Revision: 207690
>
> URL: http://llvm.org/viewvc/llvm-project?rev=207690&view=rev
> Log:
> [ELF] Return result from the function ASAP.
>
> No functional changes.
>
> Modified:
>     lld/trunk/lib/ReaderWriter/ELF/ELFLinkingContext.cpp
>
> Modified: lld/trunk/lib/ReaderWriter/ELF/ELFLinkingContext.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ELFLinkingContext.cpp?rev=207690&r1=207689&r2=207690&view=diff
>
> ==============================================================================
> --- lld/trunk/lib/ReaderWriter/ELF/ELFLinkingContext.cpp (original)
> +++ lld/trunk/lib/ReaderWriter/ELF/ELFLinkingContext.cpp Wed Apr 30
> 14:03:56 2014
> @@ -226,30 +226,20 @@ static void buildSearchPath(SmallString<
>  }
>
>  ErrorOr<StringRef> ELFLinkingContext::searchLibrary(StringRef libName)
> const {
> -  bool foundFile = false;
> -  StringRef pathref;
>    SmallString<128> path;
>    for (StringRef dir : _inputSearchPaths) {
>      // Search for dynamic library
>      if (!_isStaticExecutable) {
>        buildSearchPath(path, dir, _sysrootPath);
>        llvm::sys::path::append(path, Twine("lib") + libName + ".so");
> -      pathref = path.str();
> -      if (llvm::sys::fs::exists(pathref)) {
> -        foundFile = true;
> -      }
> +      if (llvm::sys::fs::exists(path.str()))
> +        return StringRef(*new (_allocator) std::string(path.str()));
>

I don't think this commit introduces a leak, but how does this not leak
memory?  BumpPtrAllocator doesn't call the destructors of things allocated
in it.


>      }
>      // Search for static libraries too
> -    if (!foundFile) {
> -      buildSearchPath(path, dir, _sysrootPath);
> -      llvm::sys::path::append(path, Twine("lib") + libName + ".a");
> -      pathref = path.str();
> -      if (llvm::sys::fs::exists(pathref)) {
> -        foundFile = true;
> -      }
> -    }
> -    if (foundFile)
> -      return StringRef(*new (_allocator) std::string(pathref));
> +    buildSearchPath(path, dir, _sysrootPath);
> +    llvm::sys::path::append(path, Twine("lib") + libName + ".a");
> +    if (llvm::sys::fs::exists(path.str()))
> +      return StringRef(*new (_allocator) std::string(path.str()));
>    }
>    if (!llvm::sys::fs::exists(libName))
>      return llvm::make_error_code(llvm::errc::no_such_file_or_directory);
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140430/09c1f069/attachment.html>


More information about the llvm-commits mailing list