summaryrefslogtreecommitdiffstats
path: root/clang/test/AST
Commit message (Collapse)AuthorAgeFilesLines
...
* [clang][OpeMP] Model OpenMP structured-block in AST (PR40563)Roman Lebedev2019-03-2049-435/+435
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: https://www.openmp.org/wp-content/uploads/OpenMP-API-Specification-5.0.pdf, page 3: ``` structured block For C/C++, an executable statement, possibly compound, with a single entry at the top and a single exit at the bottom, or an OpenMP construct. COMMENT: See Section 2.1 on page 38 for restrictions on structured blocks. ``` ``` 2.1 Directive Format Some executable directives include a structured block. A structured block: • may contain infinite loops where the point of exit is never reached; • may halt due to an IEEE exception; • may contain calls to exit(), _Exit(), quick_exit(), abort() or functions with a _Noreturn specifier (in C) or a noreturn attribute (in C/C++); • may be an expression statement, iteration statement, selection statement, or try block, provided that the corresponding compound statement obtained by enclosing it in { and } would be a structured block; and Restrictions Restrictions to structured blocks are as follows: • Entry to a structured block must not be the result of a branch. • The point of exit cannot be a branch out of the structured block. C / C++ • The point of entry to a structured block must not be a call to setjmp(). • 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't write broken code /s But i'm not sure this is a reasonable approach. I have personally had oss-fuzz issues of this origin - exception thrown inside of an OpenMP structured-block that is not caught, thus causing program termination. This issue isn't all that hard to catch, it's not any particularly different from diagnosing 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 for exceptions escaping out of OpenMP structured blocks. (D59466) All that sounds too great to be true. Indeed, there is a caveat. Presently, it's practically impossible to do. To check a OpenMP structured block you need to somehow 'get' the OpenMP structured block, and you can't because it's simply not modelled in AST. `CapturedStmt`/`CapturedDecl` is not it'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` is the structured block of said executable directive, if any. But i said //practically//. This isn'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 > 1`, so now you have code duplication. So it would be reasonable (and is fully within clang AST spirit) to not force every single consumer to do that work, but instead store that knowledge in the correct, and appropriate place - AST, class structure. Now, there is another hoop we need to get through. It isn't fully obvious //how// to model this. The best solution would of course be to simply add a `OMPStructuredBlock` transparent node. It would be optimal, it would give us two properties: * Given this `OMPExecutableDirective`, what's it OpenMP structured block? * It is trivial to check whether the `Stmt*` is a OpenMP structured block (`isa<OMPStructuredBlock>(ptr)`) But OpenMP structured block isn't **necessarily** the first, direct child of `OMP*Directive`. (even ignoring the clang's `CapturedStmt`/`CapturedDecl` that were inserted inbetween). So i'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 "structured block" 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'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's structured block. Also, since the knowledge is ingrained into the clang OpenMP implementation, it will not cause any duplication, and //hopefully// won'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't really, in general. I can see this workaround: ``` class FunctionASTVisitor : public RecursiveASTVisitor<FunctionASTVisitor> { using Base = RecursiveASTVisitor<FunctionASTVisitor>; 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<Stmt*> OmpStructuredStmts; int InOmpStructuredStmt = 0; }; ``` But i really don't see using it in practice. It's just too intrusive; and again, requires knowledge duplication. .. but no. The solution lies right on the ground. Why don't we simply store this `i'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's just a single extra bit in the bitfield. At least the static assertions don'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'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'm not seeing a third solution. If there is one, it would be interesting to hear about it. ("just don't write code that would require `isa<OMPStructuredBlock>(ptr)`" is not a solution.) Fixes [[ https://bugs.llvm.org/show_bug.cgi?id=40563 | PR40563 ]]. Reviewers: ABataev, rjmccall, hfinkel, rsmith, riccibruno, gribozavr Reviewed By: ABataev, gribozavr Subscribers: mgorny, aaron.ballman, steveire, guansong, jfb, jdoerfert, cfe-commits Tags: #clang, #openmp Differential Revision: https://reviews.llvm.org/D59214 llvm-svn: 356570
* [NFC][clang][astdump] Some baseline tests for OpenMPRoman Lebedev2019-03-2048-0/+18501
| | | | | | | | | | Summary: Split off from D59214. Not a fully exhaustive test coverage, but better than what there currently is. Differential Revision: https://reviews.llvm.org/D59306 llvm-svn: 356569
* Look through typedefs in getFunctionTypeWithExceptionSpecStephan Bergmann2019-02-131-0/+14
| | | | | | | | Fixes https://bugs.llvm.org/show_bug.cgi?id=40658 Differential Revision: https://reviews.llvm.org/D58056 llvm-svn: 353931
* Fix a few tests that were missing ':' on CHECK lines and weren't testing ↵Nico Weber2019-02-111-1/+1
| | | | | | | | | | | | anything. Found by `git grep '\/\/ CHECK-[^: ]* ' clang/test/ | grep -v RUN:`. Also tweak CodeGenCXX/arm-swiftcall.cpp to still pass now that it checks more. Differential Revision: https://reviews.llvm.org/D58061 llvm-svn: 353744
* [Sema] Make string literal init an rvalue.Eli Friedman2019-02-081-4/+4
| | | | | | | | | | | | | | | | | | | | | | | This allows substantially simplifying the expression evaluation code, because we don't have to special-case lvalues which are actually string literal initialization. This currently throws away an optimization where we would avoid creating an array APValue for string literal initialization. If we really want to optimize this case, we should fix APValue so it can store simple arrays more efficiently, like llvm::ConstantDataArray. This shouldn't affect the memory usage for other string literals. (Not sure if this is a blocker; I don't think string literal init is common enough for this to be a serious issue, but I could be wrong.) The change to test/CodeGenObjC/encode-test.m is a weird side-effect of these changes: we currently don't constant-evaluate arrays in C, so the strlen call shouldn't be folded, but lvalue string init managed to get around that check. I this this is fine. Fixes https://bugs.llvm.org/show_bug.cgi?id=40430 . llvm-svn: 353569
* [ASTDump] Add a flag indicating whether a CXXThisExpr is implicitBruno Ricci2019-02-033-4/+4
| | | | | | | | | | | There is currently no way to distinguish implicit from explicit CXXThisExpr in the AST dump output. Differential Revision: https://reviews.llvm.org/D57649 Reviewed By: steveire llvm-svn: 353003
* Revert "[AST][OpenMP] OpenMP Sections / Section constructs contain ↵Roman Lebedev2019-02-011-57/+0
| | | | | | | | | | | | Structured blocks" Further reviews (D57594, D57615) have revealed that this was not reviewed, and that the differential's description was not read during the review, thus rendering this commit invalid. This reverts commit r352882. llvm-svn: 352933
* [AST][OpenMP] OpenMP Sections / Section constructs contain Structured blocksRoman Lebedev2019-02-011-0/+57
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: I'm working on a clang-tidy check, much like existing [[ http://clang.llvm.org/extra/clang-tidy/checks/bugprone-exception-escape.html | bugprone-exception-escape ]], to detect when an exception might escape out of an OpenMP construct it isn't supposed to escape from. For that i will be using the `nothrow` bit of `CapturedDecl`s. While that bit is already correctly set for some constructs, e.g. `#pragma omp parallel`: https://godbolt.org/z/2La7pv it isn't set for the `#pragma omp sections`, or `#pragma omp section`: https://godbolt.org/z/qZ-EbP If i'm reading [[ https://www.openmp.org/wp-content/uploads/OpenMP-API-Specification-5.0.pdf | `OpenMP Application Programming Interface Version 5.0 November 2018` ]] correctly, they should be, as per `2.8.1 sections Construct`, starting with page 86: * The sections construct is a non-iterative worksharing construct that contains a set of **structured blocks** that are to be distributed among and executed by the threads in a team. Each **structured block** is executed once by one of the threads in the team in the context of its implicit task. * The syntax of the sections construct is as follows: #pragma omp sections [clause[ [,] clause] ... ] new-line { [#pragma omp section new-line] **structured-block** ... * Description 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. * Restrictions • The code enclosed in a sections construct must be a **structured block**. * A throw executed inside a sections region must cause execution to resume within the same section of the sections region, and the same thread that threw the exception must catch it. Reviewers: ABataev, #openmp Reviewed By: ABataev Subscribers: guansong, openmp-commits, cfe-commits Tags: #clang, #openmp Differential Revision: https://reviews.llvm.org/D57585 llvm-svn: 352882
* [ASTDump] Make template specialization tests more exactStephen Kelly2019-01-311-112/+307
| | | | | | | | | | Reviewers: aaron.ballman Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D57502 llvm-svn: 352804
* [ASTDumper][OpenMP] CapturedDecl has a 'nothrow' bitRoman Lebedev2019-01-301-1/+1
| | | | | | | | | | | | | | | | | | | | | Summary: Was trying to understand how complicated it would be to write a clang-tidy `openmp-exception-escape`-ish check once D57100 lands. Just so it happens, all the data is already there, it is just conveniently omitted from AST dump. Reviewers: aaron.ballman, steveire, ABataev Reviewed By: ABataev Subscribers: ABataev, guansong, cfe-commits Tags: #openmp, #clang Differential Revision: https://reviews.llvm.org/D57452 llvm-svn: 352631
* Disable _Float16 for non ARM/SPIR TargetsErich Keane2019-01-251-2/+2
| | | | | | | | | | | | | | As Discussed here: http://lists.llvm.org/pipermail/llvm-dev/2019-January/129543.html There are problems exposing the _Float16 type on architectures that haven't defined the ABI/ISel for the type yet, so we're temporarily disabling the type and making it opt-in. Differential Revision: https://reviews.llvm.org/D57188 Change-Id: I5db7366dedf1deb9485adb8948b1deb7e612a736 llvm-svn: 352221
* [Sema] Fix Modified Type in address_space AttributedTypeLeonard Chan2019-01-241-0/+23
| | | | | | | | | | | This is a fix for https://reviews.llvm.org/D51229 where we pass the address_space qualified type as the modified type of an AttributedType. This change now instead wraps the AttributedType with either the address_space qualifier or a DependentAddressSpaceType. Differential Revision: https://reviews.llvm.org/D55447 llvm-svn: 351997
* Mark the lambda function pointer conversion operator as noexcept.Aaron Ballman2019-01-211-7/+7
| | | | | | This implements CWG DR 1722 and fixes PR40309. Patch by Ignat Loskutov. llvm-svn: 351750
* Move decl context dumping to TextNodeDumperStephen Kelly2019-01-191-2/+1
| | | | | | | | | | | | Summary: Only an obscure case is moved. Reviewers: aaron.ballman Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D56829 llvm-svn: 351637
* [ASTDump] Add test for current AST dump behaviorStephen Kelly2019-01-181-0/+4
| | | | llvm-svn: 351606
* [ASTDump] Mark BlockDecls which capture this with a tagStephen Kelly2019-01-181-2/+1
| | | | | | | | | | | | | | Summary: Removal of the child node makes it easier to separate traversal from output generation. Reviewers: aaron.ballman Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D56752 llvm-svn: 351600
* [ASTDump] Mark variadic declarations with a tag instead of child nodeStephen Kelly2019-01-181-6/+3
| | | | | | | | | | | | | | Summary: This makes it easier to separate traversal of the AST from output generation. Reviewers: aaron.ballman Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D56751 llvm-svn: 351597
* Added test cases for dumping variadic-like functions; NFC.Aaron Ballman2019-01-163-0/+26
| | | | llvm-svn: 351355
* Added a test case for dumping blocks that capture 'this'; NFC.Aaron Ballman2019-01-161-0/+17
| | | | llvm-svn: 351350
* Re-order type param children of ObjC nodesStephen Kelly2019-01-151-1/+1
| | | | | | | | | | Reviewers: aaron.ballman Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D55394 llvm-svn: 351272
* Re-order overrides in FunctionDecl dumpStephen Kelly2019-01-151-1/+1
| | | | | | | | | | | | | | Output all content which is local to the FunctionDecl before traversing to child AST nodes. This is necessary so that all of the part which is local to the FunctionDecl can be split into a different method. Reviewers: aaron.ballman Differential Revision: https://reviews.llvm.org/D55083 llvm-svn: 351269
* [ASTDump] Add utility for dumping a label with child nodesStephen Kelly2019-01-111-2/+1
| | | | | | | | | | | | | | | | | | | Summary: Use it to add optional label nodes to Stmt dumps. This preserves behavior of InitExprList dump: // CHECK-NEXT: `-InitListExpr {{.+}} <col:13, col:15> 'U [3]' // CHECK-NEXT: |-array_filler: InitListExpr {{.+}} <col:15> 'U' field Field {{.+}} 'i' 'int' // CHECK-NEXT: `-InitListExpr {{.+}} <col:14> 'U' field Field {{.+}} 'i' 'int' // CHECK-NEXT: `-IntegerLiteral {{.+}} <col:14> 'int' 1 Reviewers: aaron.ballman Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D55488 llvm-svn: 350957
* [AST] Store "UsesADL" information in CallExpr.Eric Fiselier2018-12-121-0/+43
| | | | | | | | | | | | | | | | | | | | | Summary: Currently the Clang AST doesn't store information about how the callee of a CallExpr was found. Specifically if it was found using ADL. However, this information is invaluable to tooling. Consider a tool which renames usages of a function. If the originally CallExpr was formed using ADL, then the tooling may need to additionally qualify the replacement. Without information about how the callee was found, the tooling is left scratching it's head. Additionally, we want to be able to match ADL calls as quickly as possible, which means avoiding computing the answer on the fly. This patch changes `CallExpr` to store whether it's callee was found using ADL. It does not change the size of any AST nodes. Reviewers: fowles, rsmith, klimek, shafik Reviewed By: rsmith Subscribers: aaron.ballman, riccibruno, calabrese, titus, cfe-commits Differential Revision: https://reviews.llvm.org/D55534 llvm-svn: 348977
* Adding tests for -ast-dump; NFC.Aaron Ballman2018-12-111-0/+510
| | | | | | This adds tests for expressions in C++. llvm-svn: 348860
* Revert "Change InitListExpr dump to label and pointer"Stephen Kelly2018-12-101-2/+3
| | | | | | This reverts commit r348794. llvm-svn: 348799
* Re-order content of template parameter dumpsStephen Kelly2018-12-101-3/+3
| | | | | | | | | | Reviewers: aaron.ballman Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D55393 llvm-svn: 348797
* Re-order content in OMPDeclareReductionDecl dumpStephen Kelly2018-12-101-3/+3
| | | | | | | | | | Reviewers: aaron.ballman Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D55395 llvm-svn: 348795
* Change InitListExpr dump to label and pointerStephen Kelly2018-12-101-3/+2
| | | | | | | | | | | | Summary: Don't add a child just for the label. Reviewers: aaron.ballman Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D55495 llvm-svn: 348794
* Add an explicit triple to this test to fix failing test bots.Aaron Ballman2018-12-101-6/+6
| | | | llvm-svn: 348790
* Adding tests for -ast-dump; NFC.Aaron Ballman2018-12-101-0/+339
| | | | | | This adds tests for expressions in C. llvm-svn: 348786
* Fix InitListExpr testStephen Kelly2018-12-091-6/+6
| | | | | | Wrong case of Check meant this has no effect. llvm-svn: 348713
* Adding an AST dump test for statement expressions; NFC.Aaron Ballman2018-12-071-0/+11
| | | | llvm-svn: 348613
* Add an explicit triple to this test to prevent failures due to size_t ↵Aaron Ballman2018-12-071-3/+3
| | | | | | differences. llvm-svn: 348599
* Adding tests for -ast-dump; NFC.Aaron Ballman2018-12-071-2/+174
| | | | | | This adds tests for various statements in C++ that are not covered by C. llvm-svn: 348596
* Adding tests for -ast-dump; NFC.Aaron Ballman2018-12-071-5/+241
| | | | | | This adds tests for various statements in C. llvm-svn: 348588
* Add test for InitListExprStephen Kelly2018-12-071-0/+18
| | | | llvm-svn: 348553
* Add more expected content to match in testStephen Kelly2018-12-061-3/+3
| | | | llvm-svn: 348543
* Use relative line offsets in testStephen Kelly2018-12-061-12/+12
| | | | llvm-svn: 348541
* Add test for ObjC genericsStephen Kelly2018-12-061-0/+8
| | | | llvm-svn: 348471
* Extend OMP testStephen Kelly2018-12-061-0/+7
| | | | llvm-svn: 348470
* Make test resistant to line numbers changingStephen Kelly2018-12-061-11/+11
| | | | llvm-svn: 348469
* Add dump tests for inherited default template parametersStephen Kelly2018-12-051-0/+27
| | | | llvm-svn: 348408
* Adding tests for -ast-dump; NFC.Aaron Ballman2018-12-051-0/+102
| | | | | | This adds tests for various function and class template declarations. llvm-svn: 348399
* Adding tests for -ast-dump; NFC.Aaron Ballman2018-12-042-0/+636
| | | | | | This adds tests for the definition data of C++ record objects as well as special member functions. llvm-svn: 348309
* Add tests for dumping base classes; NFC.Aaron Ballman2018-12-041-0/+37
| | | | llvm-svn: 348308
* Extend test for DependentSizedArrayTypeStephen Kelly2018-12-041-0/+9
| | | | | | | Use a using declaration to force the type to appear in the -ast-dump output. llvm-svn: 348241
* Adding tests for -ast-dump; NFC.Aaron Ballman2018-12-031-0/+239
| | | | | | This adds tests for struct and union declarations in C++. llvm-svn: 348156
* [clang] Do not read from 'test/SemaCXX/Inputs' inside 'test/AST'Ilya Biryukov2018-12-032-1/+38
| | | | | | | Our integrate relies on test inputs being taken from the same diretory as the test itself. llvm-svn: 348123
* Fix whitespaceStephen Kelly2018-12-021-1/+1
| | | | llvm-svn: 348094
* Add dump tests for ArrayInitLoopExpr and ArrayInitIndexExprStephen Kelly2018-12-021-0/+10
| | | | llvm-svn: 348093
OpenPOWER on IntegriCloud