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

Fix for handling absolute include paths #1404

Merged
merged 1 commit into from
Jul 19, 2023
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
18 changes: 18 additions & 0 deletions test/llvm_ir_correct/include-self.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
!
! Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
! See https://llvm.org/LICENSE.txt for license information.
! SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
!

! RUN: %flang -cpp %s -DSELF=\"`realpath "%s"`\" -S -emit-llvm -o - | FileCheck %s

#ifndef __SELF_INCLUDED
#define __SELF_INCLUDED

#include SELF

subroutine foo
! CHECK: foo
end subroutine

#endif
11 changes: 11 additions & 0 deletions tools/flang1/flang1exe/accpp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2103,6 +2103,7 @@ add_to_incllist(char *fullname)
static void
_doincl(char *name, int type, LOGICAL include_next)
{
FILE *tmpfp;
char fullname[MAX_PATHNAME_LEN];
int i;

Expand Down Expand Up @@ -2130,6 +2131,16 @@ _doincl(char *name, int type, LOGICAL include_next)
goto found;
}

if (type == 0) { /* could be absolute path, check where it leads to */
tmpfp = fopen(name, "r");
if (tmpfp) {
snprintf(fullname, MAX_PATHNAME_LEN, "%s", name);
idir.last = 0;
if (fclose(tmpfp) == 0)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using fopen and fclose here makes the preprocessor behave different for this specific case. In the other cases, fndpath calls access to determine if an included file exists. Shall we do the same here?

goto found;
}
}

pperror(206, name, 4); /* cpp just continues, but why?? */
return;

Expand Down
11 changes: 11 additions & 0 deletions tools/flang1/flang1exe/fpp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,7 @@ dodef(void)
static void
doincl(LOGICAL include_next)
{
FILE *tmpfp;
int toktyp;
char buff[MAX_FNAME_LEN];
char fullname[MAX_FNAME_LEN];
Expand Down Expand Up @@ -1178,6 +1179,16 @@ doincl(LOGICAL include_next)
goto found;
}

if (type == 0) { /* could be absolute path, check where it leads to */
tmpfp = fopen(buff, "r");
if (tmpfp) {
snprintf(fullname, MAX_FNAME_LEN, "%s", buff);
idir.last = 0;
if (fclose(tmpfp) == 0)
goto found;
}
}

pperror(226, buff, 4); /* cpp just continues, but why?? */
return;

Expand Down
Loading