[flang-commits] [flang] [Flang] Solved issue with inline compiler directive (PR #143699)

via flang-commits flang-commits at lists.llvm.org
Thu Jun 12 00:14:09 PDT 2025


https://github.com/EbinJose2002 updated https://github.com/llvm/llvm-project/pull/143699

>From aeb12e9f01c55b7799090e9fc92e177332a61a91 Mon Sep 17 00:00:00 2001
From: EbinJose2002 <ebin.jose at multicorewareinc.com>
Date: Wed, 11 Jun 2025 18:00:42 +0530
Subject: [PATCH 1/2] Solved an issue with preprocessor comment handling Issue
 was with pointer passing

---
 flang/lib/Parser/prescan.cpp  |  2 +-
 flang/test/temp_test/m.mod    | 16 ++++++++++++++++
 flang/test/temp_test/test.f90 | 19 +++++++++++++++++++
 3 files changed, 36 insertions(+), 1 deletion(-)
 create mode 100644 flang/test/temp_test/m.mod
 create mode 100644 flang/test/temp_test/test.f90

diff --git a/flang/lib/Parser/prescan.cpp b/flang/lib/Parser/prescan.cpp
index 9aef0c9981e3c..2232b94b8da11 100644
--- a/flang/lib/Parser/prescan.cpp
+++ b/flang/lib/Parser/prescan.cpp
@@ -564,7 +564,7 @@ bool Prescanner::MustSkipToEndOfLine() const {
     return true; // skip over ignored columns in right margin (73:80)
   } else if (*at_ == '!' && !inCharLiteral_ &&
       (!inFixedForm_ || tabInCurrentLine_ || column_ != 6)) {
-    return !IsCompilerDirectiveSentinel(at_);
+    return !IsCompilerDirectiveSentinel(at_ + 1);
   } else {
     return false;
   }
diff --git a/flang/test/temp_test/m.mod b/flang/test/temp_test/m.mod
new file mode 100644
index 0000000000000..da352f0465237
--- /dev/null
+++ b/flang/test/temp_test/m.mod
@@ -0,0 +1,16 @@
+!mod$ v1 sum:17d756d2fb56521c
+module m
+contains
+subroutine func1(foo)
+real(2)::foo
+!dir$ ignore_tkr(d) foo
+end
+subroutine func3(foo)
+real(2)::foo
+!dir$ ignore_tkr(d) foo
+end
+subroutine func4(foo)
+real(2)::foo
+!dir$ ignore_tkr(d) foo
+end
+end
diff --git a/flang/test/temp_test/test.f90 b/flang/test/temp_test/test.f90
new file mode 100644
index 0000000000000..5f0bdc457da74
--- /dev/null
+++ b/flang/test/temp_test/test.f90
@@ -0,0 +1,19 @@
+module m
+ contains
+
+! Directive inside macro on same line; works
+#define MACRO(X)  subroutine func1(X);    real(2) :: X;    !dir$ ignore_tkr(d) X; end subroutine func1;
+MACRO(foo)
+
+! Same subroutine, but after preprocessor expansion (-e -fno-reformat); syntax error
+  ! subroutine func2(foo);  real(2) :: foo; !dir$ ignore_tkr(d) foo;  end subroutine func2;
+
+! Parses with line wrap before !dir$
+  subroutine func3(foo);     real(2) :: foo;
+  !dir$ ignore_tkr(d) foo; end subroutine func3;
+
+! Parses with line wrap after !dir$, but swallows the directive
+  subroutine func4(foo); real(2) :: foo; !dir$ ignore_tkr(d) foo;
+  end subroutine func4;
+
+end module
\ No newline at end of file

>From 82125ccf36259b9c072a533230798073531ad8d2 Mon Sep 17 00:00:00 2001
From: EbinJose2002 <ebin.jose at multicorewareinc.com>
Date: Thu, 12 Jun 2025 12:26:56 +0530
Subject: [PATCH 2/2] - Created test for inlined compiler directives

---
 flang/test/Parser/inline-directives.f90 | 29 +++++++++++++++++++++++++
 flang/test/temp_test/m.mod              | 16 --------------
 flang/test/temp_test/test.f90           | 19 ----------------
 3 files changed, 29 insertions(+), 35 deletions(-)
 create mode 100644 flang/test/Parser/inline-directives.f90
 delete mode 100644 flang/test/temp_test/m.mod
 delete mode 100644 flang/test/temp_test/test.f90

diff --git a/flang/test/Parser/inline-directives.f90 b/flang/test/Parser/inline-directives.f90
new file mode 100644
index 0000000000000..24d4f95759a6e
--- /dev/null
+++ b/flang/test/Parser/inline-directives.f90
@@ -0,0 +1,29 @@
+! RUN: %flang_fc1 -fdebug-unparse %s 2>&1 | FileCheck %s
+
+! Test that checks whether compiler directives can be inlined without mistaking it as comment.
+
+module m
+contains
+#define MACRO(X)  subroutine func1(X); real(2) :: X; !dir$ ignore_tkr(d) X; end subroutine func1;
+MACRO(foo)
+
+!CHECK: SUBROUTINE func1 (foo)
+!CHECK: !DIR$ IGNORE_TKR (d) foo
+!CHECK: END SUBROUTINE func1
+
+  subroutine func2(foo)
+    real(2) :: foo; !dir$ ignore_tkr(d) foo;
+  end subroutine func2
+
+!CHECK: SUBROUTINE func2 (foo)
+!CHECK: !DIR$ IGNORE_TKR (d) foo
+!CHECK: END SUBROUTINE func2
+
+  subroutine func3(foo)
+    real(2) :: foo; !dir$ ignore_tkr(d) foo; end subroutine func3;
+
+!CHECK: SUBROUTINE func3 (foo)
+!CHECK: !DIR$ IGNORE_TKR (d) foo
+!CHECK: END SUBROUTINE func3
+
+end module
diff --git a/flang/test/temp_test/m.mod b/flang/test/temp_test/m.mod
deleted file mode 100644
index da352f0465237..0000000000000
--- a/flang/test/temp_test/m.mod
+++ /dev/null
@@ -1,16 +0,0 @@
-!mod$ v1 sum:17d756d2fb56521c
-module m
-contains
-subroutine func1(foo)
-real(2)::foo
-!dir$ ignore_tkr(d) foo
-end
-subroutine func3(foo)
-real(2)::foo
-!dir$ ignore_tkr(d) foo
-end
-subroutine func4(foo)
-real(2)::foo
-!dir$ ignore_tkr(d) foo
-end
-end
diff --git a/flang/test/temp_test/test.f90 b/flang/test/temp_test/test.f90
deleted file mode 100644
index 5f0bdc457da74..0000000000000
--- a/flang/test/temp_test/test.f90
+++ /dev/null
@@ -1,19 +0,0 @@
-module m
- contains
-
-! Directive inside macro on same line; works
-#define MACRO(X)  subroutine func1(X);    real(2) :: X;    !dir$ ignore_tkr(d) X; end subroutine func1;
-MACRO(foo)
-
-! Same subroutine, but after preprocessor expansion (-e -fno-reformat); syntax error
-  ! subroutine func2(foo);  real(2) :: foo; !dir$ ignore_tkr(d) foo;  end subroutine func2;
-
-! Parses with line wrap before !dir$
-  subroutine func3(foo);     real(2) :: foo;
-  !dir$ ignore_tkr(d) foo; end subroutine func3;
-
-! Parses with line wrap after !dir$, but swallows the directive
-  subroutine func4(foo); real(2) :: foo; !dir$ ignore_tkr(d) foo;
-  end subroutine func4;
-
-end module
\ No newline at end of file



More information about the flang-commits mailing list