forked from OSchip/llvm-project
[flang] Do not allow "-" to denote standard input on INCLUDE/#include.
Original-commit: flang-compiler/f18@f645036a16 Reviewed-on: https://github.com/flang-compiler/f18/pull/42 Tree-same-pre-rewrite: false
This commit is contained in:
parent
eec3705f58
commit
ff7d3c7126
|
@ -569,20 +569,22 @@ void Preprocessor::Directive(const TokenSequence &dir, Prescanner *prescanner) {
|
|||
dir.GetTokenProvenance(dirOffset));
|
||||
return;
|
||||
}
|
||||
if (include == "-") {
|
||||
prescanner->Say("#include: can't include standard input"_err_en_US,
|
||||
dir.GetTokenProvenance(dirOffset));
|
||||
return;
|
||||
}
|
||||
std::stringstream error;
|
||||
const SourceFile *included{allSources_.Open(include, &error)};
|
||||
if (included == nullptr) {
|
||||
prescanner->Say(
|
||||
MessageFormattedText("#include: %s"_err_en_US, error.str().data()),
|
||||
dir.GetTokenProvenance(dirOffset));
|
||||
return;
|
||||
} else if (included->bytes() > 0) {
|
||||
ProvenanceRange fileRange{
|
||||
allSources_.AddIncludedFile(*included, dir.GetProvenanceRange())};
|
||||
Prescanner{*prescanner}.Prescan(fileRange);
|
||||
}
|
||||
if (included->bytes() == 0) {
|
||||
return;
|
||||
}
|
||||
ProvenanceRange fileRange{
|
||||
allSources_.AddIncludedFile(*included, dir.GetProvenanceRange())};
|
||||
Prescanner{*prescanner}.Prescan(fileRange);
|
||||
} else {
|
||||
prescanner->Say(MessageFormattedText(
|
||||
"#%s: unknown or unimplemented directive"_err_en_US,
|
||||
|
|
|
@ -540,7 +540,7 @@ std::optional<std::size_t> Prescanner::IsIncludeLine(const char *start) const {
|
|||
return {};
|
||||
}
|
||||
|
||||
bool Prescanner::FortranInclude(const char *firstQuote) {
|
||||
void Prescanner::FortranInclude(const char *firstQuote) {
|
||||
const char *p{firstQuote};
|
||||
while (*p != '"' && *p != '\'') {
|
||||
++p;
|
||||
|
@ -558,13 +558,17 @@ bool Prescanner::FortranInclude(const char *firstQuote) {
|
|||
}
|
||||
if (*p != quote) {
|
||||
Say("malformed path name string"_err_en_US, GetProvenance(p));
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
for (++p; *p == ' ' || *p == '\t'; ++p) {
|
||||
}
|
||||
if (*p != '\n' && *p != '!') {
|
||||
Say("excess characters after path name"_en_US, GetProvenance(p));
|
||||
}
|
||||
if (path == "-") {
|
||||
Say("cannot INCLUDE standard input"_err_en_US, GetProvenance(p));
|
||||
return;
|
||||
}
|
||||
std::stringstream error;
|
||||
Provenance provenance{GetProvenance(lineStart_)};
|
||||
AllSources &allSources{cooked_.allSources()};
|
||||
|
@ -579,17 +583,13 @@ bool Prescanner::FortranInclude(const char *firstQuote) {
|
|||
if (included == nullptr) {
|
||||
Say(MessageFormattedText("INCLUDE: %s"_err_en_US, error.str().data()),
|
||||
provenance);
|
||||
return true;
|
||||
} else if (included->bytes() > 0) {
|
||||
ProvenanceRange includeLineRange{
|
||||
provenance, static_cast<std::size_t>(p - lineStart_)};
|
||||
ProvenanceRange fileRange{
|
||||
allSources.AddIncludedFile(*included, includeLineRange)};
|
||||
Prescanner{*this}.Prescan(fileRange);
|
||||
}
|
||||
if (included->bytes() == 0) {
|
||||
return true;
|
||||
}
|
||||
ProvenanceRange includeLineRange{
|
||||
provenance, static_cast<std::size_t>(p - lineStart_)};
|
||||
ProvenanceRange fileRange{
|
||||
allSources.AddIncludedFile(*included, includeLineRange)};
|
||||
Prescanner{*this}.Prescan(fileRange);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Prescanner::IsPreprocessorDirectiveLine(const char *start) const {
|
||||
|
|
|
@ -132,7 +132,7 @@ private:
|
|||
bool IsFixedFormCommentLine(const char *) const;
|
||||
bool IsFreeFormComment(const char *) const;
|
||||
std::optional<std::size_t> IsIncludeLine(const char *) const;
|
||||
bool FortranInclude(const char *quote);
|
||||
void FortranInclude(const char *quote);
|
||||
bool IsPreprocessorDirectiveLine(const char *) const;
|
||||
const char *FixedFormContinuationLine();
|
||||
bool FixedFormContinuation();
|
||||
|
|
Loading…
Reference in New Issue