This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [C PATCH] Make attributes accept enum values (PR c/50459)


On Mon, 14 Apr 2014, Marek Polacek wrote:

Currently it is not possible to use an enum value (or const int in
C++) as an attribute argument (where compiler wants INTEGER_CST).  This
is because the values are represented by CONST_DECL nodes -- and
we don't deal with them.  I think it's viable to accept them too,
and that is what this patch does along with some clean ups.

Thanks.

+/* Perform default promotions or extract the integer constant from
+   an enum value.  This function is used for getting a value from
+   an attribute argument.  */
+
+static tree
+get_attrib_value (tree val)
+{
+  if (val
+      && TREE_CODE (val) != IDENTIFIER_NODE
+      && TREE_CODE (val) != FUNCTION_DECL)
+    val = default_conversion (val);
+  else if (TREE_CODE (val) == IDENTIFIER_NODE)
+    {
+      tree t = lookup_name (val);
+      if (t && TREE_CODE (t) == CONST_DECL)
+	return DECL_INITIAL (t);
+    }
+  return val;
+}

If val is NULL, it seems you still end up looking at its TREE_CODE?
(don't know if that can happen)

In C++, default_conversion probably handles IDENTIFIER_NODE just fine, but having different code for the 2 languages would not be nice, right?

--
Marc Glisse


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]