Skip to content

Commit 6ffcfc5

Browse files
authored
[flang][OpenMP] Make OmpDirectiveNameModifier a distrinct type (#150768)
It was an alias for OmpDirectiveName, which could cause confusion in parse-tree visitors: a visitor for OmpDirectiveNameModifier could be executed for an OmpDirectiveName node, leading to unexpected results.
1 parent 6727339 commit 6ffcfc5

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3469,13 +3469,20 @@ WRAPPER_CLASS(PauseStmt, std::optional<StopCode>);
34693469

34703470
// --- Common definitions
34713471

3472+
#define INHERITED_WRAPPER_CLASS_BOILERPLATE(classname, basename) \
3473+
BOILERPLATE(classname); \
3474+
using basename::basename; \
3475+
classname(basename &&base) : basename(std::move(base)) {} \
3476+
using WrapperTrait = std::true_type
3477+
34723478
struct OmpClause;
34733479
struct OmpDirectiveSpecification;
34743480

34753481
struct OmpDirectiveName {
34763482
// No boilerplates: this class should be copyable, movable, etc.
34773483
constexpr OmpDirectiveName() = default;
34783484
constexpr OmpDirectiveName(const OmpDirectiveName &) = default;
3485+
constexpr OmpDirectiveName(llvm::omp::Directive x) : v(x) {}
34793486
// Construct from an already parsed text. Use Verbatim for this because
34803487
// Verbatim's source corresponds to an actual source ___location.
34813488
// This allows "construct<OmpDirectiveName>(Verbatim("<name>"))".
@@ -3848,7 +3855,10 @@ struct OmpDeviceModifier {
38483855
// [*] The IF clause is allowed on CANCEL in OpenMP 4.5, but only without
38493856
// the directive-name-modifier. For the sake of uniformity CANCEL can be
38503857
// considered a valid value in 4.5 as well.
3851-
using OmpDirectiveNameModifier = OmpDirectiveName;
3858+
struct OmpDirectiveNameModifier : public OmpDirectiveName {
3859+
INHERITED_WRAPPER_CLASS_BOILERPLATE(
3860+
OmpDirectiveNameModifier, OmpDirectiveName);
3861+
};
38523862

38533863
// Ref: [5.1:205-209], [5.2:166-168]
38543864
//

flang/lib/Parser/openmp-parsers.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,8 @@ TYPE_PARSER(construct<OmpDeviceModifier>(
466466
"ANCESTOR" >> pure(OmpDeviceModifier::Value::Ancestor) ||
467467
"DEVICE_NUM" >> pure(OmpDeviceModifier::Value::Device_Num)))
468468

469+
TYPE_PARSER(construct<OmpDirectiveNameModifier>(OmpDirectiveNameParser{}))
470+
469471
TYPE_PARSER(construct<OmpExpectation>( //
470472
"PRESENT" >> pure(OmpExpectation::Value::Present)))
471473

@@ -609,7 +611,8 @@ TYPE_PARSER(sourced(construct<OmpFromClause::Modifier>(
609611
TYPE_PARSER(sourced(
610612
construct<OmpGrainsizeClause::Modifier>(Parser<OmpPrescriptiveness>{})))
611613

612-
TYPE_PARSER(sourced(construct<OmpIfClause::Modifier>(OmpDirectiveNameParser{})))
614+
TYPE_PARSER(sourced(
615+
construct<OmpIfClause::Modifier>(Parser<OmpDirectiveNameModifier>{})))
613616

614617
TYPE_PARSER(sourced(
615618
construct<OmpInitClause::Modifier>(

flang/test/Examples/omp-atomic.f90

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,21 @@
3131
! CHECK-NEXT: - clause: read
3232
! CHECK-NEXT: details: ''
3333
! CHECK-NEXT: - clause: seq_cst
34-
! CHECK-NEXT: details: 'name_modifier=atomic;'
34+
! CHECK-NEXT: details: ''
3535
! CHECK-NEXT:- file: '{{[^"]*}}omp-atomic.f90'
3636
! CHECK-NEXT: line: 12
3737
! CHECK-NEXT: construct: atomic
3838
! CHECK-NEXT: clauses:
3939
! CHECK-NEXT: - clause: seq_cst
40-
! CHECK-NEXT: details: 'name_modifier=atomic;'
40+
! CHECK-NEXT: details: ''
4141
! CHECK-NEXT: - clause: write
4242
! CHECK-NEXT: details: ''
4343
! CHECK-NEXT:- file: '{{[^"]*}}omp-atomic.f90'
4444
! CHECK-NEXT: line: 16
4545
! CHECK-NEXT: construct: atomic
4646
! CHECK-NEXT: clauses:
4747
! CHECK-NEXT: - clause: capture
48-
! CHECK-NEXT: details: 'name_modifier=atomic;name_modifier=atomic;'
48+
! CHECK-NEXT: details: ''
4949
! CHECK-NEXT: - clause: seq_cst
5050
! CHECK-NEXT: details: ''
5151
! CHECK-NEXT:- file: '{{[^"]*}}omp-atomic.f90'

0 commit comments

Comments
 (0)