Patchwork [testuite] : Fix bad testcase assuming int = int32_t

login
register
mail settings
Submitter Georg-Johann Lay
Date Jan. 12, 2012, 4:44 p.m.
Message ID <4F0F0DD3.60405@gjlay.de>
Download mbox | patch
Permalink /patch/135650/
State New
Headers show

Comments

Georg-Johann Lay - Jan. 12, 2012, 4:44 p.m.
Again: A test case that fails because it incorrectly assumes int is 32 bits wide.

Ok to apply?

	* gcc.c-torture/execute/20120111-1.c: Fix wrong int = int32_t
	assumption.
Mike Stump - Jan. 12, 2012, 6:45 p.m.
On Jan 12, 2012, at 8:44 AM, Georg-Johann Lay wrote:
> Again: A test case that fails because it incorrectly assumes int is 32 bits wide.
> 
> Ok to apply?

I'd think the testcase is more naturally:

> return ~((uint32_t) (arg > -3));

Does that work for you?  Anyone want to weigh in on which version is better (if the second version works)?  I think I have a preference for the form above.

> -  return ~(arg > -3);
> +  return ~((unsigned) (arg > -3));
Georg-Johann Lay - Jan. 12, 2012, 10:05 p.m.
Mike Stump schrieb:
> On Jan 12, 2012, at 8:44 AM, Georg-Johann Lay wrote:
> 
>>Again: A test case that fails because it incorrectly assumes int is 32 bits wide.
>>
>>Ok to apply?
> 
> I'd think the testcase is more naturally:
> 
>>return ~((uint32_t) (arg > -3));

That not equivalent to the proposed patch: It extends to 32 and then 
inverts all bits.

> Does that work for you?  Anyone want to weigh in on which version is better (if the second version works)?  I think I have a preference for the form above.
> 
>>-  return ~(arg > -3);
>>+  return ~((unsigned) (arg > -3));

This inverts the 16 bits of unsigned and then zero-extends to 32 bits 
(the original code sign extends to 32 bits as "arg > 3" is int (16 bits).

Patch

Index: gcc.c-torture/execute/20120111-1.c
===================================================================
--- gcc.c-torture/execute/20120111-1.c  (revision 183128)
+++ gcc.c-torture/execute/20120111-1.c  (working copy)
@@ -6,7 +6,7 @@  uint32_t f0a (uint64_t arg2) __attribute
 uint32_t
 f0a (uint64_t arg)
 {
-  return ~(arg > -3);
+  return ~((unsigned) (arg > -3));
 }

 int main() {