Commit 59d49708 by Jason Merrill Committed by Jason Merrill

re PR c++/35652 (offset warning should be given in the front-end)

	PR c++/35652
	* builtins.c (c_strlen): Use EXPR_LOCATION in diagnostics.

From-SVN: r156469
parent 5440c0e7
2010-02-03 Jason Merrill <jason@redhat.com>
PR c++/35652
* builtins.c (c_strlen): Use EXPR_LOCATION in diagnostics.
2010-02-03 Alexandre Oliva <aoliva@redhat.com> 2010-02-03 Alexandre Oliva <aoliva@redhat.com>
PR debug/42896 PR debug/42896
......
...@@ -433,6 +433,7 @@ c_strlen (tree src, int only_value) ...@@ -433,6 +433,7 @@ c_strlen (tree src, int only_value)
HOST_WIDE_INT offset; HOST_WIDE_INT offset;
int max; int max;
const char *ptr; const char *ptr;
location_t loc;
STRIP_NOPS (src); STRIP_NOPS (src);
if (TREE_CODE (src) == COND_EXPR if (TREE_CODE (src) == COND_EXPR
...@@ -450,6 +451,11 @@ c_strlen (tree src, int only_value) ...@@ -450,6 +451,11 @@ c_strlen (tree src, int only_value)
&& (only_value || !TREE_SIDE_EFFECTS (TREE_OPERAND (src, 0)))) && (only_value || !TREE_SIDE_EFFECTS (TREE_OPERAND (src, 0))))
return c_strlen (TREE_OPERAND (src, 1), only_value); return c_strlen (TREE_OPERAND (src, 1), only_value);
if (EXPR_HAS_LOCATION (src))
loc = EXPR_LOCATION (src);
else
loc = input_location;
src = string_constant (src, &offset_node); src = string_constant (src, &offset_node);
if (src == 0) if (src == 0)
return NULL_TREE; return NULL_TREE;
...@@ -475,7 +481,7 @@ c_strlen (tree src, int only_value) ...@@ -475,7 +481,7 @@ c_strlen (tree src, int only_value)
and return that. This would perhaps not be valid if we were dealing and return that. This would perhaps not be valid if we were dealing
with named arrays in addition to literal string constants. */ with named arrays in addition to literal string constants. */
return size_diffop_loc (input_location, size_int (max), offset_node); return size_diffop_loc (loc, size_int (max), offset_node);
} }
/* We have a known offset into the string. Start searching there for /* We have a known offset into the string. Start searching there for
...@@ -494,7 +500,7 @@ c_strlen (tree src, int only_value) ...@@ -494,7 +500,7 @@ c_strlen (tree src, int only_value)
/* Suppress multiple warnings for propagated constant strings. */ /* Suppress multiple warnings for propagated constant strings. */
if (! TREE_NO_WARNING (src)) if (! TREE_NO_WARNING (src))
{ {
warning (0, "offset outside bounds of constant string"); warning_at (loc, 0, "offset outside bounds of constant string");
TREE_NO_WARNING (src) = 1; TREE_NO_WARNING (src) = 1;
} }
return NULL_TREE; return NULL_TREE;
......
// PR c++/35652
// { dg-options "-O" }
#include <string>
int main() {
// blank line padding, could also be code...
//
//
//
//
//
//
//
//
//
std::string s = "";
s += 'x' + "y"; // { dg-warning "bounds of constant string" }
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment