-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[flang] Silence spurious error on non-CUDA use of CUDA module #107444
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Member
|
@llvm/pr-subscribers-flang-semantics Author: Peter Klausler (klausler) ChangesWhen a module file has been compiled with CUDA enabled, don't emit spurious errors about non-interoperable types when that module is read by a USE statement in a later non-CUDA compilation. Full diff: https://github.com/llvm/llvm-project/pull/107444.diff 5 Files Affected:
diff --git a/flang/include/flang/Semantics/type.h b/flang/include/flang/Semantics/type.h
index 04f8b11e992a01..e2d47d38f927f7 100644
--- a/flang/include/flang/Semantics/type.h
+++ b/flang/include/flang/Semantics/type.h
@@ -459,8 +459,5 @@ inline const DerivedTypeSpec *DeclTypeSpec::AsDerived() const {
return const_cast<DeclTypeSpec *>(this)->AsDerived();
}
-std::optional<bool> IsInteroperableIntrinsicType(
- const DeclTypeSpec &, const common::LanguageFeatureControl &);
-
} // namespace Fortran::semantics
#endif // FORTRAN_SEMANTICS_TYPE_H_
diff --git a/flang/lib/Evaluate/type.cpp b/flang/lib/Evaluate/type.cpp
index 5ecc3701b4f246..a1df40667471ad 100644
--- a/flang/lib/Evaluate/type.cpp
+++ b/flang/lib/Evaluate/type.cpp
@@ -820,8 +820,8 @@ std::optional<bool> IsInteroperableIntrinsicType(const DynamicType &type,
return true;
case TypeCategory::Real:
case TypeCategory::Complex:
- return (features && features->IsEnabled(common::LanguageFeature::CUDA)) ||
- type.kind() >= 4; // no short or half floats
+ return type.kind() >= 4 /* not a short or half float */ || !features ||
+ features->IsEnabled(common::LanguageFeature::CUDA);
case TypeCategory::Logical:
return type.kind() == 1; // C_BOOL
case TypeCategory::Character:
diff --git a/flang/lib/Semantics/check-declarations.cpp b/flang/lib/Semantics/check-declarations.cpp
index 734c34276b13b9..c896ee7d293818 100644
--- a/flang/lib/Semantics/check-declarations.cpp
+++ b/flang/lib/Semantics/check-declarations.cpp
@@ -3003,17 +3003,17 @@ parser::Messages CheckHelper::WhyNotInteroperableDerivedType(
} else {
msgs.Annex(std::move(bad));
}
- } else if (!IsInteroperableIntrinsicType(
- *type, context_.languageFeatures())
+ } else if (auto dyType{evaluate::DynamicType::From(*type)}; dyType &&
+ !evaluate::IsInteroperableIntrinsicType(
+ *dyType, &context_.languageFeatures())
.value_or(false)) {
- auto maybeDyType{evaluate::DynamicType::From(*type)};
if (type->category() == DeclTypeSpec::Logical) {
if (context_.ShouldWarn(common::UsageWarning::LogicalVsCBool)) {
msgs.Say(component.name(),
"A LOGICAL component of an interoperable type should have the interoperable KIND=C_BOOL"_port_en_US);
}
- } else if (type->category() == DeclTypeSpec::Character &&
- maybeDyType && maybeDyType->kind() == 1) {
+ } else if (type->category() == DeclTypeSpec::Character && dyType &&
+ dyType->kind() == 1) {
if (context_.ShouldWarn(common::UsageWarning::BindCCharLength)) {
msgs.Say(component.name(),
"A CHARACTER component of an interoperable type should have length 1"_port_en_US);
@@ -3106,10 +3106,15 @@ parser::Messages CheckHelper::WhyNotInteroperableObject(const Symbol &symbol) {
type->category() == DeclTypeSpec::Character &&
type->characterTypeSpec().length().isDeferred()) {
// ok; F'2023 18.3.7 p2(6)
- } else if (derived ||
- IsInteroperableIntrinsicType(*type, context_.languageFeatures())
- .value_or(false)) {
+ } else if (derived) { // type has been checked
+ } else if (auto dyType{evaluate::DynamicType::From(*type)}; dyType &&
+ evaluate::IsInteroperableIntrinsicType(*dyType,
+ InModuleFile() ? nullptr : &context_.languageFeatures())
+ .value_or(false)) {
// F'2023 18.3.7 p2(4,5)
+ // N.B. Language features are not passed to IsInteroperableIntrinsicType
+ // when processing a module file, since the module file might have been
+ // compiled with CUDA while the client is not.
} else if (type->category() == DeclTypeSpec::Logical) {
if (context_.ShouldWarn(common::UsageWarning::LogicalVsCBool) &&
!InModuleFile()) {
diff --git a/flang/lib/Semantics/expression.cpp b/flang/lib/Semantics/expression.cpp
index 60db02dc764b46..1dbc580c5735b7 100644
--- a/flang/lib/Semantics/expression.cpp
+++ b/flang/lib/Semantics/expression.cpp
@@ -1956,7 +1956,7 @@ MaybeExpr ExpressionAnalyzer::Analyze(const parser::ArrayConstructor &array) {
// Check if implicit conversion of expr to the symbol type is legal (if needed),
// and make it explicit if requested.
-static MaybeExpr implicitConvertTo(const semantics::Symbol &sym,
+static MaybeExpr ImplicitConvertTo(const semantics::Symbol &sym,
Expr<SomeType> &&expr, bool keepConvertImplicit) {
if (!keepConvertImplicit) {
return ConvertToType(sym, std::move(expr));
@@ -2196,7 +2196,7 @@ MaybeExpr ExpressionAnalyzer::Analyze(
// convert would cause a segfault. Lowering will deal with
// conditionally converting and preserving the lower bounds in this
// case.
- if (MaybeExpr converted{implicitConvertTo(
+ if (MaybeExpr converted{ImplicitConvertTo(
*symbol, std::move(*value), IsAllocatable(*symbol))}) {
if (auto componentShape{GetShape(GetFoldingContext(), *symbol)}) {
if (auto valueShape{GetShape(GetFoldingContext(), *converted)}) {
diff --git a/flang/lib/Semantics/type.cpp b/flang/lib/Semantics/type.cpp
index cfaee0b8ba6dc5..aa6e8973ebd304 100644
--- a/flang/lib/Semantics/type.cpp
+++ b/flang/lib/Semantics/type.cpp
@@ -893,13 +893,4 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &o, const DeclTypeSpec &x) {
return o << x.AsFortran();
}
-std::optional<bool> IsInteroperableIntrinsicType(
- const DeclTypeSpec &type, const common::LanguageFeatureControl &features) {
- if (auto dyType{evaluate::DynamicType::From(type)}) {
- return IsInteroperableIntrinsicType(*dyType, &features);
- } else {
- return std::nullopt;
- }
-}
-
} // namespace Fortran::semantics
|
When a module file has been compiled with CUDA enabled, don't emit spurious errors about non-interoperable types when that module is read by a USE statement in a later non-CUDA compilation.
wangzpgi
approved these changes
Sep 5, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When a module file has been compiled with CUDA enabled, don't emit spurious errors about non-interoperable types when that module is read by a USE statement in a later non-CUDA compilation.