Skip to contentSkip to conversation

tests/gem_softpin: Fix compiler warning on 32bit systems

PATCH In review Mika Kuoppala 4 participants 4 messages Dec 10, 2015 – Dec 11, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tests/gem_softpin: Fix compiler warning on 32bit systems

We get build error as we try to cast from ptr to integer of different size on 32 bit platforms. Use unsigned long as the cast, it will work with both 32 and 64 bit systems.

Cc Vinay Belgaumkar <[email protected]>
---
 tests/gem_softpin.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
tests/gem_softpin.c +3 -3
index 7bee16b..0919716 100644
@@ -155,7 +155,7 @@ static uint32_t init_userptr(int fd, i915_gem_userptr *userptr, void *ptr,
 
 	memset((void*)userptr, 0, sizeof(i915_gem_userptr));
 
-	userptr->user_ptr = (uint64_t)ptr; /* Need the cast to overcome compiler warning */
+	userptr->user_ptr = (unsigned long)ptr; /* Need the cast to overcome compiler warning */
 	userptr->user_size = size;
 	userptr->flags = 0; /* use synchronized operation */
 
@@ -270,7 +270,7 @@ static void setup_execbuffer(struct drm_i915_gem_execbuffer2 *execbuf,
 			     struct drm_i915_gem_exec_object2 *exec_object,
 			     int ring, int buffer_count, int batch_length)
 {
-	execbuf->buffers_ptr = (uint64_t)exec_object;
+	execbuf->buffers_ptr = (unsigned long)exec_object;
 	execbuf->buffer_count = buffer_count;
 	execbuf->batch_start_offset = 0;
 	execbuf->batch_len = batch_length;
@@ -417,7 +417,7 @@ static void gem_pin_bo_test(void)
 		       EXEC_OBJECT_PINNED, pinning_offset);
 	setup_exec_obj(&exec_object2[1], batch_buf_handle, 0, 0);
 	exec_object2[1].relocation_count = 1;
-	exec_object2[1].relocs_ptr = (uint64_t)reloc;
+	exec_object2[1].relocs_ptr = (unsigned long)reloc;
 
 	ring = I915_EXEC_RENDER;
 
Signature · 6 lines
2.5.0

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Reviewed-by on v1 1/1
#1 lore raw

Hi,

Quoted 35 lines · Mika Kuoppala

We get build error as we try to cast from ptr to integer of different size on 32 bit platforms. Use unsigned long as the cast, it will work with both 32 and 64 bit systems.

Cc Vinay Belgaumkar <[email protected]>
---
  tests/gem_softpin.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
tests/gem_softpin.c +2 -2
index 7bee16b..0919716 100644
@@ -155,7 +155,7 @@ static uint32_t init_userptr(int fd, i915_gem_userptr *userptr, void *ptr,
 
  	memset((void*)userptr, 0, sizeof(i915_gem_userptr));
 
-	userptr->user_ptr = (uint64_t)ptr; /* Need the cast to overcome compiler warning */
+	userptr->user_ptr = (unsigned long)ptr; /* Need the cast to overcome compiler warning */
  	userptr->user_size = size;
  	userptr->flags = 0; /* use synchronized operation */
 
@@ -270,7 +270,7 @@ static void setup_execbuffer(struct drm_i915_gem_execbuffer2 *execbuf,
  			     struct drm_i915_gem_exec_object2 *exec_object,
  			     int ring, int buffer_count, int batch_length)
  {
-	execbuf->buffers_ptr = (uint64_t)exec_object;
+	execbuf->buffers_ptr = (unsigned long)exec_object;
  	execbuf->buffer_count = buffer_count;
  	execbuf->batch_start_offset = 0;
  	execbuf->batch_len = batch_length;

tests/gem_softpin.c static void gem_pin_bo_test(void) · line 423

Quoted 8 lines
tests/gem_softpin.c +1 -1
@@ -417,7 +417,7 @@ static void gem_pin_bo_test(void)
  		       EXEC_OBJECT_PINNED, pinning_offset);
  	setup_exec_obj(&exec_object2[1], batch_buf_handle, 0, 0);
  	exec_object2[1].relocation_count = 1;
-	exec_object2[1].relocs_ptr = (uint64_t)reloc;
+	exec_object2[1].relocs_ptr = (unsigned long)reloc;
 
  	ring = I915_EXEC_RENDER;
 

I had to try it to believe it and indeed gcc complains with "warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]", which I don't really understand since cast is to a wider or equally wide data type.

Vinay had uintptr_t there originally which does not suffer from this warning so this one is my fault. I don't get the gcc logic but whatever.

Regards,

Tvrtko
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#2 lore raw
Quoted 48 lines · Tvrtko Ursulin

Hi,

Quoted 44 lines · Mika Kuoppala

We get build error as we try to cast from ptr to integer of different size on 32 bit platforms. Use unsigned long as the cast, it will work with both 32 and 64 bit systems.

Cc Vinay Belgaumkar <[email protected]>
---
  tests/gem_softpin.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
tests/gem_softpin.c +0 -1
index 7bee16b..0919716 100644
@@ -155,7 +155,7 @@ static uint32_t init_userptr(int fd,
 i915_gem_userptr *userptr, void *ptr,
 
      memset((void*)userptr, 0, sizeof(i915_gem_userptr));
 
-    userptr->user_ptr = (uint64_t)ptr; /* Need the cast to overcome

compiler warning */
+ userptr->user_ptr = (unsigned long)ptr; /* Need the cast to
overcome compiler warning */

      userptr->user_size = size;
      userptr->flags = 0; /* use synchronized operation */
tests/gem_softpin.c +1 -1
@@ -270,7 +270,7 @@ static void setup_execbuffer(struct
 drm_i915_gem_execbuffer2 *execbuf,
                   struct drm_i915_gem_exec_object2 *exec_object,
                   int ring, int buffer_count, int batch_length)
  {
-    execbuf->buffers_ptr = (uint64_t)exec_object;
+    execbuf->buffers_ptr = (unsigned long)exec_object;
      execbuf->buffer_count = buffer_count;
      execbuf->batch_start_offset = 0;
      execbuf->batch_len = batch_length;
tests/gem_softpin.c +1 -1
@@ -417,7 +417,7 @@ static void gem_pin_bo_test(void)
                 EXEC_OBJECT_PINNED, pinning_offset);
      setup_exec_obj(&exec_object2[1], batch_buf_handle, 0, 0);
      exec_object2[1].relocation_count = 1;
-    exec_object2[1].relocs_ptr = (uint64_t)reloc;
+    exec_object2[1].relocs_ptr = (unsigned long)reloc;
 
Quoted 6 lines

tests/gem_softpin.c static void gem_pin_bo_test(void) · line 422

Quoted 1 line
tests/gem_softpin.c +0 -0
      ring = I915_EXEC_RENDER;

I had to try it to believe it and indeed gcc complains with "warning:
cast from pointer to integer of different size [-Wpointer-to-int-cast]", which I don't really understand since cast is to a wider or equally wide data type.

I think the warning is really there for the pointer-to-signed-int conversion, in case that does an unexpected sign extension -- yes, I have seen machines where pointers were considered signed :( I suppose the result of converting a signed-pointer to unsigned-long-long might be "surprising" ...

Or maybe the gcc writers just thought it was more general to check for dest_size != source_size rather than < :-?

Quoted 2 lines

Vinay had uintptr_t there originally which does not suffer from this warning so this one is my fault. I don't get the gcc logic but whatever.

'uintptr_t' should be the right type for the cast; and you should then be able assign that to any larger unsigned type without getting compiler warnings!

[Aside: I've also seen at one machine where there simply wasn't any type that could be used for uintptr_t; it had 4-byte 'long's and no 'long long', but pointers were 6 bytes!]

.Dave.

Quoted 9 lines

Regards,

Tvrtko
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#3 lore raw
In reply to Tvrtko Ursulin
Quoted 59 lines · Tvrtko Ursulin

Hi,

Quoted 35 lines · Mika Kuoppala

We get build error as we try to cast from ptr to integer of different size on 32 bit platforms. Use unsigned long as the cast, it will work with both 32 and 64 bit systems.

Cc Vinay Belgaumkar <[email protected]>
---
 tests/gem_softpin.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
tests/gem_softpin.c +2 -2
index 7bee16b..0919716 100644
@@ -155,7 +155,7 @@ static uint32_t init_userptr(int fd, i915_gem_userptr *userptr, void *ptr,
 
 	memset((void*)userptr, 0, sizeof(i915_gem_userptr));
 
-	userptr->user_ptr = (uint64_t)ptr; /* Need the cast to overcome compiler warning */
+	userptr->user_ptr = (unsigned long)ptr; /* Need the cast to overcome compiler warning */
 	userptr->user_size = size;
 	userptr->flags = 0; /* use synchronized operation */
 
@@ -270,7 +270,7 @@ static void setup_execbuffer(struct drm_i915_gem_execbuffer2 *execbuf,
 			     struct drm_i915_gem_exec_object2 *exec_object,
 			     int ring, int buffer_count, int batch_length)
 {
-	execbuf->buffers_ptr = (uint64_t)exec_object;
+	execbuf->buffers_ptr = (unsigned long)exec_object;
 	execbuf->buffer_count = buffer_count;
 	execbuf->batch_start_offset = 0;
 	execbuf->batch_len = batch_length;

tests/gem_softpin.c static void gem_pin_bo_test(void) · line 423

Quoted 8 lines
tests/gem_softpin.c +1 -1
@@ -417,7 +417,7 @@ static void gem_pin_bo_test(void)
 		       EXEC_OBJECT_PINNED, pinning_offset);
 	setup_exec_obj(&exec_object2[1], batch_buf_handle, 0, 0);
 	exec_object2[1].relocation_count = 1;
-	exec_object2[1].relocs_ptr = (uint64_t)reloc;
+	exec_object2[1].relocs_ptr = (unsigned long)reloc;
 
 	ring = I915_EXEC_RENDER;
 

I had to try it to believe it and indeed gcc complains with "warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]", which I don't really understand since cast is to a wider or equally wide data type.

Vinay had uintptr_t there originally which does not suffer from this warning so this one is my fault. I don't get the gcc logic but whatever.

Quoted 7 lines

Regards,

Tvrtko

Should have tested the build on 32-bit system as well. Thanks for the fix.

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx