uint32_t with volatile bug?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

uint32_t with volatile bug?

Yann Ramin
The following code produces the following error. It doesn't trigger the error
if the global is not marked volatile. Any ideas?



gcc-current from CVS as of a week ago
gcc-3.4.4
Linux


Code:

volatile uint32_t t;

int main() {
  int count;
  count = count << 3;

  uint32_t g = count;

  t = g | t;
}


Error:

msp430-gcc -g -mmcu=msp430x1611 -o main main.c
main.c: In function `main':
main.c:61: error: unrecognizable insn:
(insn 75 74 28 0 main.c:27 (set:HI (subreg:HI (mem/v/f:SI (symbol_ref:HI ("t")
<var_decl 0xb7cfbaf8 t>) [0 t+0 S4 A16]) 2)
        (ior:HI (subreg:HI (mem/v/f:SI (symbol_ref:HI ("t") <var_decl
0xb7cfbaf8 t>) [0 t+0 S4 A16]) 2)
            (mem/f:HI (plus:HI (reg/f:HI 4 r4)
                    (const_int 4 [0x4])) [0 g+2 S2 A16]))) -1 (nil)
    (nil))
main.c:61: internal compiler error: in extract_insn, at recog.c:2083
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.
make: *** [main] Error 1


-------------------------------------------------------
This SF.Net email is sponsored by the 'Do More With Dual!' webinar happening
July 14 at 8am PDT/11am EDT. We invite you to explore the latest in dual
core and dual graphics technology at this free one hour event hosted by HP,
AMD, and NVIDIA.  To register visit http://www.hp.com/go/dualwebinar
_______________________________________________
Mspgcc-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/mspgcc-users
Reply | Threaded
Open this post in threaded view
|

RE: uint32_t with volatile bug?

Dmitry-2
Use gcc-3.2...
3.4  does not work properly

~d


-----Original Message-----
From: [hidden email]
[mailto:[hidden email]] On Behalf Of Yann Ramin
Sent: Tuesday, July 12, 2005 6:13 AM
To: [hidden email]
Subject: [Mspgcc-users] uint32_t with volatile bug?

The following code produces the following error. It doesn't trigger the
error
if the global is not marked volatile. Any ideas?



gcc-current from CVS as of a week ago
gcc-3.4.4
Linux


Code:

volatile uint32_t t;

int main() {
  int count;
  count = count << 3;

  uint32_t g = count;

  t = g | t;
}


Error:

msp430-gcc -g -mmcu=msp430x1611 -o main main.c
main.c: In function `main':
main.c:61: error: unrecognizable insn:
(insn 75 74 28 0 main.c:27 (set:HI (subreg:HI (mem/v/f:SI (symbol_ref:HI
("t")
<var_decl 0xb7cfbaf8 t>) [0 t+0 S4 A16]) 2)
        (ior:HI (subreg:HI (mem/v/f:SI (symbol_ref:HI ("t") <var_decl
0xb7cfbaf8 t>) [0 t+0 S4 A16]) 2)
            (mem/f:HI (plus:HI (reg/f:HI 4 r4)
                    (const_int 4 [0x4])) [0 g+2 S2 A16]))) -1 (nil)
    (nil))
main.c:61: internal compiler error: in extract_insn, at recog.c:2083
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.
make: *** [main] Error 1


-------------------------------------------------------
This SF.Net email is sponsored by the 'Do More With Dual!' webinar happening
July 14 at 8am PDT/11am EDT. We invite you to explore the latest in dual
core and dual graphics technology at this free one hour event hosted by HP,
AMD, and NVIDIA.  To register visit http://www.hp.com/go/dualwebinar
_______________________________________________
Mspgcc-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/mspgcc-users



-------------------------------------------------------
This SF.Net email is sponsored by the 'Do More With Dual!' webinar happening
July 14 at 8am PDT/11am EDT. We invite you to explore the latest in dual
core and dual graphics technology at this free one hour event hosted by HP,
AMD, and NVIDIA.  To register visit http://www.hp.com/go/dualwebinar
_______________________________________________
Mspgcc-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/mspgcc-users
Reply | Threaded
Open this post in threaded view
|

Re: uint32_t with volatile bug?

arnd-hendrik.mathias (Bugzilla)
In reply to this post by Yann Ramin
Hi,
the compiler output message reads a bit confusing. I'm no expert in gcc
internals but as for your code..

Yann Ramin wrote:

> The following code produces the following error. It doesn't trigger the error
> if the global is not marked volatile. Any ideas?
>
>
>
> gcc-current from CVS as of a week ago
> gcc-3.4.4
> Linux
>
>
> Code:
>
> volatile uint32_t t;
>
> int main() {
>   int count;
>   count = count << 3;

The local variable count is uninitialized and used as rvalue. This is no
syntactical "error" but a semantical one. It leads to undefined results.

>
>   uint32_t g = count;

Did you tell your compiler to compile C++ code? In C you cannot
declare/define new local variables inside a block after the first
instructions (you have to omit the preceding line count = count << 3;).
-> This is a syntactical error!
A possible reason for the difference with or without volatile is the
optimization:
The assignment of t is the last executed line of code. t is not used and
can be optimized away and so can the last line. As a next step you can
see that if you omit the last line g is not used anywhere else and thus
can be optimized away. (Finally for the same reason also count can be
omitted and main() is ... empty).
The situation differs if you plan to access t from out of main's control
flow (i.e. from an ISR). In this case all the other lines are needed
too. You use volatile to inform the compiler about this very fact.
Regards

Arnd-Hendrik

>
>   t = g | t;
> }
>
>
> Error:
>
> msp430-gcc -g -mmcu=msp430x1611 -o main main.c
> main.c: In function `main':
> main.c:61: error: unrecognizable insn:
> (insn 75 74 28 0 main.c:27 (set:HI (subreg:HI (mem/v/f:SI (symbol_ref:HI ("t")
> <var_decl 0xb7cfbaf8 t>) [0 t+0 S4 A16]) 2)
>         (ior:HI (subreg:HI (mem/v/f:SI (symbol_ref:HI ("t") <var_decl
> 0xb7cfbaf8 t>) [0 t+0 S4 A16]) 2)
>             (mem/f:HI (plus:HI (reg/f:HI 4 r4)
>                     (const_int 4 [0x4])) [0 g+2 S2 A16]))) -1 (nil)
>     (nil))
> main.c:61: internal compiler error: in extract_insn, at recog.c:2083
> Please submit a full bug report,
> with preprocessed source if appropriate.
> See <URL:http://gcc.gnu.org/bugs.html> for instructions.
> make: *** [main] Error 1
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by the 'Do More With Dual!' webinar happening
> July 14 at 8am PDT/11am EDT. We invite you to explore the latest in dual
> core and dual graphics technology at this free one hour event hosted by HP,
> AMD, and NVIDIA.  To register visit http://www.hp.com/go/dualwebinar
> _______________________________________________
> Mspgcc-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/mspgcc-users
>
>


-------------------------------------------------------
This SF.Net email is sponsored by the 'Do More With Dual!' webinar happening
July 14 at 8am PDT/11am EDT. We invite you to explore the latest in dual
core and dual graphics technology at this free one hour event hosted by HP,
AMD, and NVIDIA.  To register visit http://www.hp.com/go/dualwebinar
_______________________________________________
Mspgcc-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/mspgcc-users
Reply | Threaded
Open this post in threaded view
|

Re: uint32_t with volatile bug?

Yann Ramin

>
> Did you tell your compiler to compile C++ code? In C you cannot
> declare/define new local variables inside a block after the first
> instructions (you have to omit the preceding line count = count << 3;).
> -> This is a syntactical error!

This is a copy & paste error.

And yes, count is undefined. Doesn't really matter in this case. I don't care
what the value of count is in this example.

> A possible reason for the difference with or without volatile is the
> optimization:
> The assignment of t is the last executed line of code. t is not used and
> can be optimized away and so can the last line. As a next step you can
> see that if you omit the last line g is not used anywhere else and thus
> can be optimized away. (Finally for the same reason also count can be
> omitted and main() is ... empty).
> The situation differs if you plan to access t from out of main's control
> flow (i.e. from an ISR). In this case all the other lines are needed
> too. You use volatile to inform the compiler about this very fact.

Thats exactly why I'm trying to use volatile.

And the compilation suceeds with -O0 without voltaile, which should prevent
any dead stripping of code.


-------------------------------------------------------
This SF.Net email is sponsored by the 'Do More With Dual!' webinar happening
July 14 at 8am PDT/11am EDT. We invite you to explore the latest in dual
core and dual graphics technology at this free one hour event hosted by HP,
AMD, and NVIDIA.  To register visit http://www.hp.com/go/dualwebinar
_______________________________________________
Mspgcc-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/mspgcc-users
Reply | Threaded
Open this post in threaded view
|

Re: uint32_t with volatile bug?

arnd-hendrik.mathias (Bugzilla)


Yann Ramin wrote:
>>Did you tell your compiler to compile C++ code? In C you cannot
>>declare/define new local variables inside a block after the first
>>instructions (you have to omit the preceding line count = count << 3;).
>>-> This is a syntactical error!
>
>
> This is a copy & paste error.

Oh, sorry! So what is your real code?

>
> And yes, count is undefined. Doesn't really matter in this case. I don't care
> what the value of count is in this example.
>
>
>>A possible reason for the difference with or without volatile is the
>>optimization:
>>The assignment of t is the last executed line of code. t is not used and
>>can be optimized away and so can the last line. As a next step you can
>>see that if you omit the last line g is not used anywhere else and thus
>>can be optimized away. (Finally for the same reason also count can be
>>omitted and main() is ... empty).
>>The situation differs if you plan to access t from out of main's control
>>flow (i.e. from an ISR). In this case all the other lines are needed
>>too. You use volatile to inform the compiler about this very fact.
>
>
> Thats exactly why I'm trying to use volatile.
>
> And the compilation suceeds with -O0 without voltaile, which should prevent
> any dead stripping of code.
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by the 'Do More With Dual!' webinar happening
> July 14 at 8am PDT/11am EDT. We invite you to explore the latest in dual
> core and dual graphics technology at this free one hour event hosted by HP,
> AMD, and NVIDIA.  To register visit http://www.hp.com/go/dualwebinar
> _______________________________________________
> Mspgcc-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/mspgcc-users
>
>


-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
Mspgcc-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/mspgcc-users