* C++ PATCH for abi_tag sanity checking
@ 2015-02-02 17:43 Jason Merrill
2015-02-02 22:44 ` Matthias Klose
0 siblings, 1 reply; 2+ messages in thread
From: Jason Merrill @ 2015-02-02 17:43 UTC (permalink / raw)
To: gcc-patches List
[-- Attachment #1: Type: text/plain, Size: 315 bytes --]
One of the EDG guys pointed out to me that we weren't doing any sanity
checking on the arguments to the abi_tag attribute. This patch adds
checks to require that the arguments be strings containing valid
identifiers, so they work appropriately in mangled names.
Tested x86_64-pc-linux-gnu, applying to trunk.
[-- Attachment #2: tag-diag.patch --]
[-- Type: text/x-patch, Size: 2215 bytes --]
commit 3c9202343aca0b0a9d74fee4e6843000f3a612cf
Author: Jason Merrill <jason@redhat.com>
Date: Fri Jan 30 07:45:02 2015 -0500
* tree.c (handle_abi_tag_attribute): Diagnose invalid arguments.
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" }
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: C++ PATCH for abi_tag sanity checking
2015-02-02 17:43 C++ PATCH for abi_tag sanity checking Jason Merrill
@ 2015-02-02 22:44 ` Matthias Klose
0 siblings, 0 replies; 2+ messages in thread
From: Matthias Klose @ 2015-02-02 22:44 UTC (permalink / raw)
To: Jason Merrill, gcc-patches List
On 02/02/2015 06:43 PM, Jason Merrill wrote:
> One of the EDG guys pointed out to me that we weren't doing any sanity checking
> on the arguments to the abi_tag attribute. This patch adds checks to require
> that the arguments be strings containing valid identifiers, so they work
> appropriately in mangled names.
>
> Tested x86_64-pc-linux-gnu, applying to trunk.
thanks, however it would be nice to document what this flags does at all.
Please see PR 64859.
Matthias
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-02-02 22:44 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-02 17:43 C++ PATCH for abi_tag sanity checking Jason Merrill
2015-02-02 22:44 ` Matthias Klose
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).