Skip to content

Commit

Permalink
Fix for handling absolute include paths
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Osmialowski <pawel.osmialowski@arm.com>
  • Loading branch information
pawosm-arm committed Jul 11, 2023
1 parent bbf70ee commit a6baa41
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
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)
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

0 comments on commit a6baa41

Please sign in to comment.