Skip to content

Conversation

clementval
Copy link
Contributor

@clementval clementval commented Oct 2, 2025

Add support for the !@acc compiler sentinel for conditional compilation line similar to !@cuf sentinel.

@clementval clementval requested a review from klausler October 2, 2025 17:36
@llvmbot llvmbot added flang Flang issues not falling into any other category openacc flang:semantics flang:parser labels Oct 2, 2025
@llvmbot
Copy link
Member

llvmbot commented Oct 2, 2025

@llvm/pr-subscribers-openacc
@llvm/pr-subscribers-flang-parser

@llvm/pr-subscribers-flang-semantics

Author: Valentin Clement (バレンタイン クレメン) (clementval)

Changes

Add support for the !@<!-- -->acc compiler sentinel similar to !@<!-- -->cuf sentinel.


Full diff: https://github.com/llvm/llvm-project/pull/161706.diff

3 Files Affected:

  • (modified) flang/lib/Parser/parsing.cpp (+1)
  • (modified) flang/lib/Parser/prescan.cpp (+5)
  • (added) flang/test/Semantics/OpenACC/acc-sentinel.f90 (+14)
diff --git a/flang/lib/Parser/parsing.cpp b/flang/lib/Parser/parsing.cpp
index 8a8c6ef673a8c..2df6881146af8 100644
--- a/flang/lib/Parser/parsing.cpp
+++ b/flang/lib/Parser/parsing.cpp
@@ -85,6 +85,7 @@ const SourceFile *Parsing::Prescan(const std::string &path, Options options) {
   if (options.features.IsEnabled(LanguageFeature::OpenACC) ||
       (options.prescanAndReformat && noneOfTheAbove)) {
     prescanner.AddCompilerDirectiveSentinel("$acc");
+    prescanner.AddCompilerDirectiveSentinel("@acc");
   }
   if (options.features.IsEnabled(LanguageFeature::OpenMP) ||
       (options.prescanAndReformat && noneOfTheAbove)) {
diff --git a/flang/lib/Parser/prescan.cpp b/flang/lib/Parser/prescan.cpp
index 865c149380d85..66e5b2cbd5c7f 100644
--- a/flang/lib/Parser/prescan.cpp
+++ b/flang/lib/Parser/prescan.cpp
@@ -147,6 +147,11 @@ void Prescanner::Statement() {
         directiveSentinel_[4] == '\0') {
       // CUDA conditional compilation line.
       condOffset = 5;
+    } else if (directiveSentinel_[0] == '@' && directiveSentinel_[1] == 'a' &&
+        directiveSentinel_[2] == 'c' && directiveSentinel_[3] == 'c' &&
+        directiveSentinel_[4] == '\0') {
+      // OpenACC conditional compilation line.
+      condOffset = 5;
     }
     if (condOffset && !preprocessingOnly_) {
       at_ += *condOffset, column_ += *condOffset;
diff --git a/flang/test/Semantics/OpenACC/acc-sentinel.f90 b/flang/test/Semantics/OpenACC/acc-sentinel.f90
new file mode 100644
index 0000000000000..d34d97e8b1b5d
--- /dev/null
+++ b/flang/test/Semantics/OpenACC/acc-sentinel.f90
@@ -0,0 +1,14 @@
+! RUN: %python %S/../test_errors.py %s %flang_fc1 -fopenacc
+
+subroutine test_sentinel()
+! Test for error since we currently do not have an OpenACC module upstream.
+!ERROR: Cannot parse module file for module 'openacc': Source file 'openacc.mod' was not found
+  !@acc use openacc
+  integer :: i
+
+  !$acc parallel loop
+  do i = 1, 10
+  end do
+  !$acc end parallel
+
+end subroutine

@clementval clementval merged commit 6048c2f into llvm:main Oct 2, 2025
12 of 13 checks passed
@clementval clementval deleted the acc_sentinel branch October 2, 2025 20:00
mahesh-attarde pushed a commit to mahesh-attarde/llvm-project that referenced this pull request Oct 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

flang:parser flang:semantics flang Flang issues not falling into any other category openacc

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants