[llvm-dev] Alignment of GVMemoryBlocks

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[llvm-dev] Alignment of GVMemoryBlocks

David Jones via llvm-dev
Hello,

Is anyone familiar with the ExecutionEngine, particularly the handling of GVMemoryBlocks?

Line 114 in Create(GV,TD) is suspicious [1]:

  static char *Create(const GlobalVariable *GV, const DataLayout& TD) {
    Type *ElTy = GV->getValueType();
    size_t GVSize = (size_t)TD.getTypeAllocSize(ElTy);
    void *RawMemory = ::operator new(
        alignTo(sizeof(GVMemoryBlock), TD.getPreferredAlignment(GV)) + GVSize);
    new(RawMemory) GVMemoryBlock(GV);
    return static_cast<char*>(RawMemory) + sizeof(GVMemoryBlock); // <— [1]
  }

Example:

Suppose sizeof(GVMemoryBlock) == 3 bytes. Further, assume the preferred TD-alignment is on 4-byte boundaries. Finally, for sake of argument, assume RawMemory points to address 4. Then Create(GV, TD) returns 7, a non-aligned address with respect to the preferred TD-alignment.

Is this expected?

Many thanks for your time!

- Alex


PS

Also, if anyone happens to know, why is the empty ~GVMemoryBlock() destructor explicitly called in the deleted() callback? The last comment left there seems to indicate someone else before me was also puzzled by this :)

_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev