<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">
Dear All,
<div class=""><br class="">
</div>
<div class="">I’m working on a project that extends C. I’m adding a new type of pointer</div>
<div class="">that is a fat pointer. It has some metadata about the pointed object besides</div>
<div class="">the starting address of the object. Currently I implemented this pointer as</div>
<div class="">an llvm:StructType. In llvm::Type generation function</div>
<div class=""><i class="">llvm::Type *CodeGenTypes::ConvertType(QualType T)</i></div>
<div class="">in the case for <i class="">clang::Type::Pointer</i>, instead of creating an llvm::PointerType</div>
<div class="">I create an llvm::StructType type for this new type of pointer. And I added some</div>
<div class="">helper code in llvm::StructType and in multiple places I added code to trick</div>
<div class="">the compiler to believe sometimes a struct is actually a pointer. Until now</div>
<div class="">it compile test programs fine with -O0 but I got lots of assertion failures when</div>
<div class="">compiling with -O1 or -O2 majorly because of the confusion of type mismatch.</div>
<div class=""><br class="">
</div>
<div class="">LLVM assumes that a PointerType is essentially an Integer (32 or 64 bit depending</div>
<div class="">on the architecture), and since this is quite a fundamental assumption, I started</div>
<div class="">to question whether my way of implementing the fat pointer is feasible.</div>
<div class="">I thought about adding a new llvm type that inherits both llvm:PointerType</div>
<div class="">and llvm:StructType; but I’m not sure if this is the correct path. It looks like</div>
<div class="">this demands substantial changes to the compiler including adding code</div>
<div class="">for bitcode generation. Can you give me some advice on how to implement</div>
<div class="">a fat pointer in llvm?</div>
<div class=""><br class="">
</div>
<div class="">Thanks,</div>
<div class="">- Jie</div>
</body>
</html>