<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="/rss.xsl.xml"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
    <title>Changes in stmt-openmp_structured_block-bit.cpp</title>
    <description></description>
    <language>en</language>
    <copyright>Copyright 2015</copyright>
    <generator>Java</generator><item>
        <title>50542d50 - Modify TypePrinter to differentiate between anonymous struct and unnamed struct</title>
        <link>http://172.16.0.5:8080/history/llvm-project-15.0.7/clang/test/PCH/stmt-openmp_structured_block-bit.cpp#50542d50</link>
        <description>Modify TypePrinter to differentiate between anonymous struct and unnamed structCurrently TypePrinter lumps anonymous classes and unnamed classes in one group &quot;anonymous&quot; this is not correct and can be confusing in some contexts.Differential Revision: https://reviews.llvm.org/D96807

            List of files:
            /llvm-project-15.0.7/clang/test/PCH/stmt-openmp_structured_block-bit.cpp</description>
        <pubDate>Mon, 22 Feb 2021 17:58:26 +0000</pubDate>
        <dc:creator>Shafik Yaghmour &lt;syaghmour@apple.com&gt;</dc:creator>
    </item>
<item>
        <title>9068dab1 - Revert &quot;Modify TypePrinter to differentiate between anonymous struct and unnamed struct&quot;</title>
        <link>http://172.16.0.5:8080/history/llvm-project-15.0.7/clang/test/PCH/stmt-openmp_structured_block-bit.cpp#9068dab1</link>
        <description>Revert &quot;Modify TypePrinter to differentiate between anonymous struct and unnamed struct&quot;I missed clangd test suite and may need some time to get those working, so reverting for now.This reverts commit ecb90b55454ee94733481247486729a504aa43a1.

            List of files:
            /llvm-project-15.0.7/clang/test/PCH/stmt-openmp_structured_block-bit.cpp</description>
        <pubDate>Fri, 19 Feb 2021 02:17:08 +0000</pubDate>
        <dc:creator>Shafik Yaghmour &lt;syaghmour@apple.com&gt;</dc:creator>
    </item>
<item>
        <title>ecb90b55 - Modify TypePrinter to differentiate between anonymous struct and unnamed struct</title>
        <link>http://172.16.0.5:8080/history/llvm-project-15.0.7/clang/test/PCH/stmt-openmp_structured_block-bit.cpp#ecb90b55</link>
        <description>Modify TypePrinter to differentiate between anonymous struct and unnamed structCurrently TypePrinter lumps anonymous classes and unnamed classes in one group &quot;anonymous&quot; this is not correct and can be confusing in some contexts.Differential Revision: https://reviews.llvm.org/D96807

            List of files:
            /llvm-project-15.0.7/clang/test/PCH/stmt-openmp_structured_block-bit.cpp</description>
        <pubDate>Fri, 19 Feb 2021 01:05:46 +0000</pubDate>
        <dc:creator>Shafik Yaghmour &lt;syaghmour@apple.com&gt;</dc:creator>
    </item>
<item>
        <title>d5edcb90 - [clang] Prune &apos;IsOMPStructuredBlock&apos; Stmt bit</title>
        <link>http://172.16.0.5:8080/history/llvm-project-15.0.7/clang/test/PCH/stmt-openmp_structured_block-bit.cpp#d5edcb90</link>
        <description>[clang] Prune &apos;IsOMPStructuredBlock&apos; Stmt bitAs discussed in https://reviews.llvm.org/D59214#1916596and in some other reviews dealing with FPenv,bits in Stmt are scarce, and i got so burnout with D59214and https://bugs.llvm.org/show_bug.cgi?id=40563 specificallythat i never actually followed up with the usages for this bit.So let&apos;s unhoard it, at least for now?

            List of files:
            /llvm-project-15.0.7/clang/test/PCH/stmt-openmp_structured_block-bit.cpp</description>
        <pubDate>Thu, 12 Mar 2020 09:18:01 +0000</pubDate>
        <dc:creator>Roman Lebedev &lt;lebedev.ri@gmail.com&gt;</dc:creator>
    </item>
<item>
        <title>91f8066d - [OpenMP] Set pragma start loc to `#pragma` loc</title>
        <link>http://172.16.0.5:8080/history/llvm-project-15.0.7/clang/test/PCH/stmt-openmp_structured_block-bit.cpp#91f8066d</link>
        <description>[OpenMP] Set pragma start loc to `#pragma` locThis patch adjusts `PragmaOpenMPHandler` to set the location of`tok::annot_pragma_openmp` to the `#pragma` location instead of the`omp` location so that the former becomes the start location of theOpenMP AST node.  This can be useful when, for example, rewriting adirective using Clang&apos;s Rewrite facility.  Most of this patch updatestests for changes to locations in diagnostics and `-ast-dump` output.Reviewed By: ABataev, lebedev.ri, Meinersbur, aaron.ballmanDifferential Revision: https://reviews.llvm.org/D61509llvm-svn: 361867

            List of files:
            /llvm-project-15.0.7/clang/test/PCH/stmt-openmp_structured_block-bit.cpp</description>
        <pubDate>Tue, 28 May 2019 19:27:19 +0000</pubDate>
        <dc:creator>Joel E. Denny &lt;jdenny.ornl@gmail.com&gt;</dc:creator>
    </item>
<item>
        <title>b570060f - [clang][OpeMP] Model OpenMP structured-block in AST (PR40563)</title>
        <link>http://172.16.0.5:8080/history/llvm-project-15.0.7/clang/test/PCH/stmt-openmp_structured_block-bit.cpp#b570060f</link>
        <description>[clang][OpeMP] Model OpenMP structured-block in AST (PR40563)Summary:https://www.openmp.org/wp-content/uploads/OpenMP-API-Specification-5.0.pdf, page 3:```structured blockFor C/C++, an executable statement, possibly compound, with a single entry at thetop and a single exit at the bottom, or an OpenMP construct.COMMENT: See Section 2.1 on page 38 for restrictions on structuredblocks.``````2.1 Directive FormatSome executable directives include a structured block. A structured block:&#8226; may contain infinite loops where the point of exit is never reached;&#8226; may halt due to an IEEE exception;&#8226; may contain calls to exit(), _Exit(), quick_exit(), abort() or functions with a_Noreturn specifier (in C) or a noreturn attribute (in C/C++);&#8226; may be an expression statement, iteration statement, selection statement, or try block, providedthat the corresponding compound statement obtained by enclosing it in { and } would be astructured block; andRestrictionsRestrictions to structured blocks are as follows:&#8226; Entry to a structured block must not be the result of a branch.&#8226; The point of exit cannot be a branch out of the structured block.C / C++&#8226; The point of entry to a structured block must not be a call to setjmp().&#8226; longjmp() and throw() must not violate the entry/exit criteria.```Of particular note here is the fact that OpenMP structured blocks are as-if `noexcept`,in the same sense as with the normal `noexcept` functions in C++.I.e. if throw happens, and it attempts to travel out of the `noexcept` function(here: out of the current structured-block), then the program terminates.Now, one of course can say that since it is explicitly prohibited by the Specification,then any and all programs that violate this Specification contain undefined behavior,and are unspecified, and thus no one should care about them. Just don&apos;t write broken code /sBut i&apos;m not sure this is a reasonable approach.I have personally had oss-fuzz issues of this origin - exception thrown insideof an OpenMP structured-block that is not caught, thus causing program termination.This issue isn&apos;t all that hard to catch, it&apos;s not any particularly different fromdiagnosing the same situation with the normal `noexcept` function.Now, clang static analyzer does not presently model exceptions.But clang-tidy has a simplisic [[ https://clang.llvm.org/extra/clang-tidy/checks/bugprone-exception-escape.html | bugprone-exception-escape ]] check,and it is even refactored as a `ExceptionAnalyzer` class for reuse.So it would be trivial to use that analyzer to check forexceptions escaping out of OpenMP structured blocks. (D59466)All that sounds too great to be true. Indeed, there is a caveat.Presently, it&apos;s practically impossible to do. To check a OpenMP structured blockyou need to somehow &apos;get&apos; the OpenMP structured block, and you can&apos;t becauseit&apos;s simply not modelled in AST. `CapturedStmt`/`CapturedDecl` is not it&apos;s representation.Now, it is of course possible to write e.g. some AST matcher that would e.g.match every OpenMP executable directive, and then return the whatever `Stmt` isthe structured block of said executable directive, if any.But i said //practically//. This isn&apos;t practical for the following reasons:1. This **will** bitrot. That matcher will need to be kept up-to-date,   and refreshed with every new OpenMP spec version.2. Every single piece of code that would want that knowledge would need to   have such matcher. Well, okay, if it is an AST matcher, it could be shared.   But then you still have `RecursiveASTVisitor` and friends.   `2 &gt; 1`, so now you have code duplication.So it would be reasonable (and is fully within clang AST spirit) to notforce every single consumer to do that work, but instead store that knowledgein the correct, and appropriate place - AST, class structure.Now, there is another hoop we need to get through.It isn&apos;t fully obvious //how// to model this.The best solution would of course be to simply add a `OMPStructuredBlock` transparentnode. It would be optimal, it would give us two properties:* Given this `OMPExecutableDirective`, what&apos;s it OpenMP structured block?* It is trivial to  check whether the `Stmt*` is a OpenMP structured block (`isa&lt;OMPStructuredBlock&gt;(ptr)`)But OpenMP structured block isn&apos;t **necessarily** the first, direct child of `OMP*Directive`.(even ignoring the clang&apos;s `CapturedStmt`/`CapturedDecl` that were inserted inbetween).So i&apos;m not sure whether or not we could re-create AST statements after they were already created?There would be other costs to a new AST node: https://bugs.llvm.org/show_bug.cgi?id=40563#c12```1. You will need to break the representation of loops. The body should be replaced by the &quot;structured block&quot; entity.2. You will need to support serialization/deserialization.3. You will need to support template instantiation.4. You will need to support codegen and take this new construct to account in each OpenMP directive.```Instead, there **is** an functionally-equivalent, alternative solution, consisting of two parts.Part 1:* Add a member function `isStandaloneDirective()` to the `OMPExecutableDirective` class,  that will tell whether this directive is stand-alone or not, as per the spec.  We need it because we can&apos;t just check for the existance of associated statements,  see code comment.* Add a member function `getStructuredBlock()` to the OMPExecutableDirective` class itself,  that assert that this is not a stand-alone directive, and either return the correct loop body  if this is a loop-like directive, or the captured statement.This way, given an `OMPExecutableDirective`, we can get it&apos;s structured block.Also, since the knowledge is ingrained into the clang OpenMP implementation,it will not cause any duplication, and //hopefully// won&apos;t bitrot.Great we achieved 1 of 2 properties of `OMPStructuredBlock` approach.Thus, there is a second part needed:* How can we check whether a given `Stmt*` is `OMPStructuredBlock`?Well, we can&apos;t really, in general. I can see this workaround:```class FunctionASTVisitor : public RecursiveASTVisitor&lt;FunctionASTVisitor&gt; {  using Base = RecursiveASTVisitor&lt;FunctionASTVisitor&gt;;public:  bool VisitOMPExecDir(OMPExecDir *D) {    OmpStructuredStmts.emplace_back(D.getStructuredStmt());  }  bool VisitSOMETHINGELSE(???) {    if(InOmpStructuredStmt)      HI!  }  bool TraverseStmt(Stmt *Node) {    if (!Node)      return Base::TraverseStmt(Node);    if (OmpStructuredStmts.back() == Node)      ++InOmpStructuredStmt;    Base::TraverseStmt(Node);    if (OmpStructuredStmts.back() == Node) {      OmpStructuredStmts.pop_back();      --InOmpStructuredStmt;    }    return true;  }  std::vector&lt;Stmt*&gt; OmpStructuredStmts;  int InOmpStructuredStmt = 0;};```But i really don&apos;t see using it in practice.It&apos;s just too intrusive; and again, requires knowledge duplication... but no. The solution lies right on the ground.Why don&apos;t we simply store this `i&apos;m a openmp structured block` in the bitfield of the `Stmt` itself?This does not appear to have any impact on the memory footprint of the clang AST,since it&apos;s just a single extra bit in the bitfield. At least the static assertions don&apos;t fail.Thus, indeed, we can achieve both of the properties without a new AST node.We can cheaply set that bit right in sema, at the end of `Sema::ActOnOpenMPExecutableDirective()`,by just calling the `getStructuredBlock()` that we just added.Test coverage that demonstrates all this has been added.This isn&apos;t as great with serialization though. Most of it does not use abbrevs,so we do end up paying the full price (4 bytes?) instead of a single bit.That price, of course, can be reclaimed by using abbrevs.In fact, i suspect that //might// not just reclaim these bytes, but pack these PCH significantly.I&apos;m not seeing a third solution. If there is one, it would be interesting to hear about it.(&quot;just don&apos;t write code that would require `isa&lt;OMPStructuredBlock&gt;(ptr)`&quot; is not a solution.)Fixes [[ https://bugs.llvm.org/show_bug.cgi?id=40563 | PR40563 ]].Reviewers: ABataev, rjmccall, hfinkel, rsmith, riccibruno, gribozavrReviewed By: ABataev, gribozavrSubscribers: mgorny, aaron.ballman, steveire, guansong, jfb, jdoerfert, cfe-commitsTags: #clang, #openmpDifferential Revision: https://reviews.llvm.org/D59214llvm-svn: 356570

            List of files:
            /llvm-project-15.0.7/clang/test/PCH/stmt-openmp_structured_block-bit.cpp</description>
        <pubDate>Wed, 20 Mar 2019 16:32:36 +0000</pubDate>
        <dc:creator>Roman Lebedev &lt;lebedev.ri@gmail.com&gt;</dc:creator>
    </item>
</channel>
</rss>
