[LLVMdev] Prevent sizeof being replaced by a constant in IR

Reid Kleckner rnk at google.com
Mon Apr 14 10:33:56 PDT 2014


No, there is no such clang option to control this.

Even if there were, the size would bleed through in lots of other places.
 For example, C++ features like templates and constexpr will require baking
in these sizes.

I also doubt LLVM IR supports array dimensions that aren't constant ints,
so the following code would have to use a constant:
struct foo { ... };
foo a1[NUMBER];
foo a2[sizeof(a1) / sizeof(foo)];


On Mon, Apr 14, 2014 at 6:35 AM, Peter Conn <conn.peter at gmail.com> wrote:

> Hello,
>
> Using the following command:
>
> clang -O0 -S -emit-llvm size.c
>
> Will generate an LLVM IR file where uses of 'sizeof' have been replaced by
> constants. Is there any way to prevent this, and perhaps leave the
> 'sizeof's replaced by GEPs as detailed here:
> http://nondot.org/sabre/LLVMNotes/SizeOf-OffsetOf-VariableSizedStructs.txt
>
> Thanks,
> Peter
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140414/6d8e030f/attachment.html>


More information about the llvm-dev mailing list