Skip to content

Commit 1995b54

Browse files
committed
[OpenMP] Missing implicit otherwise clause in metadirective.
1 parent f3a1d55 commit 1995b54

File tree

4 files changed

+93
-5
lines changed

4 files changed

+93
-5
lines changed

clang/lib/Parse/ParseOpenMP.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2882,6 +2882,12 @@ StmtResult Parser::ParseOpenMPDeclarativeOrExecutableDirective(
28822882
/*ReadDirectiveWithinMetadirective=*/true);
28832883
break;
28842884
}
2885+
// If no match is found and no otherwise clause is present, skip
2886+
// OMP5.2 Chapter 7.4: If no otherwise clause is specified the effect is as
2887+
// if one was specified without an associated directive variant.
2888+
if (BestIdx == -1 && Idx == 1) {
2889+
SkipUntil(tok::annot_pragma_openmp_end);
2890+
}
28852891
break;
28862892
}
28872893
case OMPD_threadprivate: {

clang/test/OpenMP/metadirective_ast_print.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
// RUN: %clang_cc1 -verify -fopenmp -triple x86_64-unknown-linux-gnu -x c -std=c99 -ast-print %s -o - | FileCheck %s
1+
// RUN: %clang_cc1 -verify -fopenmp -triple x86_64-unknown-linux-gnu -x c -std=c99 -ast-print %s -o - | FileCheck %s --check-prefixes=CHECK
22

3-
// RUN: %clang_cc1 -verify -fopenmp-simd -triple x86_64-unknown-linux-gnu -x c -std=c99 -ast-print %s -o - | FileCheck %s
3+
// RUN: %clang_cc1 -verify -fopenmp-simd -triple x86_64-unknown-linux-gnu -x c -std=c99 -ast-print %s -o - | FileCheck %s --check-prefixes=CHECK
44

5-
// RUN: %clang_cc1 -verify -fopenmp -triple amdgcn-amd-amdhsa -x c -std=c99 -ast-print %s -o - | FileCheck %s --check-prefix=CHECK-AMDGCN
5+
// RUN: %clang_cc1 -verify -fopenmp -triple amdgcn-amd-amdhsa -x c -std=c99 -ast-print %s -o - | FileCheck %s --check-prefixes=CHECK-AMDGCN
66

7-
// RUN: %clang_cc1 -verify -fopenmp-simd -triple amdgcn-amd-amdhsa -x c -std=c99 -ast-print %s -o - | FileCheck %s --check-prefix=CHECK-AMDGCN
7+
// RUN: %clang_cc1 -verify -fopenmp-simd -triple amdgcn-amd-amdhsa -x c -std=c99 -ast-print %s -o - | FileCheck %s --check-prefixes=CHECK-AMDGCN
88
// expected-no-diagnostics
99

1010
#ifndef HEADER
@@ -77,6 +77,16 @@ void foo(void) {
7777
: parallel) default(nothing)
7878
for (int i = 0; i < 16; i++)
7979
;
80+
81+
#pragma omp metadirective when(user = {condition(0)} \
82+
: parallel for) otherwise()
83+
for (int i=0; i<10; i++)
84+
;
85+
#pragma omp metadirective when(user = {condition(0)} \
86+
: parallel for)
87+
for (int i=0; i<10; i++)
88+
;
89+
8090
}
8191

8292
// CHECK: void bar(void);
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple x86_64-unknown-linux -emit-llvm %s -o - | FileCheck %s
2+
// expected-no-diagnostics
3+
4+
#ifndef HEADER
5+
#define HEADER
6+
7+
void func1() {
8+
#pragma omp metadirective when(user = {condition(0)} \
9+
: parallel for) otherwise()
10+
for (int i = 0; i < 100; i++)
11+
;
12+
13+
#pragma omp metadirective when(user = {condition(0)} \
14+
: parallel for)
15+
for (int i = 0; i < 100; i++)
16+
;
17+
}
18+
19+
// CHECK-LABEL: define dso_local void @_Z5func1v()
20+
// CHECK: entry
21+
// CHECK-NEXT: [[I:%.*]] = alloca i32, align 4
22+
// CHECK-NEXT: [[I1:%.*]] = alloca i32, align 4
23+
// CHECK-NEXT: store i32 0, ptr [[I]], align 4
24+
// CHECK-NEXT: br label %[[FOR_COND:.*]]
25+
// CHECK: [[FOR_COND]]:
26+
// CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[I]], align 4
27+
// CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[TMP0]], 100
28+
// CHECK-NEXT: br i1 [[CMP]], label %[[FOR_BODY:.*]], label %[[FOR_END:.*]]
29+
// CHECK: [[FOR_BODY]]:
30+
// CHECK-NEXT: br label %[[FOR_INC:.*]]
31+
// CHECK: [[FOR_INC]]:
32+
// CHECK-NEXT: [[TMP1:%.*]] = load i32, ptr [[I]], align 4
33+
// CHECK-NEXT: [[INC:%.*]] = add nsw i32 [[TMP1]], 1
34+
// CHECK-NEXT: store i32 [[INC]], ptr [[I]], align 4
35+
// CHECK-NEXT: br label %[[FOR_COND]], !llvm.loop [[LOOP3:![0-9]+]]
36+
// CHECK: [[FOR_END]]:
37+
// CHECK-NEXT: store i32 0, ptr [[I1]], align 4
38+
// CHECK-NEXT: br label %[[FOR_COND2:.*]]
39+
// CHECK: [[FOR_COND2]]:
40+
// CHECK-NEXT: [[TMP2:%.*]] = load i32, ptr [[I1]], align 4
41+
// CHECK-NEXT: [[CMP3:%.*]] = icmp slt i32 [[TMP2]], 100
42+
// CHECK-NEXT: br i1 [[CMP3]], label %[[FOR_BODY4:.*]], label %[[FOR_END7:.*]]
43+
// CHECK: [[FOR_BODY4]]:
44+
// CHECK-NEXT: br label %[[FOR_INC5:.*]]
45+
// CHECK: [[FOR_INC5]]:
46+
// CHECK-NEXT: [[TMP3:%.*]] = load i32, ptr [[I1]], align 4
47+
// CHECK-NEXT: [[INC6:%.*]] = add nsw i32 [[TMP3]], 1
48+
// CHECK-NEXT: store i32 [[INC6]], ptr [[I1]], align 4
49+
// CHECK-NEXT: br label %[[FOR_COND2]], !llvm.loop [[LOOP5:![0-9]+]]
50+
// CHECK: [[FOR_END7]]:
51+
// CHECK-NEXT: ret void
52+
53+
void func2() {
54+
#pragma omp metadirective when(user = {condition(1)} \
55+
: parallel for) otherwise()
56+
for (int i = 0; i < 100; i++)
57+
;
58+
59+
#pragma omp metadirective when(user = {condition(1)} \
60+
: parallel for)
61+
for (int i = 0; i < 100; i++)
62+
;
63+
}
64+
65+
// CHECK-LABEL: define dso_local void @_Z5func2v()
66+
// CHECK: entry
67+
// CHECK-NEXT: call void (ptr, i32, ptr, ...) @__kmpc_fork_call(ptr @[[GLOB2:[0-9]+]], i32 0, ptr @_Z5func2v.omp_outlined)
68+
// CHECK-NEXT: call void (ptr, i32, ptr, ...) @__kmpc_fork_call(ptr @[[GLOB2]], i32 0, ptr @_Z5func2v.omp_outlined.1)
69+
// CHECK-NEXT: ret void
70+
71+
72+
#endif

llvm/include/llvm/Frontend/OpenMP/OMPContext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ bool isVariantApplicableInContext(const VariantMatchInfo &VMI,
188188
bool DeviceSetOnly = false);
189189

190190
/// Return the index (into \p VMIs) of the variant with the highest score
191-
/// from the ones applicble in \p Ctx. See llvm::isVariantApplicableInContext.
191+
/// from the ones applicable in \p Ctx. See llvm::isVariantApplicableInContext.
192192
int getBestVariantMatchForContext(const SmallVectorImpl<VariantMatchInfo> &VMIs,
193193
const OMPContext &Ctx);
194194

0 commit comments

Comments
 (0)