aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests
AgeCommit message (Collapse)AuthorFilesLines
2022-10-27[clang][driver] Remove dynamic gcc-toolset/devtoolset logicTimm Bäder1-92/+0
This breaks when the newest available devtoolset directory is not a complete toolset: https://github.com/llvm/llvm-project/issues/57843 Remove this again in favor or just adding the two new directories for devtoolset/gcc-toolset 12. This reverts commit 35aaf548237a4f213ba9d95de53b33c5ce1eadce. This reverts commit 9f97720268911abae2ad9d90e270358db234a1c1. Fixes https://github.com/llvm/llvm-project/issues/57843 Differential Revision: https://reviews.llvm.org/D136435
2022-10-10[Syntax] Fix macro-arg handling in TokenBuffer::spelledForExpandedSam McCall1-0/+56
A few cases were not handled correctly. Notably: #define ID(X) X #define HIDE a ID(b) HIDE spelledForExpanded() would claim HIDE is an equivalent range of the 'b' it contains, despite the fact that HIDE also covers 'a'. While trying to fix this bug, I found findCommonRangeForMacroArgs hard to understand (both the implementation and how it's used in spelledForExpanded). It relies on details of the SourceLocation graph that are IMO fairly obscure. So I've added/revised quite a lot of comments and made some naming tweaks. Fixes https://github.com/clangd/clangd/issues/1289 Differential Revision: https://reviews.llvm.org/D134618 (cherry picked from commit 67268ee11c220b1dfdf84afb10a12371c5ae6400)
2022-09-28Fix build error in StmtPrinterTest.cppNathan Ridge1-9/+11
(cherry picked from commit c933453858307d060a1b79e257feb99c9ac828d7)
2022-09-28[clangd] Avoid crash when printing call to string literal operator templateNathan Ridge1-2/+33
Differential Revision: https://reviews.llvm.org/D132830 (cherry picked from commit 898c421975ed36b99ec2047589384539bd29a40b)
2022-09-08[clang-format] Distinguish logical and after bracket from referencejackh2-0/+5
Fix commit `b646f0955574` and remove redundant code. Differential Revision: https://reviews.llvm.org/D131750 (cherry picked from commit ef71383b0cfbacdbebf495015f6ead5294bf7759)
2022-08-11Revert "[clang] Pass FoundDecl to DeclRefExpr creator for operator overloads"Kadir Cetinkaya1-3/+0
This reverts commit 4e94f6653150511de434fa7e29b684ae7f0e52b6. See https://reviews.llvm.org/D129973#3698969 for reasoning. (cherry picked from commit df48e3fbcc8be1f4c04bd97517d12e662f54de75)
2022-07-26[CGDebugInfo] Access the current working directory from the `VFS`Argyrios Kyrtzidis2-6/+41
...instead of calling `llvm::sys::fs::current_path()` directly. Differential Revision: https://reviews.llvm.org/D130443
2022-07-26[clang] Pass FoundDecl to DeclRefExpr creator for operator overloadsDanny Mösch1-0/+3
Without the "found declaration" it is later not possible to know where the operator declaration was brought into the scope calling it. The initial motivation for this fix came from #55095. However, this also has an influence on `clang -ast-dump` which now prints a `UsingShadow` attribute for operators only visible through `using` statements. Also, clangd now correctly references the `using` statement instead of the operator directly. Reviewed By: shafik Differential Revision: https://reviews.llvm.org/D129973
2022-07-26[clang][dataflow] Analyze calls to in-TU functionsSam Estep1-8/+106
This patch adds initial support for context-sensitive analysis of simple functions whose definition is available in the translation unit, guarded by the `ContextSensitive` flag in the new `TransferOptions` struct. When this option is true, the `VisitCallExpr` case in the builtin transfer function has a fallthrough case which checks for a direct callee with a body. In that case, it constructs a CFG from that callee body, uses the new `pushCall` method on the `Environment` to make an environment to analyze the callee, and then calls `runDataflowAnalysis` with a `NoopAnalysis` (disabling context-sensitive analysis on that sub-analysis, to avoid problems with recursion). After the sub-analysis completes, the `Environment` from its exit block is simply assigned back to the environment at the callsite. The `pushCall` method (which currently only supports non-method functions with some restrictions) maps the `SourceLocation`s for all the parameters to the existing source locations for the corresponding arguments from the callsite. This patch adds a few tests to check that this context-sensitive analysis works on simple functions. More sophisticated functionality will be added later; the most important next step is to explicitly model context in some fields of the `DataflowAnalysisContext` class, as mentioned in a `FIXME` comment in the `pushCall` implementation. Reviewed By: ymandel, xazax.hun Differential Revision: https://reviews.llvm.org/D130306
2022-07-26Revert "[clang][dataflow] Analyze calls to in-TU functions"Sam Estep1-106/+8
This reverts commit fa2b83d07ecab3b24b4c5ee2e7dc4b6bbc895317.
2022-07-26[clang][dataflow] Analyze calls to in-TU functionsSam Estep1-8/+106
Depends On D130305 This patch adds initial support for context-sensitive analysis of simple functions whose definition is available in the translation unit, guarded by the `ContextSensitive` flag in the new `TransferOptions` struct. When this option is true, the `VisitCallExpr` case in the builtin transfer function has a fallthrough case which checks for a direct callee with a body. In that case, it constructs a CFG from that callee body, uses the new `pushCall` method on the `Environment` to make an environment to analyze the callee, and then calls `runDataflowAnalysis` with a `NoopAnalysis` (disabling context-sensitive analysis on that sub-analysis, to avoid problems with recursion). After the sub-analysis completes, the `Environment` from its exit block is simply assigned back to the environment at the callsite. The `pushCall` method (which currently only supports non-method functions with some restrictions) first calls `initGlobalVars`, then maps the `SourceLocation`s for all the parameters to the existing source locations for the corresponding arguments from the callsite. This patch adds a few tests to check that this context-sensitive analysis works on simple functions. More sophisticated functionality will be added later; the most important next step is to explicitly model context in some fields of the `DataflowAnalysisContext` class, as mentioned in a `TODO` comment in the `pushCall` implementation. Reviewed By: ymandel, xazax.hun Differential Revision: https://reviews.llvm.org/D130306
2022-07-26[clang][dataflow] Add explicit "AST" nodes for implications and iffDmitri Gribenko4-40/+124
Previously we used to desugar implications and biconditionals into equivalent CNF/DNF as soon as possible. However, this desugaring makes debug output (Environment::dump()) less readable than it could be. Therefore, it makes sense to keep the sugared representation of a boolean formula, and desugar it in the solver. Reviewed By: sgatev, xazax.hun, wyt Differential Revision: https://reviews.llvm.org/D130519
2022-07-26[clang][dataflow] Fix SAT solver crashes on `X ^ X` and `X v X`Dmitri Gribenko1-1/+19
BooleanFormula::addClause has an invariant that a clause has no duplicated literals. When the solver was desugaring a formula into CNF clauses, it could construct a clause with such duplicated literals in two cases. Reviewed By: sgatev, ymandel, xazax.hun Differential Revision: https://reviews.llvm.org/D130522
2022-07-25[clang-format] Fix a hang when formatting C# $@ string literalsowenca1-0/+1
Fixes #56624. Differential Revision: https://reviews.llvm.org/D130411
2022-07-25[clang][dataflow] Fix MapLattice::insert() to not drop return valueEric Li1-2/+7
Fix `MapLattice` API to return `std::pair<iterator, bool>`, allowing users to detect when an element has been inserted without performing a redundant map lookup. Differential Revision: https://reviews.llvm.org/D130497
2022-07-25[C++20] [Modules] Make the linkage consistent for class template and itsChuanqi Xu1-1/+20
specialization Previously in D120397, we've handled the linkage for function template and its specialization. But we forgot to handle it for class templates and their specialization. So we make it in the patch with the similar approach.
2022-07-25[clang][ASTImporter] Improved handling of functions with auto return type.Balázs Kéri1-0/+18
Avoid a crash if a function is imported that has auto return type that references to a template with an expression-type of argument that references into the function's body. Fixes issue #56047 Reviewed By: martong Differential Revision: https://reviews.llvm.org/D129640
2022-07-24[clang-tidy] implement new check 'misc-const-correctness' to add 'const' to ↵Jonas Toth1-2/+2
unmodified variables This patch connects the check for const-correctness with the new general utility to add `const` to variables. The code-transformation is only done, if the detected variable for const-ness is not part of a group-declaration. The check allows to control multiple facets of adding `const`, e.g. if pointers themself should be marked as `const` if they are not changed. Reviewed By: njames93 Differential Revision: https://reviews.llvm.org/D54943
2022-07-23Use llvm::sort instead of std::sort where possibleDmitri Gribenko1-4/+4
llvm::sort is beneficial even when we use the iterator-based overload, since it can optionally shuffle the elements (to detect non-determinism). However llvm::sort is not usable everywhere, for example, in compiler-rt. Reviewed By: nhaehnle Differential Revision: https://reviews.llvm.org/D130406
2022-07-23[clang][dataflow] Add DataflowEnvironment::dump()Dmitri Gribenko1-0/+25
Start by dumping the flow condition. Reviewed By: ymandel Differential Revision: https://reviews.llvm.org/D130398
2022-07-22[clang][dataflow] Move NoopAnalysis from unittests to includeSam Estep6-49/+5
This patch moves `Analysis/FlowSensitive/NoopAnalysis.h` from `clang/unittests/` to `clang/include/clang/`, so that we can use it for doing context-sensitive analysis. Reviewed By: ymandel, gribozavr2, sgatev Differential Revision: https://reviews.llvm.org/D130304
2022-07-22[ASTMatchers] Fix standalone buildNathan James1-1/+3
Disable the tests and remove private include introduced in d89f9e963e4979466193dc6a15fe091bf7ca5c47.
2022-07-21[ASTMatchers] Adding a new matcher for callee declarations of Obj-CZiqing Luo2-0/+58
message expressions For an Obj-C message expression `[o m]`, the adding matcher will match the declaration of the method `m`. This commit overloads the existing `callee` ASTMatcher, which originally was only for C/C++ nodes but also applies to Obj-C messages now. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D129398
2022-07-20[clang-format][NFC] Refactor RequiresDoesNotChangeParsingOfTheRestowenca1-315/+163
Differential Revision: https://reviews.llvm.org/D129982
2022-07-20[clang-format] Indent tokens after hash only if it starts a lineowenca1-0/+4
Fixes #56602. Differential Revision: https://reviews.llvm.org/D130136
2022-07-19Use value instead of getValue (NFC)Kazu Hirata1-5/+5
2022-07-19Use has_value instead of hasValue (NFC)Kazu Hirata1-5/+5
2022-07-18[unittests/Tooling/DependencyScannerTest] Add a target triple for ↵Argyrios Kyrtzidis1-1/+5
`ScanDepsWithFS` test This should fix the `clang-ppc64-aix` builder.
2022-07-18[clang-format] Mark constexpr lambdas as lambdaBjörn Schäpers1-0/+7
Otherwise the brace was detected as a function brace, not wrong per se, but when directly calling the lambda the calling parens were put on the next line. Differential Revision: https://reviews.llvm.org/D129946
2022-07-18[clang-format] Indent TT_CtorInitializerColon after requires clausesBjörn Schäpers1-0/+12
Fixes https://github.com/llvm/llvm-project/issues/56215 Differential Revision: https://reviews.llvm.org/D129942
2022-07-18[clang-format] Fix misannotation of colon in presence of requires clauseBjörn Schäpers1-0/+64
For clauses without parentheses it was annotated as TT_InheritanceColon. Relates to https://github.com/llvm/llvm-project/issues/56215 Differential Revision: https://reviews.llvm.org/D129940
2022-07-18[Tooling/DependencyScanning] Enable passing a `vfs::FileSystem` object to ↵Argyrios Kyrtzidis1-1/+33
`DependencyScanningTool` Also include a unit test to validate that the `vfs::FileSystem` object is properly used. Differential Revision: https://reviews.llvm.org/D129912
2022-07-18Don't include private gtest/gmock headersBenjamin Kramer1-3/+1
Only gmock.h and gtest.h are supposed to be user-visible.
2022-07-18[clang] Emit SARIF Diagnostics: Create `clang::SarifDocumentWriter` interfaceVaibhav Yenamandra2-0/+326
[clang] Emit SARIF Diagnostics: Create clang::SarifDocumentWriter interface Create an interface for writing SARIF documents from within clang: The primary intent of this change is to introduce the interface clang::SarifDocumentWriter, which allows incrementally adding diagnostic data to a JSON backed document. The proposed interface is not yet connected to the compiler internals, which will be covered in future work. As such this change will not change the input/output interface of clang. This change also introduces the clang::FullSourceRange type that is modeled after clang::SourceRange + clang::FullSourceLoc, this is useful for packaging a pair of clang::SourceLocation objects with their corresponding SourceManagers. Previous discussions: RFC for this change: https://lists.llvm.org/pipermail/cfe-dev/2021-March/067907.html https://lists.llvm.org/pipermail/cfe-dev/2021-July/068480.html SARIF Standard (2.1.0): https://docs.oasis-open.org/sarif/sarif/v2.1.0/os/sarif-v2.1.0-os.html Differential Revision: https://reviews.llvm.org/D109701
2022-07-16[test] Fix memory leak in validateTargetProfileVitaly Buka1-43/+48
Unfortunatly fixing leak expose use-after-free if delete more then one Compilation for the same Driver, so I am changing validateTargetProfile to create own Driver each time. The test was added by D122865.
2022-07-16[test] Don't leak DerivedArgList in testVitaly Buka1-6/+10
2022-07-16[clang-format] Never remove braces in macro definitionsowenca1-0/+7
Fixes #56559. Differential Revision: https://reviews.llvm.org/D129921
2022-07-16[test] Fix leak in testVitaly Buka1-1/+4
2022-07-15[unittests/Tooling/DependencyScannerTest.cpp] Use `using namespace` instead ↵Argyrios Kyrtzidis1-5/+2
of wrapping the `.cpp` file contents in namespaces, NFC This makes the file consistent with the coding style of the rest of LLVM.
2022-07-15[clang-format] distinguish multiplication after brace-init from pointerKrasimir Georgiev2-0/+6
After https://github.com/llvm/llvm-project/commit/b646f0955574c6ad4c156c9db522e46f597cfda9, the added regression test started being formatted as-if the multiplication `*` was a pointer. This adapts the heuristic to distinguish between these two cases. Reviewed By: jackhong12, curdeius, HazardyKnusperkeks, owenpan Differential Revision: https://reviews.llvm.org/D129771
2022-07-15[syntax] Introduce a TokenManager interface.Haojian Wu6-86/+94
TokenManager defines Token interfaces for the clang syntax-tree. This is the level of abstraction that the syntax-tree should use to operate on Tokens. It decouples the syntax-tree from a particular token implementation (TokenBuffer previously). This enables us to use a different underlying token implementation for the syntax Leaf node -- in clang pseudoparser, we want to produce a syntax-tree with its own pseudo::Token rather than syntax::Token. Differential Revision: https://reviews.llvm.org/D128411
2022-07-14Revert "[clang] Implement ElaboratedType sugaring for types written bare"Jonas Devlieghere13-285/+183
This reverts commit 7c51f02effdbd0d5e12bfd26f9c3b2ab5687c93f because it stills breaks the LLDB tests. This was re-landed without addressing the issue or even agreement on how to address the issue. More details and discussion in https://reviews.llvm.org/D112374.
2022-07-15[clang] Implement ElaboratedType sugaring for types written bareMatheus Izvekov13-183/+285
Without this patch, clang will not wrap in an ElaboratedType node types written without a keyword and nested name qualifier, which goes against the intent that we should produce an AST which retains enough details to recover how things are written. The lack of this sugar is incompatible with the intent of the type printer default policy, which is to print types as written, but to fall back and print them fully qualified when they are desugared. An ElaboratedTypeLoc without keyword / NNS uses no storage by itself, but still requires pointer alignment due to pre-existing bug in the TypeLoc buffer handling. --- Troubleshooting list to deal with any breakage seen with this patch: 1) The most likely effect one would see by this patch is a change in how a type is printed. The type printer will, by design and default, print types as written. There are customization options there, but not that many, and they mainly apply to how to print a type that we somehow failed to track how it was written. This patch fixes a problem where we failed to distinguish between a type that was written without any elaborated-type qualifiers, such as a 'struct'/'class' tags and name spacifiers such as 'std::', and one that has been stripped of any 'metadata' that identifies such, the so called canonical types. Example: ``` namespace foo { struct A {}; A a; }; ``` If one were to print the type of `foo::a`, prior to this patch, this would result in `foo::A`. This is how the type printer would have, by default, printed the canonical type of A as well. As soon as you add any name qualifiers to A, the type printer would suddenly start accurately printing the type as written. This patch will make it print it accurately even when written without qualifiers, so we will just print `A` for the initial example, as the user did not really write that `foo::` namespace qualifier. 2) This patch could expose a bug in some AST matcher. Matching types is harder to get right when there is sugar involved. For example, if you want to match a type against being a pointer to some type A, then you have to account for getting a type that is sugar for a pointer to A, or being a pointer to sugar to A, or both! Usually you would get the second part wrong, and this would work for a very simple test where you don't use any name qualifiers, but you would discover is broken when you do. The usual fix is to either use the matcher which strips sugar, which is annoying to use as for example if you match an N level pointer, you have to put N+1 such matchers in there, beginning to end and between all those levels. But in a lot of cases, if the property you want to match is present in the canonical type, it's easier and faster to just match on that... This goes with what is said in 1), if you want to match against the name of a type, and you want the name string to be something stable, perhaps matching on the name of the canonical type is the better choice. 3) This patch could exposed a bug in how you get the source range of some TypeLoc. For some reason, a lot of code is using getLocalSourceRange(), which only looks at the given TypeLoc node. This patch introduces a new, and more common TypeLoc node which contains no source locations on itself. This is not an inovation here, and some other, more rare TypeLoc nodes could also have this property, but if you use getLocalSourceRange on them, it's not going to return any valid locations, because it doesn't have any. The right fix here is to always use getSourceRange() or getBeginLoc/getEndLoc which will dive into the inner TypeLoc to get the source range if it doesn't find it on the top level one. You can use getLocalSourceRange if you are really into micro-optimizations and you have some outside knowledge that the TypeLocs you are dealing with will always include some source location. 4) Exposed a bug somewhere in the use of the normal clang type class API, where you have some type, you want to see if that type is some particular kind, you try a `dyn_cast` such as `dyn_cast<TypedefType>` and that fails because now you have an ElaboratedType which has a TypeDefType inside of it, which is what you wanted to match. Again, like 2), this would usually have been tested poorly with some simple tests with no qualifications, and would have been broken had there been any other kind of type sugar, be it an ElaboratedType or a TemplateSpecializationType or a SubstTemplateParmType. The usual fix here is to use `getAs` instead of `dyn_cast`, which will look deeper into the type. Or use `getAsAdjusted` when dealing with TypeLocs. For some reason the API is inconsistent there and on TypeLocs getAs behaves like a dyn_cast. 5) It could be a bug in this patch perhaps. Let me know if you need any help! Signed-off-by: Matheus Izvekov <mizvekov@gmail.com> Differential Revision: https://reviews.llvm.org/D112374
2022-07-14[clang-format] Fix invalid-code-generation by RemoveBracesLLVMowenca1-0/+11
When removing an r_brace that is the first token of an annotated line, if the line above ends with a line comment, clang-format generates invalid code by merging the tokens after the r_brace into the line comment. Fixes #56488. Differential Revision: https://reviews.llvm.org/D129742
2022-07-14[analyzer] Fixing SVal::getType returns Null Type for NonLoc::ConcreteInt in ↵Ella Ma1-0/+5
boolean type In method `TypeRetrievingVisitor::VisitConcreteInt`, `ASTContext::getIntTypeForBitwidth` is used to get the type for `ConcreteInt`s. However, the getter in ASTContext cannot handle the boolean type with the bit width of 1, which will make method `SVal::getType` return a Null `Type`. In this patch, a check for this case is added to fix this problem by returning the bool type directly when the bit width is 1. Differential Revision: https://reviews.llvm.org/D129737
2022-07-13[clang] Use value instead of getValue (NFC)Kazu Hirata3-56/+54
2022-07-13Revert "[clang] Implement ElaboratedType sugaring for types written bare"Jonas Devlieghere13-285/+183
This reverts commit bdc6974f92304f4ed542241b9b89ba58ba6b20aa because it breaks all the LLDB tests that import the std module. import-std-module/array.TestArrayFromStdModule.py import-std-module/deque-basic.TestDequeFromStdModule.py import-std-module/deque-dbg-info-content.TestDbgInfoContentDequeFromStdModule.py import-std-module/forward_list.TestForwardListFromStdModule.py import-std-module/forward_list-dbg-info-content.TestDbgInfoContentForwardListFromStdModule.py import-std-module/list.TestListFromStdModule.py import-std-module/list-dbg-info-content.TestDbgInfoContentListFromStdModule.py import-std-module/queue.TestQueueFromStdModule.py import-std-module/stack.TestStackFromStdModule.py import-std-module/vector.TestVectorFromStdModule.py import-std-module/vector-bool.TestVectorBoolFromStdModule.py import-std-module/vector-dbg-info-content.TestDbgInfoContentVectorFromStdModule.py import-std-module/vector-of-vectors.TestVectorOfVectorsFromStdModule.py https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/45301/
2022-07-13[clang][dataflow] Generate readable form of input and output of ↵Wei Yi Tee1-0/+239
satisfiability checking. Differential Revision: https://reviews.llvm.org/D129548
2022-07-13[clang][dataflow] Generate readable form of boolean values.Wei Yi Tee2-0/+191
Differential Revision: https://reviews.llvm.org/D129547
2022-07-13[clang][dataflow] Refactor boolean creation as a test utility.Wei Yi Tee1-0/+1
Differential Revision: https://reviews.llvm.org/D129546