bugs in Clang function StmtResult Sema::ActOnOpenMPSectionsDirective

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

bugs in Clang function StmtResult Sema::ActOnOpenMPSectionsDirective

xiaohui chen-2
Hi, 
I am using clang version 3.6.0 (trunk 224915).

Clang can not parse the following valid OpenMP code:

 1 #include<omp.h>
  2 void main()
  3 {
  4         int i;
  5         #pragma omp parallel
  6         #pragma omp sections
  7         {
  8                 i++;
  9                 i++;
 10                 #pragma omp section
 11                 i++;
 12         }
 13 }

The bug comes from line 8 and 9.

In OpenMP documentation (http://www.openmp.org/mp-documents/OpenMP4.0.0.pdf) page 62,
it says"Each structured block in the sections construct is preceded by a section directive 
except possibly the first block, for which a preceding section directive is optional." .

it means that the section directive is optional for the first block, but not the first statement.

in function  StmtResult Sema::ActOnOpenMPSectionsDirective, 

3021 StmtResult Sema::ActOnOpenMPSectionsDirective(ArrayRef<OMPClause *> Clauses,
3022                                               Stmt *AStmt,
3023                                               SourceLocation StartLoc,
3024                                               SourceLocation EndLoc) {
3025   assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected");
3026   auto BaseStmt = AStmt;
3027   while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt))
3028     BaseStmt = CS->getCapturedStmt();
3029   if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) {
3030     auto S = C->children();
3031     if (!S)
3032       return StmtError();
3033     // All associated statements must be '#pragma omp section' except for
3034     // the first one.
3035     for (++S; S; ++S) {
3036       auto SectionStmt = *S;
3037       if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) {
3038         if (SectionStmt)
3039           Diag(SectionStmt->getLocStart(),
3040                diag::err_omp_sections_substmt_not_section);
3041         return StmtError();
3042       }
3043     }
3044   } else {
3045     Diag(AStmt->getLocStart(), diag::err_omp_sections_not_compound_stmt);
3046     return StmtError();
3047   }
3048 
3049   getCurFunction()->setHasBranchProtectedScope();
3050 
3051   return OMPSectionsDirective::Create(Context, StartLoc, EndLoc, Clauses,
3052                                       AStmt);
3053 }

Notice from line 3035 to line 3042, it just checks the first statement not the first statement.



_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: bugs in Clang function StmtResult Sema::ActOnOpenMPSectionsDirective

xiaohui chen-2

just correct a typo, please read the below message. 

On Wed, Mar 18, 2015 at 1:01 PM, xiaohui chen <[hidden email]> wrote:
Hi, 
I am using clang version 3.6.0 (trunk 224915).

Clang can not parse the following valid OpenMP code:

 1 #include<omp.h>
  2 void main()
  3 {
  4         int i;
  5         #pragma omp parallel
  6         #pragma omp sections
  7         {
  8                 i++;
  9                 i++;
 10                 #pragma omp section
 11                 i++;
 12         }
 13 }

The bug comes from line 8 and 9.

In OpenMP documentation (http://www.openmp.org/mp-documents/OpenMP4.0.0.pdf) page 62,
it says"Each structured block in the sections construct is preceded by a section directive 
except possibly the first block, for which a preceding section directive is optional." .

it means that the section directive is optional for the first block, but not the first statement.

in function  StmtResult Sema::ActOnOpenMPSectionsDirective, 

3021 StmtResult Sema::ActOnOpenMPSectionsDirective(ArrayRef<OMPClause *> Clauses,
3022                                               Stmt *AStmt,
3023                                               SourceLocation StartLoc,
3024                                               SourceLocation EndLoc) {
3025   assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected");
3026   auto BaseStmt = AStmt;
3027   while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt))
3028     BaseStmt = CS->getCapturedStmt();
3029   if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) {
3030     auto S = C->children();
3031     if (!S)
3032       return StmtError();
3033     // All associated statements must be '#pragma omp section' except for
3034     // the first one.
3035     for (++S; S; ++S) {
3036       auto SectionStmt = *S;
3037       if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) {
3038         if (SectionStmt)
3039           Diag(SectionStmt->getLocStart(),
3040                diag::err_omp_sections_substmt_not_section);
3041         return StmtError();
3042       }
3043     }
3044   } else {
3045     Diag(AStmt->getLocStart(), diag::err_omp_sections_not_compound_stmt);
3046     return StmtError();
3047   }
3048 
3049   getCurFunction()->setHasBranchProtectedScope();
3050 
3051   return OMPSectionsDirective::Create(Context, StartLoc, EndLoc, Clauses,
3052                                       AStmt);
3053 }

Notice from line 3035 to line 3042, it just checks the first statement not the first block.




_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: bugs in Clang function StmtResult Sema::ActOnOpenMPSectionsDirective

Alexey Bataev
Hi,
I don't think your code is correct, because actually there are 2 structured blocks where you think there is only one.
According to OpenMP standard structured block "For C/C++, an executable statement, ...", i.e. single statement, not several statements. So, the detection is correct.
You have to enclose two first stmts into braces to make it compatible with OpenMP standard.

-- 
Best regards,
Alexey Bataev
=============
Software Engineer
Intel Compiler Team

18.03.2015 21:08, xiaohui chen пишет:

just correct a typo, please read the below message. 

On Wed, Mar 18, 2015 at 1:01 PM, xiaohui chen <[hidden email]> wrote:
Hi, 
I am using clang version 3.6.0 (trunk 224915).

Clang can not parse the following valid OpenMP code:

 1 #include<omp.h>
  2 void main()
  3 {
  4         int i;
  5         #pragma omp parallel
  6         #pragma omp sections
  7         {
  8                 i++;
  9                 i++;
 10                 #pragma omp section
 11                 i++;
 12         }
 13 }

The bug comes from line 8 and 9.

In OpenMP documentation (http://www.openmp.org/mp-documents/OpenMP4.0.0.pdf) page 62,
it says"Each structured block in the sections construct is preceded by a section directive 
except possibly the first block, for which a preceding section directive is optional." .

it means that the section directive is optional for the first block, but not the first statement.

in function  StmtResult Sema::ActOnOpenMPSectionsDirective, 

3021 StmtResult Sema::ActOnOpenMPSectionsDirective(ArrayRef<OMPClause *> Clauses,
3022                                               Stmt *AStmt,
3023                                               SourceLocation StartLoc,
3024                                               SourceLocation EndLoc) {
3025   assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected");
3026   auto BaseStmt = AStmt;
3027   while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt))
3028     BaseStmt = CS->getCapturedStmt();
3029   if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) {
3030     auto S = C->children();
3031     if (!S)
3032       return StmtError();
3033     // All associated statements must be '#pragma omp section' except for
3034     // the first one.
3035     for (++S; S; ++S) {
3036       auto SectionStmt = *S;
3037       if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) {
3038         if (SectionStmt)
3039           Diag(SectionStmt->getLocStart(),
3040                diag::err_omp_sections_substmt_not_section);
3041         return StmtError();
3042       }
3043     }
3044   } else {
3045     Diag(AStmt->getLocStart(), diag::err_omp_sections_not_compound_stmt);
3046     return StmtError();
3047   }
3048 
3049   getCurFunction()->setHasBranchProtectedScope();
3050 
3051   return OMPSectionsDirective::Create(Context, StartLoc, EndLoc, Clauses,
3052                                       AStmt);
3053 }

Notice from line 3035 to line 3042, it just checks the first statement not the first block.











_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
--
Best regards,
Alexey Bataev
=============
Software Engineer
Intel Compiler Team
Intel Corp.
Reply | Threaded
Open this post in threaded view
|

Re: bugs in Clang function StmtResult Sema::ActOnOpenMPSectionsDirective

xiaohui chen-2
Hi Alexey,

make sense. My confusion comes from the fact that GCC could compile and run the code. But your explanation is compatible 
with OpenMP specification. Thanks very much!  

Sincerely
Xiaohui

On Wed, Mar 18, 2015 at 11:56 PM, Bataev, Alexey <[hidden email]> wrote:
Hi,
I don't think your code is correct, because actually there are 2 structured blocks where you think there is only one.
According to OpenMP standard structured block "For C/C++, an executable statement, ...", i.e. single statement, not several statements. So, the detection is correct.
You have to enclose two first stmts into braces to make it compatible with OpenMP standard.

-- 
Best regards,
Alexey Bataev
=============
Software Engineer
Intel Compiler Team

18.03.2015 21:08, xiaohui chen пишет:

just correct a typo, please read the below message. 

On Wed, Mar 18, 2015 at 1:01 PM, xiaohui chen <[hidden email]> wrote:
Hi, 
I am using clang version 3.6.0 (trunk 224915).

Clang can not parse the following valid OpenMP code:

 1 #include<omp.h>
  2 void main()
  3 {
  4         int i;
  5         #pragma omp parallel
  6         #pragma omp sections
  7         {
  8                 i++;
  9                 i++;
 10                 #pragma omp section
 11                 i++;
 12         }
 13 }

The bug comes from line 8 and 9.

In OpenMP documentation (http://www.openmp.org/mp-documents/OpenMP4.0.0.pdf) page 62,
it says"Each structured block in the sections construct is preceded by a section directive 
except possibly the first block, for which a preceding section directive is optional." .

it means that the section directive is optional for the first block, but not the first statement.

in function  StmtResult Sema::ActOnOpenMPSectionsDirective, 

3021 StmtResult Sema::ActOnOpenMPSectionsDirective(ArrayRef<OMPClause *> Clauses,
3022                                               Stmt *AStmt,
3023                                               SourceLocation StartLoc,
3024                                               SourceLocation EndLoc) {
3025   assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected");
3026   auto BaseStmt = AStmt;
3027   while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt))
3028     BaseStmt = CS->getCapturedStmt();
3029   if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) {
3030     auto S = C->children();
3031     if (!S)
3032       return StmtError();
3033     // All associated statements must be '#pragma omp section' except for
3034     // the first one.
3035     for (++S; S; ++S) {
3036       auto SectionStmt = *S;
3037       if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) {
3038         if (SectionStmt)
3039           Diag(SectionStmt->getLocStart(),
3040                diag::err_omp_sections_substmt_not_section);
3041         return StmtError();
3042       }
3043     }
3044   } else {
3045     Diag(AStmt->getLocStart(), diag::err_omp_sections_not_compound_stmt);
3046     return StmtError();
3047   }
3048 
3049   getCurFunction()->setHasBranchProtectedScope();
3050 
3051   return OMPSectionsDirective::Create(Context, StartLoc, EndLoc, Clauses,
3052                                       AStmt);
3053 }

Notice from line 3035 to line 3042, it just checks the first statement not the first block.












_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: bugs in Clang function StmtResult Sema::ActOnOpenMPSectionsDirective

Alexey Bataev
Ok, no problems!
Best regards,
Alexey Bataev
=============
Software Engineer
Intel Compiler Team
19.03.2015 17:29, xiaohui chen пишет:
Hi Alexey,

make sense. My confusion comes from the fact that GCC could compile and run the code. But your explanation is compatible 
with OpenMP specification. Thanks very much!  

Sincerely
Xiaohui

On Wed, Mar 18, 2015 at 11:56 PM, Bataev, Alexey <[hidden email]> wrote:
Hi,
I don't think your code is correct, because actually there are 2 structured blocks where you think there is only one.
According to OpenMP standard structured block "For C/C++, an executable statement, ...", i.e. single statement, not several statements. So, the detection is correct.
You have to enclose two first stmts into braces to make it compatible with OpenMP standard.

-- 
Best regards,
Alexey Bataev
=============
Software Engineer
Intel Compiler Team

18.03.2015 21:08, xiaohui chen пишет:

just correct a typo, please read the below message. 

On Wed, Mar 18, 2015 at 1:01 PM, xiaohui chen <[hidden email]> wrote:
Hi, 
I am using clang version 3.6.0 (trunk 224915).

Clang can not parse the following valid OpenMP code:

 1 #include<omp.h>
  2 void main()
  3 {
  4         int i;
  5         #pragma omp parallel
  6         #pragma omp sections
  7         {
  8                 i++;
  9                 i++;
 10                 #pragma omp section
 11                 i++;
 12         }
 13 }

The bug comes from line 8 and 9.

In OpenMP documentation (http://www.openmp.org/mp-documents/OpenMP4.0.0.pdf) page 62,
it says"Each structured block in the sections construct is preceded by a section directive 
except possibly the first block, for which a preceding section directive is optional." .

it means that the section directive is optional for the first block, but not the first statement.

in function  StmtResult Sema::ActOnOpenMPSectionsDirective, 

3021 StmtResult Sema::ActOnOpenMPSectionsDirective(ArrayRef<OMPClause *> Clauses,
3022                                               Stmt *AStmt,
3023                                               SourceLocation StartLoc,
3024                                               SourceLocation EndLoc) {
3025   assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected");
3026   auto BaseStmt = AStmt;
3027   while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt))
3028     BaseStmt = CS->getCapturedStmt();
3029   if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) {
3030     auto S = C->children();
3031     if (!S)
3032       return StmtError();
3033     // All associated statements must be '#pragma omp section' except for
3034     // the first one.
3035     for (++S; S; ++S) {
3036       auto SectionStmt = *S;
3037       if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) {
3038         if (SectionStmt)
3039           Diag(SectionStmt->getLocStart(),
3040                diag::err_omp_sections_substmt_not_section);
3041         return StmtError();
3042       }
3043     }
3044   } else {
3045     Diag(AStmt->getLocStart(), diag::err_omp_sections_not_compound_stmt);
3046     return StmtError();
3047   }
3048 
3049   getCurFunction()->setHasBranchProtectedScope();
3050 
3051   return OMPSectionsDirective::Create(Context, StartLoc, EndLoc, Clauses,
3052                                       AStmt);
3053 }

Notice from line 3035 to line 3042, it just checks the first statement not the first block.













_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
--
Best regards,
Alexey Bataev
=============
Software Engineer
Intel Compiler Team
Intel Corp.
Reply | Threaded
Open this post in threaded view
|

Re: bugs in Clang function StmtResult Sema::ActOnOpenMPSectionsDirective

Vassil Vassilev via cfe-dev
Hi guys,

I am writing a libtooling tool with pragma, like

#pragma xxx vars(a, b,c)

I register the pragma as usual, like
CI.getPreprocessor().AddPragmaHandler( new .......)

Up to now it works well.

Now I want to do something tricky here.
step 1.  mark the "xxx" as the end of the directive. (done)
step 2. rely on ParseAssignmentExpression() to parse the three vars, i.e. a, b, c

But in step 2, how to get the object of Parser?  Because  ParseAssignmentExpression() is a member of Parser.

BTW:
Alternative I tried to create a new parser but it failed:

std::unique_ptr<Parser> ParseOP(new Parser(PP, S, false));

Thanks in advance!


On Mon, Nov 16, 2015 at 12:45 PM, xiaohui chen <[hidden email]> wrote:

Hi guys,

I am writing a libtooling tool with pragma, like

#pragma xxx vars(a, b,c)

I register the pragma as usual, like
CI.getPreprocessor().AddPragmaHandler( new .......)

Up to now it works well.

Now I want to do something tricky here.
step 1.  mark the "xxx" as the end of the directive. (done)
step 2. rely on ParseAssignmentExpression() to parse the three vars, i.e. a, b, c

But in step 2, how to get the object of Parser?  Because  ParseAssignmentExpression() is a member of Parser.

Thanks in advance!

Sincerely
xiaohui

On Fri, Mar 20, 2015 at 12:26 AM, Bataev, Alexey <[hidden email]> wrote:
Ok, no problems!
Best regards,
Alexey Bataev
=============
Software Engineer
Intel Compiler Team
19.03.2015 17:29, xiaohui chen пишет:
Hi Alexey,

make sense. My confusion comes from the fact that GCC could compile and run the code. But your explanation is compatible 
with OpenMP specification. Thanks very much!  

Sincerely
Xiaohui

On Wed, Mar 18, 2015 at 11:56 PM, Bataev, Alexey <[hidden email]> wrote:
Hi,
I don't think your code is correct, because actually there are 2 structured blocks where you think there is only one.
According to OpenMP standard structured block "For C/C++, an executable statement, ...", i.e. single statement, not several statements. So, the detection is correct.
You have to enclose two first stmts into braces to make it compatible with OpenMP standard.

-- 
Best regards,
Alexey Bataev
=============
Software Engineer
Intel Compiler Team

18.03.2015 21:08, xiaohui chen пишет:

just correct a typo, please read the below message. 

On Wed, Mar 18, 2015 at 1:01 PM, xiaohui chen <[hidden email]> wrote:
Hi, 
I am using clang version 3.6.0 (trunk 224915).

Clang can not parse the following valid OpenMP code:

 1 #include<omp.h>
  2 void main()
  3 {
  4         int i;
  5         #pragma omp parallel
  6         #pragma omp sections
  7         {
  8                 i++;
  9                 i++;
 10                 #pragma omp section
 11                 i++;
 12         }
 13 }

The bug comes from line 8 and 9.

In OpenMP documentation (http://www.openmp.org/mp-documents/OpenMP4.0.0.pdf) page 62,
it says"Each structured block in the sections construct is preceded by a section directive 
except possibly the first block, for which a preceding section directive is optional." .

it means that the section directive is optional for the first block, but not the first statement.

in function  StmtResult Sema::ActOnOpenMPSectionsDirective, 

3021 StmtResult Sema::ActOnOpenMPSectionsDirective(ArrayRef<OMPClause *> Clauses,
3022                                               Stmt *AStmt,
3023                                               SourceLocation StartLoc,
3024                                               SourceLocation EndLoc) {
3025   assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected");
3026   auto BaseStmt = AStmt;
3027   while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt))
3028     BaseStmt = CS->getCapturedStmt();
3029   if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) {
3030     auto S = C->children();
3031     if (!S)
3032       return StmtError();
3033     // All associated statements must be '#pragma omp section' except for
3034     // the first one.
3035     for (++S; S; ++S) {
3036       auto SectionStmt = *S;
3037       if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) {
3038         if (SectionStmt)
3039           Diag(SectionStmt->getLocStart(),
3040                diag::err_omp_sections_substmt_not_section);
3041         return StmtError();
3042       }
3043     }
3044   } else {
3045     Diag(AStmt->getLocStart(), diag::err_omp_sections_not_compound_stmt);
3046     return StmtError();
3047   }
3048 
3049   getCurFunction()->setHasBranchProtectedScope();
3050 
3051   return OMPSectionsDirective::Create(Context, StartLoc, EndLoc, Clauses,
3052                                       AStmt);
3053 }

Notice from line 3035 to line 3042, it just checks the first statement not the first block.















_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Fwd: bugs in Clang function StmtResult Sema::ActOnOpenMPSectionsDirective

Vassil Vassilev via cfe-dev
In reply to this post by xiaohui chen-2

Hi guys,

I am writing a libtooling tool. 
My tool can compile and run with Clang version 3.6.2.
However, if I compile with Clang version 3.9.0, it reports an error:

/Project/clang+llvm-3.9.0-x86_64-linux-gnu-ubuntu-14.04/bin/../lib/libclangTooling.a(Refactoring.cpp.o): In function `clang::tooling::formatAndApplyAllReplacements(std::set<clang::tooling::Replacement, std::less<clang::tooling::Replacement>, std::allocator<clang::tooling::Replacement> > const&, clang::Rewriter&, llvm::StringRef)':
/home/development/llvm/3.9.0/final/llvm.src/tools/clang/lib/Tooling/Refactoring.cpp:(.text._ZN5clang7tooling29formatAndApplyAllReplacementsERKSt3setINS0_11ReplacementESt4lessIS2_ESaIS2_EERNS_8RewriterEN4llvm9StringRefE+0x184): undefined reference to `clang::format::getStyle(llvm::StringRef, llvm::StringRef, llvm::StringRef, clang::vfs::FileSystem*)'
/home/development/llvm/3.9.0/final/llvm.src/tools/clang/lib/Tooling/Refactoring.cpp:(.text._ZN5clang7tooling29formatAndApplyAllReplacementsERKSt3setINS0_11ReplacementESt4lessIS2_ESaIS2_EERNS_8RewriterEN4llvm9StringRefE+0x19f): undefined reference to `clang::format::formatReplacements(llvm::StringRef, std::set<clang::tooling::Replacement, std::less<clang::tooling::Replacement>, std::allocator<clang::tooling::Replacement> > const&, clang::format::FormatStyle const&)'
clang-3.9: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [main] Error 1


Do you have any hints?

Best 
xiaohui


On Wed, Mar 18, 2015 at 10:01 AM, xiaohui chen <[hidden email]> wrote:
Hi, 
I am using clang version 3.6.0 (trunk 224915).

Clang can not parse the following valid OpenMP code:

 1 #include<omp.h>
  2 void main()
  3 {
  4         int i;
  5         #pragma omp parallel
  6         #pragma omp sections
  7         {
  8                 i++;
  9                 i++;
 10                 #pragma omp section
 11                 i++;
 12         }
 13 }

The bug comes from line 8 and 9.

In OpenMP documentation (http://www.openmp.org/mp-documents/OpenMP4.0.0.pdf) page 62,
it says"Each structured block in the sections construct is preceded by a section directive 
except possibly the first block, for which a preceding section directive is optional." .

it means that the section directive is optional for the first block, but not the first statement.

in function  StmtResult Sema::ActOnOpenMPSectionsDirective, 

3021 StmtResult Sema::ActOnOpenMPSectionsDirective(ArrayRef<OMPClause *> Clauses,
3022                                               Stmt *AStmt,
3023                                               SourceLocation StartLoc,
3024                                               SourceLocation EndLoc) {
3025   assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected");
3026   auto BaseStmt = AStmt;
3027   while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt))
3028     BaseStmt = CS->getCapturedStmt();
3029   if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) {
3030     auto S = C->children();
3031     if (!S)
3032       return StmtError();
3033     // All associated statements must be '#pragma omp section' except for
3034     // the first one.
3035     for (++S; S; ++S) {
3036       auto SectionStmt = *S;
3037       if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) {
3038         if (SectionStmt)
3039           Diag(SectionStmt->getLocStart(),
3040                diag::err_omp_sections_substmt_not_section);
3041         return StmtError();
3042       }
3043     }
3044   } else {
3045     Diag(AStmt->getLocStart(), diag::err_omp_sections_not_compound_stmt);
3046     return StmtError();
3047   }
3048 
3049   getCurFunction()->setHasBranchProtectedScope();
3050 
3051   return OMPSectionsDirective::Create(Context, StartLoc, EndLoc, Clauses,
3052                                       AStmt);
3053 }

Notice from line 3035 to line 3042, it just checks the first statement not the first statement.





_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: bugs in Clang function StmtResult Sema::ActOnOpenMPSectionsDirective

Vassil Vassilev via cfe-dev

Seems to me you're missing clangFormat library

Best regards,
Alexey Bataev
On 09/21/2016 04:57 PM, xiaohui chen wrote:

Hi guys,

I am writing a libtooling tool. 
My tool can compile and run with Clang version 3.6.2.
However, if I compile with Clang version 3.9.0, it reports an error:

/Project/clang+llvm-3.9.0-x86_64-linux-gnu-ubuntu-14.04/bin/../lib/libclangTooling.a(Refactoring.cpp.o): In function `clang::tooling::formatAndApplyAllReplacements(std::set<clang::tooling::Replacement, std::less<clang::tooling::Replacement>, std::allocator<clang::tooling::Replacement> > const&, clang::Rewriter&, llvm::StringRef)':
/home/development/llvm/3.9.0/final/llvm.src/tools/clang/lib/Tooling/Refactoring.cpp:(.text._ZN5clang7tooling29formatAndApplyAllReplacementsERKSt3setINS0_11ReplacementESt4lessIS2_ESaIS2_EERNS_8RewriterEN4llvm9StringRefE+0x184): undefined reference to `clang::format::getStyle(llvm::StringRef, llvm::StringRef, llvm::StringRef, clang::vfs::FileSystem*)'
/home/development/llvm/3.9.0/final/llvm.src/tools/clang/lib/Tooling/Refactoring.cpp:(.text._ZN5clang7tooling29formatAndApplyAllReplacementsERKSt3setINS0_11ReplacementESt4lessIS2_ESaIS2_EERNS_8RewriterEN4llvm9StringRefE+0x19f): undefined reference to `clang::format::formatReplacements(llvm::StringRef, std::set<clang::tooling::Replacement, std::less<clang::tooling::Replacement>, std::allocator<clang::tooling::Replacement> > const&, clang::format::FormatStyle const&)'
clang-3.9: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [main] Error 1


Do you have any hints?

Best 
xiaohui


On Wed, Mar 18, 2015 at 10:01 AM, xiaohui chen <[hidden email]> wrote:
Hi, 
I am using clang version 3.6.0 (trunk 224915).

Clang can not parse the following valid OpenMP code:

 1 #include<omp.h>
  2 void main()
  3 {
  4         int i;
  5         #pragma omp parallel
  6         #pragma omp sections
  7         {
  8                 i++;
  9                 i++;
 10                 #pragma omp section
 11                 i++;
 12         }
 13 }

The bug comes from line 8 and 9.

In OpenMP documentation (http://www.openmp.org/mp-documents/OpenMP4.0.0.pdf) page 62,
it says"Each structured block in the sections construct is preceded by a section directive 
except possibly the first block, for which a preceding section directive is optional." .

it means that the section directive is optional for the first block, but not the first statement.

in function  StmtResult Sema::ActOnOpenMPSectionsDirective, 

3021 StmtResult Sema::ActOnOpenMPSectionsDirective(ArrayRef<OMPClause *> Clauses,
3022                                               Stmt *AStmt,
3023                                               SourceLocation StartLoc,
3024                                               SourceLocation EndLoc) {
3025   assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected");
3026   auto BaseStmt = AStmt;
3027   while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt))
3028     BaseStmt = CS->getCapturedStmt();
3029   if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) {
3030     auto S = C->children();
3031     if (!S)
3032       return StmtError();
3033     // All associated statements must be '#pragma omp section' except for
3034     // the first one.
3035     for (++S; S; ++S) {
3036       auto SectionStmt = *S;
3037       if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) {
3038         if (SectionStmt)
3039           Diag(SectionStmt->getLocStart(),
3040                diag::err_omp_sections_substmt_not_section);
3041         return StmtError();
3042       }
3043     }
3044   } else {
3045     Diag(AStmt->getLocStart(), diag::err_omp_sections_not_compound_stmt);
3046     return StmtError();
3047   }
3048 
3049   getCurFunction()->setHasBranchProtectedScope();
3050 
3051   return OMPSectionsDirective::Create(Context, StartLoc, EndLoc, Clauses,
3052                                       AStmt);
3053 }

Notice from line 3035 to line 3042, it just checks the first statement not the first statement.






_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: bugs in Clang function StmtResult Sema::ActOnOpenMPSectionsDirective

Vassil Vassilev via cfe-dev
😃, you are totally right. Thank you Alexey.

On Wed, Sep 21, 2016 at 7:13 AM, Alexey Bataev <[hidden email]> wrote:

Seems to me you're missing clangFormat library

Best regards,
Alexey Bataev
On 09/21/2016 04:57 PM, xiaohui chen wrote:

Hi guys,

I am writing a libtooling tool. 
My tool can compile and run with Clang version 3.6.2.
However, if I compile with Clang version 3.9.0, it reports an error:

/Project/clang+llvm-3.9.0-x86_64-linux-gnu-ubuntu-14.04/bin/../lib/libclangTooling.a(Refactoring.cpp.o): In function `clang::tooling::formatAndApplyAllReplacements(std::set<clang::tooling::Replacement, std::less<clang::tooling::Replacement>, std::allocator<clang::tooling::Replacement> > const&, clang::Rewriter&, llvm::StringRef)':
/home/development/llvm/3.9.0/final/llvm.src/tools/clang/lib/Tooling/Refactoring.cpp:(.text._ZN5clang7tooling29formatAndApplyAllReplacementsERKSt3setINS0_11ReplacementESt4lessIS2_ESaIS2_EERNS_8RewriterEN4llvm9StringRefE+0x184): undefined reference to `clang::format::getStyle(llvm::StringRef, llvm::StringRef, llvm::StringRef, clang::vfs::FileSystem*)'
/home/development/llvm/3.9.0/final/llvm.src/tools/clang/lib/Tooling/Refactoring.cpp:(.text._ZN5clang7tooling29formatAndApplyAllReplacementsERKSt3setINS0_11ReplacementESt4lessIS2_ESaIS2_EERNS_8RewriterEN4llvm9StringRefE+0x19f): undefined reference to `clang::format::formatReplacements(llvm::StringRef, std::set<clang::tooling::Replacement, std::less<clang::tooling::Replacement>, std::allocator<clang::tooling::Replacement> > const&, clang::format::FormatStyle const&)'
clang-3.9: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [main] Error 1


Do you have any hints?

Best 
xiaohui


On Wed, Mar 18, 2015 at 10:01 AM, xiaohui chen <[hidden email]> wrote:
Hi, 
I am using clang version 3.6.0 (trunk 224915).

Clang can not parse the following valid OpenMP code:

 1 #include<omp.h>
  2 void main()
  3 {
  4         int i;
  5         #pragma omp parallel
  6         #pragma omp sections
  7         {
  8                 i++;
  9                 i++;
 10                 #pragma omp section
 11                 i++;
 12         }
 13 }

The bug comes from line 8 and 9.

In OpenMP documentation (http://www.openmp.org/mp-documents/OpenMP4.0.0.pdf) page 62,
it says"Each structured block in the sections construct is preceded by a section directive 
except possibly the first block, for which a preceding section directive is optional." .

it means that the section directive is optional for the first block, but not the first statement.

in function  StmtResult Sema::ActOnOpenMPSectionsDirective, 

3021 StmtResult Sema::ActOnOpenMPSectionsDirective(ArrayRef<OMPClause *> Clauses,
3022                                               Stmt *AStmt,
3023                                               SourceLocation StartLoc,
3024                                               SourceLocation EndLoc) {
3025   assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected");
3026   auto BaseStmt = AStmt;
3027   while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt))
3028     BaseStmt = CS->getCapturedStmt();
3029   if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) {
3030     auto S = C->children();
3031     if (!S)
3032       return StmtError();
3033     // All associated statements must be '#pragma omp section' except for
3034     // the first one.
3035     for (++S; S; ++S) {
3036       auto SectionStmt = *S;
3037       if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) {
3038         if (SectionStmt)
3039           Diag(SectionStmt->getLocStart(),
3040                diag::err_omp_sections_substmt_not_section);
3041         return StmtError();
3042       }
3043     }
3044   } else {
3045     Diag(AStmt->getLocStart(), diag::err_omp_sections_not_compound_stmt);
3046     return StmtError();
3047   }
3048 
3049   getCurFunction()->setHasBranchProtectedScope();
3050 
3051   return OMPSectionsDirective::Create(Context, StartLoc, EndLoc, Clauses,
3052                                       AStmt);
3053 }

Notice from line 3035 to line 3042, it just checks the first statement not the first statement.







_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev