aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2010-02-03 11:28:07 -0500
committerJason Merrill <jason@gcc.gnu.org>2010-02-03 11:28:07 -0500
commit59d49708b2f28dfd32e760dbdabe8b97ba5504e1 (patch)
tree65f55d088c341eb4bc1ca12f65d19dddbb3ac8c0 /gcc
parent5440c0e74197052ca981f29b74df9f187f88385e (diff)
downloadgcc-59d49708b2f28dfd32e760dbdabe8b97ba5504e1.zip
gcc-59d49708b2f28dfd32e760dbdabe8b97ba5504e1.tar.gz
gcc-59d49708b2f28dfd32e760dbdabe8b97ba5504e1.tar.bz2
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
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/builtins.c10
-rw-r--r--gcc/testsuite/g++.dg/warn/string1.C18
3 files changed, 31 insertions, 2 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 180d604..8e5b7bc 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+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>
PR debug/42896
diff --git a/gcc/builtins.c b/gcc/builtins.c
index ac96934..b6fd1ea 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -433,6 +433,7 @@ c_strlen (tree src, int only_value)
HOST_WIDE_INT offset;
int max;
const char *ptr;
+ location_t loc;
STRIP_NOPS (src);
if (TREE_CODE (src) == COND_EXPR
@@ -450,6 +451,11 @@ c_strlen (tree src, int only_value)
&& (only_value || !TREE_SIDE_EFFECTS (TREE_OPERAND (src, 0))))
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);
if (src == 0)
return NULL_TREE;
@@ -475,7 +481,7 @@ c_strlen (tree src, int only_value)
and return that. This would perhaps not be valid if we were dealing
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
@@ -494,7 +500,7 @@ c_strlen (tree src, int only_value)
/* Suppress multiple warnings for propagated constant strings. */
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;
}
return NULL_TREE;
diff --git a/gcc/testsuite/g++.dg/warn/string1.C b/gcc/testsuite/g++.dg/warn/string1.C
new file mode 100644
index 0000000..3027727
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/string1.C
@@ -0,0 +1,18 @@
+// 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" }
+}