diff options
author | David Malcolm <dmalcolm@redhat.com> | 2018-07-24 16:06:58 +0000 |
---|---|---|
committer | David Malcolm <dmalcolm@gcc.gnu.org> | 2018-07-24 16:06:58 +0000 |
commit | dad2580c8349b4fc465a695f2e251548861f8c31 (patch) | |
tree | fcbc70ee67c79c6671935010a9ff4e91b5119c4a /gcc/json.cc | |
parent | 8da03df56724152e4f524160b68e63c615d4632a (diff) | |
download | gcc-dad2580c8349b4fc465a695f2e251548861f8c31.zip gcc-dad2580c8349b4fc465a695f2e251548861f8c31.tar.gz gcc-dad2580c8349b4fc465a695f2e251548861f8c31.tar.bz2 |
Fix segfault in -fsave-optimization-record (PR tree-optimization/86636)
There are various ways that it's possible for a gimple statement to
have an UNKNOWN_LOCATION, and for that UNKNOWN_LOCATION to be wrapped
in an ad-hoc location to capture inlining information.
For such a location, LOCATION_FILE (loc) is NULL.
Various places in -fsave-optimization-record were checking for
loc != UNKNOWN_LOCATION
and were passing LOCATION_FILE (loc) to code that assumed a non-NULL
filename, thus leading to segfaults for the above cases.
This patch updates the tests to use
LOCATION_LOCUS (loc) != UNKNOWN_LOCATION
instead, to look through ad-hoc location wrappers, fixing the segfaults.
It also adds various assertions to the affected code.
gcc/ChangeLog:
PR tree-optimization/86636
* json.cc (json::object::set): Fix comment. Add assertions.
(json::array::append): Move here from json.h. Add comment and an
assertion.
(json::string::string): Likewise.
* json.h (json::array::append): Move to json.cc.
(json::string::string): Likewise.
* optinfo-emit-json.cc
(optrecord_json_writer::impl_location_to_json): Assert that we
aren't attempting to write out UNKNOWN_LOCATION, or an ad-hoc
wrapper around it. Expand the location once, rather than three
times.
(optrecord_json_writer::inlining_chain_to_json): Fix the check for
UNKNOWN_LOCATION, to use LOCATION_LOCUS to look through ad-hoc
wrappers.
(optrecord_json_writer::optinfo_to_json): Likewise, in four
places. Fix some overlong lines.
gcc/testsuite/ChangeLog:
PR tree-optimization/86636
* gcc.c-torture/compile/pr86636.c: New test.
From-SVN: r262950
Diffstat (limited to 'gcc/json.cc')
-rw-r--r-- | gcc/json.cc | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/gcc/json.cc b/gcc/json.cc index 3c2aa77..3ead980 100644 --- a/gcc/json.cc +++ b/gcc/json.cc @@ -76,12 +76,15 @@ object::print (pretty_printer *pp) const pp_character (pp, '}'); } -/* Set the json::value * for KEY, taking ownership of VALUE +/* Set the json::value * for KEY, taking ownership of V (and taking a copy of KEY if necessary). */ void object::set (const char *key, value *v) { + gcc_assert (key); + gcc_assert (v); + value **ptr = m_map.get (key); if (ptr) { @@ -126,6 +129,15 @@ array::print (pretty_printer *pp) const pp_character (pp, ']'); } +/* Append non-NULL value V to a json::array, taking ownership of V. */ + +void +array::append (value *v) +{ + gcc_assert (v); + m_elements.safe_push (v); +} + /* class json::number, a subclass of json::value, wrapping a double. */ /* Implementation of json::value::print for json::number. */ @@ -140,6 +152,16 @@ number::print (pretty_printer *pp) const /* class json::string, a subclass of json::value. */ +/* json::string's ctor. */ + +string::string (const char *utf8) +{ + gcc_assert (utf8); + m_utf8 = xstrdup (utf8); +} + +/* Implementation of json::value::print for json::string. */ + void string::print (pretty_printer *pp) const { |