Skip to content

Commit

Permalink
fixed forrangelooptest
Browse files Browse the repository at this point in the history
  • Loading branch information
eliecuevas committed Dec 19, 2024
1 parent 466b163 commit b32e07f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 23 deletions.
2 changes: 1 addition & 1 deletion clang/include/clang/Basic/DiagnosticParseKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -1400,7 +1400,7 @@ def warn_pragma_cilk_grainsize_equals: Warning<
"'#pragma cilk grainsize' no longer requires '='">,
InGroup<SourceUsesCilkPlus>;
def warn_cilk_for_forrange_loop_experimental: Warning<
"'_Cilk_for' support for for-range loops is currently EXPERIMENTAL only!">,
"'cilk_for' support for for-range loops is currently EXPERIMENTAL only!">,
InGroup<SourceUsesCilkPlus>;
def error_hyperobject_arguments: Error<
"hyperobject must have 0 or 2 callbacks">;
Expand Down
4 changes: 0 additions & 4 deletions clang/lib/CodeGen/CGCilk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -533,14 +533,10 @@ CodeGenFunction::EmitCilkForRangeStmt(const CilkForRangeStmt &S,
JumpDest Continue = getJumpDestInCurrentScope("pfor.cond");
llvm::BasicBlock *CondBlock = Continue.getBlock();

// TODO: need to check condition and then get to pfor.end
llvm::BasicBlock *InitialEntryBlock = createBasicBlock("pfor.initial.entry");
EmitBlock(InitialEntryBlock);
llvm::Value *InitialBoolCondVal = EvaluateExprAsBool(S.getCond());
// llvm::MDNode *Weights =
// createProfileWeightsForLoop(S.getCond(), getProfileCount(S.getBody()));

// Do we need weights?
Builder.CreateCondBr(InitialBoolCondVal, Continue.getBlock(), LoopExit.getBlock());


Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Sema/SemaStmtAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ static Attr *handleLoopHintAttr(Sema &S, Stmt *St, const ParsedAttr &A,
// This could be handled automatically by adding a Subjects definition in
// Attr.td, but that would make the diagnostic behavior worse in this case
// because the user spells this attribute as a pragma.
if (!isa<DoStmt, ForStmt, CXXForRangeStmt, WhileStmt, CilkForStmt>(St)) {
if (!isa<DoStmt, ForStmt, CXXForRangeStmt, WhileStmt, CilkForStmt, CilkForRangeStmt>(St)) {
std::string Pragma = "#pragma " + std::string(PragmaName);
S.Diag(St->getBeginLoc(), diag::err_pragma_loop_precedes_nonloop) << Pragma;
return nullptr;
Expand Down
36 changes: 19 additions & 17 deletions clang/test/Cilk/rangelooptest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,40 +53,42 @@ int Cilk_for_range_tests(int n) {
for (int i = 0; i < n; i++)
v[i] = i;

_Cilk_for(auto x : v); // expected-warning {{range-based for loop has empty body}} expected-warning {{Cilk for loop has empty body}} expected-warning {{'_Cilk_for' support for for-range loops is currently EXPERIMENTAL only!}}
_Cilk_for(auto &x : v); // expected-warning {{range-based for loop has empty body}} expected-warning {{Cilk for loop has empty body}} expected-warning {{'_Cilk_for' support for for-range loops is currently EXPERIMENTAL only!}}
_Cilk_for(int x : v); // expected-warning {{range-based for loop has empty body}} expected-warning {{Cilk for loop has empty body}} expected-warning {{'_Cilk_for' support for for-range loops is currently EXPERIMENTAL only!}}
_Cilk_for(StdMock::Empty x : v); // expected-warning {{range-based for loop has empty body}} expected-warning {{Cilk for loop has empty body}} expected-error {{no viable conversion from 'int' to 'StdMock::Empty'}} expected-warning {{'_Cilk_for' support for for-range loops is currently EXPERIMENTAL only!}}
_Cilk_for(auto x : v); // expected-warning {{range-based for loop has empty body}} expected-warning {{'cilk_for' loop has empty body}} expected-warning {{'cilk_for' support for for-range loops is currently EXPERIMENTAL only!}}
_Cilk_for(auto &x : v); // expected-warning {{range-based for loop has empty body}} expected-warning {{'cilk_for' loop has empty body}} expected-warning {{'cilk_for' support for for-range loops is currently EXPERIMENTAL only!}}
_Cilk_for(int x : v); // expected-warning {{range-based for loop has empty body}} expected-warning {{'cilk_for' loop has empty body}} expected-warning {{'cilk_for' support for for-range loops is currently EXPERIMENTAL only!}}
_Cilk_for(StdMock::Empty x : v); // expected-warning {{range-based for loop has empty body}} expected-warning {{'cilk_for' loop has empty body}} expected-error {{no viable conversion from 'int' to 'StdMock::Empty'}} expected-error {{no viable conversion from 'int' to 'StdMock::Empty'}} expected-warning {{'cilk_for' support for for-range loops is currently EXPERIMENTAL only!}}
// in line above, the "no viable conversion" error comes twice because of the new CodeGen structure of cilk_for_range loops, which now adds an extra check to the initial condition before entering the loop ("pfor.initial.entry")


// Pairs are aggregate types, which initially had a bug. Assert that they work
StdMock::Vector<StdMock::Pair<int, int>> vp(n);
for (int i = 0; i < n; i++) {
vp[i] = {i, i + 1};
}
_Cilk_for(auto p : vp) // expected-warning {{'_Cilk_for' support for for-range loops is currently EXPERIMENTAL only!}}
_Cilk_for(auto p : vp) // expected-warning {{'cilk_for' support for for-range loops is currently EXPERIMENTAL only!}}
continue;
_Cilk_for(auto &p : vp) { // expected-warning {{'_Cilk_for' support for for-range loops is currently EXPERIMENTAL only!}}
_Cilk_for(auto &p : vp) { // expected-warning {{'cilk_for' support for for-range loops is currently EXPERIMENTAL only!}}
continue;
}

int a[5];
_Cilk_for(int x : a) // expected-warning {{'_Cilk_for' support for for-range loops is currently EXPERIMENTAL only!}}
_Cilk_for(int x : a) // expected-warning {{'cilk_for' support for for-range loops is currently EXPERIMENTAL only!}}
continue;

StdMock::Set<int> s(n);
_Cilk_for(int x : s); // expected-error {{Cannot determine length with '__end - __begin'. Please use a random access iterator.}} expected-error {{invalid operands to binary expression ('StdMock::Set<int>::It' and 'StdMock::Set<int>::It')}} expected-warning {{'_Cilk_for' support for for-range loops is currently EXPERIMENTAL only!}}
_Cilk_for(int x : s); // expected-error {{Cannot determine length with '__end - __begin'. Please use a random access iterator.}} expected-error {{invalid operands to binary expression ('It' and 'It')}} expected-warning {{'cilk_for' support for for-range loops is currently EXPERIMENTAL only!}}

// Check for return statements, which cannot appear anywhere in the body of a
// _Cilk_for loop.
_Cilk_for(int i : v) return 7; // expected-error{{cannot return}} expected-warning {{'_Cilk_for' support for for-range loops is currently EXPERIMENTAL only!}}
_Cilk_for(int i : v) // expected-warning {{'_Cilk_for' support for for-range loops is currently EXPERIMENTAL only!}}
_Cilk_for(int i : v) return 7; // expected-error{{cannot return}} expected-warning {{'cilk_for' support for for-range loops is currently EXPERIMENTAL only!}}
_Cilk_for(int i : v) // expected-warning {{'cilk_for' support for for-range loops is currently EXPERIMENTAL only!}}
for (int j = 1; j < i; ++j)
return 7; // expected-error{{cannot return}}

// Check for illegal break statements, which cannot bind to the scope of a
// _Cilk_for loop, but can bind to loops nested within.
_Cilk_for(int i : v) break; // expected-error{{cannot break}} expected-warning {{'_Cilk_for' support for for-range loops is currently EXPERIMENTAL only!}}
_Cilk_for(int i : v) // expected-warning {{'_Cilk_for' support for for-range loops is currently EXPERIMENTAL only!}}
_Cilk_for(int i : v) break; // expected-error{{cannot break}} expected-warning {{'cilk_for' support for for-range loops is currently EXPERIMENTAL only!}}
_Cilk_for(int i : v) // expected-warning {{'cilk_for' support for for-range loops is currently EXPERIMENTAL only!}}
for (int j = 1; j < i; ++j)
break;

Expand All @@ -99,19 +101,19 @@ int range_pragma_tests(int n) {
v[i] = i;

#pragma clang loop unroll_count(4)
_Cilk_for(auto i : v) // expected-warning {{'_Cilk_for' support for for-range loops is currently EXPERIMENTAL only!}}
_Cilk_for(auto i : v) // expected-warning {{'cilk_for' support for for-range loops is currently EXPERIMENTAL only!}}
foo(i);

#pragma cilk grainsize(4)
_Cilk_for(int i : v) // expected-warning {{'_Cilk_for' support for for-range loops is currently EXPERIMENTAL only!}}
_Cilk_for(int i : v) // expected-warning {{'cilk_for' support for for-range loops is currently EXPERIMENTAL only!}}
foo(i);

#pragma cilk grainsize 4
_Cilk_for(auto i : v) // expected-warning {{'_Cilk_for' support for for-range loops is currently EXPERIMENTAL only!}}
_Cilk_for(auto i : v) // expected-warning {{'cilk_for' support for for-range loops is currently EXPERIMENTAL only!}}
foo(i);

#pragma cilk grainsize = 4 // expected-warning{{'#pragma cilk grainsize' no longer requires '='}}
_Cilk_for(int i : v) // expected-warning {{'_Cilk_for' support for for-range loops is currently EXPERIMENTAL only!}}
_Cilk_for(int i : v) // expected-warning {{'cilk_for' support for for-range loops is currently EXPERIMENTAL only!}}
foo(i);

return 0;
Expand All @@ -122,7 +124,7 @@ int range_scope_tests(int n) {
for (int i = 0; i < n; i++)
v[i] = i;
int A[5];
_Cilk_for(int i : v) { // expected-warning {{'_Cilk_for' support for for-range loops is currently EXPERIMENTAL only!}}
_Cilk_for(int i : v) { // expected-warning {{'cilk_for' support for for-range loops is currently EXPERIMENTAL only!}}
int A[5];
A[i % 5] = i;
}
Expand Down

0 comments on commit b32e07f

Please sign in to comment.