Operating System - OpenVMS
cancel
Showing results for 
Search instead for 
Did you mean: 

Volatile access appears unaligned on local variable - Pascal

 

Volatile access appears unaligned on local variable - Pascal

I have a local definded varying of char and when I try to give it a value I get a compiler warning.

 

The compiler warning is:

 

%PASCAL-I-PROCESSFILE, Compiling file SYS$SYSDEVICE:[DM9415.WORK.SOURCE.SUPPORT]
STE.PAS;28

     String := SteLowbayAisleMemRec [ LowbayAisleRecNo ].AisleBarcode;
....^
%PASCAL-W-UNAVOLACC, Volatile access appears unaligned, but must be aligned at r
un-time to ensure atomicity and byte granularity
at line number 37 in file SYS$SYSDEVICE:[DM9415.WORK.SOURCE.SUPPORT]STE.PAS;28
%PASCAL-W-ENDDIAGS, PASCAL completed with 1 diagnostic

 

String is defined as VARYING [BARCODE_MAX_LEN] OF CHAR

 

I have tried adding [ALIGNED(4)] or 2 but it still gives me the warning.

 

Does anyone have an idea of the possible fix for this?

9 REPLIES 9
Steven Schweda
Honored Contributor

Re: Volatile access appears unaligned on local variable - Pascal

   I know nothing, but I'd expect a Pascal problem report to begin with:

      pascal /version

   An actual, complete test case might be helpful, too.

> I have tried adding [ALIGNED(4)] or 2 [...]

   While interesting, a vague description of what you did tends to be
less useful than another complete test case with the change.

Re: Volatile access appears unaligned on local variable - Pascal

The pascal version is 6.1 and on Integrity 8.4

 

As it is not a large program I have attached it.

 

 I had to attach it as a txt file as the attach option does not allow pas files

Steven Schweda
Honored Contributor

Re: Volatile access appears unaligned on local variable - Pascal

> I had to attach it as a txt file [...]

   Not the biggest problem...

 

alp $ pas shaw.pas

          'ENV:LB_DECLARATIONS' )]
...........^
%PASCAL-F-DEV, error in device name or inappropriate device type for operation
 at line number 4 in file ALP$DKC0:[SMS.itrc]shaw.pas;1

Dennis Handly
Acclaimed Contributor

Re: Volatile access appears unaligned on local variable - Pascal

Why do you want to have a volatile local?  Are you passing its address?

Also, volatile on large arrays is pretty meaningless, you need a locking mechanism.

John Reagan
Respected Contributor

Re: Volatile access appears unaligned on local variable - Pascal

+1 for Dennis

 

Placing volatile on an array doesn't mean much.  You are saying "please make sure that any assignment to the array is done in an atomic fashion".  There isn't any Alpha or Itanium instruction sequence that can do that.  You would need some higher level locking mechanism.

 

Unfortunately, Pascal doesn't have any sort of "weak volatile" attribute that says "I've taken the address of this buffer and its contents might change when any routine might be called".  The language (C isn't any better) says to put volatile on it.  That then gets you the warnings you described.

 

Personally, you can remove the volatile from the array.  The compiler isn't going to cache the array contents into some register (or sequence of registers).

Re: Volatile access appears unaligned on local variable - Pascal

Sorry for the delay in replying but I have been travelling with work.

 

The reason why it has ENV:LB_DECLARATIONS at the top is because a lot of the things defined are in there. It is part of our build system.

 

The resons for volatile is because originally the issue was in a much larger set of library files and I have moved the array into the local file, changed the name and reduced the size so that it could be used as an example for this post.

 

I was going to do a new version but without needing ENV:LB_DECLARATIONS so that you could all be able to compile it but in doing so I wanted to remove some of the fields from some of the records defined in there. This ended up leading me to the solution for the issue.

 

The issue is related to the enum in the type defined.

 

I found that for some of the types defined [ALIGNED(4)] the enum would get rid of the warning and for some of the others changing the ordering of the fields based on type got rid of it.

 

This does not always work if the code is within a WITH block.

 

if you have an array and an element is referenced using a WITH and another element which isn't and you try to copy from the one element that isn't into the one that is then it can also get the same issue.

 

Example (not perfect syntax)

 

 WITH ArrayBob[ i ]

  str := ArrayBob[j].str;

 

This one caused a warning where as this one doesn't:

 

WITH ArrayBob[ i ]

  ArrayBob[ i ].str := ArrayBob[j].str;

 

 

John Reagan
Respected Contributor

Re: Volatile access appears unaligned on local variable - Pascal

The message comes from the code generator when it sees a volatile tag and an operation that it simply cannot do atomically.  Sometimes it is alignment related (ie, an unaligned integer) but in other cases (like strings and arrays), it can never do a large memory operation in an atomic fashion.

 

The lack of the message in your example above is that the string to string move probably turned into a call to OTS$MOVEM directely early in the GEM optimizer such that by the time the code generator say the assignment, it wasn't an assignment anymore, but just a routine call. 

 

Looking back at all the confusion about putting on arrays and records, the frontend should probably have issued its own set of infos/warnings.

 

There may be a switch that can suppress that message from GEM, but I can't access the sources at the moment to look it up.

 

As I mentioned above, just remove the VOLATILE on the array, it really doesn't do anything for array operations.   You sometimes need the VOLATILE if you access that array from an exception handler used with the ESTABLISH builtin.

 

We can have the discussion as to whether a 'volatile array of integers' is the same as an 'array of volatile integers' and if a higher level VOLATILE propagates downward.  For example, if you put VOLATILE on a RECORD, do you want all the field operations to be volatile?  It is rather tricky.  There could be a compiler bug somewhere in this area.

 

 

Dennis Handly
Acclaimed Contributor

Re: Volatile access appears unaligned on local variable - Pascal

>The language (C isn't any better) says to put volatile on it.

 

The HP-UX C/aC++ compiler has 16 types of volatile, just for that purpose.  :-)

Hoff
Honored Contributor

Re: Volatile access appears unaligned on local variable - Pascal


@John Reagan wrote:

 

(C isn't any better)


Correct.   Probably somewhat worse, the volatile keyword is of somewhat limited use as far back as C99; it doesn't quite do all of what (many) folks want when they use that keyword.   In C, volatile is intended for accessing device registers, and not particularly for concurrent access to shared data.   C11 can do better here, with the _Atomic and _Alignas and the threading features that are (optionally) available.

 

Hello "Your post has been changed because invalid HTML was found in the message body. The invalid HTML has been removed. Please review the message and submit the message when you are satisfied."  Glad to see you again.