From e9332c72565a9c04473072d59db57813c5e9af5a Mon Sep 17 00:00:00 2001 From: peter klausler Date: Thu, 15 Feb 2018 15:56:50 -0800 Subject: [PATCH] [flang] Fix a couple bugs noticed while resolving merge. Original-commit: flang-compiler/f18@dbb32c60a6f9789d2a341959672fd4244a413d1d Reviewed-on: https://github.com/flang-compiler/f18/pull/9 --- flang/lib/parser/preprocessor.cc | 27 ++++++++++++++++----------- flang/lib/parser/prescan.h | 2 +- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/flang/lib/parser/preprocessor.cc b/flang/lib/parser/preprocessor.cc index d9185ae..aa3486b 100644 --- a/flang/lib/parser/preprocessor.cc +++ b/flang/lib/parser/preprocessor.cc @@ -10,6 +10,7 @@ #include #include #include +#include // TODO pmk rm namespace Fortran { namespace parser { @@ -246,11 +247,13 @@ bool Preprocessor::MacroReplacement(const TokenSequence &input, def.set_isDisabled(true); TokenSequence replaced{ReplaceMacros(def.replacement(), prescanner)}; def.set_isDisabled(false); - ProvenanceRange from{def.replacement().GetProvenanceRange()}; - ProvenanceRange use{input.GetTokenProvenanceRange(j)}; - ProvenanceRange newRange{ - allSources_->AddMacroCall(from, use, replaced.ToString())}; - result->Put(replaced, newRange); + if (!replaced.empty()) { + ProvenanceRange from{def.replacement().GetProvenanceRange()}; + ProvenanceRange use{input.GetTokenProvenanceRange(j)}; + ProvenanceRange newRange{ + allSources_->AddMacroCall(from, use, replaced.ToString())}; + result->Put(replaced, newRange); + } continue; } // Possible function-like macro call. Skip spaces and newlines to see @@ -299,11 +302,13 @@ bool Preprocessor::MacroReplacement(const TokenSequence &input, TokenSequence replaced{ ReplaceMacros(def.Apply(args, *allSources_), prescanner)}; def.set_isDisabled(false); - ProvenanceRange from{def.replacement().GetProvenanceRange()}; - ProvenanceRange use{input.GetIntervalProvenanceRange(j, k - j)}; - ProvenanceRange newRange{ - allSources_->AddMacroCall(from, use, replaced.ToString())}; - result->Put(replaced, newRange); + if (!replaced.empty()) { + ProvenanceRange from{def.replacement().GetProvenanceRange()}; + ProvenanceRange use{input.GetIntervalProvenanceRange(j, k - j)}; + ProvenanceRange newRange{ + allSources_->AddMacroCall(from, use, replaced.ToString())}; + result->Put(replaced, newRange); + } j = k; // advance to the terminal ')' } return true; @@ -438,7 +443,7 @@ bool Preprocessor::Directive(const TokenSequence &dir, Prescanner *prescanner) { definitions_.emplace(std::make_pair( nameToken, Definition{argName, dir, j, tokens - j, isVariadic})); } else { - j = SkipBlanks(dir, j + 1, tokens); + j = SkipBlanks(dir, j, tokens); definitions_.emplace( std::make_pair(nameToken, Definition{dir, j, tokens - j})); } diff --git a/flang/lib/parser/prescan.h b/flang/lib/parser/prescan.h index 7130c42..fbdedf0 100644 --- a/flang/lib/parser/prescan.h +++ b/flang/lib/parser/prescan.h @@ -114,7 +114,7 @@ private: int newlineDebt_{0}; // newline characters consumed but not yet emitted bool inCharLiteral_{false}; bool inPreprocessorDirective_{false}; - bool inFixedForm_{true}; + bool inFixedForm_{false}; int fixedFormColumnLimit_{72}; bool enableOldDebugLines_{false}; bool enableBackslashEscapesInCharLiterals_{true}; -- 2.7.4