rework atomic and related types
[cparser] / attribute.c
1 /*
2  * This file is part of cparser.
3  * Copyright (C) 2007-2009 Matthias Braun <matze@braunis.de>
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
18  * 02111-1307, USA.
19  */
20 #include <config.h>
21
22 #include <assert.h>
23 #include "diagnostic.h"
24 #include "warning.h"
25 #include "attribute_t.h"
26 #include "symbol_t.h"
27 #include "adt/error.h"
28 #include "type_t.h"
29
30 static const char *const attribute_names[ATTRIBUTE_LAST+1] = {
31         [ATTRIBUTE_GNU_CONST]                  = "const",
32         [ATTRIBUTE_GNU_VOLATILE]               = "volatile",
33         [ATTRIBUTE_GNU_CDECL]                  = "cdecl",
34         [ATTRIBUTE_GNU_STDCALL]                = "stdcall",
35         [ATTRIBUTE_GNU_FASTCALL]               = "fastcall",
36         [ATTRIBUTE_GNU_DEPRECATED]             = "deprecated",
37         [ATTRIBUTE_GNU_NOINLINE]               = "noinline",
38         [ATTRIBUTE_GNU_RETURNS_TWICE]          = "returns_twice",
39         [ATTRIBUTE_GNU_NORETURN]               = "noreturn",
40         [ATTRIBUTE_GNU_NAKED]                  = "naked",
41         [ATTRIBUTE_GNU_PURE]                   = "pure",
42         [ATTRIBUTE_GNU_ALWAYS_INLINE]          = "always_inline",
43         [ATTRIBUTE_GNU_MALLOC]                 = "malloc",
44         [ATTRIBUTE_GNU_WEAK]                   = "weak",
45         [ATTRIBUTE_GNU_CONSTRUCTOR]            = "constructor",
46         [ATTRIBUTE_GNU_DESTRUCTOR]             = "destructor",
47         [ATTRIBUTE_GNU_NOTHROW]                = "nothrow",
48         [ATTRIBUTE_GNU_TRANSPARENT_UNION]      = "transparent_union",
49         [ATTRIBUTE_GNU_COMMON]                 = "common",
50         [ATTRIBUTE_GNU_NOCOMMON]               = "nocommon",
51         [ATTRIBUTE_GNU_PACKED]                 = "packed",
52         [ATTRIBUTE_GNU_SHARED]                 = "shared",
53         [ATTRIBUTE_GNU_NOTSHARED]              = "notshared",
54         [ATTRIBUTE_GNU_USED]                   = "used",
55         [ATTRIBUTE_GNU_UNUSED]                 = "unused",
56         [ATTRIBUTE_GNU_NO_INSTRUMENT_FUNCTION] = "no_instrument_function",
57         [ATTRIBUTE_GNU_WARN_UNUSED_RESULT]     = "warn_unused_result",
58         [ATTRIBUTE_GNU_LONGCALL]               = "longcall",
59         [ATTRIBUTE_GNU_SHORTCALL]              = "shortcall",
60         [ATTRIBUTE_GNU_LONG_CALL]              = "long_call",
61         [ATTRIBUTE_GNU_SHORT_CALL]             = "short_call",
62         [ATTRIBUTE_GNU_FUNCTION_VECTOR]        = "function_vector",
63         [ATTRIBUTE_GNU_INTERRUPT]              = "interrupt",
64         [ATTRIBUTE_GNU_INTERRUPT_HANDLER]      = "interrupt_handler",
65         [ATTRIBUTE_GNU_NMI_HANDLER]            = "nmi_handler",
66         [ATTRIBUTE_GNU_NESTING]                = "nesting",
67         [ATTRIBUTE_GNU_NEAR]                   = "near",
68         [ATTRIBUTE_GNU_FAR]                    = "far",
69         [ATTRIBUTE_GNU_SIGNAL]                 = "signal",
70         [ATTRIBUTE_GNU_EIGTHBIT_DATA]          = "eightbit_data",
71         [ATTRIBUTE_GNU_TINY_DATA]              = "tiny_data",
72         [ATTRIBUTE_GNU_SAVEALL]                = "saveall",
73         [ATTRIBUTE_GNU_FLATTEN]                = "flatten",
74         [ATTRIBUTE_GNU_SSEREGPARM]             = "sseregparm",
75         [ATTRIBUTE_GNU_EXTERNALLY_VISIBLE]     = "externally_visible",
76         [ATTRIBUTE_GNU_MAY_ALIAS]              = "may_alias",
77         [ATTRIBUTE_GNU_MS_STRUCT]              = "ms_struct",
78         [ATTRIBUTE_GNU_GCC_STRUCT]             = "gcc_struct",
79         [ATTRIBUTE_GNU_DLLIMPORT]              = "dllimport",
80         [ATTRIBUTE_GNU_DLLEXPORT]              = "dllexport",
81         [ATTRIBUTE_GNU_ALIGNED]                = "aligned",
82         [ATTRIBUTE_GNU_ALIAS]                  = "alias",
83         [ATTRIBUTE_GNU_SECTION]                = "section",
84         [ATTRIBUTE_GNU_FORMAT]                 = "format",
85         [ATTRIBUTE_GNU_FORMAT_ARG]             = "format_arg",
86         [ATTRIBUTE_GNU_WEAKREF]                = "weakref",
87         [ATTRIBUTE_GNU_NONNULL]                = "nonnull",
88         [ATTRIBUTE_GNU_TLS_MODEL]              = "tls_model",
89         [ATTRIBUTE_GNU_VISIBILITY]             = "visibility",
90         [ATTRIBUTE_GNU_REGPARM]                = "regparm",
91         [ATTRIBUTE_GNU_MODE]                   = "mode",
92         [ATTRIBUTE_GNU_MODEL]                  = "model",
93         [ATTRIBUTE_GNU_TRAP_EXIT]              = "trap_exit",
94         [ATTRIBUTE_GNU_SP_SWITCH]              = "sp_switch",
95         [ATTRIBUTE_GNU_SENTINEL]               = "sentinel",
96
97         [ATTRIBUTE_MS_ALIGN]                   = "align",
98         [ATTRIBUTE_MS_ALLOCATE]                = "allocate",
99         [ATTRIBUTE_MS_DLLIMPORT]               = "dllimport",
100         [ATTRIBUTE_MS_DLLEXPORT]               = "dllexport",
101         [ATTRIBUTE_MS_NAKED]                   = "naked",
102         [ATTRIBUTE_MS_NOINLINE]                = "noinline",
103         [ATTRIBUTE_MS_RETURNS_TWICE]           = "returns_twice",
104         [ATTRIBUTE_MS_NORETURN]                = "noreturn",
105         [ATTRIBUTE_MS_NOTHROW]                 = "nothrow",
106         [ATTRIBUTE_MS_NOVTABLE]                = "novtable",
107         [ATTRIBUTE_MS_PROPERTY]                = "property",
108         [ATTRIBUTE_MS_SELECTANY]               = "selectany",
109         [ATTRIBUTE_MS_THREAD]                  = "thread",
110         [ATTRIBUTE_MS_UUID]                    = "uuid",
111         [ATTRIBUTE_MS_DEPRECATED]              = "deprecated",
112         [ATTRIBUTE_MS_RESTRICT]                = "restrict",
113         [ATTRIBUTE_MS_NOALIAS]                 = "noalias",
114 };
115
116 const char *get_attribute_name(attribute_kind_t kind)
117 {
118         assert(kind <= ATTRIBUTE_LAST);
119         return attribute_names[kind];
120 }
121
122 /**
123  * compare two string, ignoring double underscores on the second.
124  */
125 static int strcmp_underscore(const char *s1, const char *s2)
126 {
127         if (s2[0] == '_' && s2[1] == '_') {
128                 size_t len2 = strlen(s2);
129                 size_t len1 = strlen(s1);
130                 if (len1 == len2-4 && s2[len2-2] == '_' && s2[len2-1] == '_') {
131                         return strncmp(s1, s2+2, len2-4);
132                 }
133         }
134
135         return strcmp(s1, s2);
136 }
137
138 type_t *handle_attribute_mode(const attribute_t *attribute, type_t *orig_type)
139 {
140         type_t *type = skip_typeref(orig_type);
141
142         /* at least: byte, word, pointer, list of machine modes
143          * __XXX___ is interpreted as XXX */
144
145         /* This isn't really correct, the backend should provide a list of machine
146          * specific modes (according to gcc philosophy that is...) */
147         attribute_argument_t *arg = attribute->a.arguments;
148         if (arg == NULL) {
149                 errorf(&attribute->source_position,
150                        "__attribute__((mode(X))) misses argument");
151                 return orig_type;
152         }
153
154         const char         *symbol_str = arg->v.symbol->string;
155         bool                sign       = is_type_signed(type);
156         atomic_type_kind_t  akind;
157         if (strcmp_underscore("QI",   symbol_str) == 0 ||
158             strcmp_underscore("byte", symbol_str) == 0) {
159                 akind = sign ? ATOMIC_TYPE_CHAR : ATOMIC_TYPE_UCHAR;
160         } else if (strcmp_underscore("HI", symbol_str) == 0) {
161                 akind = sign ? ATOMIC_TYPE_SHORT : ATOMIC_TYPE_USHORT;
162         } else if (strcmp_underscore("SI",      symbol_str) == 0
163                 || strcmp_underscore("word",    symbol_str) == 0
164                 || strcmp_underscore("pointer", symbol_str) == 0) {
165                 akind = sign ? ATOMIC_TYPE_INT : ATOMIC_TYPE_UINT;
166         } else if (strcmp_underscore("DI", symbol_str) == 0) {
167                 akind = sign ? ATOMIC_TYPE_LONGLONG : ATOMIC_TYPE_ULONGLONG;
168         } else {
169                 source_position_t const *const pos = &attribute->source_position;
170                 warningf(WARN_OTHER, pos, "ignoring unknown mode '%s'", symbol_str);
171                 return orig_type;
172         }
173
174         if (type->kind == TYPE_ATOMIC || type->kind == TYPE_ENUM) {
175                 type_t *copy       = duplicate_type(type);
176                 copy->atomic.akind = akind;
177                 return identify_new_type(copy);
178         } else if (is_type_pointer(type)) {
179                 source_position_t const *const pos = &attribute->source_position;
180                 warningf(WARN_OTHER, pos, "__attribute__((mode)) on pointers not implemented yet (ignored)");
181                 return type;
182         }
183
184         errorf(&attribute->source_position,
185                "__attribute__((mode)) only allowed on integer, enum or pointer type");
186         return orig_type;
187 }
188
189 static inline bool is_po2(unsigned x)
190 {
191         return (x & (x-1)) == 0;
192 }
193
194 static void handle_attribute_aligned(const attribute_t *attribute,
195                                      entity_t *entity)
196 {
197         int alignment = 32; /* TODO: fill in maximum useful alignment for
198                                                    target machine */
199         if (attribute->a.arguments) {
200                 attribute_argument_t *argument = attribute->a.arguments;
201                 alignment = fold_constant_to_int(argument->v.expression);
202         }
203
204         if (!is_po2(alignment)) {
205                 errorf(&attribute->source_position,
206                            "alignment must be a power of 2 but is %d\n",
207                            alignment);
208                 return;
209         }
210         if (alignment <= 0) {
211                 errorf(&attribute->source_position,
212                            "alignment must be bigger than 0 but is %d\n",
213                            alignment);
214                 return;
215         }
216
217         switch (entity->kind) {
218         DECLARATION_KIND_CASES
219                 entity->declaration.alignment = alignment;
220         case ENTITY_TYPEDEF:
221                 entity->typedefe.alignment = alignment;
222                 break;
223         case ENTITY_STRUCT:
224         case ENTITY_UNION:
225                 if (alignment > (int)entity->compound.alignment) {
226                         entity->compound.alignment = alignment;
227                 }
228                 break;
229         default: {
230                 source_position_t const *const pos  = &attribute->source_position;
231                 char              const *const what = get_entity_kind_name(entity->kind);
232                 symbol_t          const *const sym  = entity->base.symbol;
233                 warningf(WARN_OTHER, pos, "alignment attribute specification on %s '%S' ignored", what, sym);
234                 break;
235         }
236         }
237 }
238
239 static const char *get_argument_string(const attribute_argument_t *argument)
240 {
241         if (argument == NULL)
242                 return NULL;
243         if (argument->kind != ATTRIBUTE_ARGUMENT_EXPRESSION)
244                 return NULL;
245         expression_t *expression = argument->v.expression;
246         if (expression->kind != EXPR_STRING_LITERAL)
247                 return NULL;
248         return expression->literal.value.begin;
249 }
250
251 static void handle_attribute_visibility(const attribute_t *attribute,
252                                         entity_t *entity)
253 {
254         /* This isn't really correct, the backend should provide a list of machine
255          * specific modes (according to gcc philosophy that is...) */
256         attribute_argument_t *arg = attribute->a.arguments;
257         if (arg == NULL) {
258                 errorf(&attribute->source_position,
259                        "__attribute__((visibility(X))) misses argument");
260                 return;
261         }
262         const char *string = get_argument_string(arg);
263         if (string == NULL) {
264                 errorf(&attribute->source_position,
265                        "__attribute__((visibility(X))) argument is not a string");
266                 return;
267         }
268         elf_visibility_tag_t visibility = get_elf_visibility_from_string(string);
269         if (visibility == ELF_VISIBILITY_ERROR) {
270                 errorf(&attribute->source_position,
271                        "unknown visibility type '%s'", string);
272                 return;
273         }
274
275         switch (entity->kind) {
276         case ENTITY_VARIABLE:
277                 entity->variable.elf_visibility = visibility;
278                 break;
279         case ENTITY_FUNCTION:
280                 entity->function.elf_visibility = visibility;
281                 break;
282         default: {
283                 source_position_t const *const pos  = &attribute->source_position;
284                 char              const *const what = get_entity_kind_name(entity->kind);
285                 symbol_t          const *const sym  = entity->base.symbol;
286                 warningf(WARN_OTHER, pos, "visibility attribute specification on %s '%S' ignored", what, sym);
287                 break;
288         }
289         }
290 }
291
292 static void warn_arguments(const attribute_t *attribute)
293 {
294         if (attribute->a.arguments == NULL)
295                 return;
296
297         source_position_t const *const pos  = &attribute->source_position;
298         char              const *const what = get_attribute_name(attribute->kind);
299         warningf(WARN_OTHER, pos, "attribute '%s' needs no arguments", what);
300 }
301
302 static void handle_attribute_packed_e(const attribute_t *attribute,
303                                       entity_t *entity)
304 {
305 #if 0
306         if (entity->kind != ENTITY_STRUCT) {
307                 source_position_t const *const pos  = &attribute->source_position;
308                 char              const *const what = get_entity_kind_name(entity->kind);
309                 symbol_t          const *const sym  = entity->base.symbol;
310                 warningf(WARN_OTHER, pos, "packed attribute on %s '%S' ignored", what, sym);
311                 return;
312         }
313 #endif
314
315         warn_arguments(attribute);
316         entity->compound.packed = true;
317 }
318
319 static void handle_attribute_packed(const attribute_t *attribute, type_t *type)
320 {
321         if (type->kind != TYPE_COMPOUND_STRUCT) {
322                 source_position_t const *const pos  = &attribute->source_position;
323                 warningf(WARN_OTHER, pos, "packed attribute on type '%T' ignored", type);
324                 return;
325         }
326
327         handle_attribute_packed_e(attribute, (entity_t*) type->compound.compound);
328 }
329
330 static void handle_attribute_asm(const attribute_t *attribute,
331                                       entity_t *entity)
332 {
333         attribute_argument_t *argument = attribute->a.arguments;
334         assert (argument->kind == ATTRIBUTE_ARGUMENT_EXPRESSION);
335         expression_t *expression = argument->v.expression;
336         if (expression->kind != EXPR_STRING_LITERAL)
337                 errorf(&attribute->source_position,
338                        "Invalid asm attribute expression");
339         symbol_t *sym = symbol_table_insert(expression->string_literal.value.begin);
340         entity->function.actual_name = sym;
341         assert(argument->next == NULL);
342         return;
343 }
344
345 void handle_entity_attributes(const attribute_t *attributes, entity_t *entity)
346 {
347         if (entity->kind == ENTITY_TYPEDEF) {
348                 type_t *type = entity->typedefe.type;
349                 type = handle_type_attributes(attributes, type);
350                 entity->typedefe.type = type;
351         } else if (is_declaration(entity)) {
352                 type_t *type = entity->declaration.type;
353                 type = handle_type_attributes(attributes, type);
354                 entity->declaration.type = type;
355         }
356
357         decl_modifiers_t modifiers = 0;
358         const attribute_t *attribute = attributes;
359         for ( ; attribute != NULL; attribute = attribute->next) {
360                 switch(attribute->kind) {
361                 case ATTRIBUTE_GNU_CONST:         modifiers |= DM_CONST; break;
362                 case ATTRIBUTE_GNU_DEPRECATED:    modifiers |= DM_DEPRECATED; break;
363                 case ATTRIBUTE_GNU_NOINLINE:      modifiers |= DM_NOINLINE; break;
364                 case ATTRIBUTE_GNU_RETURNS_TWICE: modifiers |= DM_RETURNS_TWICE; break;
365                 case ATTRIBUTE_GNU_NORETURN:      modifiers |= DM_NORETURN; break;
366                 case ATTRIBUTE_GNU_NAKED:         modifiers |= DM_NAKED; break;
367                 case ATTRIBUTE_GNU_PURE:          modifiers |= DM_PURE; break;
368                 case ATTRIBUTE_GNU_ALWAYS_INLINE: modifiers |= DM_FORCEINLINE; break;
369                 case ATTRIBUTE_GNU_MALLOC:        modifiers |= DM_MALLOC; break;
370                 case ATTRIBUTE_GNU_CONSTRUCTOR:   modifiers |= DM_CONSTRUCTOR; break;
371                 case ATTRIBUTE_GNU_DESTRUCTOR:    modifiers |= DM_DESTRUCTOR; break;
372                 case ATTRIBUTE_GNU_NOTHROW:       modifiers |= DM_NOTHROW; break;
373                 case ATTRIBUTE_GNU_TRANSPARENT_UNION:
374                                                                                   modifiers |= DM_TRANSPARENT_UNION;
375                                                                                   break;
376                 case ATTRIBUTE_GNU_USED:          modifiers |= DM_USED; break;
377                 case ATTRIBUTE_GNU_UNUSED:        modifiers |= DM_UNUSED; break;
378                 case ATTRIBUTE_GNU_DLLIMPORT:     modifiers |= DM_DLLIMPORT; break;
379                 case ATTRIBUTE_GNU_DLLEXPORT:     modifiers |= DM_DLLEXPORT; break;
380                 case ATTRIBUTE_GNU_WEAK:          modifiers |= DM_WEAK; break;
381
382                 case ATTRIBUTE_MS_ALLOCATE:      modifiers |= DM_MALLOC; break;
383                 case ATTRIBUTE_MS_DLLIMPORT:     modifiers |= DM_DLLIMPORT; break;
384                 case ATTRIBUTE_MS_DLLEXPORT:     modifiers |= DM_DLLEXPORT; break;
385                 case ATTRIBUTE_MS_NAKED:         modifiers |= DM_NAKED; break;
386                 case ATTRIBUTE_MS_NOINLINE:      modifiers |= DM_NOINLINE; break;
387                 case ATTRIBUTE_MS_RETURNS_TWICE: modifiers |= DM_RETURNS_TWICE; break;
388                 case ATTRIBUTE_MS_NORETURN:      modifiers |= DM_NORETURN; break;
389                 case ATTRIBUTE_MS_NOTHROW:       modifiers |= DM_NOTHROW; break;
390                 case ATTRIBUTE_MS_THREAD:        modifiers |= DM_THREAD; break;
391                 case ATTRIBUTE_MS_DEPRECATED:    modifiers |= DM_DEPRECATED; break;
392                 case ATTRIBUTE_MS_RESTRICT:      modifiers |= DM_RESTRICT; break;
393                 case ATTRIBUTE_MS_NOALIAS:       modifiers |= DM_NOALIAS; break;
394
395                 case ATTRIBUTE_GNU_PACKED:
396                         handle_attribute_packed_e(attribute, entity);
397                         break;
398
399                 case ATTRIBUTE_GNU_ASM:
400                         handle_attribute_asm(attribute, entity);
401                         break;
402
403                 case ATTRIBUTE_GNU_VISIBILITY:
404                         handle_attribute_visibility(attribute, entity);
405                         break;
406
407                 case ATTRIBUTE_MS_ALIGN:
408                 case ATTRIBUTE_GNU_ALIGNED:
409                         handle_attribute_aligned(attribute, entity);
410                         break;
411                 default: break;
412                 }
413         }
414
415         if (modifiers != 0) {
416                 switch(entity->kind) {
417                 case ENTITY_TYPEDEF:
418                         entity->typedefe.modifiers |= modifiers;
419                         break;
420                 case ENTITY_UNION:
421                 case ENTITY_STRUCT:
422                         entity->compound.modifiers |= modifiers;
423                         break;
424                 case ENTITY_COMPOUND_MEMBER:
425                 case ENTITY_VARIABLE:
426                 case ENTITY_FUNCTION:
427                         entity->declaration.modifiers |= modifiers;
428                         break;
429                 default:
430                         /* TODO: warning */
431                         break;
432                 }
433         }
434 }
435
436 static type_t *change_calling_convention(type_t *type, cc_kind_t cconv)
437 {
438         if (is_typeref(type) || !is_type_function(type)) {
439                 return type;
440         }
441
442         if (type->function.calling_convention == cconv)
443                 return type;
444
445         type_t* new_type = duplicate_type(type);
446         new_type->function.calling_convention = cconv;
447         return identify_new_type(new_type);
448 }
449
450 type_t *handle_type_attributes(const attribute_t *attributes, type_t *type)
451 {
452         const attribute_t *attribute = attributes;
453         for ( ; attribute != NULL; attribute = attribute->next) {
454                 switch(attribute->kind) {
455                 case ATTRIBUTE_GNU_PACKED:
456                         handle_attribute_packed(attribute, type);
457                         break;
458                 case ATTRIBUTE_GNU_CDECL:
459                 case ATTRIBUTE_MS_CDECL:
460                         type = change_calling_convention(type, CC_CDECL);
461                         break;
462                 case ATTRIBUTE_MS_STDCALL:
463                 case ATTRIBUTE_GNU_STDCALL:
464                         type = change_calling_convention(type, CC_STDCALL);
465                         break;
466                 case ATTRIBUTE_MS_FASTCALL:
467                 case ATTRIBUTE_GNU_FASTCALL:
468                         type = change_calling_convention(type, CC_FASTCALL);
469                         break;
470                 case ATTRIBUTE_MS_THISCALL:
471                         type = change_calling_convention(type, CC_THISCALL);
472                         break;
473                 case ATTRIBUTE_GNU_MODE:
474                         type = handle_attribute_mode(attribute, type);
475                         break;
476                 default:
477                         break;
478                 }
479         }
480
481         return type;
482 }
483
484 const char *get_deprecated_string(const attribute_t *attribute)
485 {
486         for ( ; attribute != NULL; attribute = attribute->next) {
487                 if (attribute->kind != ATTRIBUTE_MS_DEPRECATED)
488                         continue;
489
490                 attribute_argument_t *argument = attribute->a.arguments;
491                 return get_argument_string(argument);
492         }
493         return NULL;
494 }
495
496 static bool property_attribute_equal(const attribute_property_argument_t *prop1,
497                                      const attribute_property_argument_t *prop2)
498 {
499         return prop1->put_symbol == prop2->put_symbol
500                 && prop1->get_symbol == prop2->get_symbol;
501 }
502
503 static bool attribute_argument_equal(const attribute_argument_t *arg1,
504                                      const attribute_argument_t *arg2)
505 {
506         if (arg1->kind != arg2->kind)
507                 return false;
508
509         switch (arg1->kind) {
510         case ATTRIBUTE_ARGUMENT_SYMBOL:
511                 return arg1->v.symbol == arg2->v.symbol;
512         case ATTRIBUTE_ARGUMENT_EXPRESSION:
513                 /* TODO */
514                 return false;
515         }
516         panic("Unknown argument type found");
517 }
518
519 static bool attribute_arguments_equal(const attribute_argument_t *args1,
520                                       const attribute_argument_t *args2)
521 {
522         for ( ; args1 != NULL && args2 != NULL;
523              args1 = args1->next, args2 = args2->next) {
524                 if (!attribute_argument_equal(args1, args2))
525                         return false;
526         }
527         /* both should be NULL now */
528         return args1 == args2;
529 }
530
531 bool attributes_equal(const attribute_t *attr1, const attribute_t *attr2)
532 {
533         if (attr1->kind != attr2->kind)
534                 return false;
535
536         switch (attr1->kind) {
537         case ATTRIBUTE_MS_PROPERTY:
538                 return property_attribute_equal(attr1->a.property, attr2->a.property);
539         default:
540                 return attribute_arguments_equal(attr1->a.arguments,
541                                                  attr2->a.arguments);
542         }
543 }