Commit Graph

94428 Commits

Author SHA1 Message Date
Fred Tingaud 1ec1cdcfb4 [analyzer] Inline operator delete when MayInlineCXXAllocator is set.
This patch restores the symmetry between how operator new and operator delete
are handled by also inlining the content of operator delete when possible.

Patch by Fred Tingaud.

Reviewed By: martong

Differential Revision: https://reviews.llvm.org/D124845
2022-05-09 15:44:33 +02:00
Aaron Puchert 44ae49e1a7 Thread safety analysis: Handle compound assignment and ->* overloads
Like regular assignment, compound assignment operators can be assumed to
write to their left-hand side operand. So we strengthen the requirements
there. (Previously only the default read access had been required.)

Just like operator->, operator->* can also be assumed to dereference the
left-hand side argument, so we require read access to the pointee. This
will generate new warnings if the left-hand side has a pt_guarded_by
attribute. This overload is rarely used, but it was trivial to add, so
why not. (Supporting the builtin operator requires changes to the TIL.)

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D124966
2022-05-09 15:35:43 +02:00
Erich Keane a425cac31e "Re-apply 4b6c2cd642 "Deferred Concept Instantiation Implementation""""
This includes a fix for the libc++ issue I ran across with friend
declarations not properly being identified as overloads.

This reverts commit 45c07db31c.
2022-05-09 06:29:47 -07:00
Simon Pilgrim ec6024d081 [X86] Replace avx512f integer mul reduction builtins with generic builtin
D117829 added the generic "__builtin_reduce_mul" which we can use to replace the x86 specific integer mul reduction builtins - internally these were mapping to the same intrinsic already so there are no test changes required.

Differential Revision: https://reviews.llvm.org/D125222
2022-05-09 14:10:28 +01:00
Simon Pilgrim 8a92c45e07 [Clang] Add integer mul reduction builtin
Similar to the existing bitwise reduction builtins, this lowers to a llvm.vector.reduce.mul intrinsic call.

For other reductions, we've tried to share builtins for float/integer vectors, but the fmul reduction intrinsic also take a starting value argument and can either do unordered or serialized, but not reduction-trees as specified for the builtins. However we address fmul support this shouldn't affect the integer case.

Differential Revision: https://reviews.llvm.org/D117829
2022-05-09 12:12:53 +01:00
Marek Kurdej 85ec8a9ac1 [clang-format] Correctly handle SpaceBeforeParens for builtins.
That's a partial fix for https://github.com/llvm/llvm-project/issues/55292.

Before, known builtins behaved differently from other identifiers:
```
void f () { return F (__builtin_LINE() + __builtin_FOO ()); }
```
After:
```
void f () { return F (__builtin_LINE () + __builtin_FOO ()); }
```

Reviewed By: owenpan

Differential Revision: https://reviews.llvm.org/D125085
2022-05-09 11:42:41 +02:00
Marek Kurdej 50cd52d935 [clang-format] Fix WhitespaceSensitiveMacros not being honoured when macro closing parenthesis is followed by a newline.
Fixes https://github.com/llvm/llvm-project/issues/54522.

This fixes regression introduced in 5e5efd8a91.

Before the culprit commit, macros in WhitespaceSensitiveMacros were correctly formatted even if their closing parenthesis weren't followed by semicolon (or, to be precise, when they were followed by a newline).
That commit changed the type of the macro token type from TT_UntouchableMacroFunc to TT_FunctionLikeOrFreestandingMacro.

Correct formatting (with `WhitespaceSensitiveMacros = ['FOO']`):
```
FOO(1+2)
FOO(1+2);
```

Regressed formatting:
```
FOO(1 + 2)
FOO(1+2);
```

Reviewed By: HazardyKnusperkeks, owenpan, ksyx

Differential Revision: https://reviews.llvm.org/D123676
2022-05-09 10:59:33 +02:00
Simon Pilgrim 72eb630207 [Headers][X86] Enable basic Wdocumentation testing on X86 headers
First part of Issue #35297 - we want to enable Wdocumentation-pedantic as well, but need '\n' support first which Issue #55319 is addressing
2022-05-08 10:53:28 +01:00
Simon Pilgrim 6b3a111a28 [Headers][X86] Replace \operation with \code{.operation}
\operation ... \endoperation are not valid doxygen commands and cause issues when -Wdocumentation is enabled (Issue #35297)

This patch proposes to replace them with \code{.operation} ... \endcode blocks so that the pseudo-code is correctly retained in any documentation and downstream can use the ".operation" type for its own formatting.

Differential Revision: https://reviews.llvm.org/D125170
2022-05-08 10:46:26 +01:00
Simon Pilgrim f2b1648812 [X86] Fix some signedness errors in x86 headers
Another step toward enabling full -Wsystem-headers testing across all x86 headers

Fix a number of cases where the arg / return value signedness doesn't match the C/C++ intrinsic.

So far I've just added explicit casts as necessary, but we might want to address some of the mismatches directly

Differential Revision: https://reviews.llvm.org/D125164
2022-05-08 09:42:58 +01:00
Sam McCall 6bbf51f3ed [Frontend] Move, don't copy the predefines buffer into PP. NFC.
It's not trivially small, >10kb.
2022-05-08 01:04:46 +02:00
Simon Pilgrim e7806c08dc [Headers][X86] amxintrin.h - fixed unknown parameter Wdocumentation warning. NFC
Noticed while triaging Issue #35297
2022-05-07 16:20:39 +01:00
Simon Pilgrim 4750be4907 [X86] Add 32-bit target test coverage to clean header tests 2022-05-07 15:23:46 +01:00
Simon Pilgrim 2cd080c884 [X86] rdrand-builtins.c - add 32-bit target coverage and enable -Wall/-Werror 2022-05-07 14:35:42 +01:00
Simon Pilgrim 6e345426de [X86] Remove unused 'hint' argument from prefetch tests
hint is a compile time constant and can't be passed in as a variable - we already hardcode
2022-05-07 13:38:40 +01:00
Sam McCall e571e1a6c3 Reland "[FuzzMutate] Split out FuzzerCLI library that doesn't depend on IR."
This reverts commit a1bb952e83.

I'd somehow missed updating llvm-yaml-parser-fuzzer, now fixed.
2022-05-07 13:49:54 +02:00
Aaron Ballman a1bb952e83 Revert "[FuzzMutate] Split out FuzzerCLI library that doesn't depend on IR."
This reverts commit 1c5e85b3da.

It broke a lot of bots with a link error:
https://lab.llvm.org/buildbot/#/builders/171/builds/14222
https://lab.llvm.org/buildbot/#/builders/188/builds/13748
https://lab.llvm.org/buildbot/#/builders/109/builds/38127
2022-05-07 07:29:57 -04:00
Sam McCall 1c5e85b3da [FuzzMutate] Split out FuzzerCLI library that doesn't depend on IR.
All llvm-project fuzzers use this library to parse command-line arguments.
Many of them don't deal with LLVM IR or modules in any way. Bundling those
functions in one library forces build dependencies that don't need to be there.

Among other things, this means check-clang-pseudo no longer depends on most of
LLVM.

Differential Revision: https://reviews.llvm.org/D125081
2022-05-07 12:11:51 +02:00
Petr Hosek 57636c2590 [CMake] Include llvm-debuginfod-find in Fuchsia toolchain
Differential Revision: https://reviews.llvm.org/D125082
2022-05-06 16:55:05 -07:00
owenca af4cf1c6b8 [clang-format][NFC] Make all TokenAnnotator member functions const
Differential Revision: https://reviews.llvm.org/D125064
2022-05-06 14:46:32 -07:00
Joseph Huber 509b631f84 [OpenMP] Try to Infer target triples using the offloading architecture
Currently we require the `-fopenmp-targets=` option to specify the
triple to use for the offloading toolchains, and the `-Xopenmp-target=`
option to specify architectures to a specific toolchain. The changes
made in D124721 allowed us to use `--offload-arch=` to specify multiple
target architectures. However, this can become combersome with many
different architectures. This patch introduces functinality that
attempts to deduce the target triple and architectures from the
offloading action. Currently we will deduce known GPU architectures when
only `-fopenmp` is specified.

This required a bit of a hack to cache the deduced architectures,
without this we would've just thrown an error when we tried to look up
the architecture again when generating the job. Normally we require the
user to manually specify the toolchain arguments, but here they would
confict unless we overrode them.

Depends on: D124721

Reviewed By: saiislam

Differential Revision: https://reviews.llvm.org/D125050
2022-05-06 16:57:18 -04:00
Joseph Huber 8477a0d769 [OpenMP] Allow compiling multiple target architectures with OpenMP
This patch adds support for OpenMP to use the `--offload-arch` and
`--no-offload-arch` options. Traditionally, OpenMP has only supported
compiling for a single architecture via the `-Xopenmp-target` option.
Now we can pass in a bound architecture and use that if given, otherwise
we default to the value of the `-march` option as before.

Note that this only applies the basic support, the OpenMP target runtime
does not yet know how to choose between multiple architectures.
Additionally other parts of the offloading toolchain (e.g. LTO) require
the `-march` option, these should be worked out later.

Reviewed By: tra

Differential Revision: https://reviews.llvm.org/D124721
2022-05-06 16:57:16 -04:00
Petr Hosek 7f0e741db9 [Driver] Pass --fix-cortex-a53-843419 automatically on Fuchsia
When targeting cortex-a53, set this linker flag rather than relying
on the toolchain users to do it in their build.

Differential Revision: https://reviews.llvm.org/D114023
2022-05-06 13:27:10 -07:00
Shivam bbd031943a
Update ReleaseNotes.rst 2022-05-07 01:20:45 +05:30
Shivam b390173408
update the doc for the static analyzer checker 2022-05-07 01:19:46 +05:30
Shivam 24e9d90e65
Added the brief discription about the new CSA checker. 2022-05-07 01:16:22 +05:30
Yitzhak Mandelbaum 7e63a0d479 [clang-tidy] New check for safe usage of `std::optional` and like types.
This check verifies the safety of access to `std::optional` and related
types (including `absl::optional`). It is based on a corresponding Clang
Dataflow Analysis, which does most of the work. This check merely runs it and
converts its findings into diagnostics.

Differential Revision: https://reviews.llvm.org/D121120
2022-05-06 18:50:36 +00:00
python3kgae 3fa5eb4cfc [HLSL] add -fcgl option flag.
fcgl option will make compilation stop after clang codeGen and output the llvm ir.
It is added to check clang codeGen output for HLSL.

It will be translated into -S -emit-llvm and -disable-llvm-passes.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D124983
2022-05-06 11:42:15 -07:00
Joseph Huber e12905b4d5 [OpenMP] Add basic support for properly handling static libraries
Currently we handle static libraries like any other object in the
linker wrapper. However, this does not preserve the sematnics that
dictate static libraries should be lazily loaded as the symbols are
needed. This allows us to ignore linking in architectures that are not
used by the main application being compiled. This patch adds the basic
support for detecting if a file came from a static library, and only
including it in the link job if it's used by other object files.

This patch only adds the basic support, to be more correct we should
check the symbols and only inclue the library if the link job contains
symbols that are needed. Ideally we could just put this on the linker
itself, but nvlink doesn't seem to support `.a` files.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D125092
2022-05-06 11:20:58 -04:00
Sam McCall f44552ab38 [Frontend] Fix broken createInvocation test due to bad merge 2022-05-06 17:06:13 +02:00
Sam McCall d2405e1da5 Fix lifetime of DiagnosticsEngine in diagtool. 2022-05-06 16:21:49 +02:00
Sam McCall 499d0b96cb [clang] createInvocationFromCommandLine -> createInvocation, delete former. NFC
(Followup from 40c13720a4)

Differential Revision: https://reviews.llvm.org/D125012
2022-05-06 16:21:48 +02:00
Simon Pilgrim 102824f048 [clang][X86] Rename some intrinsics tests to use the *-builtins.c naming convention 2022-05-06 14:49:46 +01:00
Ben Shi 3902ebdd57 [compiler-rt][builtins] Fix wrong ABI of AVR __mulqi3 & __mulhi3
Reviewed By: aykevl, dylanmckay

Differential Revision: https://reviews.llvm.org/D125077
2022-05-06 13:46:49 +00:00
Yitzhak Mandelbaum a45647d82b [clang][dataflow][NFC] Clarify guarantees on returned vector size for `runDataflowAnalysis`.
Adjusts the comment to specify that the output vector's size matches the number of CFG blocks.

Differential Revision: https://reviews.llvm.org/D125091
2022-05-06 13:30:01 +00:00
Aaron Ballman 43d8ffeeb1 Fix underlining length; NFC 2022-05-06 08:47:45 -04:00
Sam McCall 7cc8377f2c Generalize "check-all" umbrella targets, use for check-clang-tools
The mechanism behind "check-all" is recording params of add_lit_testsuite()
calls in global variables LLVM_LIT_*, and then creating an extra suite with
their union at the end.
This avoids composing the check-* targets directly, which doesn't work well.

We generalize this by allowing multiple families of variables LLVM_{name}_LIT_*:
  umbrella_lit_testsuite_begin(check-foo)
  ... test suites here will be added to LLVM_FOO_LIT_* variables ...
  umbrella_lit_testsuite_end(check-foo)
(This also moves some implementation muck out of {llvm,clang}/CMakeLists.txt

This patch also changes check-clang-tools to use be an umbrella test target,
which means the clangd and clang-pseudo tests are included in it, along with the
the other testsuites that already are (like check-clang-extra-clang-tidy).

Differential Revision: https://reviews.llvm.org/D121838
2022-05-06 12:30:49 +02:00
Balazs Benics da5b5ae852 Revert "[analyzer] Canonicalize SymIntExpr so the RHS is positive when possible"
It seems like multiple users are affected by a crash introduced by this
commit, thus I'm reverting it for the time being.
Read more about the found reproducers at Phabricator.

Differential Revision: https://reviews.llvm.org/D124658

This reverts commit f0d6cb4a5c.
2022-05-06 12:13:51 +02:00
Andrzej Warzynski a65afce731 [flang][driver] Add support for -save-temps
This patch adds support for `-save-temps` in `flang-new`, Flang's
compiler driver. The semantics of this option are inherited from Clang.

The file extension for temporary Fortran preprocessed files is set to
`i`. This is identical to what Clang uses for C (or C++) preprocessed
files. I have tried researching what other compilers do here, but I
couldn't find any definitive answers. One GFortran thread [1] suggests
that indeed it is not clear what the right approach should be.

Normally, various phases in Clang/Flang are combined. The `-save-temps`
option works by forcing the compiler to run every phase separately. As
there is no integrated assembler driver in Flang, user will have to use
`-save-temps` together with `-fno-integrated-as`. Otherwise, an
invocation to the integrated assembler would be generated generated,
which is going to fail (i.e. something equivalent to `clang -cc1as` from
Clang).

There are no specific plans for implementing an integrated assembler for
Flang for now. One possible solution would be to share it entirely with
Clang.

Note that on Windows you will get the following error when using
`-fno-integrated-as`:
```bash
  flang-new: error: there is no external assembler that can be used on this platform
```
Unfortunately, I don't have access to a Windows machine to investigate
this. Instead, I marked the tests in this patch as unsupported on
Windows.

[1] https://gcc.gnu.org/bugzilla//show_bug.cgi?id=81615

Differential Revision: https://reviews.llvm.org/D124669
2022-05-06 08:41:29 +00:00
Sam McCall 817550919e [Lex] Don't assert when decoding invalid UCNs.
Currently if a lexically-valid UCN encodes an invalid codepoint, then we
diagnose that, and then hit an assertion while trying to decode it.

Since there isn't anything preventing us reaching this state, remove the
assertion. expandUCNs("X\UAAAAAAAAY") will produce "XY".

Differential Revision: https://reviews.llvm.org/D125059
2022-05-06 08:51:42 +02:00
Volodymyr Sapsai 3b762b3ab8 [clang][NFC] In parts of Objective-C Sema use Obj-C-specific types instead of `Decl`.
Differential Revision: https://reviews.llvm.org/D124285
2022-05-05 19:19:41 -07:00
Richard Smith f6c74932b5 [docs] Fix uses of `foo` that should be ``foo`` throughout release notes. 2022-05-05 16:04:19 -07:00
Richard Smith c2572d8b1f [docs] Add blank lines to help Sphinx parse nested bullets. 2022-05-05 15:58:26 -07:00
Aaron Ballman 1c50909f6f Revert "Pedantically warn about // comments in gnu89 mode"
This reverts commit f6dff93641.

This diagnostic is also in the -Wcomment group, which is in the -Wall
group, so the diagnostic is enabled in a wider context than GCC does.
That turns out to be disruptive for the Linux kernel builds still using
-std=gnu89 because the kernel requires C source files to start with //
comments: https://kernel.org/doc/html/v5.18-rc5/process/license-rules.html#license-identifier-syntax
2022-05-05 18:39:13 -04:00
owenca e7aed737eb [clang-format][NFC] Add a few regression tests 2022-05-05 15:12:24 -07:00
Richard Smith c4f95ef86a Reimplement `__builtin_dump_struct` in Sema.
Compared to the old implementation:

* In C++, we only recurse into aggregate classes.
* Unnamed bit-fields are not printed.
* Constant evaluation is supported.
* Proper conversion is done when passing arguments through `...`.
* Additional arguments are supported and are injected prior to the
  format string; this directly supports use with `fprintf`, for example.
* An arbitrary callable can be passed rather than only a function
  pointer. In particular, in C++, a function template or overload set is
  acceptable.
* All text generated by Clang is printed via `%s` rather than directly;
  this avoids issues where Clang's pretty-printing output might itself
  contain a `%` character.
* Fields of types that we don't know how to print are printed with a
  `"*%p"` format and passed by address to the print function.
* No return value is produced.

Reviewed By: aaron.ballman, erichkeane, yihanaa

Differential Revision: https://reviews.llvm.org/D124221
2022-05-05 14:55:47 -07:00
owenca 8b626a2caa [clang-format] Fix another bug in AlignConsecutiveAssignments
The ShouldShiftBeAdded lambda checks if extra space should be
added before the wrapped part of a braced list. If the first
element of the list is wrapped, no extra space should be added.

Fixes #55161.

Differential Revision: https://reviews.llvm.org/D124956
2022-05-05 14:48:56 -07:00
Lang Hames 16dcbb53dc [ORC] Return ExecutorAddrs rather than JITEvaluatedSymbols from LLJIT::lookup.
Clients don't care about linkage, and ExecutorAddr is much more ergonomic.
2022-05-05 13:56:00 -07:00
Eric Li 45643cfcc1 [clang][dataflow] Centralize expression skipping logic
A follow-up to 62b2a47 to centralize the logic that skips expressions
that the CFG does not emit. This allows client code to avoid
sprinkling this logic everywhere.

Add redirects in the transfer function to similarly skip such
expressions by forwarding the visit to the sub-expression.

Differential Revision: https://reviews.llvm.org/D124965
2022-05-05 20:28:11 +00:00
phyBrackets dcb906757a [clang][ASTImporter][NFC]: Move clang::ImportError into own header.
Reviewed By: martong

Differential Revision: https://reviews.llvm.org/D124774
2022-05-06 00:14:32 +05:30
Aaron Ballman f6dff93641 Pedantically warn about // comments in gnu89 mode
GCC warns with a pedantic warning when -std=gnu89, but Clang would only
diagnose in -std=c89 mode. Clang now matches the GCC behavior in both
modes.

Fixes #18427
2022-05-05 14:35:47 -04:00
Aaron Ballman 967137ca3c No longer accept scoped enumerations in C
We had a think-o that would allow a user to declare a scoped
enumeration in C language modes "as a C++11 extension". This is a
think-o because there's no way for the user to spell the name of the
enumerators; C does not have '::' for a fully-qualified name. See
commit d0d87b5972 for details on why this
is unintentional for C.

Fixes #42372
2022-05-05 14:00:01 -04:00
Aaron Ballman 199dfb4d0c Silence a false positive about an unevaluated expr w/side effects
If the operand to `sizeof` is an expression of VLA type, the operand is
still evaluated, so we should not issue a diagnostic about ignoring the
side effects in this case, as they're not actually ignored.

Fixes #48010
2022-05-05 12:12:30 -04:00
Ilya Biryukov 1e95d1bee6 [clang] Fix Clang release notes
I have forgotten a space by mistake in the previous commit.
2022-05-05 16:11:45 +00:00
Ilya Biryukov e13c28ec59 [Driver] Remove -fno-concept-satisfaction-caching
The flag was added when the C++20 draft did not allow for concept
caching. The final C++20 standard permits the caching, so flag is
redundant. See http://wg21.link/p2104r0.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D125014
2022-05-05 15:53:00 +00:00
Brian Tracy 87a55137e2 Fix "the the" typo in documentation and user facing strings
There are many more instances of this pattern, but I chose to limit this change to .rst files (docs), anything in libcxx/include, and string literals. These have the highest chance of being seen by end users.

Reviewed By: #libc, Mordante, martong, ldionne

Differential Revision: https://reviews.llvm.org/D124708
2022-05-05 17:52:08 +02:00
Tomasz Kamiński f0d6cb4a5c [analyzer] Canonicalize SymIntExpr so the RHS is positive when possible
This PR changes the `SymIntExpr` so the expression that uses a
negative value as `RHS`, for example: `x +/- (-N)`, is modeled as
`x -/+ N` instead.

This avoids producing a very large `RHS` when the symbol is cased to
an unsigned number, and as consequence makes the value more robust in
presence of casts.

Note that this change is not applied if `N` is the lowest negative
value for which negation would not be representable.

Reviewed By: steakhal

Patch By: tomasz-kaminski-sonarsource!

Differential Revision: https://reviews.llvm.org/D124658
2022-05-05 17:48:49 +02:00
Andrzej Warzynski b9f3b7f89a [flang][driver] Add support for consuming LLVM IR/BC files
This change makes sure that Flang's driver recognises LLVM IR and BC as
supported file formats. To this end, `isFortran` is extended and renamed
as `isSupportedByFlang` (the latter better reflects the new
functionality).

New tests are added to verify that the target triple is correctly
overridden by the frontend driver's default value or the value specified
with `-triple`. Strictly speaking, this is not a functionality that's
new in this patch (it was added in D124664). This patch simply enables
us to write such tests and hence I'm including them here.

Differential Revision: https://reviews.llvm.org/D124667
2022-05-05 15:11:50 +00:00
Ilya Biryukov ad2263de9f [Sema] Replace invalid FIXME about memory leak. NFC
Added in my previous patch by mistake.
2022-05-05 15:04:11 +00:00
Sam McCall 04b4190489 [Driver] Make "upgrade" of -include to include-pch optional; disable in clangd
If clang is passed "-include foo.h", it will rewrite to "-include-pch foo.h.pch"
before passing it to cc1, if foo.h.pch exists.

Existence is checked, but validity is not. This is probably a reasonable
assumption for the compiler itself, but not for clang-based tools where the
actual compiler may be a different version of clang, or even GCC.
In the end, we lose our -include, we gain a -include-pch that can't be used,
and the file often fails to parse.

I would like to turn this off for all non-clang invocations (i.e.
createInvocationFromCommandLine), but we have explicit tests of this behavior
for libclang and I can't work out the implications of changing it.

Instead this patch:
 - makes it optional in the driver, default on (no change)
 - makes it optional in createInvocationFromCommandLine, default on (no change)
 - changes driver to do IO through the VFS so it can be tested
 - tests the option
 - turns the option off in clangd where the problem was reported

Subsequent patches should make libclang opt in explicitly and flip the default
for all other tools. It's probably also time to extract an options struct
for createInvocationFromCommandLine.

Fixes https://github.com/clangd/clangd/issues/856
Fixes https://github.com/clangd/vscode-clangd/issues/324

Differential Revision: https://reviews.llvm.org/D124970
2022-05-05 16:47:17 +02:00
Fred Tingaud c894e85fc6 In MSVC compatibility mode, handle unqualified templated base class initialization
Before C++20, MSVC was supporting not mentioning the template argument of the base class when initializing a class inheriting a templated base class.
So the following code compiled correctly:
```
template <class T>
class Base {
};

template <class T>
class Derived : public Base<T> {
public:
  Derived() : Base() {}
};

void test() {
    Derived<int> d;
}
```
See https://godbolt.org/z/Pxxe7nccx for a conformance view.

This patch adds support for such construct when in MSVC compatibility mode.

Reviewed By: rnk

Differential Revision: https://reviews.llvm.org/D124666
2022-05-05 16:03:39 +02:00
Sam McCall 40c13720a4 [Frontend] give createInvocationFromCommandLine an options struct
It's accumulating way too many optional params (see D124970)

While here, improve the name and the documentation.

Differential Revision: https://reviews.llvm.org/D124971
2022-05-05 15:12:07 +02:00
einvbri df5801806d [analyzer] Get direct binding for specific punned case
Region store was not able to see through this case to the actual
initialized value of STRUCT ff. This change addresses this case by
getting the direct binding. This was found and debugged in a downstream
compiler, with debug guidance from @steakhal. A positive and negative
test case is added.

The specific case where this issue was exposed.

  typedef struct {
    int a:1;
    int b[2];
  } STRUCT;

  int main() {
    STRUCT ff = {0};
    STRUCT* pff = &ff;
    int a = ((int)pff + 1);
    return a;
  }

Reviewed By: steakhal, martong

Differential Revision: https://reviews.llvm.org/D124349
2022-05-05 04:53:45 -05:00
Adrian Kuegel cc344d262a [clang] Add static_cast to fix Bazel build.
Differential Revision: https://reviews.llvm.org/D124995
2022-05-05 10:29:47 +02:00
Zakk Chen 6c10014f1d [RISCV][Clang] add more tests for clang driver. (NFC)
Test experimental arch, Zfh, Zfmin and Zve arch.

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D124611
2022-05-04 23:55:52 -07:00
Wael Yehia 2407c13aa4 [AIX][PGO] Enable linux style PGO on AIX
This patch switches the PGO implementation on AIX from using the runtime
registration-based section tracking to the __start_SECNAME/__stop_SECNAME
based. In order to enable the recognition of __start_SECNAME/__stop_SECNAME
symbols in the AIX linker, the -bdbg:namedsects:ss needs to be used.

Reviewed By: jsji, MaskRay, davidxl

Differential Revision: https://reviews.llvm.org/D124857
2022-05-05 04:10:39 +00:00
Eric Li 58abe36ae7 [clang][dataflow] Add flowConditionIsTautology function
Provide a way for users to check if a flow condition is
unconditionally true.

Differential Revision: https://reviews.llvm.org/D124943
2022-05-05 03:57:43 +00:00
Phoebe Wang aa25b55bde [X86] Add `void` to void function. NFC 2022-05-05 10:58:46 +08:00
Zixu Wang cb5bb28511 Revert "Revert "[clang][extract-api] Use relative includes""
Reapply the change after fixing sanitizer errors.
The original problem was that `StringRef`s in `Matches` are pointing to
temporary local `std::string`s created by `path::convert_to_slash` in
the regex match call. This patch does the conversion up front in
container `FilePath`.

This reverts commit 2966f0fa50.

Differential Revision: https://reviews.llvm.org/D124964
2022-05-04 14:52:45 -07:00
Aaron Ballman b1a55d0895 Fix a crash on targets where __bf16 isn't supported
We'd nondeterministically assert (and later crash) when calculating the size or
alignment of a __bf16 type when the type isn't supported on a target because of
reading uninitialized values. Now we check whether the type is supported first.

Fixes #50171
2022-05-04 16:45:59 -04:00
Zixu Wang 2966f0fa50 Revert "[clang][extract-api] Use relative includes"
This reverts commit 4c262fee08.
Revert to fix Msan and Asan errors.
2022-05-04 12:27:20 -07:00
owenca 342e1c77c3 [clang-format] Fix a bug in AlignConsecutiveAssignments
Fixes #55113.

Differential Revision: https://reviews.llvm.org/D124868
2022-05-04 12:04:43 -07:00
Zixu Wang 5f841c71fc [NFC] Remove unfinished test case
4c262fee08 accidentally added local
unfinished test case clang/test/Index/annotate-comments-enum-constant.c
This patch removes it.
2022-05-04 10:40:25 -07:00
Zixu Wang 4c262fee08 [clang][extract-api] Use relative includes
This patch transforms the given input headers to relative include names
using header search entries and some heuritics.
For example: `/Path/To/Header.h` will be included as `<Header.h>` with a
search path of `-I /Path/To/`; and
`/Path/To/Framework.framework/Headers/Header.h` will be included as
`<Framework/Header.h>`, given a search path of `-F /Path/To`.
Headermaps will also be queried in reverse to find a spelled name to
include headers.

Differential Revision: https://reviews.llvm.org/D123831
2022-05-04 10:28:01 -07:00
Aaron Ballman 859d923948 Fix a failing assertion with vector type initialization
When constant evaluating the initializer for an object of vector type,
we would call APInt::trunc() but truncate to the same bit-width the
object already had, which would cause an assertion. Instead, use
APInt::truncOrSelf() so that we no longer assert in this situation.

Fix #50216
2022-05-04 13:25:21 -04:00
Yaxun (Sam) Liu 62501bc45a [NFC][CUDA][HIP] rework mangling number for aux target
CUDA/HIP needs to mangle for aux target. When mangling for aux target,
the mangler should use mangling number for aux target. Previously
in https://reviews.llvm.org/D122734 a state was introduced in
ASTContext to let the mangler get mangling number for aux target
from ASTContext. This patch removes that state from ASTConext
and add an IsAux member to MangleContext to indicate that
the mangle context is for aux target. This reflects the reality that
the mangle context is created for mangling aux target and makes
ASTContext cleaner.

Reviewed by: Artem Belevich, Reid Kleckner

Differential Revision: https://reviews.llvm.org/D124842
2022-05-04 13:05:33 -04:00
Cyndy Ishida b6c67c3c67 [clang] Track how headers get included generally during lookup time
tapi & clang-extractapi both attempt to construct then check against
how a header was included to determine api information when working
against multiple search paths, headermap, and vfsoverlay mechanisms.
Validating this against what the preprocessor sees during lookup time
makes this check more reliable.

Reviewed By: zixuw, jansvoboda11

Differential Revision: https://reviews.llvm.org/D124638
2022-05-04 09:52:31 -07:00
Aaron Ballman 94d36fdbd7 Fix a crash on invalid with _Generic expressions
We were failing to check if the controlling expression is dependent or
not when testing whether it has side effects. This would trigger an
assertion. Instead, if the controlling expression is dependent, we
suppress the check and diagnostic.

This fixes Issue 50227.
2022-05-04 12:41:56 -04:00
Ilya Biryukov 726d7b07fc [Sema] Simplify CheckConstraintSatisfaction. NFC
- Exit early when constraint caching is disabled.
- Use unique_ptr to manage temporary lifetime.
- Fix a typo in a comment (InsertPos instead of InsertNode).

The new code duplicates the forwarding call to CheckConstraintSatisfaction,
but reduces the number of interconnected if statements and simplifies lifetime
management.

This increases the overall readability.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D124923
2022-05-04 15:53:07 +00:00
Eric Li 62b2a47a9f [clang][dataflow] Only skip ExprWithCleanups when visiting terminators
`IgnoreParenImpCasts` will remove implicit casts to bool
(e.g. `PointerToBoolean`), such that the resulting expression may not
be of the `bool` type. The `cast_or_null<BoolValue>` in
`extendFlowCondition` will then trigger an assert, as the pointer
expression will not have a `BoolValue`.

Instead, we only skip `ExprWithCleanups` and `ParenExpr` nodes, as the
CFG does not emit them.

Differential Revision: https://reviews.llvm.org/D124807
2022-05-04 15:31:49 +00:00
Phoebe Wang 2d18a86d14 [X86] Fix uninitialized variable warnings in cetintrin.h reported by #55224
Fix uninitialized variables introduced by D116325.

Differential Revision: https://reviews.llvm.org/D124916
2022-05-04 21:12:12 +08:00
Aaron Ballman 1587f6bb3c Bump the serialization major version number
This is a speculative fix for a build bot which does not put the LLVM
revision information into the PCH hash.

http://45.33.8.238/linux/75290/step_7.txt
2022-05-04 09:07:57 -04:00
Aaron Ballman 2cb2cd242c Change the behavior of implicit int diagnostics
C89 allowed a type specifier to be elided with the resulting type being
int, aka implicit int behavior. This feature was subsequently removed
in C99 without a deprecation period, so implementations continued to
support the feature. Now, as with implicit function declarations, is a
good time to reevaluate the need for this support.

This patch allows -Wimplicit-int to issue warnings in C89 mode (off by
default), defaults the warning to an error in C99 through C17, and
disables support for the feature entirely in C2x. It also removes a
warning about missing declaration specifiers that really was just an
implicit int warning in disguise and other minor related cleanups.
2022-05-04 08:35:47 -04:00
Phoebe Wang b540ee5402 [X86] Fix redundant `%s` in RUN command. NFC 2022-05-04 20:29:50 +08:00
Joseph Huber 46a5a8029e [OpenMP] Fix save-temps name in linker wrapper
Summary:
The wrapped registration code had a typo in the save-temps version of
the name.
2022-05-03 20:51:05 -04:00
David Pagan 37471cf2c3 [clang][OpenMP] Local variable alignment incorrect with align clause
If alignment specified with align clause is less than natural alignment for
list item type, the alignment should be set to the natural alignment.

See OMP5.1 specification, page 185, lines 7-10

Differential Revision: https://reviews.llvm.org/D124676
2022-05-03 13:10:01 -07:00
Duncan P. N. Exon Smith c1e17c7dfe ExtractAPI: Use %clang_cc1 and -verify in enum.c
Fix one test (enum.c) in ExtractAPI to use %clang_cc1 and -verify
instead of calling the full driver and FileCheck. This is an example for
my comment from https://reviews.llvm.org/D121873.

Differential Revision: https://reviews.llvm.org/D124634
2022-05-03 11:57:24 -07:00
Richard Smith c7ecfadf9b Fix some places where PseudoObjectExpr handling assumed that a
PseudoObjectExpr is only used for ObjC properties and subscripts.

For now, these assumptions are generally correct, but that's not part of
the design of PseudoObjectExpr. No functionality change intended.
2022-05-03 11:55:14 -07:00
owenca 397188036d [clang-format][NFC] Clean up tryToParseLambdaIntroducer()
Differential Revision: https://reviews.llvm.org/D124818
2022-05-03 11:36:38 -07:00
Bill Wendling f2639cf3fe [randstruct] Move initializer check to be more effective
If a randomized structure has an initializer with a dedicated
initializer in it, the field initialzed by that dedicated initializer
may end up at the end of the RecordDecl. This however may skip the
random layout initization check.

  struct t {
     int a, b, c, d, e;
  } x = { .a = 2, 4, 5, 6 };

Let's say that "a" is lands as the last field after randomization. The
call to CheckDesignatedInitializer sets the iterator to the end of the
initializer list. During the next iteration of the initializer list
check, it detects that and fails to issue the error about initializing
a randomized struct with non-designated initializer. Instead, it issues
an error about "excess elements in struct initializer", which is
confusing under these circumstances.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D124694
2022-05-03 11:23:12 -07:00
Kugan Vivekanandarajah 2deebc0048 [RFC] Add and sort decl to maintain order instead of inserting in order
ASTWriter::associateDeclWithFile shows a lot in clangd perf profile due to O(n^2) behaviour in insertion of DeclIDs in SortedFileDeclIDs. Instead of doing that, this patch just appends it to the DeclIDs vector and sorts them at the end.

Reviewed By: akyrtzi

Differential Revision: https://reviews.llvm.org/D124840
2022-05-03 17:06:22 +01:00
Shilei Tian 9c1085c7e2 [Clang][OpenMP] Add the support for floating-point variables for specific atomic clauses
Currently when using `atomic update` with floating-point variables, if
the operation is add or sub, `cmpxchg`, instead of `atomicrmw` is emitted, as
shown in [1].  In fact, about three years ago, llvm-svn: 351850 added the
support for FP operations. This patch adds the support in OpenMP as well.

[1] https://godbolt.org/z/M7b4ba9na

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D124724
2022-05-03 11:30:54 -04:00
Philipp Tomsich 64816e68f4 [AArch64] Support for Ampere1 core
Add support for the Ampere Computing Ampere1 core.
Ampere1 implements the AArch64 state and is compatible with ARMv8.6-A.

Differential Revision: https://reviews.llvm.org/D117112
2022-05-03 15:54:02 +01:00
Aaron Ballman 50c959b4fa Add explicit OpenMP 5.0 case for version macros; NFC
This adds an explicit case for OpenMP 5.0 as a reminder to still define
the correct macro value when the default OpenMP version changes in the
future.
2022-05-03 10:01:47 -04:00
Aaron Ballman 50b51b1860 Fix a typo in an OpenMP test
This fixes the typo and corrects the default OpenMP version being
tested.
2022-05-03 10:01:46 -04:00
David Truby 8bc29d1427 [clang][AArch64][SVE] Implement conditional operator for SVE vectors
This patch adds support for the conditional (ternary) operator on SVE
scalable vector types in C++, matching the behaviour for NEON vector
types. Like the conditional operator for NEON types, this is disabled in
C mode.

Differential Revision: https://reviews.llvm.org/D124091
2022-05-03 13:10:32 +00:00
Ali Shuja Siddiqui cf7cd664f3 [analyzer] Check for std::__addressof for inner pointer checker
This is an extension to diff D99260. This adds an additional exception
for `std::__addressof` in `InnerPointerChecker`.

Patch By alishuja (Ali Shuja Siddiqui)!

Reviewed By: martong, alishuja

Differential Revision: https://reviews.llvm.org/D109467
2022-05-03 14:05:19 +02:00
Aaron Ballman 1fc208d400 Fix Clang sphinx build
It seems we don't have this option exposed via RST, so switching to use
generic backticks instead.
2022-05-03 07:14:12 -04:00
Fred Tingaud ad47114ad8 In MSVC compatibility mode, friend function declarations behave as function declarations
Before C++20, MSVC treated any friend function declaration as a function declaration, so the following code would compile despite funGlob being declared after its first call:

```
class Glob {
public:
  friend void funGlob();

  void test() {
    funGlob();
  }
};

void funGlob() {}
```
This proposed patch mimics the MSVC behavior when in MSVC compatibility mode

Reviewed By: rnk

Differential Revision: https://reviews.llvm.org/D124613
2022-05-03 11:31:50 +02:00
Marco Antognini 68ee5ec07d [Analyzer] Fix assumptions about const field with member-initializer
Essentially, having a default member initializer for a constant member
does not necessarily imply the member will have the given default value.

Remove part of a2e053638b ([analyzer] Treat more const variables and
fields as known contants., 2018-05-04).

Fix #47878

Reviewed By: r.stahl, steakhal

Differential Revision: https://reviews.llvm.org/D124621
2022-05-03 11:27:45 +02:00
Marek Kurdej c819dce2d3 [clang-format] Add a regression test for aligning macros with keywords.
Test from issue https://github.com/llvm/llvm-project/issues/54953.
2022-05-03 11:09:38 +02:00
Ivan Murashko f6112f490c [docs] PCH usage documentation update
The documentation has an incorrect example of PCH files usage via `-include` option. The possibility has not been available since [llvm-svn: 174385](https://reviews.llvm.org/rG48b72d81c8968f3d342557582db986a60aef2c54).

Differential Revision: https://reviews.llvm.org/D124719
2022-05-03 08:26:13 +01:00
Weverything 32eb7b863e [Driver][test] Remove clang{{.*}} when testing -cc1 command lines
The majority of tests omit testing "clang" for -cc1 command lines. In addition,
some distributions symlink %clang to an executable with a content hash based
filename so clang{{.*}} check won't work.

With this change, we can remove many -no-canonical-prefixes whose purpose was to
make the tests pass on such distributions.
2022-05-02 17:08:20 -07:00
Fangrui Song 4d34c4e0e6 [OpenMP] Fix -Wswitch (due to new OMPC_cancellation_construct_type) after D123828 2022-05-02 12:10:09 -07:00
Erich Keane 45c07db31c Revert "Re-apply 4b6c2cd642 "Deferred Concept Instantiation Implementation"""
This reverts commit a97899108e.

The patch caused some problems with the libc++ `__range_adaptor_closure`
that I haven't been able to figure out the cause of, so I am reverting
while I figure out whether this is a solvable problem/issue with the
  CFE, or libc++ depending on an older 'incorrect' behavior.
2022-05-02 11:12:14 -07:00
Paul Robinson 2ed0123b7f [PS5] Check for HasNativeLLVMSupport 2022-05-02 11:06:33 -07:00
Paul Robinson 214265bce9 [NFC] Add test for HasNativeLLVMSupport
It looks like there used to be a test for this, but the test evolved
in a way that caused the check for the diagnostic to be eliminated.
Add a test that is obviously and specifically for that diagnostic.
2022-05-02 11:06:33 -07:00
Fangrui Song 980679981f [Driver][test] Remove clang{{.*}} when testing -cc1 command lines
The majority of tests omit testing "clang" for -cc1 command lines. In addition,
some distributions symlink %clang to an executable with a content hash based
filename so clang{{.*}} check won't work.

With this change, we can remove many -no-canonical-prefixes whose purpose was to
make the tests pass on such distributions.
2022-05-02 11:02:19 -07:00
Harald van Dijk fed7be096f
Mark identifier prefixes as substitutable
The Itanium C++ ABI says prefixes are substitutable. For most prefixes
we already handle this: the manglePrefix(const DeclContext *, bool) and
manglePrefix(QualType) overloads explicitly handles substitutions or
defer to functions that handle substitutions on their behalf. The
manglePrefix(NestedNameSpecifier *) overload, however, is different and
handles some cases implicitly, but not all. The Identifier case was not
handled; this change adds handling for it, as well as a test case.

Reviewed By: erichkeane

Differential Revision: https://reviews.llvm.org/D122663
2022-05-02 18:07:47 +01:00
Amy Kwan 2534dc120a [PowerPC] Enable CR bits support for Power8 and above.
This patch turns on support for CR bit accesses for Power8 and above. The reason
why CR bits are turned on as the default for Power8 and above is that because
later architectures make use of builtins and instructions that require CR bit
accesses (such as the use of setbc in the vector string isolate predicate
and bcd builtins on Power10).

This patch also adds the clang portion to allow for turning on CR bits in the
front end if the user so desires to.

Differential Revision: https://reviews.llvm.org/D124060
2022-05-02 12:06:15 -05:00
Fangrui Song 3d09c9b30f [Driver][test] Avoiding producing object file in the current directory 2022-05-02 10:00:57 -07:00
Fangrui Song 46cc04de34 [Driver][test] Add back some -no-canonical-prefixes
To make them meaningful, it's useful to check "clang". Use
-no-canonical-prefixes to support distributions that symlink %clang to an
executable with a filename not ending in "clang".
2022-05-02 09:35:58 -07:00
Marco Antognini f34639828f [Analyzer] Minor cleanups in StreamChecker
Remove unnecessary conversion to Optional<> and incorrect assumption
that BindExpr can return a null state.

Reviewed By: steakhal

Differential Revision: https://reviews.llvm.org/D124681
2022-05-02 17:50:10 +02:00
Marco Antognini 5a47accda8 [Analyzer] Fix clang::ento::taint::dumpTaint definition
Ensure the definition is in the "taint" namespace, like its declaration.

Reviewed By: steakhal

Differential Revision: https://reviews.llvm.org/D124462
2022-05-02 17:44:06 +02:00
Erich Keane a97899108e Re-apply 4b6c2cd642 "Deferred Concept Instantiation Implementation""
This reverts commit 0c31da4838.

I've solved the issue with the PointerUnion by making the
`FunctionTemplateDecl` pointer be a NamedDecl, that could be a
`FunctionDecl` or `FunctionTemplateDecl` depending.  This is enforced
with an assert.
2022-05-02 07:49:26 -07:00
Simon Pilgrim 9a14c369c4 [X86] Replace avx512f integer add reduction builtins with generic builtin
D124741 added the generic "__builtin_reduce_add" which we can use to replace the x86 specific integer add reduction builtins - internally these were mapping to the same intrinsic already so there are no test changes required.

Differential Revision: https://reviews.llvm.org/D124757
2022-05-02 14:39:17 +01:00
Erich Keane 0c31da4838 Revert "Deferred Concept Instantiation Implementation"
This reverts commit 4b6c2cd647.

The patch caused numerous ARM 32 bit build failures, since we added a
5th item to the PointerUnion, and went over the 2-bits available in the
32 bit pointers.
2022-05-02 06:25:38 -07:00
Erich Keane 4b6c2cd647 Deferred Concept Instantiation Implementation
As reported here: https://github.com/llvm/llvm-project/issues/44178

Concepts are not supposed to be instantiated until they are checked, so
this patch implements that and goes through significant amounts of work
to make sure we properly re-instantiate the concepts correctly.

Differential Revision: https://reviews.llvm.org/D119544
2022-05-02 05:49:15 -07:00
Simon Pilgrim a23291b7db [Clang] Add integer add reduction builtin
Similar to the existing bitwise reduction builtins, this lowers to a llvm.vector.reduce.add intrinsic call.

For other reductions, we've tried to share builtins for float/integer vectors, but the fadd reduction intrinsics also take a starting value argument and can either do unordered or serialized, but not reduction-trees as specified for the builtins. However we address fadd support this shouldn't affect the integer case.

(Split off from D117829)

Differential Revision: https://reviews.llvm.org/D124741
2022-05-02 11:03:25 +01:00
Balazs Benics 29dff0d4fb [analyzer] Allow CFG dumps in release builds
This is a similar commit to D124442, but for CFG dumps.
The binary size diff remained the same demonstrated in that patch.

This time I'm adding tests for demonstrating that all the dump debug
checkers work - even in regular builds without asserts.

Reviewed By: martong

Differential Revision: https://reviews.llvm.org/D124443
2022-05-02 11:48:52 +02:00
Balazs Benics 5ce7050f70 [analyzer] Allow exploded graph dumps in release builds
Historically, exploded graph dumps were disabled in non-debug builds.
It was done so probably because a regular user should not dump the
internal representation of the analyzer anyway and the dump methods
might introduce unnecessary binary size overhead.

It turns out some of the users actually want to dump this.

Note that e.g. `LiveExpressionsDumper`, `LiveVariablesDumper`,
`ControlDependencyTreeDumper` etc. worked previously, and they are
unaffected by this change.
However, `CFGViewer` and `CFGDumper` still won't work for a similar
reason. AFAIK only these two won't work after this change.

Addresses #53873

---

**baseline**

| binary | size | size after strip |
| clang | 103M | 83M |
| clang-tidy | 67M | 54M |

**after this change**

| binary | size | size after strip |
| clang | 103M | 84M |
| clang-tidy | 67M | 54M |

CMake configuration:
```
cmake -S llvm -GNinja -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=Release
-DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang
-DLLVM_ENABLE_ASSERTIONS=OFF -DLLVM_USE_LINKER=lld
-DLLVM_ENABLE_DUMP=OFF -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra"
-DLLVM_ENABLE_Z3_SOLVER=ON -DLLVM_TARGETS_TO_BUILD="X86"
```
Built by `clang-14.0.0`.

Reviewed By: martong

Differential Revision: https://reviews.llvm.org/D124442
2022-05-02 11:42:08 +02:00
Balazs Benics fd7efe33f1 [analyzer] Fix cast evaluation on scoped enums in ExprEngine
We ignored the cast if the enum was scoped.
This is bad since there is no implicit conversion from the scoped enum to the corresponding underlying type.

The fix is basically: isIntegralOrEnumerationType() -> isIntegralOr**Unscoped**EnumerationType()

This materialized in crashes on analyzing the LLVM itself using the Z3 refutation.
Refutation synthesized the given Z3 Binary expression (`BO_And` of `unsigned char` aka. 8 bits
and an `int` 32 bits) with the wrong bitwidth in the end, which triggered an assert.

Now, we evaluate the cast according to the standard.

This bug could have been triggered using the Z3 CM according to
https://bugs.llvm.org/show_bug.cgi?id=44030

Fixes #47570 #43375

Reviewed By: martong

Differential Revision: https://reviews.llvm.org/D85528
2022-05-02 10:54:26 +02:00
owenca c8603db071 [clang-format] Fix a bug that misformats Access Specifier after *[]
Fixes #55132.

Differential Revision: https://reviews.llvm.org/D124589
2022-05-02 01:39:26 -07:00
Balazs Benics 464c9833df [analyzer][docs] Document alpha.security.cert.pos.34c limitations
Reviewed By: martong

Differential Revision: https://reviews.llvm.org/D124659
2022-05-02 10:37:23 +02:00
Balazs Benics 5a2e595eb8 [analyzer] Fix Static Analyzer g_memdup false-positive
`g_memdup()` allocates and copies memory, thus we should not assume that
the returned memory region is uninitialized because it might not be the
case.

PS: It would be even better to copy the bindings to mimic the actual
content of the buffer, but this works too.

Fixes #53617

Reviewed By: martong

Differential Revision: https://reviews.llvm.org/D124436
2022-05-02 10:35:51 +02:00
Ben Shi 42fa5bae7a [clang][preprocessor] Add more macros to target AVR
Reviewed By: MaskRay, aykevl

Differential Revision: https://reviews.llvm.org/D124157
2022-05-02 04:37:57 +00:00
Brad Smith a132e527f2 [Driver][Ananas] -r: imply -nostdlib like GCC
Similar to D116843 for Gnu.cpp

Reviewed By: zhmu, MaskRay

Differential Revision: https://reviews.llvm.org/D124729
2022-05-02 00:28:14 -04:00
Fangrui Song 6cfcfbdc95 [Driver][test] Remove unneeded -no-canonical-prefixes and use preferred --target=
Similar to D119309
2022-05-01 20:44:13 -07:00
Stanislav Gatev 955a05a278 [clang][dataflow] Optimize flow condition representation
Enable efficient implementation of context-aware joining of distinct
boolean values. It can be used to join distinct boolean values while
preserving flow condition information.

Flow conditions are represented as Token <=> Clause iff formulas. To
perform context-aware joining, one can simply add the tokens of flow
conditions to the formula when joining distinct boolean values, e.g:
`makeOr(makeAnd(FC1, Val1), makeAnd(FC2, Val2))`. This significantly
simplifies the implementation of `Environment::join`.

This patch removes the `DataflowAnalysisContext::getSolver` method.
The `DataflowAnalysisContext::flowConditionImplies` method should be
used instead.

Reviewed-by: ymandel, xazax.hun

Differential Revision: https://reviews.llvm.org/D124395
2022-05-01 16:25:29 +00:00
Andrew Ng 57c55165eb [analyzer] Fix return of llvm::StringRef to destroyed std::string
This issue was discovered whilst testing with ASAN.

Differential Revision: https://reviews.llvm.org/D124683
2022-05-01 12:24:32 +01:00
sstwcw 43c146c96d [clang-format] Take out common code for parsing blocks NFC
Differential Revision: https://reviews.llvm.org/D121757
2022-05-01 08:58:40 +00:00
Aaron Ballman 786954db06 Accept -fno-knr-functions as a driver flag as well
Due to a think-o, it was only being accepted as a -cc1 flag. This adds
the proper forwarding from the driver to the frontend and adds test
coverage for the option.
2022-04-30 13:37:55 -04:00
Aaron Ballman a9d68a5524 Generalize calls to ImplicitlyDefineFunction
In C++ and C2x, we would avoid calling ImplicitlyDefineFunction at all,
but in OpenCL mode we would still call the function and have it produce
an error diagnostic. Instead, we now have a helper function to
determine when implicit function definitions are allowed and we use
that to determine whether to call ImplicitlyDefineFunction so that the
behavior is more consistent across language modes.

This changes the diagnostic behavior from telling the users that an
implicit function declaration is not allowed in OpenCL to reporting use
of an unknown identifier and going through typo correction, as done in
C++ and C2x.
2022-04-30 10:03:51 -04:00
Sam McCall 816399cac2 Reland [clangd] More precisely enable clang warnings through ClangTidy options
This reverts commit 26c82f3d1d.

When tests enable 'Checks: *', we may get extra diagnostics.
2022-04-30 11:07:11 +02:00
NAKAMURA Takumi a60ef98bb1 ClangDriverTests:ToolChainTest.cpp: Fix warnings. [-Wsign-compare]
EXPECT_EQ(num,num) is aware of signedness, even if rhs is a constant.
2022-04-30 17:19:26 +09:00
Kito Cheng 41b951c929 [RISCV] Fix int16 -> __fp16 conversion code gen
clang emit wrong code sequence for `int16`(`short`) to `__fp16` conversion,
and that should fix the code gen directly is the right way I think,
but I found there is a FIXME comment in clang/Basic/TargetInfo.h say
that's should be removed in future so I think just let swich to using
generic LLVM IR rather than llvm.convert.to.fp16 intrinsics code gen
path is enough.

```
  /// Check whether llvm intrinsics such as llvm.convert.to.fp16 should be used
  /// to convert to and from __fp16.
  /// FIXME: This function should be removed once all targets stop using the
  /// conversion intrinsics.
  virtual bool useFP16ConversionIntrinsics() const {
    return true;
  }
```

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D124509
2022-04-30 11:10:44 +08:00
Kito Cheng 02c7de3a4c [RISCV] Precommit test for D124509
Test case to show the wrong code gen for `int16` -> `__fp16` conversion,
clang just emit a load and store without did conversion in the case,

and another case used for demonstrate the code gen change of `__fp16`
-> `int16`.

Reviewed By: khchen

Differential Revision: https://reviews.llvm.org/D124510
2022-04-30 11:09:12 +08:00
Joseph Huber 9f7ac522ae [OpenMP] Fix printing commands twice in verbose mode
Summary:
A previous patch merged the command execution and printing into a helper
function. The old printing code wasn't removed causing each to be
printed twice.
2022-04-29 23:06:22 -04:00
Nico Weber 26c82f3d1d Revert "[clangd] More precisely enable clang warnings through ClangTidy options"
This reverts commit 5227be8b6a.
Broke check-clangd, see comment on https://reviews.llvm.org/D124679
2022-04-29 20:34:10 -04:00
joker881 19978e0874 [RISCV]Add CTZ Intrinsic for ZBB in Clang
Add Intrinsics and test for B extension (updating coming soon (:

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D124348
2022-04-30 08:18:10 +08:00
python3kgae 73417c5176 [HLSL][clang][Driver] Support validator version command line option.
The DXIL validator version option(/validator-version) decide the validator version when compile hlsl.
The format is major.minor like 1.0.

In normal case, the value of validator version should be got from DXIL validator. Before we got DXIL validator ready for llvm/main, DXIL validator version option is added first to set validator version.

It will affect code generation for DXIL, so it is treated as a code gen option.

A new member std::string DxilValidatorVersion is added to clang::CodeGenOptions.

Then CGHLSLRuntime is added to clang::CodeGenModule.
It is used to translate clang::CodeGenOptions::DxilValidatorVersion into a ModuleFlag under key "dx.valver" at end of clang code generation.

Reviewed By: beanz

Differential Revision: https://reviews.llvm.org/D123884
2022-04-29 16:48:08 -07:00
Petr Hosek 4bdb505d62 [Driver] Support for compressed debug info on Fuchsia
Pass the --compress-debug-sections=zlib argument to the linker when
the use of compressed debug info is requested.

Differential Revision: https://reviews.llvm.org/D114115
2022-04-29 15:38:51 -07:00
Aaron Puchert 0314dbac02 Thread safety analysis: Don't pass capability kind where not needed (NFC)
If no capability is held, or the capability expression is invalid, there
is obviously no capability kind and so none would be reported.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D124132
2022-04-29 22:30:33 +02:00
Aaron Puchert f8afb8fded Thread safety analysis: Store capability kind in CapabilityExpr
This should make us print the right capability kind in many more cases,
especially when attributes name multiple capabilities of different kinds.

Previously we were trying to deduce the capability kind from the
original attribute, but most attributes can name multiple capabilities,
which could be of different kinds. So instead we derive the kind when
translating the attribute expression, and then store it in the returned
CapabilityExpr. Then we can extract the corresponding capability name
when we need it, which saves us lots of plumbing and almost guarantees
that the name is right.

I didn't bother adding any tests for this because it's just a usability
improvement and it's pretty much evident from the code that we don't
fall back to "mutex" anymore (save for a few cases that I'll address in
a separate change).

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D124131
2022-04-29 22:30:33 +02:00
Aaron Puchert d65c922450 Thread safety analysis: Store CapabilityExprs in ScopedLockableFactEntry (NFC)
For now this doesn't make a whole lot of sense, but it will allow us to
store the capability kind in a CapabilityExpr and make sure it doesn't
get lost. The capabilities managed by a scoped lockable can of course be
of different kind, so we'll need to store that per entry.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D124128
2022-04-29 22:30:33 +02:00
Aaron Puchert dd1790cd05 Thread safety analysis: Pack CapabilityExpr using PointerIntPair (NFC)
We're storing these quite frequently: FactEntry inherits from
CapabilityExpr, and the FactManager has a vector of such entries.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D124127
2022-04-29 22:30:33 +02:00
Sam McCall 5227be8b6a [clangd] More precisely enable clang warnings through ClangTidy options
clang-tidy's behavior is to add the -W flags, and then map all clang diagnostics
to "clang-diagnostic-foo" pseudo-check-names, then use Checks to filter those.

Previous to this patch, we were handling -W flags but not filtering the
diagnostics, assuming both sets of information encoded the same thing.

However this intersection is nontrivial when diagnostic group hierarchy is
involved. e.g. -Wunused + clang-diagnostic-unused-function should not enable
unused label warnings.

This patch more closely emulates clang-tidy's behavior, while not going to
the extreme of generating tidy check names for all clang diagnostics and
filtering them with regexes.

Differential Revision: https://reviews.llvm.org/D124679
2022-04-29 22:24:34 +02:00
Joe Nash 8bdfc73f63 [AMDGPU][clang] Definition of gfx11 subtarget
Contributors:
Jay Foad <jay.foad@amd.com>
Konstantin Zhuravlyov <kzhuravl_dev@outlook.com>

Patch 2/N for upstreaming of AMDGPU gfx11 architecture

Depends on D124536

Reviewed By: foad, kzhuravl, #amdgpu, arsenm

Differential Revision: https://reviews.llvm.org/D124537
2022-04-29 13:55:56 -04:00
Bill Wendling 6f79700830 [randstruct] Automatically randomize a structure of function pointers
Strutures of function pointers are a good surface area for attacks. We
should therefore randomize them unless explicitly told not to.

Reviewed By: aaron.ballman, MaskRay

Differential Revision: https://reviews.llvm.org/D123544
2022-04-29 11:05:09 -07:00
Aaron Ballman ef87865b98 Silence -Wstrict-prototype diagnostics in C2x mode
This also disables the diagnostic when the user passes -fno-knr-functions.
2022-04-29 13:37:33 -04:00