Commit Graph

95899 Commits

Author SHA1 Message Date
David Truby 13a784f368 [clang][AArch64][SVE] Change SVE_VECTOR_OPERATORS macro for VLA vectors
The __ARM_FEATURE_SVE_VECTOR_OPERATORS macro should be changed to
indicate that this feature is now supported on VLA vectors as well as
VLS vectors. There is a complementary PR to the ACLE spec here
https://github.com/ARM-software/acle/pull/213

Reviewed By: peterwaller-arm

Differential Revision: https://reviews.llvm.org/D131573
2022-08-11 13:23:52 +00:00
David Truby bbb30bd54a [clang][AArch64][SVE] Clarify documentation for sizeof operator on SVE
Previously the table in LanguageExtensions said that sizeof worked on
SVE types but this is only correct for fixed-length vectors so a
clarification has been added.
2022-08-11 13:22:23 +00:00
Sam Estep d09d4bd66c [clang][dataflow] Don't crash when caller args are missing storage locations
This patch modifies `Environment`'s `pushCall` method to pass over arguments that are missing storage locations, instead of crashing.

Reviewed By: gribozavr2

Differential Revision: https://reviews.llvm.org/D131600
2022-08-11 13:00:42 +00:00
Sam Estep eb91fd5cbc [clang][dataflow] Analyze constructor bodies
This patch adds the ability to context-sensitively analyze constructor bodies, by changing `pushCall` to allow both `CallExpr` and `CXXConstructExpr`, and extracting the main context-sensitive logic out of `VisitCallExpr` into a new `transferInlineCall` method which is now also called at the end of `VisitCXXConstructExpr`.

Reviewed By: ymandel, sgatev, xazax.hun

Differential Revision: https://reviews.llvm.org/D131438
2022-08-11 12:46:20 +00:00
Aaron Ballman 7309e8cfbe Do not use the same identifier for a data member as a type; NFC
This should help address a build failure found after
09117b2189

../tools/clang/lib/Sema/SemaDeclCXX.cpp: In member function ‘void clang::Sema::DiagnoseStaticAssertDetails(const clang::Expr*)’:
../tools/clang/lib/Sema/SemaDeclCXX.cpp:16666:19: error: declaration of ‘const clang::Expr* clang::Sema::DiagnoseStaticAssertDetails(const clang::Expr*)::<unnamed struct>::Expr’ changes meaning of ‘Expr’ [-fpermissive]
16666 |       const Expr *Expr;
      |                   ^~~~
In file included from ../tools/clang/include/clang/AST/DeclCXX.h:22,
                 from ../tools/clang/include/clang/AST/ASTLambda.h:18,
                 from ../tools/clang/lib/Sema/SemaDeclCXX.cpp:15:
../tools/clang/include/clang/AST/Expr.h:109:7: note: ‘Expr’ declared here as ‘class clang::Expr’
  109 | class Expr : public ValueStmt {
      |       ^~~~
2022-08-11 07:32:32 -04:00
Florian Hahn ef110a491f
[Builtins] Do not claim most libfuncs are readnone with trapping math.
At the moment, Clang only considers errno when deciding if a builtin
is const. This ignores the fact that some library functions may raise
floating point exceptions, which may modify global state, e.g. when
updating FP status registers.

To model the fact that some library functions/builtins may raise
floating point exceptions, this patch adds a new 'g' modifier for
builtins. If a builtin is marked with 'g', it cannot be considered
const, unless FP exceptions are ignored.

So far I've not added CHECK lines for all calls in math-libcalls.c. I'll
do that once we agree on the overall direction.

A consequence seems to be that we fail to select some of the constrained
math builtins now, but I am not entirely sure what's going on there.

Reviewed By: john.brawn

Differential Revision: https://reviews.llvm.org/D129231
2022-08-11 12:29:01 +01:00
Wei Yi Tee 2cb51449f0 [clang][dataflow] Store DeclContext of block being analysed in Environment if available.
Differential Revision: https://reviews.llvm.org/D131065
2022-08-11 07:36:57 +00:00
Martin Storsjö 5d89f90443 [clang] [HLSL] Fix GCC warnings about virtual methods that are hidden
This fixes the following warnings produced by GCC 9:

In file included from ../tools/clang/include/clang/Sema/ExternalSemaSource.h:15,
                 from ../tools/clang/include/clang/Sema/HLSLExternalSemaSource.h:17,
                 from ../tools/clang/lib/Sema/HLSLExternalSemaSource.cpp:12:
../tools/clang/include/clang/AST/ExternalASTSource.h:211:16: warning: ‘virtual void clang::ExternalASTSource::CompleteType(clang::ObjCInterfaceDecl*)’ was hidden [-Woverloaded-virtual]
  211 |   virtual void CompleteType(ObjCInterfaceDecl *Class);
      |                ^~~~~~~~~~~~
In file included from ../tools/clang/lib/Sema/HLSLExternalSemaSource.cpp:12:
../tools/clang/include/clang/Sema/HLSLExternalSemaSource.h:49:8: warning:   by  virtual void clang::HLSLExternalSemaSource::CompleteType(clang::TagDecl*)’ [-Woverloaded-virtual]
   49 |   void CompleteType(TagDecl *Tag) override;
      |        ^~~~~~~~~~~~

Differential Revision: https://reviews.llvm.org/D130969
2022-08-11 10:15:13 +03:00
Timm Bäder ebe0674acb [clang] Try to fix builders
Try to fix these errors:

SemaDeclCXX.cpp:16666:19: error: declaration of ‘const clang::Expr* clang::Sema::DiagnoseStaticAssertDetails(const clang::Expr*)::<unnamed struct>::Expr’ changes meaning of ‘Expr’ [-fpermissive]
16666 |       const Expr *Expr;
      |                   ^~~~
2022-08-11 09:07:44 +02:00
Timm Bäder 09117b2189 [clang][sema] Print more information about failed static assertions
For failed static assertions, try to take the expression apart and print
useful information about why it failed. In particular, look at binary
operators and print the compile-time evaluated value of the LHS/RHS.

Differential Revision: https://reviews.llvm.org/D130894
2022-08-11 08:44:38 +02:00
Corentin Jabot bcc90f6268 [Clang] Update cxx_dr_status [NFC]
Update the DR status page with the C++ Standard Core
Issues List revision 109.
2022-08-11 08:24:31 +02:00
Clement Courbet 156c0754bc [clang][transformer] Finish plumbing `Note` all the way to the output.
Right now we can only add a single warning, notes are not possible.

Apparently some provisions were made to allow notes, but they were never
propagated all the way to the diagnostics.

Differential Revision: https://reviews.llvm.org/D128807
2022-08-11 07:54:44 +02:00
Gergely Meszaros 3f801e07fa [clang-format] git-clang-format --staged should format the index
When --staged (or --cached) use the index for formatting as well, not just
for the line numbers to format. Without this change git-clang-format gets
the changed line numbers based on the index, but then formats these lines on
the working tree version of the file.

This is a problem when the working tree and index differ. One common case
would be (and is the motivation behind this patch) when applying the
suggested changes git-clang-format --staged, then forgetting to add the
applied changes. When git-clang-format --staged --diff is used in a
pre-commit hook in this scenario, then the hook would allow committing the
improperly formatted changes, as the file is correctly formatted in the work
tree.

Fixes #56797.

Differential Revision: https://reviews.llvm.org/D130108
2022-08-10 19:30:41 -07:00
Jan Svoboda d5fcf8a5e2 [clang][deps] NFC: Move dependency consumer into header file 2022-08-10 15:25:09 -07:00
Evgenii Stepanov 8d3c960295 Revert "[clang][dataflow] Store DeclContext of block being analysed in Environment if available."
Use of uninitialized memory.
https://lab.llvm.org/buildbot/#/builders/74/builds/12713

This reverts commit 8a4c40bfe8.
2022-08-10 14:22:04 -07:00
Evgenii Stepanov 7587065043 Revert "[clang][dataflow] Analyze constructor bodies"
https://lab.llvm.org/buildbot/#/builders/74/builds/12713

This reverts commit 000c8fef86.
2022-08-10 14:21:56 -07:00
Evgenii Stepanov 26089d4da4 Revert "[clang][dataflow] Don't crash when caller args are missing storage locations"
https://lab.llvm.org/buildbot/#/builders/74/builds/12713

This reverts commit 43b298ea12.
2022-08-10 14:21:46 -07:00
Martin Storsjö c843c921a1 [clang] Require strict matches for defines for PCH in GCC style directories
When clang includes a PCH, it tolerates some amount of differences
between the defines used when creating and when including the PCH
- this seems to be intentionally allowed in
c379c07240 (and later extended in
b636875196).

When using a PCH (or when picking a PCH out of a directory containing
multiple candidates) Clang used to accept the header if there were
defines on the command line when creating the PCH that are missing
when using the PCH, or vice versa, defines only set when using the
PCH.

The only cases where Clang explicitly rejected the use of a PCH
is if there was an explicit conflict between the options, e.g.
-DFOO=1 vs -DFOO=2, or -DFOO vs -UFOO.

The latter commit added a FIXME that we really should check whether
mismatched defines actually were used somewhere in the PCH, so that
the define would affect the outcome. This FIXME has stood unaddressed
since 2012.

This differs from GCC, which rejects PCH files if the defines differ
at all.

When explicitly including a single PCH file, the relaxed policy
of allowing minor differences is harmless for correct use cases
(but may fail to diagnose mismtaches), and potentially allow using
PCHs in wider cases (where the user intentionally know that the
differences in defines are harmless for the PCH).

However, for GCC style PCH directories, with a directory containing
multiple PCH variants and the compiler should pick the correct match
out of them, Clang's relaxed logic was problematic. The directory
could contain two otherwise identical PCHs, but one built with -DFOO
and one without. When attempting to include a PCH and iterating over
the candidates in the directory, Clang would essentially pick the
first one out of the two, even if there existed a better, exact
match in the directory.

Keep the relaxed checking when specificlly including one named
PCH file, but require strict matches when trying to pick the right
candidate out of a GCC style directory with alternatives.

This fixes https://github.com/lhmouse/mcfgthread/issues/63.

Differential Revision: https://reviews.llvm.org/D126676
2022-08-10 22:47:27 +03:00
Jan Svoboda 71e32d5cf0 [clang][deps] Always generate module paths
Since D129389 (and downstream PR https://github.com/apple/llvm-project/pull/4965), the dependency scanner is responsible for generating full command-lines, including the modules paths. This patch removes the flag that was making this an opt-in behavior in clang-scan-deps.

Reviewed By: benlangmuir

Differential Revision: https://reviews.llvm.org/D131420
2022-08-10 11:58:28 -07:00
Shafik Yaghmour 4e458765aa [Clang] Restrict non fixed enum to a value outside the range of the enumeration values warning to context requiring a constant expression
In D131307 we allowed the diagnostic to be turned into a warning for a
transition period.

This had the side effect of triggering the warning in contexts not required to
be constant expression. This change will restrict the diagnostic to constant
expression contexts. This should reduce the fallout of this diagnostic.

Differential Revision: https://reviews.llvm.org/D131528
2022-08-10 11:12:01 -07:00
Aaron Ballman af01f717c4 Default implicit function pointer conversions diagnostic to be an error
Implicitly converting between incompatible function pointers in C is
currently a default-on warning (it is an error in C++). However, this
is very poor security posture. A mismatch in parameters or return
types, or a mismatch in calling conventions, etc can lead to
exploitable security vulnerabilities. Rather than allow this unsafe
practice with a warning, this patch strengthens the warning to be an
error (while still allowing users the ability to disable the error or
the warning entirely to ease migration). Users should either ensure the
signatures are correctly compatible or they should use an explicit cast
if they believe that's more reasonable.

Differential Revision: https://reviews.llvm.org/D131351
2022-08-10 13:54:17 -04:00
Yuanfang Chen ec08114133 [NFC][Clang] make AtomicConstraint::ParameterMapping const
It was not const due to the way it is initialized. This is needed for
a following patch.
2022-08-10 10:51:39 -07:00
Sam Estep 43b298ea12 [clang][dataflow] Don't crash when caller args are missing storage locations
This patch modifies `Environment`'s `pushCall` method to pass over arguments that are missing storage locations, instead of crashing.

Reviewed By: gribozavr2

Differential Revision: https://reviews.llvm.org/D131600
2022-08-10 17:50:34 +00:00
Ofek Shilon 73a1b162a4 Add docs for function attributes hot/cold
Following https://reviews.llvm.org/D92493, this add docs for the hot
and cold function attributes.

Differential Revision: https://reviews.llvm.org/D130933
2022-08-10 13:48:43 -04:00
Denys Petrov 7e2b995e0c [analyzer] [NFC] Add more test cases for equality tracking
Summary: Cover `ConstraintAssignor::assign(EquivalenceClass, RangeSet)` function with more regression tests.

Differential Revision: https://reviews.llvm.org/D131514
2022-08-10 19:52:55 +03:00
Manoj Gupta 06fc5a7714 Driver: Refactor and support per target dirs in baremetal
Refactor baremetal driver code to reduce the bespoke
additions and base class overrides.
This lets us use the per target runtimes like other clang
targets. E.g. clang -target armv7m-cros-none-eabi will now
be able to use the runtimes installed at
<resource_dir>/lib/armv7m-cros-none-eabi instead of the hardcoded
path <resource_dir>/lib/baremetal.
The older code paths should still continue to work as before if
<resource_dir>/lib/<tuple> does not exist.

Reviewed By: MaskRay, barannikov88

Differential Revision: https://reviews.llvm.org/D131225
2022-08-10 09:13:30 -07:00
Ivan Murashko e78c80e3d6 [clang] SourceManager: fix at SourceManager::getFileIDLoaded for the case of invalid SLockEntry
There is a fix for the search procedure at `SourceManager::getFileIDLoaded`. It might return an invalid (not loaded) entry. That might cause clang/clangd crashes. At my case the scenario was the following:
- `SourceManager::getFileIDLoaded` returned an invalid file id for a non loaded entry and incorrectly set `SourceManager::LastFileIDLookup` to the value
- `getSLocEntry` returned `SourceManager::FakeSLocEntryForRecovery` introduced at [D89748](https://reviews.llvm.org/D89748).
- The result entry is not tested at `SourceManager::isOffsetInFileID`and as result the call `return SLocOffset < getSLocEntryByID(FID.ID+1).getOffset();` returned `true` value because `FID.ID+1` pointed to a non-fake entry
- The tested offset was marked as one that belonged to the fake `SLockEntry`

Such behaviour might cause a weird clangd crash when preamble contains some header files that were removed just after the preamble created. Unfortunately it's not so easy to reproduce the crash in the form of a LIT test thus I provided the fix only.

Test Plan:
```
ninja check-clang
```

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D130847
2022-08-10 16:37:42 +01:00
David Truby e4642d78a8 [clang] Correct documentation for NEON and SVE operator support
Previously the language extension documentation didn't mention SVE and
was incomplete in listing the C/C++ operators supported on NEON. This
corrects the documentation to be in line with the implementation.
2022-08-10 15:16:38 +01:00
Sam Estep 000c8fef86 [clang][dataflow] Analyze constructor bodies
This patch adds the ability to context-sensitively analyze constructor bodies, by changing `pushCall` to allow both `CallExpr` and `CXXConstructExpr`, and extracting the main context-sensitive logic out of `VisitCallExpr` into a new `transferInlineCall` method which is now also called at the end of `VisitCXXConstructExpr`.

Reviewed By: ymandel, sgatev, xazax.hun

Differential Revision: https://reviews.llvm.org/D131438
2022-08-10 14:01:45 +00:00
Wei Yi Tee 8a4c40bfe8 [clang][dataflow] Store DeclContext of block being analysed in Environment if available.
Differential Revision: https://reviews.llvm.org/D131065
2022-08-10 11:27:03 +00:00
David Truby 286d59ef6f [clang][AArch64][SVE] Add unary +/- operators for SVE types
This patch enables the unary promotion and negation operators on
SVE types.

Differential Revision: https://reviews.llvm.org/D130984
2022-08-10 10:32:43 +00:00
Clement Courbet 5331e1229a [clang][transformer] Fix crash on replacement-less ASTEdit.
Given that we provide an EditGenerator edit(ASTEdit), we can't ever be
sure that the user won't give us an empty replacement.

Differential Revision: https://reviews.llvm.org/D128887
2022-08-10 09:08:05 +02:00
Freddy Ye e4888a37d3 [X86][BF16] Enable __bf16 for x86 targets.
X86 psABI has updated to support __bf16 type, the ABI of which is the
same as FP16. See https://discourse.llvm.org/t/patch-add-optional-bfloat16-support/63149

Reviewed By: pengfei

Differential Revision: https://reviews.llvm.org/D130964
2022-08-10 09:00:47 +08:00
YingChi Long 55d3b79d15
[clang] add APValue type check in `TryPrintAsStringLiteral`
Fixes https://github.com/llvm/llvm-project/issues/57013

https://reviews.llvm.org/D115031 improved printing of non-type template
parameter args. But checking if the end of Inits is 0 without checking
if APValue is an integer, causes clang to segfault. This patch adds
the code to check the type. (May not be a proper bugfix.)

Reviewed By: aaron.ballman, lichray

Differential Revision: https://reviews.llvm.org/D131466
2022-08-10 08:42:59 +08:00
malavikasamak c74a204826 [analyzer] Fix false positive in use-after-move checker
Differential Revision: https://reviews.llvm.org/D131525
2022-08-09 17:26:30 -07:00
Shawn Zhong 82afc9b169 Fix -Wbitfield-constant-conversion on 1-bit signed bitfield
A one-bit signed bit-field can only hold the values 0 and -1; this
corrects the diagnostic behavior accordingly.

Fixes #53253
Differential Revision: https://reviews.llvm.org/D131255
2022-08-09 11:43:50 -04:00
Thorsten Schütt e486e48c3d [clang] fix deprecation 2022-08-09 17:42:55 +02:00
Aaron Ballman 4c02ab8c97 Change prototype merging error into a warning for builtins
As was observed in https://reviews.llvm.org/D123627#3707635, it's
confusing that a user can write:
```
float rintf(void) {}
```
and get a warning, but writing:
```
float rintf() {}
```
gives an error. This patch changes the behavior so that both are
warnings, so that users who have functions which conflict with a
builtin identifier can still use that identifier as they wish.

Differential Revision: https://reviews.llvm.org/D131499
2022-08-09 11:36:48 -04:00
Ariel Burton f53f2f232f Extend ptr32 support to be applied on typedef
Earlier, if the QualType was sugared, then we would error out
as it was not a pointer type, for example,

typedef int *int_star;

int_star __ptr32 p;

Now, if ptr32 is given we apply it if the raw Canonical Type
(i.e., the desugared type) is a PointerType, instead of only
checking whether the sugared type is a pointer type.

As before, we still disallow ptr32 usage if the pointer is used
as a pointer to a member.

Differential Revision: https://reviews.llvm.org/D130123
2022-08-09 11:08:52 -04:00
Matheus Izvekov 1d1a56929b
Clang: fix AST representation of expanded template arguments.
Extend clang's SubstTemplateTypeParm to represent the pack substitution index.

Fixes PR56099.

Signed-off-by: Matheus Izvekov <mizvekov@gmail.com>

Differential Revision: https://reviews.llvm.org/D128113
2022-08-09 14:26:16 +02:00
Ilya Biryukov 07529996d9 [Sema] Merge variable template specializations
Clang used to produce redefinition errors, see tests for examples.

Reviewed By: ChuanqiXu

Differential Revision: https://reviews.llvm.org/D131258
2022-08-09 12:17:41 +02:00
Simon Pilgrim af0052ef74 Fix MSVC "not all control paths return a value" warning. NFC. 2022-08-09 09:55:57 +01:00
Balázs Kéri d4ff9eff76 [clang][ASTImporter] Improve import of functions with auto return type.
ASTImporter used to crash in some cases when a function is imported with
`auto` return type and the return type has references into the function.
The handling of such cases is improved and crash should not occur any more
but it is not fully verified, there are very many different types of
cases to care for.

Reviewed By: martong

Differential Revision: https://reviews.llvm.org/D130705
2022-08-09 09:20:06 +02:00
Fangrui Song 32197830ef [clang][clang-tools-extra] LLVM_NODISCARD => [[nodiscard]]. NFC 2022-08-09 07:11:18 +00:00
Kazu Hirata 8e207e4c09 [Basic] Deprecate MapEntryOptionalStorage::{hasValue,getValue}
MapEntryOptionalStorage is an underlying storage class for
OptionalStorage<clang::DirectoryEntryRef>.

This patch deprecates:

  OptionalStorage<clang::DirectoryEntryRef>::hasValue
  OptionalStorage<clang::DirectoryEntryRef>::getValue

as there is no known users of these two methods.

Differential Revision: https://reviews.llvm.org/D131368
2022-08-08 21:33:09 -07:00
Fangrui Song 8d9d27db47 [Driver] Add -Xclang= as an alias for -Xclang
Driver options taking a value typically use `=` as the separator, instead of a
space. Unfortunately many older driver options do not stick with the rule, but I
find -Xclang used a lot and will be convenient if -Xclang= exists.

For build systems using a string array instead of a string to indicate compiler options,
`["-Xclang=-foo"]` is more convenient than `["-Xclang", "-foo"]`.
If a tool wants to filter out -Xclang=-foo, it is trivial for the `=` form, but
complex for the space separated form.

Reviewed By: jhuber6

Differential Revision: https://reviews.llvm.org/D131455
2022-08-08 19:05:24 -07:00
Shafik Yaghmour cc104113dd [Clang] Allow downgrading to a warning the diagnostic for setting a non fixed enum to a value outside the range of the enumeration values
In D130058 we diagnose the undefined behavior of setting the value outside the
range of the enumerations values for an enum without a fixed underlying type.

Based on feedback we will provide users to the ability to downgrade this
diagnostic to a waring to allow for a transition period. We expect to turn this
diagnostic to an error in the next release.

Differential Revision: https://reviews.llvm.org/D131307
2022-08-08 16:23:07 -07:00
Ben Langmuir 33af4b22f8 [clang][deps] Stop sharing FileManager across module builds in scanner
Sharing the FileManager across implicit module builds currently leaks
paths looked up in an importer into the built module itself. This can
cause non-deterministic results across scans. It is especially bad for
modules since the path can be saved into the pcm file itself, leading to
stateful behaviour if the cache is shared.

This should not impact the number of real filesystem accesses in the
scanner, since it is already caching in the
DependencyScanningWorkerFilesystem.

Note: this change does not affect whether or not the FileManager is
shared across TUs in the scanner, which is a separate issue.

Differential Revision: https://reviews.llvm.org/D131412
2022-08-08 12:13:54 -07:00
Joseph Huber b71b22e48d [LinkerWrapper] Use C++17 structured bindings
Summary:
This patch updates the linker wrapper to use C++17 structured bindings
now that they are availible.
2022-08-08 15:07:03 -04:00
Fangrui Song cdeb50c321 [lldb] Remove include/lldb/lldb-private.h
The header from 62e0681afb does something with
LLVM_FALLTHROUGH. Now that llvm-project has switched to C++17 and
LLVM_FALLTHROUGH uses have been migrated to [[fallthrough]], the header is
unneeded.

Reviewed By: JDevlieghere

Differential Revision: https://reviews.llvm.org/D131422
2022-08-08 12:03:53 -07:00
Fangrui Song 3f18f7c007 [clang] LLVM_FALLTHROUGH => [[fallthrough]]. NFC
With C++17 there is no Clang pedantic warning or MSVC C5051.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D131346
2022-08-08 09:12:46 -07:00
Aaron Ballman e640250454 Update the C status page from the latest working draft
WG14 N3047 is the last C working draft before the document goes out
for committee ballot, so this should be the last of the C2x compiler
features to be added.
2022-08-08 11:30:49 -04:00
Chris Bieneman fc470013d1 [Docs] Add HLSL ResourceType documentation
Along with the new documentation this also re-organizes the HLSL docs
to a subdirectory. The hope is to continue to expand this documentation
as the HLSL implementation advances.

Differential Revision: https://reviews.llvm.org/D130794
2022-08-08 09:06:38 -05:00
Benjamin Kramer 99a5a029e6 [ASTMatchers] Replace hand-coded copy of std::apply with the real C++17 function. NFCI 2022-08-08 14:08:04 +02:00
Nathan James 7042417ef1
[NFC][clang] Bring `and_present` and `if_present` casting functions to clang namespace
This should enable simpler migration when the `and_nonnull` and `or_null` functions are deprecated.
2022-08-08 08:38:50 +01:00
Ashay Rane d1bb3016dd
[mlir] fix `add_tablegen()` macro to allow installing mlir-pdll
Prior to this patch, the `add_tablegen()` macro in
llvm/cmake/modules/TableGen.cmake added the install rule only if
`project` matched `LLVM` or `MLIR`.  This patch adds an optional
`DESTINATION` argument, which, if non-empty, decides whether (and where)
to install the tablegen tool, thus eliminating the need for
project-specific overrides.  This patch also updates all other
invocations of the `add_tablegen()` macro.

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D131282
2022-08-07 15:48:38 -07:00
Sergei Barannikov 87dc7d4b61
[clang][CodeGen] Factor out Swift ABI hooks (NFCI)
Swift calling conventions stands out in the way that they are lowered in
mostly target-independent manner, with very few customization points.
As such, swift-related methods of ABIInfo do not reference the rest of
ABIInfo and vice versa.
This change follows interface segregation principle; it removes
dependency of SwiftABIInfo on ABIInfo. Targets must now implement
SwiftABIInfo separately if they support Swift calling conventions.

Almost all targets implemented `shouldPassIndirectly` the same way. This
de-facto default implementation has been moved into the base class.

`isSwiftErrorInRegister` used to be virtual, now it is not. It didn't
accept any arguments which could have an effect on the returned value.
This is now a static property of the target ABI.

Reviewed By: rusyaev-roman, inclyc

Differential Revision: https://reviews.llvm.org/D130394
2022-08-08 00:23:23 +08:00
Kazu Hirata 7542e72188 Use llvm::is_contained (NFC) 2022-08-07 00:16:17 -07:00
YingChi Long 1f54006bca
[clang][docs] use `Fixes` instead of `This fixes` in ReleaseNotes [NFC] 2022-08-07 12:42:15 +08:00
Shilei Tian e21202dac1 [Clang][OpenMP] Fix the issue that `llvm.lifetime.end` is emitted too early for variables captured in linear clause
Currently if an OpenMP program uses `linear` clause, and is compiled with
optimization, `llvm.lifetime.end` for variables listed in `linear` clause are
emitted too early such that there could still be uses after that. Let's take the
following code as example:
```
// loop.c
int j;
int *u;

void loop(int n) {
  int i;
  for (i = 0; i < n; ++i) {
    ++j;
    u = &j;
  }
}
```
We compile using the command:
```
clang -cc1 -fopenmp-simd -O3 -x c -triple x86_64-apple-darwin10 -emit-llvm loop.c -o loop.ll
```
The following IR (simplified) will be generated:
```
@j = local_unnamed_addr global i32 0, align 4
@u = local_unnamed_addr global ptr null, align 8

define void @loop(i32 noundef %n) local_unnamed_addr {
entry:
  %j = alloca i32, align 4
  %cmp = icmp sgt i32 %n, 0
  br i1 %cmp, label %simd.if.then, label %simd.if.end

simd.if.then:                                     ; preds = %entry
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %j)
  store ptr %j, ptr @u, align 8
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %j)
  %0 = load i32, ptr %j, align 4
  store i32 %0, ptr @j, align 4
  br label %simd.if.end

simd.if.end:                                      ; preds = %simd.if.then, %entry
  ret void
}
```
The most important part is:
```
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %j)
  %0 = load i32, ptr %j, align 4
  store i32 %0, ptr @j, align 4
```
`%j` is still loaded after `@llvm.lifetime.end.p0(i64 4, ptr nonnull %j)`. This
could cause the backend incorrectly optimizes the code and further generates
incorrect code. The root cause is, when we emit a construct that could have
`linear` clause, it usually has the following pattern:
```
EmitOMPLinearClauseInit(S)
{
  OMPPrivateScope LoopScope(*this);
  ...
  EmitOMPLinearClause(S, LoopScope);
  ...
  (void)LoopScope.Privatize();
  ...
}
EmitOMPLinearClauseFinal(S, [](CodeGenFunction &) { return nullptr; });
```
Variables that need to be privatized are added into `LoopScope`, which also
serves as a RAII object. When `LoopScope` is destructed and if optimization is
enabled, a `@llvm.lifetime.end` is also emitted for each privatized variable.
However, the writing back to original variables in `linear` clause happens after
the scope in `EmitOMPLinearClauseFinal`, causing the issue we see above.

A quick "fix" seems to be, moving `EmitOMPLinearClauseFinal` inside the scope.
However, it doesn't work. That's because the local variable map has been updated
by `LoopScope` such that a variable declaration is mapped to the privatized
variable, instead of the actual one. In that way, the following code will be
generated:
```
  %0 = load i32, ptr %j, align 4
  store i32 %0, ptr %j, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %j)
```
Well, now the life time is correct, but apparently the writing back is broken.

In this patch, a new function `OMPPrivateScope::restoreMap` is added and called
before calling `EmitOMPLinearClauseFinal`. This can make sure that
`EmitOMPLinearClauseFinal` can find the orignal varaibls to write back.

Fixes #56913.

Reviewed By: ABataev

Differential Revision: https://reviews.llvm.org/D131272
2022-08-06 16:50:37 -04:00
Tom Stellard d2b158e29e clang/cmake: Drop use of llvm-config for LLVM install discovery
This has been deprecated for a while, since D51714 in 2018.

Remove it in favor of using CMake's find_package() function.

Reviewed By: phosek, mgorny

Differential Revision: https://reviews.llvm.org/D128777
2022-08-06 16:22:59 -04:00
Aarush Bhat a6cb8419b1
clang: fix typo availbility
- Fixes [[ https://github.com/llvm/llvm-project/issues/56787 | #56787 ]].

I am fixing the spelling of availability.

I am unsure if this change will have any side effects. If someone can
help on how to check if it has any side effects, I can test those out as
well.

Reviewed By: inclyc

Differential Revision: https://reviews.llvm.org/D131277
2022-08-07 03:44:55 +08:00
Kazu Hirata c8e6ebd74e Use value instead of getValue (NFC) 2022-08-06 11:21:39 -07:00
Aaron Ballman 486a3c4662 Update the status of some more C DRs
Update some of the C99-era DRs starting in the 300s.
2022-08-06 11:53:40 -04:00
Tobias Hieta b1356504e6
[LLVM] Update C++ standard to 17
Also make the soft toolchain requirements hard. This allows
us to use C++17 features in LLVM now.

If we find patterns with C++17 that improve readability
it should be recommended in the coding standards.

Reviewed By: jhenderson, cor3ntin, MaskRay

Differential Revision: https://reviews.llvm.org/D130689
2022-08-06 09:42:10 +02:00
Jun Zhang 786b503f66
[Clang][Lex] Extend HeaderSearch::LookupFile to control OpenFile behavior.
In the case of static compilation the file system is pretty much read-only
and taking a snapshot of it usually is sufficient. In the interactive C++
case the compilation is longer and people can create and include files, etc.
In that case we often do not want to open files or cache failures unless is
absolutely necessary.

This patch extends the original API call by forwarding some optional flags,
so we can continue use it in the previous way with no breakage.
Signed-off-by: Jun Zhang <jun@junz.org>

Differential Revision: https://reviews.llvm.org/D131241
2022-08-06 11:36:02 +08:00
Argyrios Kyrtzidis 7b12e561ac [test/Modules/cxx20-export-import.cpp] Pre-clean the modules cache directory of the test, NFC 2022-08-05 17:27:43 -07:00
Nico Weber 3fbbf28173 unbreak Modules/cxx20-export-import.cpp with LLVM_APPEND_VC_REV=OFF after 6635f48e4a
See revision b8b7a9dcdc for prior art.
2022-08-05 19:50:23 -04:00
Xiang Li 549542b494 [HLSL] emit-obj when set output.
When not set output, set default output to stdout.
When set output with -Fo and no -fcgl, set -emit-obj to generate dx container.

Reviewed By: beanz

Differential Revision: https://reviews.llvm.org/D130858
2022-08-05 16:27:17 -07:00
Joseph Huber 3b52341116 [CUDA] Fix output name being replaced in device-only mode
When performing device only compilation, there was an issue where
`cubin` outputs were being renamed to `cubin` despite the user's name.
This is required in a normal compilation flow as the Nvidia tools only
understand specific filenames instead of checking magic bytes for some
unknown reason. We do not want to perform this transformation when the
user is performing device only compilation.

Reviewed By: tra

Differential Revision: https://reviews.llvm.org/D131278
2022-08-05 19:08:41 -04:00
Argyrios Kyrtzidis 6635f48e4a [Serialization] Remove `ORIGINAL_PCH_DIR` record
Use of `ORIGINAL_PCH_DIR` record has been superseeded by making PCH/PCM files with relocatable paths at write time.
Removing this record is useful for producing an output-path-independent PCH file and enable sharing of the same PCH file even
when it was intended for a different output path.

Differential Revision: https://reviews.llvm.org/D131124
2022-08-05 15:40:33 -07:00
Ben Langmuir fb89cc0ddb [clang][modules] Don't depend on sharing FileManager during module build
Sharing the FileManager between the importer and the module build should
only be an optimization. Add a cc1 option -fno-modules-share-filemanager
to allow us to test this. Fix the path to modulemap files, which
previously depended on the shared FileManager when using path mapped to
an external file in a VFS.

Differential Revision: https://reviews.llvm.org/D131076
2022-08-05 12:24:40 -07:00
Ben Langmuir d038bb196c [clang] Fix redirection behaviour for cached FileEntryRef
In 6a79e2ff19 we changed Filemanager::getEntryRef() to return the
redirecting FileEntryRef instead of looking through the redirection.
This commit fixes the case when looking up a cached file path to also
return the redirecting FileEntryRef. This mainly affects the behaviour
of calling getNameAsRequested() on the resulting entry ref.

Differential Revision: https://reviews.llvm.org/D131273
2022-08-05 12:23:38 -07:00
Jack Kirk 3e0e5568a6 [CUDA] Fixed sm version constrain for __bmma_m8n8k128_mma_and_popc_b1.
As stated in
https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#warp-level-matrix-instructions-wmma-mma:
".and operation in single-bit wmma requires sm_80 or higher."

tra@: Fixed a bug in builtins-nvptx-mma.py test generator and regenerated the tests.

Differential Revision: https://reviews.llvm.org/D131265
2022-08-05 12:14:06 -07:00
Aaron Ballman 4bc9e60306 Removing redundant code; NFC
The same predicate is checked on line 12962 just above the removed code.
2022-08-05 09:17:20 -04:00
Chuanqi Xu 809b416641 [NFC] Requires x86-registered-target for test/pr56919.cpp 2022-08-05 16:46:38 +08:00
Balázs Kéri 501faaa0d6 [clang][analyzer] Add more wide-character functions to CStringChecker
Support for functions wmempcpy, wmemmove, wmemcmp is added to the checker.
The same tests are copied that exist for the non-wide versions, with
non-wide functions and character types changed to the wide version.

Reviewed By: martong

Differential Revision: https://reviews.llvm.org/D130470
2022-08-05 10:32:53 +02:00
Chuanqi Xu 230d6f93aa [Coroutines] Remove lifetime intrinsics for spliied allocas in coroutine frames
Closing https://github.com/llvm/llvm-project/issues/56919

It is meaningless to preserve the lifetime markers for the spilled
allocas in the coroutine frames and it would block some optimizations
too.
2022-08-05 14:50:43 +08:00
Xiang Li b2c9ff7273 [NFC][HLSL] Fix build error caused missing typo update.
setHLSLFnuctionAttributes to setHLSLFunctionAttributes.

Differential Revision: https://reviews.llvm.org/D131240
2022-08-04 23:20:25 -07:00
Xiang Li 6134629af0 [NFC][HLSL] Fix typo in CGHLSLRuntime.
Change setHLSLFnuctionAttributes to setHLSLFunctionAttributes.

Differential Revision: https://reviews.llvm.org/D131238
2022-08-04 23:08:40 -07:00
Timm Bäder d1942855c4 [clang] Consider array filler in MaybeElementDependentArrayfiller()
Any InitListExpr may have an array filler and since we may be evaluating
the array filler as well, we need to take into account that the array
filler expression might make the InitListExpr element dependent.

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

Differential Revision: https://reviews.llvm.org/D131155
2022-08-05 06:47:49 +02:00
Timm Bäder 8b74074731 [clang][sema] Fix collectConjunctionTerms()
Consider:

A == 5 && A != 5

IfA is 5, the old collectConjunctionTerms() would call itself again for
the LHS (which it ignores), then the RHS (which it also ignores) and
then just return without ever adding anything to the Terms array.

Differential Revision: https://reviews.llvm.org/D131070
2022-08-05 06:45:32 +02:00
Xiang Li 906e41f4e3 [HLSL] clang codeGen for HLSLShaderAttr.
Translate HLSLShaderAttr to IR level.
 1. Skip mangle for hlsl entry functions.
 2. Add function attribute for hlsl entry functions.

Reviewed By: Anastasia

Differential Revision: https://reviews.llvm.org/D124752
2022-08-04 21:23:57 -07:00
Ellis Hoag 6f4c3c0f64 [InstrProf][attempt 2] Add new format for -fprofile-list=
In D130807 we added the `skipprofile` attribute. This commit
changes the format so we can either `forbid` or `skip` profiling
functions by adding the `noprofile` or `skipprofile` attributes,
respectively. The behavior of the original format remains
unchanged.

Also, add the `skipprofile` attribute when using
`-fprofile-function-groups`.

This was originally landed as https://reviews.llvm.org/D130808 but was
reverted due to a Windows test failure.

Differential Revision: https://reviews.llvm.org/D131195
2022-08-04 17:12:56 -07:00
Richard Smith 73b62f8135 Fix parsing of comma fold-expressions as the operand of a C-style cast. 2022-08-04 17:08:08 -07:00
Xiang Li 8a27a2f89f [HLSL] Support -E option for HLSL.
-E option will set entry function for hlsl.
The format is -E entry_name.

To avoid conflict with existing option with name 'E', add an extra prefix '--'.

A new field HLSLEntry is added to TargetOption.
To share code with HLSLShaderAttr, entry function will be add HLSLShaderAttr attribute too.

Reviewed By: beanz

Differential Revision: https://reviews.llvm.org/D124751
2022-08-04 16:54:19 -07:00
Matt Arsenault c5b36ab1d6 AMDGPU/clang: Remove dead code
The order has to be a constant and should be enforced by the builtin
definition. The fallthrough behavior would have been broken anyway.

There's still an existing issue/assert if you try to use garbage for the
ordering. The IRGen should be broken, but we also hit another assert
before that.

Fixes issue 56832
2022-08-04 19:02:56 -04:00
Leonard Chan 33171df9cc Revert "[clang][Darwin] Always set the default C++ Standard Library to libc++"
This reverts commit c5ccb78ade.

We're seeing darwin-stdlib.cpp fail on our linux, mac, and windows
builders:
https://luci-milo.appspot.com/ui/p/fuchsia/builders/toolchain.ci/clang-linux-x64/b8806821020552676065/overview
2022-08-04 22:56:32 +00:00
Corentin Jabot a1a71b7dc9 [Clang] Fix capture of values initialized by bitfields
This fixes a regression introduced in 127bf44

Differential Revision: https://reviews.llvm.org/D131202
2022-08-04 23:58:47 +02:00
Zakk Chen 010f329803 [RISCV][Clang] Support policy function for all vector segment load.
We will switch all UndefValue to PoisonValue in follow up patches.

Reviewed By: kito-cheng

Differential Revision: https://reviews.llvm.org/D126750
2022-08-04 17:47:24 +00:00
Sam Estep 8611a77ee7 [clang][dataflow] Analyze method bodies
This patch adds the ability to context-sensitively analyze method bodies, by moving `ThisPointeeLoc` from `DataflowAnalysisContext` to `Environment`, and adding code in `pushCall` to set it.

Reviewed By: ymandel, sgatev, xazax.hun

Differential Revision: https://reviews.llvm.org/D131170
2022-08-04 17:45:47 +00:00
Sam Estep 0eaecbbc23 [clang][dataflow] Handle return statements
This patch adds a `ReturnLoc` field to the `Environment`, serving a similar to the `ThisPointeeLoc` field in the `DataflowAnalysisContext`. It then uses that (along with a new `VisitReturnStmt` method in `TransferVisitor`) to handle non-`void`-returning functions in context-sensitive analysis.

Reviewed By: ymandel, sgatev

Differential Revision: https://reviews.llvm.org/D130600
2022-08-04 17:42:19 +00:00
David Green 8c30f4a5ab [AArch64] Always allow the __bf16 type
We would like to make the ACLE NEON and SVE intrinsics more useable by
gating them on the target, not by ifdef preprocessor macros. In order to
do this the types they use need to be available. This patches makes
__bf16 always available under AArch64 not just when the bf16
architecture feature is present. This bringing it in-line with GCC. In
subsequent patches the NEON bfloat16x8_t and SVE svbfloat16_t types
(along with bfloat16_t used in arm_sve.h) will be made unconditional
too.

The operations valid on the types are still very limited. They can be
used as a storage type, but the intrinsics used for convertions are
still behind an ifdef guard in arm_neon.h/arm_bf16.h.

Differential Revision: https://reviews.llvm.org/D130973
2022-08-04 18:35:27 +01:00
Fangrui Song 88501dc749 [Sema] -Wformat: support C23 format specifier %b %B
Close #56885: WG14 N2630 added %b to fprintf/fscanf and recommended %B for
fprintf. This patch teaches -Wformat %b for the printf/scanf family of functions
and %B for the printf family of functions.

glibc 2.35 and latest Android bionic added %b/%B printf support. From
https://www.openwall.com/lists/libc-coord/2022/07/ no scanf support is available
yet.

Like GCC, we don't test library support.

GCC 12 -Wformat -pedantic emits a warning:

> warning: ISO C17 does not support the ‘%b’ gnu_printf format [-Wformat=]

The behavior is not ported.

Note: `freebsd_kernel_printf` uses %b differently.

Reviewed By: aaron.ballman, dim, enh

Differential Revision: https://reviews.llvm.org/D131057
2022-08-04 10:26:31 -07:00
Eric Li 5659908f4c [clang][dataflow][NFC] Resize vector directly with ctor
Differential Revision: https://reviews.llvm.org/D131177
2022-08-04 13:12:37 -04:00
Eric Li 18034aee63 [clang][dataflow][NFC] Convert mutable vector references to ArrayRef
`transferBlock` and `computeBlockInputState` only read the
`BlockStates` vector for the predecessor block(s), and do not need to
mutate any of the contents. Only `runTypeErasedDataflowAnalysis`
writes into the `vector`, so simply down to an `ArrayRef`.
2022-08-04 13:12:37 -04:00
Nico Weber 0eb7d86f58 Revert "[InstrProf] Add new format for -fprofile-list="
This reverts commit b692312ca4.
Breaks tests on Windows, see https://reviews.llvm.org/D130808#3699952
2022-08-04 13:04:59 -04:00
Ellis Hoag b692312ca4 [InstrProf] Add new format for -fprofile-list=
In D130807 we added the `skipprofile` attribute. This commit
changes the format so we can either `forbid` or `skip` profiling
functions by adding the `noprofile` or `skipprofile` attributes,
respectively. The behavior of the original format remains
unchanged.

Also, add the `skipprofile` attribute when using
`-fprofile-function-groups`.

Reviewed By: phosek

Differential Revision: https://reviews.llvm.org/D130808
2022-08-04 08:49:43 -07:00
Chelsea Cassanova bcf6ffb87e Reland "[lldb/Fuzzer] Add fuzzer for expression evaluator"
This reverts commit d959324e1e.

The target_include_directories in the clang-fuzzer CMake files
are set to PRIVATE instead of PUBLIC to prevent the clang buildbots
from breaking when symlinking clang into llvm.

The expression evaluator fuzzer itself has been modified to prevent a
bug that occurs when running it without a target.
2022-08-04 11:47:06 -04:00
Ellis Hoag 12e78ff881 [InstrProf] Add the skipprofile attribute
As discussed in [0], this diff adds the `skipprofile` attribute to
prevent the function from being profiled while allowing profiled
functions to be inlined into it. The `noprofile` attribute remains
unchanged.

The `noprofile` attribute is used for functions where it is
dangerous to add instrumentation to while the `skipprofile` attribute is
used to reduce code size or performance overhead.

[0] https://discourse.llvm.org/t/why-does-the-noprofile-attribute-restrict-inlining/64108

Reviewed By: phosek

Differential Revision: https://reviews.llvm.org/D130807
2022-08-04 08:45:27 -07:00