This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug middle-end/59125] [4.8/4.9 Regression] gcc triggers wrong strncpy_chk
- From: "rguenth at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 14 Nov 2013 09:42:20 +0000
- Subject: [Bug middle-end/59125] [4.8/4.9 Regression] gcc triggers wrong strncpy_chk
- Auto-submitted: auto-generated
- References: <bug-59125-4 at http dot gcc dot gnu dot org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59125
--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
We already re-fold whenever we fold the object-size stmt via fold_stmt looking
up the def of the address - inlining for example triggers this. We'd later
pick up more opportunities if we'd enhance forwprop for this for example with:
@@ -1002,6 +1003,22 @@ forward_propagate_addr_expr (tree name,
bool result;
tree use_rhs;
+ /* If the use is a __builtin_object_size call then try folding it. */
+ if (gimple_call_builtin_p (use_stmt, BUILT_IN_OBJECT_SIZE))
+ {
+ tree res = fold_builtin_object_size (rhs,
+ gimple_call_arg (use_stmt, 1));
+ if (res
+ && TREE_CODE (res) == INTEGER_CST
+ && !integer_all_onesp (res))
+ {
+ gimple_stmt_iterator gsi = gsi_for_stmt (use_stmt);
+ update_call_from_tree (&gsi, res);
+ update_stmt (gsi_stmt (gsi));
+ continue;
+ }
+ }
+
/* If the use is not in a simple assignment statement, then
there is nothing we can do. */
if (gimple_code (use_stmt) != GIMPLE_ASSIGN)
but it does not help this testcase as explained, but it helps the following
one:
#include <string.h>
struct s {
union u {
struct {
char vi[8];
char pi[16];
};
char all[8+16+4];
} u;
int x;
};
void f(struct s *s)
{
char vi[8+1];
char pi[16+1];
strncpy(vi, s->u.vi, sizeof(s->u.vi));
strncpy(s->u.all, "AbcdefghAbcdefghijklmnopAbcd", sizeof(s->u.all));
}