[PATCH] D83703: [flang] Use octal escapes for character literals in modfiles

Tim Keith via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 13 11:29:30 PDT 2020


tskeith created this revision.
tskeith added a reviewer: klausler.
tskeith added a project: Flang.
Herald added a reviewer: jdoerfert.
Herald added a reviewer: DavidTruby.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D83703

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


Index: flang/lib/Semantics/mod-file.h
===================================================================
--- flang/lib/Semantics/mod-file.h
+++ flang/lib/Semantics/mod-file.h
@@ -32,11 +32,13 @@
 
 class ModFileWriter {
 public:
-  ModFileWriter(SemanticsContext &context) : context_{context} {}
+  ModFileWriter(SemanticsContext &);
+  ~ModFileWriter();
   bool WriteAll();
 
 private:
   SemanticsContext &context_;
+  const bool saveUseHexadecimalEscapeSequences_;
   // Buffer to use with raw_string_ostream
   std::string usesBuf_;
   std::string useExtraAttrsBuf_;
Index: flang/lib/Semantics/mod-file.cpp
===================================================================
--- flang/lib/Semantics/mod-file.cpp
+++ flang/lib/Semantics/mod-file.cpp
@@ -98,6 +98,17 @@
   }
 };
 
+ModFileWriter::ModFileWriter(SemanticsContext &context)
+    : context_{context}, saveUseHexadecimalEscapeSequences_{
+                             parser::useHexadecimalEscapeSequences} {
+  // this flag affects character literals: force it to be consistent
+  parser::useHexadecimalEscapeSequences = false;
+}
+
+ModFileWriter::~ModFileWriter() {
+  parser::useHexadecimalEscapeSequences = saveUseHexadecimalEscapeSequences_;
+}
+
 bool ModFileWriter::WriteAll() {
   WriteAll(context_.globalScope());
   return !context_.AnyFatalError();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D83703.277505.patch
Type: text/x-patch
Size: 1326 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200713/ef3abaf0/attachment.bin>


More information about the llvm-commits mailing list