OpenCL-CTS icon indicating copy to clipboard operation
OpenCL-CTS copied to clipboard

Casting gptr & lptr to a generic pointer before the comparison

Open asudarsa opened this issue 3 years ago • 4 comments

asudarsa avatar Aug 02 '22 01:08 asudarsa

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

CLAassistant avatar Aug 02 '22 01:08 CLAassistant

Code format failure is in a location which is not touched by this change. Thanks.

asudarsa avatar Aug 02 '22 01:08 asudarsa

Interesting - I thought this wouldn't be necessary but this is changing how Clang generates code for the comparisons.

@AnastasiaStulova is this expected?

https://godbolt.org/z/PGPEjxj4T

bashbaug avatar Sep 01 '22 05:09 bashbaug

My guess is that this change forces comparison to be done using generic address space pointers instead of the named ones... but the default behavior should be a generic address space comparison. However without explicit cast clang seems to convert to a named address space for the comparison: https://godbolt.org/z/rorvWKcGM.

This seems like a bug to me as embedded C rules say this about the pointer equality operator:

If the two operands are pointers into different address spaces, one of the address spaces encloses the other. The pointer into the enclosed address space is first converted to a pointer to the same reference type except with any address-space qualifier removed and any address- space qualifier of the other pointer's reference type added. (After this conversion, both operands are pointers into the same address space.)

I don't think OpenCL overrules this...

AnastasiaStulova avatar Sep 01 '22 10:09 AnastasiaStulova