[flang-commits] [flang] [flang][cuda] Relax semantic for device variable in block construct (PR #89330)
via flang-commits
flang-commits at lists.llvm.org
Thu Apr 18 16:10:59 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-semantics
Author: Valentin Clement (バレンタイン クレメン) (clementval)
<details>
<summary>Changes</summary>
There is no restriction for device variable to be in a block construct. Semantic check was raising an error. This patch relax the check to allow the code in tests.
https://docs.nvidia.com/hpc-sdk/compilers/cuda-fortran-prog-guide/#cfref-var-attr-device-data
---
Full diff: https://github.com/llvm/llvm-project/pull/89330.diff
3 Files Affected:
- (modified) flang/lib/Semantics/check-declarations.cpp (+3-2)
- (modified) flang/test/Semantics/cuf03.cuf (+5)
- (added) flang/test/Semantics/cuf12.cuf (+8)
``````````diff
diff --git a/flang/lib/Semantics/check-declarations.cpp b/flang/lib/Semantics/check-declarations.cpp
index 824f1b6053ca39..875929e90fdd31 100644
--- a/flang/lib/Semantics/check-declarations.cpp
+++ b/flang/lib/Semantics/check-declarations.cpp
@@ -1042,9 +1042,10 @@ void CheckHelper::CheckObjectEntity(
parser::ToUpperCaseLetters(common::EnumToString(attr)));
}
} else if (!subpDetails && symbol.owner().kind() != Scope::Kind::Module &&
- symbol.owner().kind() != Scope::Kind::MainProgram) {
+ symbol.owner().kind() != Scope::Kind::MainProgram &&
+ symbol.owner().kind() != Scope::Kind::BlockConstruct) {
messages_.Say(
- "ATTRIBUTES(%s) may apply only to module, host subprogram, or device subprogram data"_err_en_US,
+ "ATTRIBUTES(%s) may apply only to module, host subprogram, block, or device subprogram data"_err_en_US,
parser::ToUpperCaseLetters(common::EnumToString(attr)));
}
}
diff --git a/flang/test/Semantics/cuf03.cuf b/flang/test/Semantics/cuf03.cuf
index 574add9faaade7..8decb8dcaa0f47 100644
--- a/flang/test/Semantics/cuf03.cuf
+++ b/flang/test/Semantics/cuf03.cuf
@@ -85,6 +85,11 @@ module m
real, unified :: ru ! ok
type(t1), unified :: tu ! ok
type(t2) :: t ! ok
+
+ block
+ real, device :: a(100) ! ok
+ end block
end subroutine
+
end module
diff --git a/flang/test/Semantics/cuf12.cuf b/flang/test/Semantics/cuf12.cuf
new file mode 100644
index 00000000000000..1b79c9889dfeaf
--- /dev/null
+++ b/flang/test/Semantics/cuf12.cuf
@@ -0,0 +1,8 @@
+! RUN: %python %S/test_errors.py %s %flang_fc1
+
+program test
+ real, device :: b(100) ! ok
+ block
+ real, device :: a(100) ! ok
+ end block
+end program
``````````
</details>
https://github.com/llvm/llvm-project/pull/89330
More information about the flang-commits
mailing list