@@ -384,6 +384,9 @@ class OmpAttributeVisitor : DirectiveAttributeVisitor<llvm::omp::Directive> {
384384 bool Pre (const parser::OpenMPSectionsConstruct &);
385385 void Post (const parser::OpenMPSectionsConstruct &) { PopContext (); }
386386
387+ bool Pre (const parser::OpenMPSectionConstruct &);
388+ void Post (const parser::OpenMPSectionConstruct &) { PopContext (); }
389+
387390 bool Pre (const parser::OpenMPCriticalConstruct &critical);
388391 void Post (const parser::OpenMPCriticalConstruct &) { PopContext (); }
389392
@@ -2003,6 +2006,12 @@ bool OmpAttributeVisitor::Pre(const parser::OpenMPSectionsConstruct &x) {
20032006 return true ;
20042007}
20052008
2009+ bool OmpAttributeVisitor::Pre (const parser::OpenMPSectionConstruct &x) {
2010+ PushContext (x.source , llvm::omp::Directive::OMPD_section);
2011+ GetContext ().withinConstruct = true ;
2012+ return true ;
2013+ }
2014+
20062015bool OmpAttributeVisitor::Pre (const parser::OpenMPCriticalConstruct &x) {
20072016 const auto &beginCriticalDir{std::get<parser::OmpCriticalDirective>(x.t )};
20082017 const auto &endCriticalDir{std::get<parser::OmpEndCriticalDirective>(x.t )};
@@ -3024,8 +3033,13 @@ void OmpAttributeVisitor::CheckLabelContext(const parser::CharBlock source,
30243033 const parser::CharBlock target, std::optional<DirContext> sourceContext,
30253034 std::optional<DirContext> targetContext) {
30263035 auto dirContextsSame = [](DirContext &lhs, DirContext &rhs) -> bool {
3027- // Sometimes nested constructs share a scope but are different contexts
3028- return (lhs.scope == rhs.scope ) && (lhs.directive == rhs.directive );
3036+ // Sometimes nested constructs share a scope but are different contexts.
3037+ // The directiveSource comparison is for OmpSection. Sections do not have
3038+ // their own scopes and two different sections both have the same directive.
3039+ // Their source however is different. This string comparison is unfortunate
3040+ // but should only happen for GOTOs inside of SECTION.
3041+ return (lhs.scope == rhs.scope ) && (lhs.directive == rhs.directive ) &&
3042+ (lhs.directiveSource == rhs.directiveSource );
30293043 };
30303044 unsigned version{context_.langOptions ().OpenMPVersion };
30313045 if (targetContext &&
0 commit comments