diff --git a/flang/lib/Semantics/check-declarations.cpp b/flang/lib/Semantics/check-declarations.cpp index 901ac20f8aae9..d49c8e059591c 100644 --- a/flang/lib/Semantics/check-declarations.cpp +++ b/flang/lib/Semantics/check-declarations.cpp @@ -984,7 +984,10 @@ void CheckHelper::CheckObjectEntity( } break; case common::CUDADataAttr::Unified: - if ((!subpDetails || inDeviceSubprogram) && !isComponent) { + if (((!subpDetails && + symbol.owner().kind() != Scope::Kind::MainProgram) || + inDeviceSubprogram) && + !isComponent) { messages_.Say( "Object '%s' with ATTRIBUTES(UNIFIED) must be declared in a host subprogram"_err_en_US, symbol.name()); diff --git a/flang/test/Semantics/cuf03.cuf b/flang/test/Semantics/cuf03.cuf index 472d53db7462a..a98dd60cdb8a4 100644 --- a/flang/test/Semantics/cuf03.cuf +++ b/flang/test/Semantics/cuf03.cuf @@ -89,3 +89,7 @@ module m end module + +program p + real, unified :: um ! ok +end program