testsuite: mallign: Handle word size of 1 byte

Message ID 20220508073104.1698197-2-dimitar@dinux.eu
State Committed
Commit e6c04ac9fd9c7b5538a6f5f45e5f9dc22954764b
Headers
Series testsuite: mallign: Handle word size of 1 byte |

Commit Message

Dimitar Dimitrov May 8, 2022, 7:31 a.m. UTC
  This patch fixes a spurious warning for pru-unknown-elf target:
  gcc/testsuite/gcc.dg/mallign.c:12:27: warning: ignoring return value of 'malloc' declared with attribute 'warn_unused_result' [-Wunused-result]

For 8-bit targets the resulting mask ignores all bits in the value
returned by malloc.  Fix by first checking the target word size.

Sanity checked that there are no new failures on x86_64-pc-linux-gnu.

Ok for trunk?

gcc/testsuite/ChangeLog:

	* gcc.dg/mallign.c: Skip check if sizeof(word)==1.

Signed-off-by: Dimitar Dimitrov <dimitar@dinux.eu>
---
 gcc/testsuite/gcc.dg/mallign.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Dimitar Dimitrov May 16, 2022, 5:18 p.m. UTC | #1
On Sun, May 08, 2022 at 10:31:04AM +0300, Dimitar Dimitrov wrote:
> This patch fixes a spurious warning for pru-unknown-elf target:
>   gcc/testsuite/gcc.dg/mallign.c:12:27: warning: ignoring return value of 'malloc' declared with attribute 'warn_unused_result' [-Wunused-result]
> 
> For 8-bit targets the resulting mask ignores all bits in the value
> returned by malloc.  Fix by first checking the target word size.
> 
> Sanity checked that there are no new failures on x86_64-pc-linux-gnu.
> 
> Ok for trunk?

Ping. Does this count as an obvious fix?

> 
> gcc/testsuite/ChangeLog:
> 
> 	* gcc.dg/mallign.c: Skip check if sizeof(word)==1.
> 
> Signed-off-by: Dimitar Dimitrov <dimitar@dinux.eu>
> ---
>  gcc/testsuite/gcc.dg/mallign.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/gcc/testsuite/gcc.dg/mallign.c b/gcc/testsuite/gcc.dg/mallign.c
> index 349cdaa343f..9a18a00c3b0 100644
> --- a/gcc/testsuite/gcc.dg/mallign.c
> +++ b/gcc/testsuite/gcc.dg/mallign.c
> @@ -9,7 +9,7 @@ typedef int word __attribute__((mode(word)));
>  
>  int main()
>  {
> -    if ((__UINTPTR_TYPE__)malloc (1) & (sizeof(word)-1))
> +    if ((sizeof(word)>1) && ((__UINTPTR_TYPE__)malloc (1) & (sizeof(word)-1)))
>  	abort ();
>      return 0;
>  }                                                                              
> -- 
> 2.35.1
>
  
Richard Sandiford May 23, 2022, 8:04 a.m. UTC | #2
Dimitar Dimitrov <dimitar@dinux.eu> writes:
> On Sun, May 08, 2022 at 10:31:04AM +0300, Dimitar Dimitrov wrote:
>> This patch fixes a spurious warning for pru-unknown-elf target:
>>   gcc/testsuite/gcc.dg/mallign.c:12:27: warning: ignoring return value of 'malloc' declared with attribute 'warn_unused_result' [-Wunused-result]
>> 
>> For 8-bit targets the resulting mask ignores all bits in the value
>> returned by malloc.  Fix by first checking the target word size.
>> 
>> Sanity checked that there are no new failures on x86_64-pc-linux-gnu.
>> 
>> Ok for trunk?
>
> Ping. Does this count as an obvious fix?
>
>> 
>> gcc/testsuite/ChangeLog:
>> 
>> 	* gcc.dg/mallign.c: Skip check if sizeof(word)==1.

OK, thanks.  Sorry for the slow review.

Richard

>> 
>> Signed-off-by: Dimitar Dimitrov <dimitar@dinux.eu>
>> ---
>>  gcc/testsuite/gcc.dg/mallign.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>> 
>> diff --git a/gcc/testsuite/gcc.dg/mallign.c b/gcc/testsuite/gcc.dg/mallign.c
>> index 349cdaa343f..9a18a00c3b0 100644
>> --- a/gcc/testsuite/gcc.dg/mallign.c
>> +++ b/gcc/testsuite/gcc.dg/mallign.c
>> @@ -9,7 +9,7 @@ typedef int word __attribute__((mode(word)));
>>  
>>  int main()
>>  {
>> -    if ((__UINTPTR_TYPE__)malloc (1) & (sizeof(word)-1))
>> +    if ((sizeof(word)>1) && ((__UINTPTR_TYPE__)malloc (1) & (sizeof(word)-1)))
>>  	abort ();
>>      return 0;
>>  }                                                                              
>> -- 
>> 2.35.1
>>
  

Patch

diff --git a/gcc/testsuite/gcc.dg/mallign.c b/gcc/testsuite/gcc.dg/mallign.c
index 349cdaa343f..9a18a00c3b0 100644
--- a/gcc/testsuite/gcc.dg/mallign.c
+++ b/gcc/testsuite/gcc.dg/mallign.c
@@ -9,7 +9,7 @@  typedef int word __attribute__((mode(word)));
 
 int main()
 {
-    if ((__UINTPTR_TYPE__)malloc (1) & (sizeof(word)-1))
+    if ((sizeof(word)>1) && ((__UINTPTR_TYPE__)malloc (1) & (sizeof(word)-1)))
 	abort ();
     return 0;
 }