Peter Conn
2014-Apr-14 13:35 UTC
[LLVMdev] Prevent sizeof being replaced by a constant in IR
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 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140414/495c49cc/attachment.html>
Krzysztof Parzyszek
2014-Apr-14 13:56 UTC
[LLVMdev] Prevent sizeof being replaced by a constant in IR
On 4/14/2014 8:35 AM, Peter Conn 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"sizeof" _is_ a constant. The technique from the note only works for aggregates that end with an array (or arrays themselves). -Krzysztof -- Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
Reid Kleckner
2014-Apr-14 17:33 UTC
[LLVMdev] Prevent sizeof being replaced by a constant in IR
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>