[flang-commits] [flang] [flang] [cuda] Move SetImplicityCUDADevice after symbols in block construct are converted to objects (PR #143791)
Peter Klausler via flang-commits
flang-commits at lists.llvm.org
Thu Jun 12 07:44:26 PDT 2025
================
@@ -2867,8 +2878,31 @@ void ScopeHandler::PopScope() {
// Entities that are not yet classified as objects or procedures are now
// assumed to be objects.
// TODO: Statement functions
+ bool inDeviceSubprogram{false};
+ Symbol *scopeSym{currScope().symbol()};
+ if (currScope().kind() == Scope::Kind::BlockConstruct) {
+ scopeSym = currScope().parent().symbol();
+ }
+ if (scopeSym) {
+ if (auto *details{scopeSym->detailsIf<SubprogramDetails>()}) {
+ // Check the current procedure is a device procedure to apply implicit
+ // attribute at the end.
+ if (auto attrs{details->cudaSubprogramAttrs()}) {
+ if (*attrs == common::CUDASubprogramAttrs::Device ||
+ *attrs == common::CUDASubprogramAttrs::Global ||
+ *attrs == common::CUDASubprogramAttrs::Grid_Global) {
+ inDeviceSubprogram = true;
+ }
+ }
+ }
+ }
for (auto &pair : currScope()) {
ConvertToObjectEntity(*pair.second);
+ if (currScope_->kind() == Scope::Kind::BlockConstruct) {
----------------
klausler wrote:
Please use `currScope()` for consistency with the reference two lines earlier.
You could also put this into its own loop or function after the loop that converts entities to objects.
```
for (auto &pair : currScope()) {
ConvertToObjectEntity(*pair.second);
}
if (inDeviceSubprogram && currScope().kind() == Scope::Kind::BlockConstruct) {
for (auto &pair : currScope()) {
SetImplicitCUDADevice(*pair.second);
}
}
```
https://github.com/llvm/llvm-project/pull/143791
More information about the flang-commits
mailing list