[flang] Use octal escapes for character literals in modfiles
authorTim Keith <tkeith@nvidia.com>
Mon, 13 Jul 2020 19:19:17 +0000 (12:19 -0700)
committerTim Keith <tkeith@nvidia.com>
Mon, 13 Jul 2020 19:19:18 +0000 (12:19 -0700)
Character literals can be formatted using octal or hex escapes for
non-ascii characters. This is so that the program can be unparsed for
either pgf90 or gfortran to compile. But modfiles should not be affected
by that -- they should be consistent.

This changes causes modfiles to always have character literals formatted
with octal escapes.

Differential Revision: https://reviews.llvm.org/D83703

flang/lib/Semantics/mod-file.cpp
flang/lib/Semantics/mod-file.h

index 2f813d9..6fa59f0 100644 (file)
@@ -8,6 +8,7 @@
 
 #include "mod-file.h"
 #include "resolve-names.h"
+#include "flang/Common/restorer.h"
 #include "flang/Evaluate/tools.h"
 #include "flang/Parser/message.h"
 #include "flang/Parser/parsing.h"
@@ -99,6 +100,9 @@ private:
 };
 
 bool ModFileWriter::WriteAll() {
+  // this flag affects character literals: force it to be consistent
+  auto restorer{
+      common::ScopedSet(parser::useHexadecimalEscapeSequences, false)};
   WriteAll(context_.globalScope());
   return !context_.AnyFatalError();
 }
index 8823c5f..17ffe80 100644 (file)
@@ -32,7 +32,7 @@ class SemanticsContext;
 
 class ModFileWriter {
 public:
-  ModFileWriter(SemanticsContext &context) : context_{context} {}
+  explicit ModFileWriter(SemanticsContext &context) : context_{context} {}
   bool WriteAll();
 
 private: