Skip to content

Commit

Permalink
[flang] CUDA Fortran - part 3/5: declarations checking
Browse files Browse the repository at this point in the history
Implements checks for CUDA Fortran attributes on objects, types, and
subprograms.  Includes a couple downgrades of existing errors into
warnings that were exposed during testing.

Depends on https://reviews.llvm.org/D150159 &
https://reviews.llvm.org/D150161.

Differential Revision: https://reviews.llvm.org/D150162
  • Loading branch information
klausler committed May 31, 2023
1 parent 8d82f12 commit 3332dc3
Show file tree
Hide file tree
Showing 12 changed files with 498 additions and 65 deletions.
7 changes: 5 additions & 2 deletions flang/include/flang/Evaluate/type.h
Expand Up @@ -22,6 +22,7 @@
#include "integer.h"
#include "logical.h"
#include "real.h"
#include "flang/Common/Fortran-features.h"
#include "flang/Common/Fortran.h"
#include "flang/Common/idioms.h"
#include "flang/Common/real.h"
Expand Down Expand Up @@ -472,8 +473,10 @@ int SelectedCharKind(const std::string &, int defaultKind);
std::optional<DynamicType> ComparisonType(
const DynamicType &, const DynamicType &);

bool IsInteroperableIntrinsicType(
const DynamicType &, bool checkCharLength = true);
bool IsInteroperableIntrinsicType(const DynamicType &,
const common::LanguageFeatureControl * = nullptr,
bool checkCharLength = true);
bool IsCUDAIntrinsicType(const DynamicType &);

// Determine whether two derived type specs are sufficiently identical
// to be considered the "same" type even if declared separately.
Expand Down
3 changes: 2 additions & 1 deletion flang/include/flang/Semantics/type.h
Expand Up @@ -456,7 +456,8 @@ inline const DerivedTypeSpec *DeclTypeSpec::AsDerived() const {
return const_cast<DeclTypeSpec *>(this)->AsDerived();
}

bool IsInteroperableIntrinsicType(const DeclTypeSpec &);
bool IsInteroperableIntrinsicType(
const DeclTypeSpec &, const common::LanguageFeatureControl &);

} // namespace Fortran::semantics
#endif // FORTRAN_SEMANTICS_TYPE_H_
24 changes: 21 additions & 3 deletions flang/lib/Evaluate/type.cpp
Expand Up @@ -747,14 +747,15 @@ std::optional<DynamicType> ComparisonType(
}
}

bool IsInteroperableIntrinsicType(
const DynamicType &type, bool checkCharLength) {
bool IsInteroperableIntrinsicType(const DynamicType &type,
const common::LanguageFeatureControl *features, bool checkCharLength) {
switch (type.category()) {
case TypeCategory::Integer:
return true;
case TypeCategory::Real:
case TypeCategory::Complex:
return type.kind() >= 4; // no short or half floats
return (features && features->IsEnabled(common::LanguageFeature::CUDA)) ||
type.kind() >= 4; // no short or half floats
case TypeCategory::Logical:
return type.kind() == 1; // C_BOOL
case TypeCategory::Character:
Expand All @@ -768,4 +769,21 @@ bool IsInteroperableIntrinsicType(
}
}

bool IsCUDAIntrinsicType(const DynamicType &type) {
switch (type.category()) {
case TypeCategory::Integer:
case TypeCategory::Logical:
return type.kind() <= 8;
case TypeCategory::Real:
return type.kind() >= 2 && type.kind() <= 8;
case TypeCategory::Complex:
return type.kind() == 2 || type.kind() == 4 || type.kind() == 8;
case TypeCategory::Character:
return type.kind() == 1;
default:
// Derived types are tested in Semantics/check-declarations.cpp
return false;
}
}

} // namespace Fortran::evaluate

0 comments on commit 3332dc3

Please sign in to comment.