Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[flang][preprocessor] Change handling of macros in text from Fortran … #108113

Merged
merged 1 commit into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion flang/lib/Parser/preprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ void Preprocessor::Directive(const TokenSequence &dir, Prescanner &prescanner) {
if (included->bytes() > 0) {
ProvenanceRange fileRange{
allSources_.AddIncludedFile(*included, dir.GetProvenanceRange())};
Prescanner{prescanner, /*isNestedInIncludeDirective=*/true}
Prescanner{prescanner, *this, /*isNestedInIncludeDirective=*/true}
.set_encoding(included->encoding())
.Prescan(fileRange);
}
Expand Down
17 changes: 12 additions & 5 deletions flang/lib/Parser/prescan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ Prescanner::Prescanner(Messages &messages, CookedSource &cooked,
backslashFreeFormContinuation_{preprocessor.AnyDefinitions()},
encoding_{allSources_.encoding()} {}

Prescanner::Prescanner(const Prescanner &that, bool isNestedInIncludeDirective)
: messages_{that.messages_}, cooked_{that.cooked_},
preprocessor_{that.preprocessor_}, allSources_{that.allSources_},
features_{that.features_},
Prescanner::Prescanner(const Prescanner &that, Preprocessor &prepro,
bool isNestedInIncludeDirective)
: messages_{that.messages_}, cooked_{that.cooked_}, preprocessor_{prepro},
allSources_{that.allSources_}, features_{that.features_},
isNestedInIncludeDirective_{isNestedInIncludeDirective},
backslashFreeFormContinuation_{that.backslashFreeFormContinuation_},
inFixedForm_{that.inFixedForm_},
Expand Down Expand Up @@ -1104,7 +1104,14 @@ void Prescanner::FortranInclude(const char *firstQuote) {
provenance, static_cast<std::size_t>(p - nextLine_)};
ProvenanceRange fileRange{
allSources_.AddIncludedFile(*included, includeLineRange)};
Prescanner{*this, /*isNestedInIncludeDirective=*/false}
Preprocessor cleanPrepro{allSources_};
if (preprocessor_.IsNameDefined("__FILE__"s)) {
cleanPrepro.DefineStandardMacros(); // __FILE__, __LINE__, &c.
}
if (preprocessor_.IsNameDefined("_CUDA"s)) {
cleanPrepro.Define("_CUDA"s, "1");
}
Prescanner{*this, cleanPrepro, /*isNestedInIncludeDirective=*/false}
.set_encoding(included->encoding())
.Prescan(fileRange);
}
Expand Down
3 changes: 2 additions & 1 deletion flang/lib/Parser/prescan.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ class Prescanner {
public:
Prescanner(Messages &, CookedSource &, Preprocessor &,
common::LanguageFeatureControl);
Prescanner(const Prescanner &, bool isNestedInIncludeDirective);
Prescanner(
const Prescanner &, Preprocessor &, bool isNestedInIncludeDirective);
Prescanner(const Prescanner &) = delete;
Prescanner(Prescanner &&) = delete;

Expand Down
2 changes: 1 addition & 1 deletion flang/module/__fortran_builtins.f90
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
!
!===------------------------------------------------------------------------===!

include '../include/flang/Runtime/magic-numbers.h'
#include '../include/flang/Runtime/magic-numbers.h'

! These naming shenanigans prevent names from Fortran intrinsic modules
! from being usable on INTRINSIC statements, and force the program
Expand Down
2 changes: 1 addition & 1 deletion flang/module/__fortran_ieee_exceptions.f90
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
! here under another name so that IEEE_ARITHMETIC can USE it and export its
! declarations without clashing with a non-intrinsic module in a program.

include '../include/flang/Runtime/magic-numbers.h'
#include '../include/flang/Runtime/magic-numbers.h'

module __fortran_ieee_exceptions
use __fortran_builtins, only: &
Expand Down
2 changes: 1 addition & 1 deletion flang/module/ieee_arithmetic.f90
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

! Fortran 2018 Clause 17

include '../include/flang/Runtime/magic-numbers.h'
#include '../include/flang/Runtime/magic-numbers.h'

module ieee_arithmetic
! F18 Clause 17.1p1:
Expand Down
2 changes: 1 addition & 1 deletion flang/module/iso_fortran_env.f90
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

! See Fortran 2023, subclause 16.10.2

include '../include/flang/Runtime/magic-numbers.h'
#include '../include/flang/Runtime/magic-numbers.h'

module iso_fortran_env

Expand Down
2 changes: 1 addition & 1 deletion flang/test/Driver/include-header.f90
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ program B
end

! include-test-two.f90
INCLUDE "basic-header-two.h"
#include "basic-header-two.h"
#ifdef Y
program Y
#else
Expand Down
1 change: 1 addition & 0 deletions flang/test/Preprocessing/include-file.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print *, sin(0.), j
6 changes: 6 additions & 0 deletions flang/test/Preprocessing/include-line.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
! RUN: %flang_fc1 -fdebug-unparse %s -Dj=1 2>&1 | FileCheck %s
! Ensure that macro definitions don't affect INCLUDE lines (unlike #include)
#define sin cos
!CHECK: PRINT *, 0._4, j
include "include-file.h"
end
Loading