Commit 4c5cf0b2 by Jason Merrill Committed by Jason Merrill

* tree.c (handle_abi_tag_attribute): Diagnose invalid arguments.

From-SVN: r220356
parent 6f105c50
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
......
......@@ -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))
......
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" }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment