1830098 Members
6850 Online
109998 Solutions
New Discussion

-Onovolatile behavior

 
SOLVED
Go to solution
David Ritter
Occasional Advisor

-Onovolatile behavior

Hello,

I have a question about the aCC 3.85 compiler option -Onovolatile.

Does this compiler option trump any explicit volatile declarations in the source code?

Thank you for your help,
David Ritter
10 REPLIES 10
James R. Ferguson
Acclaimed Contributor

Re: -Onovolatile behavior

Hi David:

Perhaps this helps:

http://docs.hp.com/en/14487/options.htm#opt+Onovolatile

Regards!

...JRF...
David Ritter
Occasional Advisor

Re: -Onovolatile behavior

Hi James,

My project is using the volatile keyword, but in an optimized build the compiler seems to not be respecting it unless I explicitly tell the compiler -Ovolatile.

Here is a simple test case:
// begin file

void func( volatile int& foo ) {
while(foo < 1000) {}
}
// end file

compiling without -Ovolatile the compiler will emit the following warning:

Infinite loop detected. Check for spinning on non-volatile variable.

As noted, if I add -Ovolatile the warning goes away.

Additionally I looked over the assembly code generated by the compiler and it appears that in the optimized build the volatile keyword is being stripped out and not respected.

That is the source of my confusion. I can't tell if this is a compiler bug or if I am doing something wrong.

Thanks!
David Ritter
David Ritter
Occasional Advisor

Re: -Onovolatile behavior

Hello,

Additionally the documentation you linked to was for aCC 6.20, which I understand to be for HP Itantium. I am using aCC 3.85 on PA-RISC.

I have access to the aCC 6.23 compiler and that compiler notes that -Ovolatile is not a supported compiler option.

Thank you again for any additional insights.

David Ritter
Dennis Handly
Acclaimed Contributor
Solution

Re: +Onovolatile behavior

>Does this compiler option trump any explicit volatile declarations in the source code?

No. You should not be using this option nor +Ovolatile, use the keywords. These are deprecated in aCC6.

>My project is using the volatile keyword, but in an optimized build the compiler seems to not be respecting it unless I explicitly tell the compiler +Ovolatile.
>compiling without +Ovolatile the compiler will emit the following warning:

Yes, that shows the problem.

>I can't tell if this is a compiler bug

It looks like one. Try using a pointer instead of a reference:
volatile int *foo_p = &foo:
while (*foo_p < 100)

David Ritter
Occasional Advisor

Re: -Onovolatile behavior

Hello Dennis,

Your workaround of using an int pointer does address the compiler warning. I will apply this workaround to our code base. I much prefer this to the sledgehammer of the compiler option, especially since the message I am hearing from both of you is that +Ovolatile is not ever recommended.

Thanks,
Dave
Dennis Handly
Acclaimed Contributor

Re: +Onovolatile behavior

Have you contacted the Response Center yet to report the problem?

>since the message I am hearing from both of you

You mean me and me? (Since I removed the option. :-)

David Ritter
Occasional Advisor

Re: -Onovolatile behavior

I meant you and James (the other person that replied to my post).

I have been unable to find our Response Center login information so far to file an issue.

Thanks,
Dave
Dennis Handly
Acclaimed Contributor

Re: +Onovolatile behavior

>I meant you and James.

And I meant that James was pointing to info I had added. And now I have removed the option for Integrity.

 

Aug 2011: And removed in A.06.26.

Dennis Handly
Acclaimed Contributor

Re: +Onovolatile behavior

I can duplicate the problem. It seems references to volatile fail, pointers work.
Using +O3 also fixes it.

David Ritter
Occasional Advisor

Re: -Onovolatile behavior

Thank you for the additional information. We have opted to use the pointer based workaround that you suggested, but it is good to know using +O3 is also a potential workaround if needed.

Thank you for your help regarding this Dennis.

David Ritter