<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>LPCXpresso IDEのトピックRe: Compiler bug</title>
    <link>https://community.nxp.com/t5/LPCXpresso-IDE/Compiler-bug/m-p/596187#M31697</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by starblue on Thu Mar 10 12:58:41 MST 2016&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;You are dereferencing a null pointer, which is undefined behavior. So the compiler is within its rights to generate whatever code it wants, and recent GCC versions have become quite aggressive at this (yes, people are complaining, mostly about signed overflow).&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Its a bit unfortunate if you really want to access address 0, maybe you need to hide your bad intentions better, so the compiler doesn't notice.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 15 Jun 2016 22:56:42 GMT</pubDate>
    <dc:creator>lpcware</dc:creator>
    <dc:date>2016-06-15T22:56:42Z</dc:date>
    <item>
      <title>Compiler bug</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Compiler-bug/m-p/596181#M31691</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by s3-software on Wed Mar 09 16:25:14 MST 2016&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;I found a bug with the compiler generating code with a udf (Undefined Instruction).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The following code does not create valid code for the if statement. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;uint32_t *first_location = 0;
if (*first_location == 0)
__WFI();&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The generated assembler (from the debugger) is:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;00000244:&amp;nbsp;&amp;nbsp; movs&amp;nbsp;&amp;nbsp;&amp;nbsp; r3, #0
00000246:&amp;nbsp;&amp;nbsp; ldr&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; r3, [r3, #0]
00000248:&amp;nbsp;&amp;nbsp; udf&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #255&amp;nbsp;&amp;nbsp;&amp;nbsp; ; 0xff
&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any suggestions?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This was tested with the latest lpcxpresso 8.1.2_603 (as well as earlier 8.0 version), and with LPC1768 and LPC1778 targets, and Os (Size) optimizations.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 22:56:38 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Compiler-bug/m-p/596181#M31691</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T22:56:38Z</dc:date>
    </item>
    <item>
      <title>Re: Compiler bug</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Compiler-bug/m-p/596182#M31692</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by MikeSimmonds on Thu Mar 10 08:46:08 MST 2016&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Of course, the initialisation of the pointer is invalid in that you are setting the &lt;/SPAN&gt;&lt;I&gt;address&lt;/I&gt;&lt;SPAN&gt; of the pointer to zero (and not a valid location).&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;And, therefore, the intended initialisation of the variables &lt;/SPAN&gt;&lt;I&gt;value&lt;/I&gt;&lt;SPAN&gt; to zero never happens.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This does not mean the the generated code is not wrong. It would have been useful to see exactly what the generated&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;op-code bytes actually are. [Is there now an option in the assembler window for this?]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Probably, the intended instruction is slightly 'off' with the operands or similar leading to an undefined variation.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers, Mike.&lt;/SPAN&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 22:56:39 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Compiler-bug/m-p/596182#M31692</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T22:56:39Z</dc:date>
    </item>
    <item>
      <title>Re: Compiler bug</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Compiler-bug/m-p/596183#M31693</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by s3-software on Thu Mar 10 09:07:06 MST 2016&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;The intention of the code is actually to look at location zero, as the code is using the IAP flash utilities to rewrite the flash, and sometimes the flash is not erased, so the code it looking at location zero to check.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is the intermediate file for the assembler&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;&amp;nbsp; 50 0014 0023&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; movsr3, #0
&amp;nbsp; 51 0016 1B68&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ldrr3, [r3]
&amp;nbsp; 52 0018 FFDE&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .inst0xdeff
&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This also generates an invalid opcode.&amp;nbsp; Very strange!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 22:56:39 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Compiler-bug/m-p/596183#M31693</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T22:56:39Z</dc:date>
    </item>
    <item>
      <title>Re: Compiler bug</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Compiler-bug/m-p/596184#M31694</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by vtw.433e on Thu Mar 10 09:46:35 MST 2016&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Maybe an unexpected bug in your code?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Try&lt;/SPAN&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;volatile uint32_t * volatile first_location = 0;
if (*first_location == 0)
__WFI();
&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;SPAN&gt;[Works for me]&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 22:56:40 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Compiler-bug/m-p/596184#M31694</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T22:56:40Z</dc:date>
    </item>
    <item>
      <title>Re: Compiler bug</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Compiler-bug/m-p/596185#M31695</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by MikeSimmonds on Thu Mar 10 09:46:50 MST 2016&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;According to the Arm Architecture Manual v7M, the top 5 bits being '11111' indicate the 1st 16-bit word of a 32 bit instruction.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The listing is seems to be incomplete (maybe that is where the bug is).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;FFDE matches neither of the two encodings for WFI.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I would have expected the generated code to be&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;movs r3 0&amp;nbsp;&amp;nbsp; (0023)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ldr r3, [r3]&amp;nbsp;&amp;nbsp; (1B68)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;it eq&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (BF08)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;WFI&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (BF30)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The beginning of the FFDE &lt;/SPAN&gt;&lt;I&gt;seems&lt;/I&gt;&lt;SPAN&gt; to indicate a co-processor instruction.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[it's complicated, I could be wrong]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;But it could just be random crap.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers, Mike. [Sorry, that's all I have time for]&lt;/SPAN&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 22:56:41 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Compiler-bug/m-p/596185#M31695</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T22:56:41Z</dc:date>
    </item>
    <item>
      <title>Re: Compiler bug</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Compiler-bug/m-p/596186#M31696</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by MikeSimmonds on Thu Mar 10 09:55:40 MST 2016&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;@vtw.433e&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Even if the volatile modifier 'fixed it' for you, the OP code (as explained)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;is also correct syntax and reportedly causes a code generation error.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Of course, we do not see the compiler and/or assembler switches applied&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;either in the OP or yours. That might be causing a problem if wrong or inappropriate&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for the particular device.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers, Mike.&lt;/SPAN&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 22:56:41 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Compiler-bug/m-p/596186#M31696</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T22:56:41Z</dc:date>
    </item>
    <item>
      <title>Re: Compiler bug</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Compiler-bug/m-p/596187#M31697</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by starblue on Thu Mar 10 12:58:41 MST 2016&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;You are dereferencing a null pointer, which is undefined behavior. So the compiler is within its rights to generate whatever code it wants, and recent GCC versions have become quite aggressive at this (yes, people are complaining, mostly about signed overflow).&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Its a bit unfortunate if you really want to access address 0, maybe you need to hide your bad intentions better, so the compiler doesn't notice.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 22:56:42 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Compiler-bug/m-p/596187#M31697</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T22:56:42Z</dc:date>
    </item>
    <item>
      <title>Re: Compiler bug</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Compiler-bug/m-p/596188#M31698</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by s3-software on Thu Mar 10 17:38:41 MST 2016&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Looks like you are right!&amp;nbsp; Appears to inject a stealth trap in the code (instead of a friendly error).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Referencing location 4 with this code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;volatile uint32_t *first_location = 4;
if (*first_location == 0)
__NOP();&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Generates:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;&amp;nbsp; 50 0014 0423&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; movsr3, #4
&amp;nbsp; 51 0016 1B68&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ldrr3, [r3]
&amp;nbsp; 52 0018 03B9&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cbnzr3, .L1
&amp;nbsp; 59 001a 00BF&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; nop
&amp;nbsp; 63&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .L1
&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Whereas referencing location 0:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;volatile uint32_t *first_location = 0;
if (*first_location == 0)
__NOP();&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Generates:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;&amp;nbsp; 50 0014 0023&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; movsr3, #0
&amp;nbsp; 51 0016 1B68&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ldrr3, [r3]
&amp;nbsp; 52 0018 FFDE&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .inst0xdeff
&amp;nbsp; 53&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .L3:
&amp;nbsp; 54 001a 00BF&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .align2
&amp;nbsp; 55&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .L2&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for the insights.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 22:56:42 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Compiler-bug/m-p/596188#M31698</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T22:56:42Z</dc:date>
    </item>
    <item>
      <title>Re: Compiler bug</title>
      <link>https://community.nxp.com/t5/LPCXpresso-IDE/Compiler-bug/m-p/596189#M31699</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;bump&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 19 Jun 2016 01:04:33 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPCXpresso-IDE/Compiler-bug/m-p/596189#M31699</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-19T01:04:33Z</dc:date>
    </item>
  </channel>
</rss>

