On Mon, 9 Nov 2026 22:56:49 GMT, Dean Long <[email protected]> wrote:
>> This trips me as well. If we put the `const volatile` after the type, that
>> would make the pointer itself volatile. My understanding is that by saying
>> `const volatile PNT_TIB`, we make the thing pointed-to by the pointer to be
>> constant and volatile.
>>
>> Here's an example to demonstrate the difference:
>>
>> ```c++
>> struct S {
>> int value;
>> };
>>
>> int volatile_pointee(volatile S* p) {
>> volatile S* q = p;
>> return q->value + q->value; // two volatile value loads
>> }
>>
>> int volatile_pointer(S* volatile p) {
>> S* q = p; // load from volatile pointer
>> return q->value + q->value;
>> }
>>
>>
>> The assembly (via [CompilerExplorer](https://godbolt.org/z/5dra7aqfE)) shows:
>>
>>
>> "volatile_pointee(S volatile*)":
>> mov eax, DWORD PTR [rdi]
>> add eax, DWORD PTR [rdi]
>> ret
>> "volatile_pointer(S*)":
>> mov QWORD PTR [rsp-8], rdi
>> mov rax, QWORD PTR [rsp-8]
>> mov eax, DWORD PTR [rax]
>> add eax, eax
>> ret
>>
>>
>> In the first case, the memory location pointed to by the pointer is read
>> twice. In the second case, the pointer is read twice but the field is read
>> just once.
>
> Right, the difference shows up when there is a "*" in the declaration. The
> problem is PNT_TIB is a typedef of a pointer type, so "const volatile
> PNT_TIB" is the same as "PNT_TIB const volatile". I think what you need is
> "const volatile TEB *" or an equivalent VOLATILE_PNT_TIB typedef.
Oh wow, I had no idea that the typedef would be a problem. Thanks, fixed in
the most recent commit. Checked that the code compiles, now running the
relevant tests locally all over again.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/33729#discussion_r4519046764