From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4771 invoked by alias); 1 Nov 2008 17:46:03 -0000 Received: (qmail 27997 invoked by uid 48); 1 Nov 2008 17:44:41 -0000 Date: Sat, 01 Nov 2008 17:46:00 -0000 Message-ID: <20081101174441.27996.qmail@sourceware.org> X-Bugzilla-Reason: CC References: Subject: [Bug c++/35652] [4.2/4.3/4.4 Regression] offset warning should be given in the front-end In-Reply-To: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "manu at gcc dot gnu dot org" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2008-11/txt/msg00068.txt.bz2 ------- Comment #8 from manu at gcc dot gnu dot org 2008-11-01 17:44 ------- This is my current patch and it works in this testcase. However, it also triggers on cases like: const char *p = str + sizeof(str) Perhaps I am doing this at the wrong place. Any suggestions? @@ -3322,10 +3323,36 @@ pointer_int_sum (enum tree_code resultco /* Create the sum or difference. */ if (resultcode == MINUS_EXPR) intop = fold_build1 (NEGATE_EXPR, sizetype, intop); + + if (TREE_CODE (intop) == INTEGER_CST) + { + tree offset_node; + tree string_cst = string_constant (ptrop, &offset_node); + + if (string_cst != 0 + && !(offset_node && TREE_CODE (offset_node) != INTEGER_CST)) + { + HOST_WIDE_INT max = TREE_STRING_LENGTH (string_cst) - 1; + HOST_WIDE_INT offset; + if (offset_node == 0) + offset = 0; + else if (! host_integerp (offset_node, 0)) + offset = -1; + else + offset = tree_low_cst (offset_node, 0); + + offset = offset + tree_low_cst (intop, 0); + if (offset < 0 || offset > max) + warning_at (location, 0, + "offset %<%ld%> outside bounds of constant string", + tree_low_cst (intop, 0)); + } + } + ret = fold_build2 (POINTER_PLUS_EXPR, result_type, ptrop, intop); fold_undefer_and_ignore_overflow_warnings (); return ret; -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35652