Index: clang/lib/Sema/SemaOpenMP.cpp =================================================================== --- clang/lib/Sema/SemaOpenMP.cpp +++ clang/lib/Sema/SemaOpenMP.cpp @@ -7413,10 +7413,7 @@ // LB = TestIsLessOp.getValue() ? min(LB(MinVal), LB(MaxVal)) : // max(LB(MinVal), LB(MaxVal)) if (InitDependOnLC) { - const LoopIterationSpace &IS = - ResultIterSpaces[ResultIterSpaces.size() - 1 - - InitDependOnLC.getValueOr( - CondDependOnLC.getValueOr(0))]; + const LoopIterationSpace &IS = ResultIterSpaces[*InitDependOnLC - 1]; if (!IS.MinValue || !IS.MaxValue) return nullptr; // OuterVar = Min @@ -7493,10 +7490,7 @@ // UB = TestIsLessOp.getValue() ? max(UB(MinVal), UB(MaxVal)) : // min(UB(MinVal), UB(MaxVal)) if (CondDependOnLC) { - const LoopIterationSpace &IS = - ResultIterSpaces[ResultIterSpaces.size() - 1 - - InitDependOnLC.getValueOr( - CondDependOnLC.getValueOr(0))]; + const LoopIterationSpace &IS = ResultIterSpaces[*CondDependOnLC - 1]; if (!IS.MinValue || !IS.MaxValue) return nullptr; // OuterVar = Min Index: clang/test/OpenMP/for_codegen.cpp =================================================================== --- clang/test/OpenMP/for_codegen.cpp +++ clang/test/OpenMP/for_codegen.cpp @@ -198,6 +198,28 @@ } } } + +// CHECK-LABEL: loop_with_counter_collapse4 +void loop_with_counter_collapse4() { + + // Check bounds calculation when collapse > 2 + // CHECK: store i32 0, i32* [[I_TMP:%.+]], + // CHECK: [[VAL:%.+]] = load i32, i32* [[I_TMP]], + // CHECK: store i32 [[VAL]], i32* [[K_LB_MIN:%.+]], + // CHECK: store i32 6, i32* [[I_TMP]], + // CHECK: [[VAL:%.+]] = load i32, i32* [[I_TMP]], + // CHECK: store i32 [[VAL]], i32* [[K_LB_MAX:%.+]], + #pragma omp for collapse(4) + for (int i = 0; i < 7; i++) { + for (int j = 0; j < 11; j++) { + for (int k = i; k < 7; k++) { + for (int l = 0; l < 11; l++) { + } + } + } + } +} + // CHECK-LABEL: define {{.*void}} @{{.*}}without_schedule_clause{{.*}}(float* {{.+}}, float* {{.+}}, float* {{.+}}, float* {{.+}}) void without_schedule_clause(float *a, float *b, float *c, float *d) { // CHECK: [[GTID:%.+]] = call i32 @__kmpc_global_thread_num([[IDENT_T_TY]]* [[DEFAULT_LOC:[@%].+]]) Index: clang/test/OpenMP/for_loop_messages.cpp =================================================================== --- clang/test/OpenMP/for_loop_messages.cpp +++ clang/test/OpenMP/for_loop_messages.cpp @@ -653,9 +653,10 @@ ; #pragma omp parallel -// expected-error@+5 2 {{expected loop invariant expression or ' * ii + ' kind of expression}} -// expected-error@+4 {{expected loop invariant expression or ' * TC::ii + ' kind of expression}} -// expected-error@+4 {{expected loop invariant expression or ' * TC::ii + ' kind of expression}} +// expected-error@+6 {{expected loop invariant expression or ' * TC::ii + ' kind of expression}} +// expected-error@+6 {{expected loop invariant expression or ' * TC::ii + ' kind of expression}} +// expected-error@+4 2 {{expected loop invariant expression or ' * ii + ' kind of expression}} +// expected-error@+4 2 {{expected loop invariant expression or ' * ii + ' kind of expression}} #pragma omp for collapse(3) for (ii = 10 + 25; ii < 1000; ii += 1) for (iii = ii * 10 + 25; iii < ii / ii - 23; iii += 1)