Skip to content

Commit 6ef437c

Browse files
authored
Merge pull request #149 from tautschnig/c-frontend
C front end fixes: attributes, packing
2 parents 29dbae6 + 6ef66d0 commit 6ef437c

File tree

6 files changed

+55
-10
lines changed

6 files changed

+55
-10
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#define STATIC_ASSERT(condition) \
2+
int some_array##__LINE__[(condition) ? 1 : -1]
3+
4+
#pragma pack(4)
5+
6+
typedef unsigned short domid_t;
7+
typedef unsigned evtchn_port_t;
8+
struct evtchn_status {
9+
domid_t dom;
10+
evtchn_port_t port;
11+
unsigned status;
12+
unsigned vcpu;
13+
union {
14+
struct {
15+
domid_t dom;
16+
} unbound;
17+
struct {
18+
domid_t dom;
19+
evtchn_port_t port;
20+
} interdomain;
21+
unsigned pirq;
22+
unsigned virq;
23+
} u;
24+
char a;
25+
};
26+
27+
int main()
28+
{
29+
STATIC_ASSERT(__builtin_offsetof(struct evtchn_status,u.interdomain.port)==20);
30+
STATIC_ASSERT(sizeof(struct evtchn_status)==28);
31+
return 0;
32+
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring
8+
^CONVERSION ERROR$

regression/ansi-c/gcc_attributes9/main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ const char* __attribute__((section("s"))) bar1();
88
const char* __attribute__((section("s"),weak)) bar2();
99
const char* __attribute__((section("s"))) __attribute__((weak)) bar();
1010

11+
volatile int __attribute__((__section__(".init.data1"))) txt_heap_base1;
12+
volatile int __attribute__((__section__(".init.data3"))) txt_heap_base, __attribute__((__section__(".init.data4"))) txt_heap_size;
13+
1114
#endif
1215

1316
int main()

src/ansi-c/c_storage_spec.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,7 @@ class c_storage_spect
8282
a.is_register |=b.is_register;
8383
a.is_inline |=b.is_inline;
8484
a.is_thread_local |=b.is_thread_local;
85-
a.is_weak |=b.is_weak;
86-
if(!b.alias.empty()) a.alias=b.alias;
87-
if(!b.asm_label.empty()) a.asm_label=b.asm_label;
88-
if(!b.section.empty()) a.section=b.section;
85+
// attributes belong to the declarator, don't replace them
8986

9087
return a;
9188
}

src/ansi-c/padding.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,9 @@ void add_padding(struct_typet &type, const namespacet &ns)
188188
}
189189
}
190190

191-
// Is the struct packed?
192-
if(type.get_bool(ID_C_packed))
191+
// Is the struct packed, without any alignment specification?
192+
if(type.get_bool(ID_C_packed) &&
193+
type.find(ID_C_alignment).is_nil())
193194
return; // done
194195

195196
mp_integer offset=0;
@@ -291,6 +292,9 @@ void add_padding(struct_typet &type, const namespacet &ns)
291292
max_alignment=tmp_i;
292293
}
293294
}
295+
// Is the struct packed, without any alignment specification?
296+
else if(type.get_bool(ID_C_packed))
297+
return; // done
294298

295299
// There may be a need for 'end of struct' padding.
296300
// We use 'max_alignment'.

src/ansi-c/parser.y

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -971,18 +971,19 @@ declaring_list:
971971
// add the initializer
972972
to_ansi_c_declaration(stack($$)).add_initializer(stack($5));
973973
}
974-
| declaring_list ',' declarator
974+
| declaring_list ',' gcc_type_attribute_opt declarator
975975
post_declarator_attributes_opt
976976
{
977977
// type attribute goes into declarator
978-
$3=merge($4, $3);
979-
PARSER.add_declarator(stack($1), stack($3));
978+
$5=merge($5, $3);
979+
$4=merge($5, $4);
980+
PARSER.add_declarator(stack($1), stack($4));
980981
}
981982
initializer_opt
982983
{
983984
// add in the initializer
984985
$$=$1;
985-
to_ansi_c_declaration(stack($$)).add_initializer(stack($6));
986+
to_ansi_c_declaration(stack($$)).add_initializer(stack($7));
986987
}
987988
;
988989

0 commit comments

Comments
 (0)