[flang-commits] [flang] [flang][OpenMP] Update semantic checks for LINEAR clause (PR #177055)
Krzysztof Parzyszek via flang-commits
flang-commits at lists.llvm.org
Thu Jan 22 06:21:26 PST 2026
================
@@ -759,54 +759,61 @@ void OmpStructureChecker::Enter(const parser::OmpClause::Linear &x) {
auto &modifiers{OmpGetModifiers(x.v)};
linearMod = OmpGetUniqueModifier<parser::OmpLinearModifier>(modifiers);
if (linearMod) {
- // 2.7 Loop Construct Restriction
- if ((llvm::omp::allDoSet | llvm::omp::allSimdSet).test(dir)) {
- context_.Say(clauseSource,
- "A modifier may not be specified in a LINEAR clause on the %s directive"_err_en_US,
- ContextDirectiveAsFortran());
- // Don't return early - continue to check other restrictions
- }
-
auto &desc{OmpGetDescriptor<parser::OmpLinearModifier>()};
- for (auto &[symbol, source] : symbols) {
- if (linearMod->v != parser::OmpLinearModifier::Value::Ref) {
- CheckIntegerNoRef(symbol, source);
- } else {
- if (!IsAllocatable(*symbol) && !IsAssumedShape(*symbol) &&
- !IsPolymorphic(*symbol)) {
- context_.Say(source,
- "The list item `%s` specified with the REF '%s' must be polymorphic variable, assumed-shape array, or a variable with the `ALLOCATABLE` attribute"_err_en_US,
- symbol->name(), desc.name.str());
- }
+ parser::CharBlock modSource{OmpGetModifierSource(modifiers, linearMod)};
+ bool valid{true};
+
+ if (version < 52) {
+ // Modifiers on LINEAR are only allowed on DECLARE SIMD
----------------
kparzysz wrote:
The `linear` clause had modifiers (which later became the _linear-modifier_) before 5.2, they just had a different syntax which was disallowed starting from 5.2[1]. Regardless of the syntax used, the modifiers are represented in the same way in the parse tree (with an extra flag indicating if the old syntax was used). What the earlier spec had in common was that they only allowed _linear-modifier_ to be present on `declare simd`. Starting with 5.2 some cases of the modifier were also allowed regardless of the construct.
This code here checks if the _linear-modifier_ satisfies these restrictions.
[1] For example `linear(val(x) : 1)` vs. `linear(x : val, 1)`
https://github.com/llvm/llvm-project/pull/177055
More information about the flang-commits
mailing list