Skip to content

Commit 467487f

Browse files
authored
[flang][OpenMP] Reuse semantic check for "constantness" of alignment (#163624)
Use ScalarIntConstantExpr in the parse tree instead of ScalarIntExpr. This will still parse a general expression, but the semantic checker for expressions will automatically perfom a test for whether the value is constant or not. Use that instead of manual checks, it will make diagnostics more uniform. There is no functional change other than that.
1 parent 0ca1447 commit 467487f

File tree

5 files changed

+8
-9
lines changed

5 files changed

+8
-9
lines changed

flang/include/flang/Parser/parse-tree.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4202,7 +4202,7 @@ struct OmpAffinityClause {
42024202

42034203
// Ref: 5.2: [174]
42044204
struct OmpAlignClause {
4205-
WRAPPER_CLASS_BOILERPLATE(OmpAlignClause, ScalarIntExpr);
4205+
WRAPPER_CLASS_BOILERPLATE(OmpAlignClause, ScalarIntConstantExpr);
42064206
};
42074207

42084208
// Ref: [4.5:72-81], [5.0:110-119], [5.1:134-143], [5.2:169-170]

flang/lib/Parser/openmp-parsers.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1094,7 +1094,7 @@ TYPE_PARSER(construct<OmpBindClause>(
10941094
"TEAMS" >> pure(OmpBindClause::Binding::Teams) ||
10951095
"THREAD" >> pure(OmpBindClause::Binding::Thread)))
10961096

1097-
TYPE_PARSER(construct<OmpAlignClause>(scalarIntExpr))
1097+
TYPE_PARSER(construct<OmpAlignClause>(scalarIntConstantExpr))
10981098

10991099
TYPE_PARSER(construct<OmpAtClause>(
11001100
"EXECUTION" >> pure(OmpAtClause::ActionTime::Execution) ||

flang/lib/Semantics/check-omp-structure.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1563,9 +1563,8 @@ void OmpStructureChecker::Leave(const parser::OpenMPRequiresConstruct &) {
15631563

15641564
void OmpStructureChecker::CheckAlignValue(const parser::OmpClause &clause) {
15651565
if (auto *align{std::get_if<parser::OmpClause::Align>(&clause.u)}) {
1566-
if (const auto &v{GetIntValue(align->v)}; !v || *v <= 0) {
1567-
context_.Say(clause.source,
1568-
"The alignment value should be a constant positive integer"_err_en_US);
1566+
if (const auto &v{GetIntValue(align->v)}; v && *v <= 0) {
1567+
context_.Say(clause.source, "The alignment should be positive"_err_en_US);
15691568
}
15701569
}
15711570
}

flang/test/Parser/OpenMP/allocate-align-tree.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ end program allocate_align_tree
2626
!CHECK: | | ExecutionPartConstruct -> ExecutableConstruct -> OpenMPConstruct -> OpenMPExecutableAllocate
2727
!CHECK-NEXT: | | | Verbatim
2828
!CHECK-NEXT: | | | OmpObjectList -> OmpObject -> Designator -> DataRef -> Name = 'xarray'
29-
!CHECK-NEXT: | | | OmpClauseList -> OmpClause -> Align -> OmpAlignClause -> Scalar -> Integer -> Expr = '32_4'
29+
!CHECK-NEXT: | | | OmpClauseList -> OmpClause -> Align -> OmpAlignClause -> Scalar -> Integer -> Constant -> Expr = '32_4'
3030
!CHECK-NEXT: | | | | LiteralConstant -> IntLiteralConstant = '32'
3131
!CHECK-NEXT: | | | OmpClause -> Allocator -> Scalar -> Integer -> Expr = '2_8'
3232
!CHECK-NEXT: | | | | Designator -> DataRef -> Name = 'omp_large_cap_mem_alloc'
3333
!CHECK-NEXT: | | | OpenMPDeclarativeAllocate
3434
!CHECK-NEXT: | | | | Verbatim
3535
!CHECK-NEXT: | | | | OmpObjectList -> OmpObject -> Designator -> DataRef -> Name = 'j'
36-
!CHECK-NEXT: | | | | OmpClauseList -> OmpClause -> Align -> OmpAlignClause -> Scalar -> Integer -> Expr = '16_4'
36+
!CHECK-NEXT: | | | | OmpClauseList -> OmpClause -> Align -> OmpAlignClause -> Scalar -> Integer -> Constant -> Expr = '16_4'
3737
!CHECK-NEXT: | | | | | LiteralConstant -> IntLiteralConstant = '16'
3838
!CHECK-NEXT: | | | AllocateStmt
3939

flang/test/Semantics/OpenMP/allocate-align01.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ program allocate_align_tree
1111
integer :: z, t, xx
1212
t = 2
1313
z = 3
14-
!ERROR: The alignment value should be a constant positive integer
14+
!ERROR: Must be a constant value
1515
!$omp allocate(j) align(xx)
1616
!WARNING: The executable form of the OpenMP ALLOCATE directive has been deprecated, please use ALLOCATORS instead [-Wopen-mp-usage]
17-
!ERROR: The alignment value should be a constant positive integer
17+
!ERROR: The alignment should be positive
1818
!$omp allocate(xarray) align(-32) allocator(omp_large_cap_mem_alloc)
1919
allocate(j(z), xarray(t))
2020
end program allocate_align_tree

0 commit comments

Comments
 (0)