From b32e07f9326fb60648a821c3555723200ff8728b Mon Sep 17 00:00:00 2001 From: Elie Cuevas Date: Wed, 18 Dec 2024 15:11:00 -0500 Subject: [PATCH] fixed forrangelooptest --- .../clang/Basic/DiagnosticParseKinds.td | 2 +- clang/lib/CodeGen/CGCilk.cpp | 4 --- clang/lib/Sema/SemaStmtAttr.cpp | 2 +- clang/test/Cilk/rangelooptest.cpp | 36 ++++++++++--------- 4 files changed, 21 insertions(+), 23 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td b/clang/include/clang/Basic/DiagnosticParseKinds.td index 1fa1ceec7d1f..82b491f5c1a5 100644 --- a/clang/include/clang/Basic/DiagnosticParseKinds.td +++ b/clang/include/clang/Basic/DiagnosticParseKinds.td @@ -1400,7 +1400,7 @@ def warn_pragma_cilk_grainsize_equals: Warning< "'#pragma cilk grainsize' no longer requires '='">, InGroup; 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; def error_hyperobject_arguments: Error< "hyperobject must have 0 or 2 callbacks">; diff --git a/clang/lib/CodeGen/CGCilk.cpp b/clang/lib/CodeGen/CGCilk.cpp index a447b98bb3fe..9737b7f08d6a 100644 --- a/clang/lib/CodeGen/CGCilk.cpp +++ b/clang/lib/CodeGen/CGCilk.cpp @@ -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()); diff --git a/clang/lib/Sema/SemaStmtAttr.cpp b/clang/lib/Sema/SemaStmtAttr.cpp index 8e2e257f13cf..ef303b8b1f5b 100644 --- a/clang/lib/Sema/SemaStmtAttr.cpp +++ b/clang/lib/Sema/SemaStmtAttr.cpp @@ -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(St)) { + if (!isa(St)) { std::string Pragma = "#pragma " + std::string(PragmaName); S.Diag(St->getBeginLoc(), diag::err_pragma_loop_precedes_nonloop) << Pragma; return nullptr; diff --git a/clang/test/Cilk/rangelooptest.cpp b/clang/test/Cilk/rangelooptest.cpp index c5dcb6200363..9e3c2507d870 100644 --- a/clang/test/Cilk/rangelooptest.cpp +++ b/clang/test/Cilk/rangelooptest.cpp @@ -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> 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 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::It' and 'StdMock::Set::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; @@ -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; @@ -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; }