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