aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
-rw-r--r--ident-list.h1
-rw-r--r--lib.c1
-rw-r--r--pre-process.c33
-rw-r--r--validation/preprocessor/has-attribute.c1
4 files changed, 26 insertions, 10 deletions
diff --git a/ident-list.h b/ident-list.h
index a37a4a1b..75740b9d 100644
--- a/ident-list.h
+++ b/ident-list.h
@@ -59,6 +59,7 @@ IDENT_RESERVED(__label__);
* sparse. */
IDENT(defined);
IDENT(once);
+IDENT(__has_attribute);
IDENT(__has_builtin);
__IDENT(pragma_ident, "__pragma__", 0);
__IDENT(__VA_ARGS___ident, "__VA_ARGS__", 0);
diff --git a/lib.c b/lib.c
index db456a63..48c6dc98 100644
--- a/lib.c
+++ b/lib.c
@@ -1287,6 +1287,7 @@ static void create_builtin_stream(void)
add_pre_buffer("#add_system \"%s/include-fixed\"\n", gcc_base_dir);
add_pre_buffer("#define __has_builtin(x) 0\n");
+ add_pre_buffer("#define __has_attribute(x) 0\n");
add_pre_buffer("#define __builtin_stdarg_start(a,b) ((a) = (__builtin_va_list)(&(b)))\n");
add_pre_buffer("#define __builtin_va_start(a,b) ((a) = (__builtin_va_list)(&(b)))\n");
add_pre_buffer("#define __builtin_ms_va_start(a,b) ((a) = (__builtin_ms_va_list)(&(b)))\n");
diff --git a/pre-process.c b/pre-process.c
index da4b7acd..bf4b8e76 100644
--- a/pre-process.c
+++ b/pre-process.c
@@ -165,6 +165,12 @@ static void replace_with_has_builtin(struct token *token)
replace_with_bool(token, sym && sym->builtin);
}
+static void replace_with_has_attribute(struct token *token)
+{
+ struct symbol *sym = lookup_symbol(token->ident, NS_KEYWORD);
+ replace_with_bool(token, sym && sym->op && sym->op->attribute);
+}
+
static void expand_line(struct token *token)
{
replace_with_integer(token, token->pos.line);
@@ -1592,6 +1598,10 @@ static int expression_value(struct token **where)
state = 4;
beginning = list;
break;
+ } else if (p->ident == &__has_attribute_ident) {
+ state = 6;
+ beginning = list;
+ break;
}
if (!expand_one_symbol(list))
continue;
@@ -1623,29 +1633,34 @@ static int expression_value(struct token **where)
*list = p->next;
continue;
- // __has_builtin(xyz)
- case 4:
+ // __has_builtin(x) or __has_attribute(x)
+ case 4: case 6:
if (match_op(p, '(')) {
- state = 5;
+ state++;
} else {
- sparse_error(p->pos, "missing '(' after \"__has_builtin\"");
+ sparse_error(p->pos, "missing '(' after \"__has_%s\"",
+ state == 4 ? "builtin" : "attribute");
state = 0;
}
*beginning = p;
break;
- case 5:
+ case 5: case 7:
if (token_type(p) != TOKEN_IDENT) {
sparse_error(p->pos, "identifier expected");
state = 0;
break;
}
if (!match_op(p->next, ')'))
- sparse_error(p->pos, "missing ')' after \"__has_builtin\"");
- state = 6;
- replace_with_has_builtin(p);
+ sparse_error(p->pos, "missing ')' after \"__has_%s\"",
+ state == 5 ? "builtin" : "attribute");
+ if (state == 5)
+ replace_with_has_builtin(p);
+ else
+ replace_with_has_attribute(p);
+ state = 8;
*beginning = p;
break;
- case 6:
+ case 8:
state = 0;
*list = p->next;
continue;
diff --git a/validation/preprocessor/has-attribute.c b/validation/preprocessor/has-attribute.c
index ec8dbb06..3149cbfa 100644
--- a/validation/preprocessor/has-attribute.c
+++ b/validation/preprocessor/has-attribute.c
@@ -44,7 +44,6 @@ __has_attribute()??? Quesako?
/*
* check-name: has-attribute
* check-command: sparse -E $file
- * check-known-to-fail
*
* check-output-start