aboutsummaryrefslogtreecommitdiff
path: root/gcc/c/c-tree.h
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2016-05-19 20:29:07 +0000
committerDavid Malcolm <dmalcolm@gcc.gnu.org>2016-05-19 20:29:07 +0000
commit8a40fef3106214c7755971f3e27c715b3968ddf4 (patch)
tree1778edbd3e7143f4500b7f5d7038f20e4466d50c /gcc/c/c-tree.h
parent2a5569fad3cd964d1c8456b07a411189695ad275 (diff)
downloadgcc-8a40fef3106214c7755971f3e27c715b3968ddf4.zip
gcc-8a40fef3106214c7755971f3e27c715b3968ddf4.tar.gz
gcc-8a40fef3106214c7755971f3e27c715b3968ddf4.tar.bz2
PR c/71171: Fix uninitialized source_range in c_parser_postfix_expression
A common way for a c_expr to have an uninitialized src_range is in error-handling, where the "value" field is set to error_mark_node without touching the src_range, leading to complaints from valgrind. This patch introduces a new method c_expr::set_error which sets the value to error_mark_node whilst initializing the src_range to UNKNOWN_LOCATION. This fixes the valgrind issue seen in PR c/71171, along with various other related issues seen when running the testsuite using the checker patch I posted here: https://gcc.gnu.org/ml/gcc-patches/2015-12/msg00887.html (this checker still doesn't fully work yet, but it seems to be good for easily detecting these issues without needing Valgrind). gcc/c/ChangeLog: PR c/71171 * c-parser.c (c_parser_generic_selection): Use c_expr::set_error in error-handling. (c_parser_postfix_expression): Likewise. * c-tree.h (c_expr::set_error): New method. * c-typeck.c (parser_build_binary_op): In error-handling, ensure that result's range is initialized. From-SVN: r236488
Diffstat (limited to 'gcc/c/c-tree.h')
-rw-r--r--gcc/c/c-tree.h9
1 files changed, 9 insertions, 0 deletions
diff --git a/gcc/c/c-tree.h b/gcc/c/c-tree.h
index 4a0236d..444e9a4 100644
--- a/gcc/c/c-tree.h
+++ b/gcc/c/c-tree.h
@@ -143,6 +143,15 @@ struct c_expr
of this expression. */
location_t get_start () const { return src_range.m_start; }
location_t get_finish () const { return src_range.m_finish; }
+
+ /* Set the value to error_mark_node whilst ensuring that src_range
+ is initialized. */
+ void set_error ()
+ {
+ value = error_mark_node;
+ src_range.m_start = UNKNOWN_LOCATION;
+ src_range.m_finish = UNKNOWN_LOCATION;
+ }
};
/* Type alias for struct c_expr. This allows to use the structure