Patch: format checking const arrays

Mark Mitchell mark@codesourcery.com
Wed Oct 18 00:06:00 GMT 2000


  +  if (TREE_CODE (format_tree) == VAR_DECL
  +      && TREE_READONLY (format_tree)
  +      && DECL_INITIAL (format_tree)
  +      && TREE_CODE (DECL_INITIAL (format_tree)) == STRING_CST)
  +    {
  +      /* Extract the string constant initializer.  Note that this may include
  +	 a trailing NUL character that is not in the array (e.g.
  +	 const char a[3] = "foo";).  */
  +      array_size = DECL_SIZE_UNIT (format_tree);
  +      format_tree = DECL_INITIAL (format_tree);
  +    }
     if (TREE_CODE (format_tree) != STRING_CST)
       {
	 res->number_non_literal++;

Does it work to use decl_constant_value instead?  That's what we're
supposed to use to pull the constant initializers out of things and it
has the advantage of checking for `volatile' which is something it
doesn't look like your code does.

Thanks,

--
Mark Mitchell                   mark@codesourcery.com
CodeSourcery, LLC               http://www.codesourcery.com


More information about the Gcc-patches mailing list