Index: lib/Sema/SemaOpenMP.cpp =================================================================== --- lib/Sema/SemaOpenMP.cpp +++ lib/Sema/SemaOpenMP.cpp @@ -1997,6 +1997,8 @@ if (isOpenMPTargetExecutionDirective(DKind) && !FD->isBitField()) { OMPClauseMappableExprCommon::MappableExprComponentList CurComponents; CheckMapClauseExpressionBase(SemaRef, E, CurComponents, OMPC_map); + if (CurComponents.empty()) + return; auto *VD = cast( CurComponents.back().getAssociatedDeclaration()->getCanonicalDecl()); if (!Stack->checkMappableExprComponentListsForDecl( Index: test/OpenMP/target_map_messages.cpp =================================================================== --- test/OpenMP/target_map_messages.cpp +++ test/OpenMP/target_map_messages.cpp @@ -269,6 +269,10 @@ {} #pragma omp target map(u.B) // expected-error {{mapped storage cannot be derived from a union}} {} + #pragma omp target + { + u.B = 0; // expected-error {{mapped storage cannot be derived from a union}} + } #pragma omp target data map(to: r.C) //expected-note {{used here}} {