aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2015-02-02 12:46:56 -0500
committerJason Merrill <jason@gcc.gnu.org>2015-02-02 12:46:56 -0500
commit4c5cf0b29adf3d1c90881ec44691e1189a6bf453 (patch)
tree84f1f32d8b6cb0021381f096ab06ef0a2fc595d4
parent6f105c502c1d53ea7352d2c20d66b8e0c87c1fa2 (diff)
downloadgcc-4c5cf0b29adf3d1c90881ec44691e1189a6bf453.zip
gcc-4c5cf0b29adf3d1c90881ec44691e1189a6bf453.tar.gz
gcc-4c5cf0b29adf3d1c90881ec44691e1189a6bf453.tar.bz2
* tree.c (handle_abi_tag_attribute): Diagnose invalid arguments.
From-SVN: r220356
-rw-r--r--gcc/cp/ChangeLog4
-rw-r--r--gcc/cp/tree.c44
-rw-r--r--gcc/testsuite/g++.dg/abi/abi-tag13.C5
3 files changed, 53 insertions, 0 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 6cbb3f3..2e5e2a5 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,7 @@
+2015-02-02 Jason Merrill <jason@redhat.com>
+
+ * tree.c (handle_abi_tag_attribute): Diagnose invalid arguments.
+
2015-01-30 Joseph Myers <joseph@codesourcery.com>
* class.c, except.c, parser.c, pt.c: All callers of fatal_error
diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c
index afb57a3..c51e42d 100644
--- a/gcc/cp/tree.c
+++ b/gcc/cp/tree.c
@@ -3501,6 +3501,50 @@ static tree
handle_abi_tag_attribute (tree* node, tree name, tree args,
int flags, bool* no_add_attrs)
{
+ for (tree arg = args; arg; arg = TREE_CHAIN (arg))
+ {
+ tree elt = TREE_VALUE (arg);
+ if (TREE_CODE (elt) != STRING_CST
+ || (!same_type_ignoring_top_level_qualifiers_p
+ (strip_array_types (TREE_TYPE (elt)),
+ char_type_node)))
+ {
+ error ("arguments to the %qE attribute must be narrow string "
+ "literals", name);
+ goto fail;
+ }
+ const char *begin = TREE_STRING_POINTER (elt);
+ const char *end = begin + TREE_STRING_LENGTH (elt);
+ for (const char *p = begin; p != end; ++p)
+ {
+ char c = *p;
+ if (p == begin)
+ {
+ if (!ISALPHA (c) && c != '_')
+ {
+ error ("arguments to the %qE attribute must contain valid "
+ "identifiers", name);
+ inform (input_location, "%<%c%> is not a valid first "
+ "character for an identifier", c);
+ goto fail;
+ }
+ }
+ else if (p == end - 1)
+ gcc_assert (c == 0);
+ else
+ {
+ if (!ISALNUM (c) && c != '_')
+ {
+ error ("arguments to the %qE attribute must contain valid "
+ "identifiers", name);
+ inform (input_location, "%<%c%> is not a valid character "
+ "in an identifier", c);
+ goto fail;
+ }
+ }
+ }
+ }
+
if (TYPE_P (*node))
{
if (!OVERLOAD_TYPE_P (*node))
diff --git a/gcc/testsuite/g++.dg/abi/abi-tag13.C b/gcc/testsuite/g++.dg/abi/abi-tag13.C
new file mode 100644
index 0000000..34e8da3
--- /dev/null
+++ b/gcc/testsuite/g++.dg/abi/abi-tag13.C
@@ -0,0 +1,5 @@
+const char *foo = "bar";
+void __attribute((abi_tag(foo))) f1() {} // { dg-error "abi_tag" }
+void __attribute((abi_tag(L"foo"))) f2(); // { dg-error "abi_tag" }
+void __attribute((abi_tag("3foo"))) f3(); // { dg-error "abi_tag" }
+void __attribute((abi_tag(1))) f5(); // { dg-error "abi_tag" }