Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions regression/ansi-c/Struct_Padding6/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#define STATIC_ASSERT(condition) \
int some_array##__LINE__[(condition) ? 1 : -1]

#pragma pack(4)

typedef unsigned short domid_t;
typedef unsigned evtchn_port_t;
struct evtchn_status {
domid_t dom;
evtchn_port_t port;
unsigned status;
unsigned vcpu;
union {
struct {
domid_t dom;
} unbound;
struct {
domid_t dom;
evtchn_port_t port;
} interdomain;
unsigned pirq;
unsigned virq;
} u;
char a;
};

int main()
{
STATIC_ASSERT(__builtin_offsetof(struct evtchn_status,u.interdomain.port)==20);
STATIC_ASSERT(sizeof(struct evtchn_status)==28);
return 0;
};
8 changes: 8 additions & 0 deletions regression/ansi-c/Struct_Padding6/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
main.c

^EXIT=0$
^SIGNAL=0$
--
^warning: ignoring
^CONVERSION ERROR$
3 changes: 3 additions & 0 deletions regression/ansi-c/gcc_attributes9/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ const char* __attribute__((section("s"))) bar1();
const char* __attribute__((section("s"),weak)) bar2();
const char* __attribute__((section("s"))) __attribute__((weak)) bar();

volatile int __attribute__((__section__(".init.data1"))) txt_heap_base1;
volatile int __attribute__((__section__(".init.data3"))) txt_heap_base, __attribute__((__section__(".init.data4"))) txt_heap_size;

#endif

int main()
Expand Down
5 changes: 1 addition & 4 deletions src/ansi-c/c_storage_spec.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,7 @@ class c_storage_spect
a.is_register |=b.is_register;
a.is_inline |=b.is_inline;
a.is_thread_local |=b.is_thread_local;
a.is_weak |=b.is_weak;
if(!b.alias.empty()) a.alias=b.alias;
if(!b.asm_label.empty()) a.asm_label=b.asm_label;
if(!b.section.empty()) a.section=b.section;
// attributes belong to the declarator, don't replace them

return a;
}
Expand Down
8 changes: 6 additions & 2 deletions src/ansi-c/padding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,9 @@ void add_padding(struct_typet &type, const namespacet &ns)
}
}

// Is the struct packed?
if(type.get_bool(ID_C_packed))
// Is the struct packed, without any alignment specification?
if(type.get_bool(ID_C_packed) &&
type.find(ID_C_alignment).is_nil())
return; // done

mp_integer offset=0;
Expand Down Expand Up @@ -291,6 +292,9 @@ void add_padding(struct_typet &type, const namespacet &ns)
max_alignment=tmp_i;
}
}
// Is the struct packed, without any alignment specification?
else if(type.get_bool(ID_C_packed))
return; // done

// There may be a need for 'end of struct' padding.
// We use 'max_alignment'.
Expand Down
9 changes: 5 additions & 4 deletions src/ansi-c/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -971,18 +971,19 @@ declaring_list:
// add the initializer
to_ansi_c_declaration(stack($$)).add_initializer(stack($5));
}
| declaring_list ',' declarator
| declaring_list ',' gcc_type_attribute_opt declarator
post_declarator_attributes_opt
{
// type attribute goes into declarator
$3=merge($4, $3);
PARSER.add_declarator(stack($1), stack($3));
$5=merge($5, $3);
$4=merge($5, $4);
PARSER.add_declarator(stack($1), stack($4));
}
initializer_opt
{
// add in the initializer
$$=$1;
to_ansi_c_declaration(stack($$)).add_initializer(stack($6));
to_ansi_c_declaration(stack($$)).add_initializer(stack($7));
}
;

Expand Down