<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;
        mso-fareast-language:EN-US;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;
        mso-fareast-language:EN-US;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-GB" link="#0563C1" vlink="#954F72" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal">Hi,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I have been using Sanitizers/Archer for testing purposes on C,C++ and Fortran test suites. I notice some change in sanitizer behaviour when I add any kind of optimization to it ( O1, O2, Ofast etc). For example, in the following test case:<o:p></o:p></p>
<p class="MsoNormal" style="text-indent:.5in">#include <alloca.h><o:p></o:p></p>
<p class="MsoNormal" style="text-indent:.5in">void foo(int index, int len) {<o:p></o:p></p>
<p class="MsoNormal">                             volatile char *str = (volatile char*)alloca(len);<o:p></o:p></p>
<p class="MsoNormal">                             str[index] = '1';  // Boom!<o:p></o:p></p>
<p class="MsoNormal" style="text-indent:.5in">}<o:p></o:p></p>
<p class="MsoNormal" style="text-indent:.5in">int main(int argc, char **argv) {<o:p></o:p></p>
<p class="MsoNormal">                            foo(-1, 10);<o:p></o:p></p>
<p class="MsoNormal" style="text-indent:.5in">}<o:p></o:p></p>
<p class="MsoNormal">Compiling it with : clang -g -fsanitize=address <i>Test_case.c</i>
<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Gives me ASan report : <o:p></o:p></p>
<p class="MsoNormal" style="text-indent:.5in">==80838==ERROR: AddressSanitizer: dynamic-stack-buffer-overflow on address 0x7ffdd959ac3f at pc 0x00000050ea21 bp 0x7ffdd959ac10 sp 0x7ffdd959ac08<o:p></o:p></p>
<p class="MsoNormal" style="text-indent:.5in">WRITE of size 1 at 0x7ffdd959ac3f thread T0<o:p></o:p></p>
<p class="MsoNormal" style="text-indent:.5in">………..<o:p></o:p></p>
<p class="MsoNormal" style="text-indent:.5in">Address 0x7ffdd959ac3f is located in stack of thread T0<o:p></o:p></p>
<p class="MsoNormal" style="text-indent:.5in">SUMMARY: AddressSanitizer: dynamic-stack-buffer-overflow (/ptmp1/bhararit/new_petest/petest/cc_address_sanitizer.ar/diffs/a.out+0x50ea20)<br>
             ……….<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">But when I compile it with optimization: clang -g -fsanitize=address -O1
<i>Test_case.c</i><o:p></o:p></p>
<p class="MsoNormal">I do not see any Sanitizer report.<br>
<br>
<o:p></o:p></p>
<p class="MsoNormal">Is this an expected behaviour? If yes, should we be disabling optimizations before using sanitizers although the clang document states that O2 or higher level of optimizations can be used to enhance the performance. Lastly, what is the
 default optimization in clang ( is it -O0?)? <br>
<br>
<o:p></o:p></p>
<p class="MsoNormal">It would be very helpful if you could give me more insights on this. Hope to hear from you. Thanks in advance.<br>
<br>
Best Regards,<o:p></o:p></p>
<p class="MsoNormal">Ritanya.<o:p></o:p></p>
</div>
</body>
</html>