![]() PR other/109163 notes that when we write out JSON files, we traverse the keys within each object via hash_map iteration, and thus the ordering is non-deterministic - it can arbitrarily vary from run to run and from different machines, making it harder for users to compare results and determine if anything has "really" changed. I'm running into this issue with SARIF output, but there are several places where we're currently emitting JSON: * -fsave-optimization-record emits SRCFILE.opt-record.json.gz "This option is experimental and the format of the data within the compressed JSON file is subject to change."; see optinfo-emit-json.{h,cc}, dumpfile.cc, etc * -fdiagnostics-format= with the various "sarif" and "json" options * -fdump-analyzer-json is a developer option in the analyzer * gcov has: "-j, --json-format: Output JSON intermediate format into .gcov.json.gz file" This patch adds an auto_vec to class json::object to preserve key-insertion order, and use it when writing out objects. Potentially this slightly slows down JSON output, but I believe that this isn't normally a bottleneck, and that the benefits to the user of deterministic output are worth it. I had first attempted to use ordered_hash_map.h for this, but ran into impenetrable template errors, so this patch uses a simpler approach of just adding an auto_vec to json::object. Testing showed a failure of diagnostic-format-json-5.c, which was using a convoluted set of regexps to consume the output; I believe that this was brittle, and was intermittently failing for some of the random orderings of output. I rewrote these regexps to work with the expected output order. The other such tests seem to pass with the now-deterministic orderings. gcc/ChangeLog: PR other/109163 * json.cc: Update comments to indicate that we now preserve insertion order of keys within objects. (object::print): Traverse keys in insertion order. (object::set): Preserve insertion order of keys. (selftest::test_writing_objects): Add an additional key to verify that we preserve insertion order. * json.h (object::m_keys): New field. gcc/testsuite/ChangeLog: PR other/109163 * c-c++-common/diagnostic-format-json-1.c: Update comment. * c-c++-common/diagnostic-format-json-2.c: Likewise. * c-c++-common/diagnostic-format-json-3.c: Likewise. * c-c++-common/diagnostic-format-json-4.c: Likewise. * c-c++-common/diagnostic-format-json-5.c: Rewrite regexps. * c-c++-common/diagnostic-format-json-stderr-1.c: Update comment. Signed-off-by: David Malcolm <dmalcolm@redhat.com> |
||
---|---|---|
c++tools | ||
config | ||
contrib | ||
fixincludes | ||
gcc | ||
gnattools | ||
gotools | ||
include | ||
INSTALL | ||
intl | ||
libada | ||
libatomic | ||
libbacktrace | ||
libcc1 | ||
libcody | ||
libcpp | ||
libdecnumber | ||
libffi | ||
libgcc | ||
libgfortran | ||
libgm2 | ||
libgo | ||
libgomp | ||
libiberty | ||
libitm | ||
libobjc | ||
libphobos | ||
libquadmath | ||
libsanitizer | ||
libssp | ||
libstdc++-v3 | ||
libvtv | ||
lto-plugin | ||
maintainer-scripts | ||
zlib | ||
.dir-locals.el | ||
.gitattributes | ||
.gitignore | ||
ABOUT-NLS | ||
ar-lib | ||
ChangeLog | ||
ChangeLog.jit | ||
ChangeLog.tree-ssa | ||
compile | ||
config-ml.in | ||
config.guess | ||
config.rpath | ||
config.sub | ||
configure | ||
configure.ac | ||
COPYING | ||
COPYING.LIB | ||
COPYING.RUNTIME | ||
COPYING3 | ||
COPYING3.LIB | ||
depcomp | ||
install-sh | ||
libtool-ldflags | ||
libtool.m4 | ||
ltgcc.m4 | ||
ltmain.sh | ||
ltoptions.m4 | ||
ltsugar.m4 | ||
ltversion.m4 | ||
lt~obsolete.m4 | ||
MAINTAINERS | ||
Makefile.def | ||
Makefile.in | ||
Makefile.tpl | ||
missing | ||
mkdep | ||
mkinstalldirs | ||
move-if-change | ||
multilib.am | ||
README | ||
symlink-tree | ||
test-driver | ||
ylwrap |
This directory contains the GNU Compiler Collection (GCC). The GNU Compiler Collection is free software. See the files whose names start with COPYING for copying permission. The manuals, and some of the runtime libraries, are under different terms; see the individual source files for details. The directory INSTALL contains copies of the installation information as HTML and plain text. The source of this information is gcc/doc/install.texi. The installation information includes details of what is included in the GCC sources and what files GCC installs. See the file gcc/doc/gcc.texi (together with other files that it includes) for usage and porting information. An online readable version of the manual is in the files gcc/doc/gcc.info*. See http://gcc.gnu.org/bugs/ for how to report bugs usefully. Copyright years on GCC source files may be listed using range notation, e.g., 1987-2012, indicating that every year in the range, inclusive, is a copyrightable year that could otherwise be listed individually.