summaryrefslogtreecommitdiff
path: root/libcpp
diff options
context:
space:
mode:
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>2014-12-19 12:20:58 +0000
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>2014-12-19 12:20:58 +0000
commit33058239ca52559e37bb4e0dd1214fb37464929a (patch)
treec196a5cfa64d537aa3ba5756e62095791c4f3ca3 /libcpp
parent58439d80f1cca7a11af69e8fe825a5b828a8d9bf (diff)
downloadgcc-33058239ca52559e37bb4e0dd1214fb37464929a.tar.gz
PR preprocessor/63831
* c-cppbuiltin.c (c_cpp_builtins): Don't define __has_attribute and __has_cpp_attribute here. * c-ppoutput.c (init_pp_output): Set cb->has_attribute to c_common_has_attribute. * c-common.h (c_common_has_attribute): New prototype. * c-lex.c (init_c_lex): Set cb->has_attribute to c_common_has_attribute instead of cb_has_attribute. (get_token_no_padding): New function. (cb_has_attribute): Renamed to ... (c_common_has_attribute): ... this. No longer static. Use get_token_no_padding, require ()s, don't build TREE_LIST unnecessarily, fix up formatting, adjust diagnostics, call init_attributes. * directives.c (lex_macro_node): Remove __has_attribute__ handling. * internal.h (struct spec_node): Remove n__has_attribute__ field. (struct lexer_state): Remove in__has_attribute__ field. * macro.c (_cpp_builtin_macro_text): Handle BT_HAS_ATTRIBUTE. * identifiers.c (_cpp_init_hashtable): Remove __has_attribute__ handling. * init.c (builtin_array): Add __has_attribute and __has_cpp_attribute. (cpp_init_special_builtins): Don't initialize __has_attribute or __has_cpp_attribute if CLK_ASM or pfile->cb.has_attribute is NULL. * traditional.c (enum ls): Remove ls_has_attribute, ls_has_attribute_close. (_cpp_scan_out_logical_line): Remove __has_attribute__ handling. * include/cpplib.h (enum cpp_builtin_type): Add BT_HAS_ATTRIBUTE. * pch.c (cpp_read_state): Remove __has_attribute__ handling. * expr.c (eval_token): Likewise. (parse_has_attribute): Removed. * c-c++-common/cpp/pr63831-1.c: New test. * c-c++-common/cpp/pr63831-2.c: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@218948 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libcpp')
-rw-r--r--libcpp/ChangeLog20
-rw-r--r--libcpp/directives.c4
-rw-r--r--libcpp/expr.c21
-rw-r--r--libcpp/identifiers.c1
-rw-r--r--libcpp/include/cpplib.h1
-rw-r--r--libcpp/init.c6
-rw-r--r--libcpp/internal.h4
-rw-r--r--libcpp/macro.c4
-rw-r--r--libcpp/pch.c1
-rw-r--r--libcpp/traditional.c18
10 files changed, 34 insertions, 46 deletions
diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog
index df71ac2597a..71a2d0d7e92 100644
--- a/libcpp/ChangeLog
+++ b/libcpp/ChangeLog
@@ -1,3 +1,23 @@
+2014-12-19 Jakub Jelinek <jakub@redhat.com>
+
+ PR preprocessor/63831
+ * directives.c (lex_macro_node): Remove __has_attribute__ handling.
+ * internal.h (struct spec_node): Remove n__has_attribute__ field.
+ (struct lexer_state): Remove in__has_attribute__ field.
+ * macro.c (_cpp_builtin_macro_text): Handle BT_HAS_ATTRIBUTE.
+ * identifiers.c (_cpp_init_hashtable): Remove __has_attribute__
+ handling.
+ * init.c (builtin_array): Add __has_attribute and __has_cpp_attribute.
+ (cpp_init_special_builtins): Don't initialize __has_attribute
+ or __has_cpp_attribute if CLK_ASM or pfile->cb.has_attribute is NULL.
+ * traditional.c (enum ls): Remove ls_has_attribute,
+ ls_has_attribute_close.
+ (_cpp_scan_out_logical_line): Remove __has_attribute__ handling.
+ * include/cpplib.h (enum cpp_builtin_type): Add BT_HAS_ATTRIBUTE.
+ * pch.c (cpp_read_state): Remove __has_attribute__ handling.
+ * expr.c (eval_token): Likewise.
+ (parse_has_attribute): Removed.
+
2014-12-11 Uros Bizjak <ubizjak@gmail.com>
* directives.c (cpp_define_formatted): Use xvasprintf.
diff --git a/libcpp/directives.c b/libcpp/directives.c
index c9be4122511..d0ff56a1861 100644
--- a/libcpp/directives.c
+++ b/libcpp/directives.c
@@ -571,10 +571,6 @@ lex_macro_node (cpp_reader *pfile, bool is_def_or_undef)
|| node == pfile->spec_nodes.n__has_include_next__))
cpp_error (pfile, CPP_DL_ERROR,
"\"__has_include__\" cannot be used as a macro name");
- else if (is_def_or_undef
- && node == pfile->spec_nodes.n__has_attribute__)
- cpp_error (pfile, CPP_DL_ERROR,
- "\"__has_attribute__\" cannot be used as a macro name");
else if (! (node->flags & NODE_POISONED))
return node;
}
diff --git a/libcpp/expr.c b/libcpp/expr.c
index 529709c8560..c24b640ba16 100644
--- a/libcpp/expr.c
+++ b/libcpp/expr.c
@@ -65,7 +65,6 @@ static unsigned int interpret_int_suffix (cpp_reader *, const uchar *, size_t);
static void check_promotion (cpp_reader *, const struct op *);
static cpp_num parse_has_include (cpp_reader *, enum include_type);
-static cpp_num parse_has_attribute (cpp_reader *);
/* Token type abuse to create unary plus and minus operators. */
#define CPP_UPLUS ((enum cpp_ttype) (CPP_LAST_CPP_OP + 1))
@@ -1055,8 +1054,6 @@ eval_token (cpp_reader *pfile, const cpp_token *token,
return parse_has_include (pfile, IT_INCLUDE);
else if (token->val.node.node == pfile->spec_nodes.n__has_include_next__)
return parse_has_include (pfile, IT_INCLUDE_NEXT);
- else if (token->val.node.node == pfile->spec_nodes.n__has_attribute__)
- return parse_has_attribute (pfile);
else if (CPP_OPTION (pfile, cplusplus)
&& (token->val.node.node == pfile->spec_nodes.n_true
|| token->val.node.node == pfile->spec_nodes.n_false))
@@ -2150,21 +2147,3 @@ parse_has_include (cpp_reader *pfile, enum include_type type)
return result;
}
-
-/* Handle meeting "__has_attribute__" in a preprocessor expression. */
-static cpp_num
-parse_has_attribute (cpp_reader *pfile)
-{
- pfile->state.in__has_attribute__++;
-
- cpp_num result;
- result.unsignedp = false;
- result.high = 0;
- result.overflow = false;
-
- result.low = pfile->cb.has_attribute (pfile);
-
- pfile->state.in__has_attribute__--;
-
- return result;
-}
diff --git a/libcpp/identifiers.c b/libcpp/identifiers.c
index 108939a65b2..35d19067495 100644
--- a/libcpp/identifiers.c
+++ b/libcpp/identifiers.c
@@ -72,7 +72,6 @@ _cpp_init_hashtable (cpp_reader *pfile, cpp_hash_table *table)
s->n__VA_ARGS__->flags |= NODE_DIAGNOSTIC;
s->n__has_include__ = cpp_lookup (pfile, DSC("__has_include__"));
s->n__has_include_next__ = cpp_lookup (pfile, DSC("__has_include_next__"));
- s->n__has_attribute__ = cpp_lookup (pfile, DSC("__has_attribute__"));
}
/* Tear down the identifier hash table. */
diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h
index 406200a2805..b36918e1b37 100644
--- a/libcpp/include/cpplib.h
+++ b/libcpp/include/cpplib.h
@@ -676,6 +676,7 @@ enum cpp_builtin_type
BT_PRAGMA, /* `_Pragma' operator */
BT_TIMESTAMP, /* `__TIMESTAMP__' */
BT_COUNTER, /* `__COUNTER__' */
+ BT_HAS_ATTRIBUTE, /* `__has_attribute__(x)' */
BT_FIRST_USER, /* User defined builtin macros. */
BT_LAST_USER = BT_FIRST_USER + 31
};
diff --git a/libcpp/init.c b/libcpp/init.c
index 2add6ea62de..cf0145b6be2 100644
--- a/libcpp/init.c
+++ b/libcpp/init.c
@@ -380,6 +380,8 @@ static const struct builtin_macro builtin_array[] =
B("__LINE__", BT_SPECLINE, true),
B("__INCLUDE_LEVEL__", BT_INCLUDE_LEVEL, true),
B("__COUNTER__", BT_COUNTER, true),
+ B("__has_attribute", BT_HAS_ATTRIBUTE, true),
+ B("__has_cpp_attribute", BT_HAS_ATTRIBUTE, true),
/* Keep builtins not used for -traditional-cpp at the end, and
update init_builtins() if any more are added. */
B("_Pragma", BT_PRAGMA, true),
@@ -460,6 +462,10 @@ cpp_init_special_builtins (cpp_reader *pfile)
for (b = builtin_array; b < builtin_array + n; b++)
{
+ if (b->value == BT_HAS_ATTRIBUTE
+ && (CPP_OPTION (pfile, lang) == CLK_ASM
+ || pfile->cb.has_attribute == NULL))
+ continue;
cpp_hashnode *hp = cpp_lookup (pfile, b->name, b->len);
hp->type = NT_MACRO;
hp->flags |= NODE_BUILTIN;
diff --git a/libcpp/internal.h b/libcpp/internal.h
index 3a111c0144c..427f4c6def6 100644
--- a/libcpp/internal.h
+++ b/libcpp/internal.h
@@ -261,9 +261,6 @@ struct lexer_state
/* Nonzero if in a __has_include__ or __has_include_next__ statement. */
unsigned char in__has_include__;
- /* Nonzero if in a __has_attribute__ statement. */
- unsigned char in__has_attribute__;
-
/* Nonzero if prevent_expansion is true only because output is
being discarded. */
unsigned char discarding_output;
@@ -287,7 +284,6 @@ struct spec_nodes
cpp_hashnode *n__VA_ARGS__; /* C99 vararg macros */
cpp_hashnode *n__has_include__; /* __has_include__ operator */
cpp_hashnode *n__has_include_next__; /* __has_include_next__ operator */
- cpp_hashnode *n__has_attribute__; /* __has_attribute__ operator */
};
typedef struct _cpp_line_note _cpp_line_note;
diff --git a/libcpp/macro.c b/libcpp/macro.c
index 678bf2b6253..c510e497da4 100644
--- a/libcpp/macro.c
+++ b/libcpp/macro.c
@@ -393,6 +393,10 @@ _cpp_builtin_macro_text (cpp_reader *pfile, cpp_hashnode *node)
"__COUNTER__ expanded inside directive with -fdirectives-only");
number = pfile->counter++;
break;
+
+ case BT_HAS_ATTRIBUTE:
+ number = pfile->cb.has_attribute (pfile);
+ break;
}
if (result == NULL)
diff --git a/libcpp/pch.c b/libcpp/pch.c
index d7a2dac347f..3ff39d7ef09 100644
--- a/libcpp/pch.c
+++ b/libcpp/pch.c
@@ -835,7 +835,6 @@ cpp_read_state (cpp_reader *r, const char *name, FILE *f,
s->n__VA_ARGS__ = cpp_lookup (r, DSC("__VA_ARGS__"));
s->n__has_include__ = cpp_lookup (r, DSC("__has_include__"));
s->n__has_include_next__ = cpp_lookup (r, DSC("__has_include_next__"));
- s->n__has_attribute__ = cpp_lookup (r, DSC("__has_attribute__"));
}
old_state = r->state;
diff --git a/libcpp/traditional.c b/libcpp/traditional.c
index 664bf054a03..3d40c2f2122 100644
--- a/libcpp/traditional.c
+++ b/libcpp/traditional.c
@@ -76,9 +76,7 @@ enum ls {ls_none = 0, /* Normal state. */
ls_predicate, /* After the predicate, maybe paren? */
ls_answer, /* In answer to predicate. */
ls_has_include, /* After __has_include__. */
- ls_has_include_close, /* Looking for ')' of __has_include__. */
- ls_has_attribute, /* After __has_attribute__. */
- ls_has_attribute_close}; /* Looking for ')' of __has_attribute__. */
+ ls_has_include_close}; /* Looking for ')' of __has_include__. */
/* Lexing TODO: Maybe handle space in escaped newlines. Stop lex.c
from recognizing comments and directives during its lexing pass. */
@@ -535,12 +533,6 @@ _cpp_scan_out_logical_line (cpp_reader *pfile, cpp_macro *macro)
lex_state = ls_has_include;
continue;
}
- else if (pfile->state.in_expression
- && node == pfile->spec_nodes.n__has_attribute__)
- {
- lex_state = ls_has_attribute;
- continue;
- }
}
break;
@@ -566,8 +558,6 @@ _cpp_scan_out_logical_line (cpp_reader *pfile, cpp_macro *macro)
lex_state = ls_defined_close;
else if (lex_state == ls_has_include)
lex_state = ls_has_include_close;
- else if (lex_state == ls_has_attribute)
- lex_state = ls_has_attribute_close;
}
break;
@@ -606,8 +596,7 @@ _cpp_scan_out_logical_line (cpp_reader *pfile, cpp_macro *macro)
}
}
else if (lex_state == ls_answer || lex_state == ls_defined_close
- || lex_state == ls_has_include_close
- || lex_state == ls_has_attribute_close)
+ || lex_state == ls_has_include_close)
lex_state = ls_none;
}
break;
@@ -689,8 +678,7 @@ _cpp_scan_out_logical_line (cpp_reader *pfile, cpp_macro *macro)
else if (lex_state == ls_hash
|| lex_state == ls_predicate
|| lex_state == ls_defined
- || lex_state == ls_has_include
- || lex_state == ls_has_attribute)
+ || lex_state == ls_has_include)
lex_state = ls_none;
/* ls_answer and ls_defined_close keep going until ')'. */