<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">On 4/15/14, 5:41 AM, Jera Hensel wrote:<br>
</div>
<blockquote
cite="mid:41D4278E-3DA5-43F9-9F86-C0BD992D8B23@gmail.com"
type="cite">
<meta http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1">
<div class="BodyFragment"><font size="2"><span
style="font-size:10pt;">
<div class="PlainText">Hello,<br>
<br>
I am currently writing my Master's Thesis on a topic
regarding the analysis of memory safety and termination of
LLVM programs. </div>
</span></font></div>
</blockquote>
<br>
<font size="2">Cool. Have you checked out the Memory Safety
Menagerie? <a class="moz-txt-link-freetext" href="http://sva.cs.illinois.edu/menagerie/">http://sva.cs.illinois.edu/menagerie/</a><br>
<br>
</font>
<blockquote
cite="mid:41D4278E-3DA5-43F9-9F86-C0BD992D8B23@gmail.com"
type="cite">
<div class="BodyFragment"><font size="2"><span
style="font-size:10pt;">
<div class="PlainText">This includes alignments in LLVM IR,
but I am not sure if I understand their semantics
correctly. I have written a program (see attachment) which
uses the instruction<br>
<br>
store i32 1, i32* %7, align 4<br>
<br>
to store an integer at an address that I forced to be
uneven, and compiled it with clang. The result is that the
integer is stored exactly there, which I expected for
alignment 1 but not for alignment 4. Changing the
alignment to any other size does not have any effect.<br>
<br>
This leads to my questions:<br>
<br>
- Do alignments provide additional semantics to be obeyed
by the compiler or are they just hints that can be
ignored?<br>
</div>
</span></font></div>
</blockquote>
<br>
<font size="2">According to the language reference manual, having a
dynamic pointer value that isn't aligned at the specified
alignment is undefined behavior. The alignment is designed as a
hint to the code generator that it can assume that the address
will be at the specified alignment so that it can generate more
efficient code. This is useful on processors that have different
memory access instructions for different word sizes (I think ARM
is an example; I am sure there are others).<br>
<br>
<br>
</font>
<blockquote
cite="mid:41D4278E-3DA5-43F9-9F86-C0BD992D8B23@gmail.com"
type="cite">
<div class="BodyFragment"><font size="2"><span
style="font-size:10pt;">
<div class="PlainText">
- What is the semantics of alignments from the perspective
of an IR analyzer as opposed to an IR emitter?<br>
</div>
</span></font></div>
</blockquote>
<br>
<font size="2">From your perspective, there's undefined behavior if
the address in the load or store isn't aligned at the proper
boundary. That said, you can probably cheat a little bit and look
at what the code generator will do. On x86, for example, the
alignment probably doesn't matter as nearly all x86 memory access
instructions can access any alignment; the memory access may
simply be slower than necessary.<br>
<br>
</font>
<blockquote
cite="mid:41D4278E-3DA5-43F9-9F86-C0BD992D8B23@gmail.com"
type="cite">
<div class="BodyFragment"><font size="2"><span
style="font-size:10pt;">
<div class="PlainText">
- Can you give me an example where wrong alignments lead
to undefined behavior?<br>
</div>
</span></font></div>
</blockquote>
<br>
<font size="2">On some processors, there are different memory access
instructions for accessing memory of difference sizes and
alignments. Using an address that isn't aligned properly would
cause a fault. I think ARM does this.<br>
<br>
Regards,<br>
<br>
John Criswell<br>
<br>
</font>
<blockquote
cite="mid:41D4278E-3DA5-43F9-9F86-C0BD992D8B23@gmail.com"
type="cite">
<div class="BodyFragment"><font size="2"><span
style="font-size:10pt;">
<div class="PlainText">
<br>
Kind regards,<br>
Jera<br>
<br>
</div>
</span></font></div>
<div class="BodyFragment"><font size="2"><span
style="font-size:10pt;">
<div class="PlainText">_______________________________________________<br>
LLVM Developers mailing list<br>
<a class="moz-txt-link-abbreviated" href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a> <a moz-do-not-send="true"
href="http://llvm.cs.uiuc.edu">http://llvm.cs.uiuc.edu</a><br>
<a moz-do-not-send="true"
href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
</div>
</span></font></div>
</blockquote>
<br>
</body>
</html>