Skip to content

Commit 66c18fa

Browse files
committed
[flang][OpenMP] Make OmpDirectiveNameModifier a distrinct type
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 9e7782d commit 66c18fa

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
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+
classname(decltype(basename::v) &&x) : basename(std::move(x)) {} \
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>(

0 commit comments

Comments
 (0)