This is an archive of the discontinued LLVM Phabricator instance.

[flang] Search for #include "file" in right directory
ClosedPublic

Authored by klausler on Jan 25 2021, 12:31 PM.

Details

Summary

Make the #include "file" preprocessing directive begin its
search in the same directory as the file containing the directive,
as other preprocessors and our Fortran INCLUDE statement do.

Avoid current working directory for all source files after the original.

Diff Detail

Event Timeline

klausler created this revision.Jan 25 2021, 12:31 PM
klausler requested review of this revision.Jan 25 2021, 12:31 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 25 2021, 12:31 PM
tskeith accepted this revision.Jan 25 2021, 12:46 PM
This revision is now accepted and ready to land.Jan 25 2021, 12:46 PM
This revision was automatically updated to reflect the committed changes.
awarzynski added a subscriber: awarzynski.EditedJan 26 2021, 2:43 AM

Hi @klausler, thank you for submitting this. This patch updates an API that's used in the new driver (i.e. updates in the new driver are missing):

As most Flang buildbots build the new driver, this patch has introduced quite a few build failures:

EDIT
Fixing the build is rather straightforward:

diff --git a/flang/lib/Frontend/FrontendActions.cpp b/flang/lib/Frontend/FrontendActions.cpp
index ee6f71cfc5af..925c7e64ed68 100644
--- a/flang/lib/Frontend/FrontendActions.cpp
+++ b/flang/lib/Frontend/FrontendActions.cpp
@@ -28,7 +28,7 @@ void InputOutputTestAction::ExecuteAction() {
   CompilerInstance &ci = instance();
   Fortran::parser::AllSources &allSources{ci.allSources()};
   const Fortran::parser::SourceFile *sf;
-  sf = allSources.Open(path, error_stream);
+  sf = allSources.Open(path, error_stream, std::nullopt);
   llvm::ArrayRef<char> fileContent = sf->content();

   // Output file descriptor to receive the content of input file.
diff --git a/flang/unittests/Frontend/CompilerInstanceTest.cpp b/flang/unittests/Frontend/CompilerInstanceTest.cpp
index b56473ea44e3..258213344363 100644
--- a/flang/unittests/Frontend/CompilerInstanceTest.cpp
+++ b/flang/unittests/Frontend/CompilerInstanceTest.cpp
@@ -47,7 +47,7 @@ TEST(CompilerInstance, SanityCheckForFileManager) {
   llvm::raw_string_ostream error_stream{buf};
   CompilerInstance compInst;
   const Fortran::parser::SourceFile *sf =
-      compInst.allSources().Open(testFilePath, error_stream);
+      compInst.allSources().Open(testFilePath, error_stream, std::nullopt);

   // 3. Verify the content of the input file
   // This is just a sanity check to make sure that CompilerInstance is capable

However, this patch changes the behavior of the fronted. This causes some of the driver tests to fail (in particular the tests introduced in https://reviews.llvm.org/D93453).

I reverted this as this is currently blocking further work in the new driver and makes our builders to fail. A fixing patch should fix both the failing build and the failing tests.

Please, could test with FLANG_BUILD_NEW_DRIVER set to ON? Also, for a fixing patch:

  • could you add more reviewers?
  • could you add tests?

Is there any way I can help way with this? Thank you!