This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/20318] RFE: add attribute to specify that a function never returns NULL
- From: "dnovillo at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 4 Mar 2005 18:01:03 -0000
- Subject: [Bug c/20318] RFE: add attribute to specify that a function never returns NULL
- References: <20050304153241.20318.jorton@redhat.com>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Additional Comments From dnovillo at gcc dot gnu dot org 2005-03-04 18:01 -------
Adding some of the early analysis that went on in private mail.
> So is there an __attribute__ that we can use to mark that function to
> always return non-NULL, so the compiler knows that path is not possible?
>
No. There is __attribute__ ((noreturn)), but the compiler has no way of knowing
that svn_fs_fs__id_parse is guaranteed to return non-NULL.
This is what the compiler sees in the IL:
root_id_41 = svn_fs_fs__id_parse (node_id_str_39, D.10885_40, pool_5);
if (root_id_41 == 0B) goto <L13>; else goto <L17>;
<L13>:;
svn_error__locate (...);
D.10887_45 = dgettext (...);
svn_err__temp_46 = svn_error_create (160004, 0B, D.10887_45);
# root_id_257 = PHI <root_id_28(10), root_id_41(8)>;
<L17>:;
[ ... ]
<L19>:;
*root_id_p_30 = root_id_257;
At L19, it sees two possible values for root_id (root_id_28 and root_id_41).
root_id_28 is the uninitialized value.
We don't have a "can't return NULL" attribute. Though it would be useful. In
this case, you're better off initializing *root_id_p at the start of the function.
Diego.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20318