|
From: | Michael Matz |
Subject: | Re: [Tinycc-devel] bitfield handling |
Date: | Mon, 1 May 2017 06:28:00 +0200 (CEST) |
User-agent: | Alpine 2.20 (LSU 67 2015-01-07) |
Hi, On Sun, 30 Apr 2017, Vicente Bergas wrote:
struct{short x:12; char y:1;}s; s.y=1;Note that the above is tricky: char can be signed and unsigned if not explicitely specified, and if it's signed then a 1-bit bitfield of char only contains values -1 and 0, so storing a 1 into it actually makes the value be -1. So depending on what you tested that might actually have been the problem. (I.e. always specify signedness of char when using it to store numeric values and not characters).There is no problem with signedness. To factor out the sign, you can also test this: struct{unsigned short x:12; unsigned char y:2;}s; s.y=1; which also fails. Both fail even after applying your patch.
Indeed, I thought I tested the above variant before writing the mail but obviously I fat-fingered something, it still failed. Fixed in mob. I chose to adjust field layout instead of field type; the latter can cause invalid mem accesses with packed structs/fields: consider the above struct being packed (hence having size 2) and placed at the last two bytes of a page with the page after that not being accessible. Reading a whole int will then segfault.
Ciao, Michael.
[Prev in Thread] | Current Thread | [Next in Thread] |