[llvm-commits] [llvm] r50880 - in /llvm/trunk/tools/lto2: LTOModule.cpp LTOModule.h
Tanya Lattner
lattner at apple.com
Thu May 8 21:47:53 PDT 2008
Can you add some doxygen style (///) comments for makeBuffer?
Thanks,
Tanya
On May 8, 2008, at 6:09 PM, Nick Kledzik wrote:
> Author: kledzik
> Date: Thu May 8 20:09:59 2008
> New Revision: 50880
>
> URL: http://llvm.org/viewvc/llvm-project?rev=50880&view=rev
> Log:
> <rdar://problem/5917641> use getMemBufferCopy if supplied buffer is
> not already zero terminated
>
> Modified:
> llvm/trunk/tools/lto2/LTOModule.cpp
> llvm/trunk/tools/lto2/LTOModule.h
>
> Modified: llvm/trunk/tools/lto2/LTOModule.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lto2/
> LTOModule.cpp?rev=50880&r1=50879&r2=50880&view=diff
>
> ======================================================================
> ========
> --- llvm/trunk/tools/lto2/LTOModule.cpp (original)
> +++ llvm/trunk/tools/lto2/LTOModule.cpp Thu May 8 20:09:59 2008
> @@ -23,6 +23,7 @@
> #include "llvm/Support/MemoryBuffer.h"
> #include "llvm/Support/MathExtras.h"
> #include "llvm/System/Path.h"
> +#include "llvm/System/Process.h"
> #include "llvm/Target/TargetMachine.h"
> #include "llvm/Target/TargetMachineRegistry.h"
> #include "llvm/Target/TargetAsmInfo.h"
> @@ -46,8 +47,7 @@
> bool LTOModule::isBitcodeFileForTarget(const void* mem, size_t
> length,
> const char* triplePrefix)
> {
> - MemoryBuffer* buffer = MemoryBuffer::getMemBuffer((char*)mem,
> - (char*)mem
> +length);
> + MemoryBuffer* buffer = makeBuffer(mem, length);
> if ( buffer == NULL )
> return false;
> return isTargetMatch(buffer, triplePrefix);
> @@ -91,11 +91,26 @@
> return makeLTOModule(buffer.get(), errMsg);
> }
>
> +
> +MemoryBuffer* LTOModule::makeBuffer(const void* mem, size_t length)
> +{
> + // MemoryBuffer requires the byte past end of the buffer to be a
> zero.
> + // We might get lucky and already be that way, otherwise make a
> copy.
> + // Also if next byte is on a different page, don't assume it is
> readable.
> + const char* startPtr = (char*)mem;
> + const char* endPtr = startPtr+length;
> + if ( (((uintptr_t)endPtr & (sys::Process::GetPageSize()-1)) == 0)
> + || (*endPtr != 0) )
> + return MemoryBuffer::getMemBufferCopy(startPtr, endPtr);
> + else
> + return MemoryBuffer::getMemBuffer(startPtr, endPtr);
> +}
> +
> +
> LTOModule* LTOModule::makeLTOModule(const void* mem, size_t length,
>
> std::string& errMsg)
> {
> - OwningPtr<MemoryBuffer> buffer(MemoryBuffer::getMemBuffer
> ((char*)mem,
> - (char*)
> mem+length));
> + OwningPtr<MemoryBuffer> buffer(makeBuffer(mem, length));
> if ( !buffer )
> return NULL;
> return makeLTOModule(buffer.get(), errMsg);
>
> Modified: llvm/trunk/tools/lto2/LTOModule.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lto2/
> LTOModule.h?rev=50880&r1=50879&r2=50880&view=diff
>
> ======================================================================
> ========
> --- llvm/trunk/tools/lto2/LTOModule.h (original)
> +++ llvm/trunk/tools/lto2/LTOModule.h Thu May 8 20:09:59 2008
> @@ -81,6 +81,7 @@
>
> static LTOModule* makeLTOModule(llvm::MemoryBuffer* buffer,
>
> std::string& errMsg);
> + static llvm::MemoryBuffer* makeBuffer(const void* mem, size_t
> length);
>
> typedef llvm::StringMap<uint8_t> StringSet;
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list