llvm/flang/lib
Tim Keith 73c630a4ea [flang] Improve module file reading and writing
Fix problems with writing a mod file while another compilation is
reading or writing. Write to a temp and then rename it:
- compute the new contents of the .mod file
- if it already exists, check if it is already correct
- if not, write new contents to a temp file
- rename the temp to the final destination

`mkstemps()` seems to be the best way to create the temp file.
It returns a file descriptor, so change the rest of the mod file
writing to use POSIX open/read/write/close. This seems to set
errno more reliably too.

There is some extra work around creating the temp to make it have
the same directory and suffix as the final file (so that if one gets
left behind by a crash, "rm *.mod" still cleans it up).
`mkstemps()` creates file with 0600 permissions so try to change it
to what it would have been if we just wrote the file.

Change module file reading to only read the file once; we used to
read it to verify the checksum and then again to parse it.
Instead, change `Parsing` so that we can get the file contents
after `Prescan()` and use that to verify the checksum. Also, it has
a mechanism for searching directories for files, so make use of that
instead of duplicating that functionality in `ModFileReader`.
This requires some changes to how errors are returned so they can
be reported in the right place.

Original-commit: flang-compiler/f18@d0d54971a5
Reviewed-on: https://github.com/flang-compiler/f18/pull/758
Tree-same-pre-rewrite: false
2019-09-25 14:55:40 -07:00
..
common [flang] More responses to pull request comments. 2019-09-24 15:33:51 -07:00
decimal [flang] Cope better with ridiculously large exponents on input 2019-08-23 11:31:47 -07:00
evaluate [flang] Fix build on OSX 2019-09-25 10:40:01 -07:00
parser [flang] Improve module file reading and writing 2019-09-25 14:55:40 -07:00
semantics [flang] Improve module file reading and writing 2019-09-25 14:55:40 -07:00
CMakeLists.txt [flang] Testing & debugging 2019-08-23 11:31:24 -07:00