Commit Graph

5406 Commits

Author SHA1 Message Date
Argyrios Kyrtzidis b340c5ae42 [Lex/DependencyDirectivesScanner] Handle the case where the source line starts with a `tok::hashhash`
Differential Revision: https://reviews.llvm.org/D133674
2022-09-13 15:48:50 -07:00
Chuanqi Xu 79fa0ec8c4 [C++20] [Modules] Make member functions with a in-class definition in HU implicitly inline
According to [dcl.inline]p7/note4,

> In the global module, a function defined within a class definition is
> implicitly inline.

And the declarations in the header unit are attached to the global
module fragment. So the function defined within a class definition in
header units should be implicitly inline too.

This fixes https://github.com/llvm/llvm-project/issues/57571.
2022-09-13 13:11:56 +08:00
Jonas Hahnfeld f0403c853b Fix build of Lex unit test with CLANG_DYLIB
If CLANG_LINK_CLANG_DYLIB, clang_target_link_libraries ignores all
indivial libraries and only links clang-cpp. As LLVMTestingSupport
is separate, pass it via target_link_libraries directly.
2022-09-12 13:49:57 +02:00
owenca 5889ed83a0 [clang-format] Don't insert braces for loops with a null statement
This is a workaround for #57539.

Fixes #57509.

Differential Revision: https://reviews.llvm.org/D133635
2022-09-12 00:37:47 -07:00
Serge Pavlov 7b9fae05b4 [Clang] Use virtual FS in processing config files
Clang has support of virtual file system for the purpose of testing, but
treatment of config files did not use it. This change enables VFS in it
as well.

Differential Revision: https://reviews.llvm.org/D132867
2022-09-09 18:24:45 +07:00
Serge Pavlov 55e1441f7b Revert "[Clang] Use virtual FS in processing config files"
This reverts commit 9424497e43.
Some buildbots failed, reverted for investigation.
2022-09-09 16:43:15 +07:00
Serge Pavlov 9424497e43 [Clang] Use virtual FS in processing config files
Clang has support of virtual file system for the purpose of testing, but
treatment of config files did not use it. This change enables VFS in it
as well.

Differential Revision: https://reviews.llvm.org/D132867
2022-09-09 16:28:51 +07:00
Joe Loser 1b3a78d1d5 [clang] Use std::size instead of llvm::array_lengthof
LLVM contains a helpful function for getting the size of a C-style
array: `llvm::array_lengthof`. This is useful prior to C++17, but not as
helpful for C++17 or later: `std::size` already has support for C-style
arrays.

Change call sites to use `std::size` instead. Leave the few call sites that
use a locally defined `array_lengthof` that are meant to test previous bugs
with NTTPs in clang analyzer and SemaTemplate.

Differential Revision: https://reviews.llvm.org/D133520
2022-09-08 17:20:25 -06:00
Timm Bäder 5777c05d16 [clang] Perform implicit lvalue-to-rvalue cast with new interpreter
The EvaluateAsRValue() documentation mentions that an implicit
lvalue-to-rvalue cast is being performed if the result is an lvalue.
However, that was not being done if the new constant interpreter was in
use.

Just always do it.

Differential Revision: https://reviews.llvm.org/D132136
2022-09-08 07:31:07 +02:00
Argyrios Kyrtzidis aa484c90cf [Lex/DependencyDirectivesScanner] Keep track of the presence of tokens between the last scanned directive and EOF
Directive `dependency_directives_scan::tokens_present_before_eof` is introduced to indicate there were tokens present before
the last scanned dependency directive and EOF.
This is useful to ensure we correctly identify the macro guards when lexing using the dependency directives.

Differential Revision: https://reviews.llvm.org/D133357
2022-09-07 10:31:29 -07:00
Emilia Dreamer 247613548b [clang-format] Change heuristic for locating lambda template arguments
Previously, the heuristic was simply to look for template argument-
specific keywords, such as typename, class, template and auto
that are preceded by a left angle bracket <.

This changes the heuristic to instead look for a left angle bracket <
preceded by a right square bracket ], since according to the C++
grammar, the template arguments must *directly* follow the introducer.
(This sort of check might just end up being *too* aggressive)

This patch also adds a bunch more token annotator tests for lambdas,
specifically for some of the stranger forms of lambdas now allowed as
of C++20 or soon-to-be-allowed as part of C++23.

Fixes https://github.com/llvm/llvm-project/issues/57093

This does NOT resolve the FIXME regarding explicit template lists, but
perhaps it gets closer

Differential Revision: https://reviews.llvm.org/D132295
2022-09-06 12:24:19 +02:00
Emilia Dreamer bd3dd10a8b [clang-format] Concepts: allow identifiers after negation
Previously, the formatter would refuse to treat identifiers within a
compound concept definition as actually part of the definition, if
they were after the negation operator !. It is now made consistent
with the likes of && and ||.

Fixes https://github.com/llvm/llvm-project/issues/55898

Differential Revision: https://reviews.llvm.org/D131978
2022-09-05 12:35:40 +02:00
Emilia Dreamer c6e7752f8e [clang-format] Allow `throw` to be a keyword in front of casts
This makes throw more similar to return. However, unlike return,
it has to more strict as to not remove spaces after usages of throw as
a (deprecated) exception specifier.

Fixes https://github.com/llvm/llvm-project/issues/57391

Differential Revision: https://reviews.llvm.org/D132762
2022-09-05 12:35:39 +02:00
Emilia Dreamer f54d42abcf [clang-format] Don't put `noexcept` on empty line following constructor
With the AlwaysBreakTemplateDeclarations option, having a constructor
template for a type consisting of all-uppercase letters with a
noexcept specifier would put said noexcept specifier on its own blank
line.

This is because the all-uppercase type is understood as a macro-like
attribute (such as DEPRECATED()), and noexcept is seen as the
declaration. However, noexcept is a keyword and cannot be an
identifier on its own.

Fixes https://github.com/llvm/llvm-project/issues/56216

Differential Revision: https://reviews.llvm.org/D132189
2022-09-05 12:35:39 +02:00
Nathan Ridge c933453858 Fix build error in StmtPrinterTest.cpp 2022-09-05 03:48:46 -04:00
Nathan Ridge 898c421975 [clangd] Avoid crash when printing call to string literal operator template
Differential Revision: https://reviews.llvm.org/D132830
2022-09-05 03:42:08 -04:00
Fangrui Song 83ea47acd7 [test] Make tests pass regardless of gnu++14/gnu++17 default
GCC from 11 onwards defaults to -std=gnu++17 for C++ source files. We want to do the same
(https://discourse.llvm.org/t/c-objc-switch-to-gnu-17-as-the-default-dialect/64360).
Split RUN lines, adjust `-verify`, or add `__cplusplus < 201703L` or `-Wno-dynamic-exception-spec`,
so that tests will pass regardless of gnu++14/gnu++17 default.

We have a desire to mark a test compatible with multiple language standards.
There are ongoing discussions how to add markers in the long term:

* https://discourse.llvm.org/t/iterating-lit-run-lines/62596
* https://discourse.llvm.org/t/lit-run-a-run-line-multiple-times-with-different-replacements/64932

As a workaround in the short term, add lit substitutions `%std_cxx98-`,
`%std_cxx11-14`, etc. They can be used for tests which work across multiple
language standards. If a range has `n` standards, run lit multiple times, with
`LIT_CLANG_STD_GROUP=0`, `LIT_CLANG_STD_GROUP=1`, etc to cover all `n` standards.

Reviewed By: #clang-language-wg, aaron.ballman

Differential Revision: https://reviews.llvm.org/D131464
2022-09-04 05:29:32 +00:00
owenca 92d8738c38 [clang-format] Fix a bug in merging blocks with a wrapped l_brace
When the opening brace of a control statement block is wrapped, we
must check the previous line to determine whether to try to merge
the block.

Fixes #38639.
Fixes #48007.
Fixes #57421.

Differential Revision: https://reviews.llvm.org/D133093
2022-09-02 21:38:36 -07:00
jackh 3bbdf06b28 [clang-format] Fix annotating when deleting array of pointers
Fixes https://github.com/llvm/llvm-project/issues/57418

The token `*` below should be annotated as `UnaryOperator`.

```
delete[] *ptr;
```

Reviewed By: owenpan, MyDeveloperDay

Differential Revision: https://reviews.llvm.org/D132911
2022-09-03 05:56:49 +08:00
Chris Bieneman 5b5329bd41 [NFC] Make MultiplexExternalSemaSource own sources
This change refactors the MuiltiplexExternalSemaSource to take ownership
of the underlying sources. As a result it makes a larger cleanup of
external source ownership in Sema and the ChainedIncludesSource.

Reviewed By: aaron.ballman, aprantl

Differential Revision: https://reviews.llvm.org/D133158
2022-09-02 13:57:39 -05:00
Luca Di Sera e7d9917a60 Expose QualType::getNonReferenceType in libclang
The method is now wrapped by clang_getNonReferenceType.

A declaration for clang_getNonReferenceType was added to clang-c/Index.h
to expose it to user of the library.

An implementation for clang_getNonReferenceType was introduced in
CXType.cpp, wrapping the equivalent method of the underlying QualType of
a CXType.

An export symbol for the new function was added to libclang.map under
the LLVM_16 version entry.

A test was added to LibclangTest.cpp that tests the removal of
ref-qualifiers for some CXTypes.

The release-notes for the clang project was updated to include a
notification of the new addition under the "libclang" section.

Differential Revision: https://reviews.llvm.org/D133195
2022-09-02 09:54:10 -04:00
Wei Yi Tee 14757d5b84 [clang][dataflow] Refactor `TypeErasedDataflowAnalysisTest` - replace usage of the deprecated overload of `checkDataflow`.
Reviewed By: gribozavr2, sgatev

Differential Revision: https://reviews.llvm.org/D132756
2022-09-01 19:17:37 +00:00
Wei Yi Tee 8dd14c427a [clang][dataflow] Use `StringMap` for storing analysis states at annotated points instead of `vector<pair<string, StateT>>`.
Reviewed By: gribozavr2, sgatev, ymandel

Differential Revision: https://reviews.llvm.org/D132763
2022-09-01 14:09:43 +00:00
Wei Yi Tee 5a4aece76d [clang][dataflow] Add `SetupTest` parameter for `AnalysisInputs`.
Moves the work required for retrieving annotation states into the `SetupTest` and `PostVisitCFG` callback to avoid having to run a separate pass over the CFG after analysis has completed.

Reviewed By: gribozavr2, sgatev, ymandel

Differential Revision: https://reviews.llvm.org/D132377
2022-09-01 13:48:29 +00:00
Wei Yi Tee db898d43b0 [clang][dataflow] Refactor `TestingSupport.h`
- Add `AnalysisInputs` struct as the parameters for `checkDataflow`, and renamed `AnalysisData` struct to `AnalysisOutputs` which contains the data structures generated from a dataflow analysis run.

- Remove compulsory binding from statement to annotations. Instead, `checkDataflow` in the most general form takes a `VerifyResults` callback which takes as input an `AnalysisOutputs` struct. This struct contains the data structures generated by the analysis that can then be tested. We then introduce two overloads/wrappers of `checkDataflow` for different mechanisms of testing - one which exposes annotation line numbers and is not restricted to statements, and the other which exposes states computed after annotated statements. In the future, we should look at retrieving the analysis states for constructs other than statements.

Reviewed By: gribozavr2, sgatev

Differential Revision: https://reviews.llvm.org/D132147
2022-09-01 13:21:34 +00:00
Wei Yi Tee d931ac9e27 [clang][dataflow] Generalise match switch utility to other AST types and add a `CFGMatchSwitch` which currently handles `CFGStmt` and `CFGInitializer`.
`MatchSwitch` currently takes in matchers and functions for the `Stmt` class.

This patch generalises the match switch utility (renamed to `ASTMatchSwitch`) to work for different AST node types by introducing a template argument which is the base type for the AST nodes that the match switch will handle.

A `CFGMatchSwitch` is introduced as a wrapper around multiple `ASTMatchSwitch`s for different base types. It works by unwrapping `CFGElement`s into their contained AST nodes and passing the nodes to the relevant `ASTMatchSwitch`. The `CFGMatchSwitch` currently only handles `CFGStmt` and `CFGInitializer`.

Reviewed By: gribozavr2, sgatev

Differential Revision: https://reviews.llvm.org/D131616
2022-09-01 10:15:53 +00:00
Wei Yi Tee 74c8d9d5fc Revert "[clang][dataflow] Generalise match switch utility to other AST types and add a `CFGMatchSwitch` which currently handles `CFGStmt` and `CFGInitializer`."
This reverts commit c9033eeb2e.
https://lab.llvm.org/buildbot#builders/57/builds/21618
Build failure due to comparison between unsigned int and const int
originating from EXPECT_EQ.
2022-08-31 18:49:56 +00:00
Wei Yi Tee c9033eeb2e [clang][dataflow] Generalise match switch utility to other AST types and add a `CFGMatchSwitch` which currently handles `CFGStmt` and `CFGInitializer`.
`MatchSwitch` currently takes in matchers and functions for the `Stmt` class.

This patch generalises the match switch utility (renamed to `ASTMatchSwitch`) to work for different AST node types by introducing a template argument which is the base type for the AST nodes that the match switch will handle.

A `CFGMatchSwitch` is introduced as a wrapper around multiple `ASTMatchSwitch`s for different base types. It works by unwrapping `CFGElement`s into their contained AST nodes and passing the nodes to the relevant `ASTMatchSwitch`. The `CFGMatchSwitch` currently only handles `CFGStmt` and `CFGInitializer`.

Reviewed By: gribozavr2, sgatev

Differential Revision: https://reviews.llvm.org/D131616
2022-08-31 17:02:07 +00:00
Wei Yi Tee 9e842dd4bd [clang][dataflow] Extend transfer functions for other `CFGElement`s
Previously, the transfer function `void transfer(const Stmt *, ...)` overriden by users is restricted to apply only on `CFGStmt`s and its contained `Stmt`.

By using a transfer function (`void transfer(const CFGElement *, ...)`) that takes a `CFGElement` as input, this patch extends user-defined analysis to all kinds of `CFGElement`. For example, users can now handle `CFGInitializer`s where `CXXCtorInitializer` AST nodes are contained.

Reviewed By: gribozavr2, sgatev

Differential Revision: https://reviews.llvm.org/D131614
2022-08-31 10:23:53 +00:00
owenca bc10ab8da1 [clang-format] Fix a bug in inserting braces at trailing comments
If the style wraps control statement braces, the opening braces
should be inserted after the trailing comments if present.

Fixes #57419.

Differential Revision: https://reviews.llvm.org/D132905
2022-08-30 22:50:36 -07:00
Luca Di Sera 123062ec2f Expose QualType::getUnqualifiedType in libclang
The method is now wrapped by clang_getUnqualifiedType.

A declaration for clang_getUnqualifiedType was added to
clang-c/Index.h to expose it to user of the library.

An implementation for clang_getUnqualifiedType was introduced in
CXType.cpp that wraps the equivalent method of the underlying
QualType of a CXType.

An export symbol was added to libclang.map under the new version entry
LLVM_16.

A test was added to LibclangTest.cpp that tests the removal of
qualifiers for some CXTypes.

Differential Revision: https://reviews.llvm.org/D132749
2022-08-29 08:16:18 -04:00
owenca f00f2b3e8d [clang-format] Fix a bug in removing braces for the LLVM style
When an l_brace is wrapped and the line above it ends with a
comment, the annotator adds ColumnLimit to the TotalLength of the
l_brace, so the actual column position of the l_brace must be
adjusted accordingly.

Fixes #57376.

Differential Revision: https://reviews.llvm.org/D132805
2022-08-28 14:22:31 -07:00
owenca 44a06b51b2 [clang-format] Rework removeBraces() in Format.cpp
Fixes #57373.

Differential Revision: https://reviews.llvm.org/D132719
2022-08-27 14:10:24 -07:00
Wei Yi Tee fb9c1b8938 Revert "[clang][dataflow] Extend transfer functions for other `CFGElement`s"
This reverts commit 4b815eb4fd.
2022-08-26 22:41:20 +00:00
Wei Yi Tee 4b815eb4fd [clang][dataflow] Extend transfer functions for other `CFGElement`s
Differential Revision: https://reviews.llvm.org/D131614
2022-08-26 22:21:29 +00:00
Matheus Izvekov 4a56470d0d
Revert "Clang: fix AST representation of expanded template arguments."
This reverts commit 1d1a56929b.
2022-08-26 13:09:55 +02:00
Ben Langmuir bdc20d61b8 [clang][tooling] Allow -cc1 arguments in ToolInvocation
ToolInvocation is useful even if you already have a -cc1 invocation,
since it provides a standard way to setup diagnostics, parse arguments,
and handoff to a ToolAction. So teach it to support -cc1 commands by
skipping the driver bits.

Differential Revision: https://reviews.llvm.org/D132615
2022-08-24 19:51:12 -07:00
Balázs Kéri 23fbfb3f72 [clang][AST] RecursiveASTVisitor should visit owned TagDecl of friend type.
A FriendDecl node can have a friend record type that owns a RecordDecl
object. This object is different than the one got from TypeSourceInfo
object of the FriendDecl. When building a ParentMapContext this owned
tag decaration has to be encountered to have the parent set for it.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D131685
2022-08-23 09:15:55 +02:00
owenca 47e70569fc [clang-format] Remove an extraneous test in TokenAnnotatorTest.cpp
This removes an obsolete test case introduced by mistake from
commit 2e36120726.
2022-08-22 21:18:37 -07:00
owenca 2e36120726 [clang-format] Fix regressions in WhitespaceSensitiveMacros
Fixes #54522.
Fixes #57158.

Differential Revision: https://reviews.llvm.org/D132001
2022-08-22 20:42:54 -07:00
owenca d90c1bcdf9 Revert "[clang-format][NFC] Fix a bug in setting type FunctionLBrace"
This reverts commit 35f7dd601d.

Fixes #57200.
2022-08-21 23:26:51 -07:00
owenca 41214456de [clang-format] Fix BeforeHash indent of comments above PPDirective
Fixes #56326.

Differential Revision: https://reviews.llvm.org/D132097
2022-08-21 18:23:14 -07:00
Kazu Hirata fc4d3a1109 [clang] Use Any::has_value instead of Any::hasValue (NFC) 2022-08-20 08:40:18 -07:00
Vaibhav Yenamandra 1bd2b2dce2 Add support for specifying the severity of a SARIF Result
* Extend SarifResult with level property, and allow rule configuration
* Create SarifReportingConfiguration which allow configuring rules with
a default priority, severity and an enable-toggle
* Support for setting the level property[1] of a result.

If unset, it defaults to "warning", which is the result of an empty
default configuration on rules[2]

[1]: https://docs.oasis-open.org/sarif/sarif/v2.1.0/os/sarif-v2.1.0-os.html#_Toc34317648
[2]: https://docs.oasis-open.org/sarif/sarif/v2.1.0/os/sarif-v2.1.0-os.html#_Toc34317855

Differential Revision: https://reviews.llvm.org/D131084
2022-08-19 07:14:50 -04:00
Chris Bieneman 0ac597f3ca [NFC] Move DXC driver tests
The DXC driver tests don't really belong mixed in with the toolchain
tests. This pulls them out to their own file and moves the
SimpleDiagnosticConsumer into a header so it can be used by both DXC and
toolchain tests.

fast-forwarded.
2022-08-18 16:06:41 -05:00
Xiang Li 140b0bf899 [HLSL] Set main as default entry.
When there's no -E option, use main as entry function.

Reviewed By: beanz

Differential Revision: https://reviews.llvm.org/D124753
2022-08-18 11:57:36 -07:00
owenca 777b6ad168 [clang-format] Handle return type auto followed by l_paren
Fixes #57160.

Differential Revision: https://reviews.llvm.org/D132008
2022-08-17 16:06:34 -07:00
owenca 2185f64771 [clang-format] Handle comments between access specifier and colon
Fixes #56740.

Differential Revision: https://reviews.llvm.org/D131940
2022-08-16 20:18:21 -07:00
Clement Courbet 672311bd77 [CFG] Fix crash on CFG building when deriving from a template.
Differential Revision: https://reviews.llvm.org/D121365
2022-08-16 13:01:13 +02:00
Chuanqi Xu efa8783290 [NFC] Add unittest for inline functions in modules 2022-08-16 13:35:38 +08:00