[PATCH] D47953: [builtin] Add bitfield support for __builtin_dump_struct

Paul Semel via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 22 07:23:21 PDT 2018


paulsemel added a comment.

First thanks all for reviewing !

Basically, what's happening is that it works good with non-packed structures.
Here is an example for packed structure (with unsigned signed short):

  c
  struct lol {
  	unsigned short a:3;
  	unsigned short b:2;
  	unsigned short c:6;
  	unsigned short d:2;
  	unsigned short e:6;
  } __attribute__((packed));
  
  int main(void)
  {
  	struct lol lolo = {
  		.a = 2,
  		.b = 1,
  		.c = 13,
  		.d = 2,
  		.e = 9
  	};
  	__builtin_dump_struct(&lolo, &printf);
  	return 0;
  }

Here is the output I get :

  sh
  unsigned short a : 2
  unsigned short b : 1
  unsigned short c : 13
  unsigned short d : 2
  unsigned short e : 1

The last `unsigned short` is incorrect.

If I switch this to signed integers, I get :

  sh
  unsigned short a : 0
  unsigned short b : 0
  unsigned short c : 0
  unsigned short d : 0
  unsigned short e : 0

All the fields are zeroed. I absolutely do not understand what is happening...
Thanks for trying to help guys !


Repository:
  rC Clang

https://reviews.llvm.org/D47953





More information about the cfe-commits mailing list