Commit Graph

96532 Commits

Author SHA1 Message Date
Balazs Benics b8e1da0506 [analyzer] Initialize ShouldEmitErrorsOnInvalidConfigValue analyzer option
Downstream users who doesn't make use of the clang cc1 frontend for
commandline argument parsing, won't benefit from the Marshalling
provided default initialization of the AnalyzerOptions entries. More
about this later.
Those analyzer option fields, as they are bitfields, cannot be default
initialized at the declaration (prior c++20), hence they are initialized
at the constructor.
The only problem is that `ShouldEmitErrorsOnInvalidConfigValue` was
forgotten.

In this patch I'm proposing to initialize that field with the rest.

Note that this value is read by
`CheckerRegistry.cpp:insertAndValidate()`.
The analyzer options are initialized by the marshalling at
`CompilerInvocation.cpp:GenerateAnalyzerArgs()` by the expansion of the
`ANALYZER_OPTION_WITH_MARSHALLING` xmacro to the appropriate default
value regardless of the constructor initialized list which I'm touching.
Due to that this only affects users using CSA as a library, without
serious effort, I believe we cannot test this.

Reviewed By: martong

Differential Revision: https://reviews.llvm.org/D133851
2022-09-14 16:45:44 +02:00
Joseph Huber 194ec844f5 [OpenMP][AMDGPU] Link bitcode ROCm device libraries per-TU
Previously, we linked in the ROCm device libraries which provide math
and other utility functions late. This is not stricly correct as this
library contains several flags that are only set per-TU, such as fast
math or denormalization. This patch changes this to pass the bitcode
libraries per-TU using the same method we use for the CUDA libraries.
This has the advantage that we correctly propagate attributes making
this implementation more correct. Additionally, many annoying unused
functions were not being fully removed during LTO. This lead to
erroneous warning messages and remarks on unused functions.

I am not sure if not finding these libraries should be a hard error. let
me know if it should be demoted to a warning saying that some device
utilities will not work without them.

Reviewed By: JonChesterfield

Differential Revision: https://reviews.llvm.org/D133726
2022-09-14 09:42:06 -05:00
Joseph Huber 2d26ecb1fb [OpenMP] Remove simplified device runtime handling
The old device runtime had a "simplified" version that prevented many of
the runtime features from being initialized. The old device runtime was
deleted in LLVM 14 and is no longer in use. Selectively deactivating
features is now done using specific flags rather than the old technique.
This patch simply removes the extra logic required for handling the old
simple runtime scheme.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D133802
2022-09-14 09:41:50 -05:00
Azat Khuzhin 44075cc34a [test][clang] run test for lld emitting dwarf-aranages only if lld is presented
Fixes: https://reviews.llvm.org/D133092
CI: https://lab.llvm.org/buildbot/#/builders/109/builds/46592

Reviewed By: hokein

Differential Revision: https://reviews.llvm.org/D133841
2022-09-14 10:17:03 +02:00
Timm Bäder a8843643cd [clang][Interp] Remove struct from a testcase
This should fix the leak sanitizer breakage introduced by
https://reviews.llvm.org/D132997, e.g.
https://lab.llvm.org/buildbot/#/builders/5/builds/27410
2022-09-14 09:44:01 +02:00
Chuanqi Xu 1c0a90fd47 [C++20] [Coroutines] Prefer sized deallocation in promise_type
Now when the compiler can't find the sized deallocation function
correctly in promise_type if there are multiple deallocation function
overloads there.

According to [dcl.fct.def.coroutine]p12:
> If both a usual deallocation function with only a pointer parameter
> and a usual deallocation function with both a pointer parameter and a
> size parameter are found, then the selected deallocation function
> shall be the one with two parameters.

So when there are multiple deallocation functions, the compiler should
choose the sized one instead of the unsized one. The patch fixes this.
2022-09-14 15:07:31 +08:00
Xiang Li f712c0131f [HLSL]Add -O and -Od option for dxc mode.
Two new dxc mode options -O and -Od are added for dxc mode.
-O is just alias of existing cc1 -O option.
-Od will be lowered into -O0 and -dxc-opt-disable.

-dxc-opt-disable is cc1 option added to for build ShaderFlags.

Reviewed By: beanz

Differential Revision: https://reviews.llvm.org/D128845
2022-09-13 21:26:18 -07:00
Alexander Shaposhnikov b6965f7246 [IR] Add alignment for llvm.threadlocal.address
This diff sets the alignment attribute for the return value
and the argument of llvm.threadlocal.address.

(https://github.com/llvm/llvm-project/issues/57438)

Test plan: ninja check-all

Differential revision: https://reviews.llvm.org/D133741
2022-09-13 23:10:55 +00:00
Argyrios Kyrtzidis b340c5ae42 [Lex/DependencyDirectivesScanner] Handle the case where the source line starts with a `tok::hashhash`
Differential Revision: https://reviews.llvm.org/D133674
2022-09-13 15:48:50 -07:00
Azat Khuzhin 6bf6730ac5 [clang] fix generation of .debug_aranges with LTO
Right now in case of LTO the section is not emited:

    $ cat test.c
    void __attribute__((optnone)) bar()
    {
    }
    void __attribute__((optnone)) foo()
    {
            bar();
    }
    int main()
    {
            foo();
    }

    $ clang -flto=thin -gdwarf-aranges -g -O3 test.c
    $ eu-readelf -waranges a.out  | fgrep -c -e foo -e bar
    0

    $ clang -gdwarf-aranges -g -O3 test.c
    $ eu-readelf -waranges a.out  | fgrep -c -e foo -e bar
    2

Fix this by passing explicitly -mllvm -generate-arange-section.

P.S. although this looks like a hack, since none of -mllvm was passed to
the lld before.

Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
Suggested-by: OCHyams <orlando.hyams@sony.com>

Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D133092
2022-09-13 22:33:56 +00:00
Chris Bieneman 0c9b242cf0 [HLSL] Adding a test change I forgot to add
This test just verifies that even at -O0 the buffer subscript operators
are inlined. The original change was
fb5baffc28.
2022-09-13 20:53:39 -05:00
Chris Bieneman fb5baffc28 [HLSL] Mark buffer subscript operators as AlwaysInline
HLSL requires aggressive inlineing for resource accesses. This just
enforces that we get resource handle accesses inlined early.
2022-09-13 20:31:29 -05:00
Evgeny Shulgin 67f08bf1bf [Clang] [Sema] Ignore invalid multiversion function redeclarations
If a redeclaration of a multiversion function is invalid,
it may be in a broken condition (for example, missing an important
attribute). We shouldn't analyze invalid redeclarations.

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

Reviewed By: tahonermann

Differential Revision: https://reviews.llvm.org/D133641
2022-09-13 20:12:09 +00:00
Chris Bieneman a8a49923dd [HLSL] Call global destructors from entries
HLSL doesn't have a C++ runtime that supports `atexit` registration. To
enable global destructors we instead rely on the `llvm.global_dtor`
mechanism.

This change disables `atexit` generation for HLSL and updates the HLSL
code generation to call global destructors on the exit from entry
functions.

Depends on D132977.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D133518
2022-09-13 15:05:47 -05:00
Aaron Ballman b8266f512a Correct the __has_c_attribute value for fallthrough
The original proposal was seen in Apr 2019 and we accidentally used
that date (201904L) as the feature testing value. However, WG14 N2408
was adopted at the Oct 2019 meeting and so that's the correct date for
the feature testing macro. The committee draft for C2x shows 201910L
for this value, so this changes brings us in line with the standard.
2022-09-13 11:08:58 -04:00
Aaron Ballman 843d074400 Update the C Status page for the Clang 15 release
Now that Clang 15 is out, we can swap all the unreleased entries over.
2022-09-13 09:36:54 -04:00
Aaron Ballman 0f28cf416d Correct the __has_c_attribute value for maybe_unused
The original proposal was adopted in Apr 2019, but was subsequently
updated by WG14 N2662 in June 2021. We already supported the attribute
on a label and it behaved as expected, but we had not bumped the
feature test value.
2022-09-13 09:33:20 -04:00
Aaron Ballman 1b19df12b8 Correct the __has_c_attribute value for nodiscard
The original proposal was adopted in Apr 2019 and so the previous value
was 201904L. However, a subsequent proposal (N2448) was adopted to add
an optional message argument to the attribute. We already support that
functionality, but had not bumped the feature test value.
2022-09-13 08:13:01 -04:00
Animesh Kumar 7f57b646d1 [OpenMP] Extend lit test for parallel for simd construct
This construct is being tested for atomic operation based upon
the test 5.0/parallel_for_simd/test_parallel_for_simd_atomic.c
from the SOLLVE repo: https://github.com/SOLLVE/sollve_vv

Differential Revision: https://reviews.llvm.org/D132643
2022-09-13 17:07:11 +05:30
Alexander Kornienko 637da9de4c Revert "[clang] template / auto deduction deduces common sugar"
This reverts commit d200db3863, which causes a
clang crash. See https://reviews.llvm.org/D111283#3785755

Test case for convenience:
```
template <typename T>
using P = int T::*;

template <typename T, typename... A>
void j(P<T>, T, A...);

template <typename T>
void j(P<T>, T);

struct S {
  int b;
};
void g(P<S> k, S s) { j(k, s); }
```
2022-09-13 12:18:07 +02:00
Sven van Haastregt 5a7764c9ff [OpenCL] Guard depth image builtins
Ensure any uses of `image2d_depth_t` and `image2d_array_depth_t` are
guarded behind the `cl_khr_depth_images` extension in
`OpenCLBuiltins.td`.

Fix a few missing guards in `opencl-c.h`.
2022-09-13 10:10:48 +01:00
Sylvestre Ledru cd20a18286 Revert "[clang, llvm] Add __declspec(safebuffers), support it in CodeView"
Causing:
https://github.com/llvm/llvm-project/issues/57709

This reverts commit ab56719acd.
2022-09-13 10:53:59 +02:00
Timm Bäder 53d8687a13 [clang][Interp][NFC] Use constexpr if in OffsetHelper
Add is a template parameter, so we can use constexpr if here.
2022-09-13 10:41:34 +02:00
Timm Bäder b02f6890f5 [clang][Interp][NFC] InterpFrame::getParam can be const
Make stackRef() const as well and use that.
2022-09-13 10:41:28 +02:00
Timm Bäder 5d2451468c [clang][Interp][NFC] InterpFrame::getLocal() can be const
Make localRef() const and use that.
2022-09-13 10:41:24 +02:00
Timm Bäder f756ddba17 [clang][Interp][NFC] InterpFrame: localBlock() can be const 2022-09-13 10:41:18 +02:00
Timm Bäder 9b087a70e6 [clang][Interp][NFC] Forward-declare Pointer in PrimType header
No need to include the full Pointer.h here.
2022-09-13 10:40:52 +02:00
Timm Bäder bf3efa8b16 [clang][Interp] Handle DeclRefExpr of reference types
References are implemented through pointers, so we need a second deref
when encountering a DeclRefExpr of a reference type.

Differential Revision: https://reviews.llvm.org/D132997
2022-09-13 10:40:51 +02:00
Martin Storsjö fbfe1db4a9 [clang] Explicitly set the EmulatedTLS codegen option. NFC.
Set the EmulatedTLS option based on `Triple::hasDefaultEmulatedTLS()`
if the user didn't specify it; set `ExplicitEmulatedTLS` to true
in `llvm::TargetOptions` and set `EmulatedTLS` to Clang's
opinion of what the default or preference is.

This avoids any risk of deviance between the two.

This affects one check of `getCodeGenOpts().EmulatedTLS` in
`shouldAssumeDSOLocal` in CodeGenModule, but as that check only
is done for `TT.isWindowsGNUEnvironment()`, and
`hasDefaultEmulatedTLS()` returns false for such environments
it doesn't make any current testable difference - thus NFC.

Some mingw distributions carry a downstream patch, that enables
emulated TLS by default for mingw targets in `hasDefaultEmulatedTLS()`
- and for such cases, this patch does make a difference and fixes the
detection of emulated TLS, if it is implicitly enabled.

Differential Revision: https://reviews.llvm.org/D132916
2022-09-13 10:40:54 +03:00
Balazs Benics 7cddf9cad1 [analyzer] Dump the environment entry kind as well
By this change the `exploded-graph-rewriter` will display the class kind
of the expression of the environment entry. It makes easier to decide if
the given entry corresponds to the lvalue or to the rvalue of some
expression.

It turns out the rewriter already had support for visualizing it, but
probably was never actually used?

Reviewed By: martong

Differential Revision: https://reviews.llvm.org/D132109
2022-09-13 09:04:27 +02:00
Balazs Benics afcd862b2e [analyzer] LazyCompoundVals should be always bound as default bindings
`LazyCompoundVals` should only appear as `default` bindings in the
store. This fixes the second case in this patch-stack.

Depends on: D132142

Reviewed By: xazax.hun

Differential Revision: https://reviews.llvm.org/D132143
2022-09-13 08:58:46 +02:00
Balazs Benics f8643a9b31 [analyzer] Prefer wrapping SymbolicRegions by ElementRegions
It turns out that in certain cases `SymbolRegions` are wrapped by
`ElementRegions`; in others, it's not. This discrepancy can cause the
analyzer not to recognize if the two regions are actually referring to
the same entity, which then can lead to unreachable paths discovered.

Consider this example:

```lang=C++
struct Node { int* ptr; };
void with_structs(Node* n1) {
  Node c = *n1; // copy
  Node* n2 = &c;
  clang_analyzer_dump(*n1); // lazy...
  clang_analyzer_dump(*n2); // lazy...
  clang_analyzer_dump(n1->ptr); // rval(n1->ptr): reg_$2<int * SymRegion{reg_$0<struct Node * n1>}.ptr>
  clang_analyzer_dump(n2->ptr); // rval(n2->ptr): reg_$1<int * Element{SymRegion{reg_$0<struct Node * n1>},0 S64b,struct Node}.ptr>
  clang_analyzer_eval(n1->ptr != n2->ptr); // UNKNOWN, bad!
  (void)(*n1);
  (void)(*n2);
}
```

The copy of `n1` will insert a new binding to the store; but for doing
that it actually must create a `TypedValueRegion` which it could pass to
the `LazyCompoundVal`. Since the memregion in question is a
`SymbolicRegion` - which is untyped, it needs to first wrap it into an
`ElementRegion` basically implementing this untyped -> typed conversion
for the sake of passing it to the `LazyCompoundVal`.
So, this is why we have `Element{SymRegion{.}, 0,struct Node}` for `n1`.

The problem appears if the analyzer evaluates a read from the expression
`n1->ptr`. The same logic won't apply for `SymbolRegionValues`, since
they accept raw `SubRegions`, hence the `SymbolicRegion` won't be
wrapped into an `ElementRegion` in that case.

Later when we arrive at the equality comparison, we cannot prove that
they are equal.

For more details check the corresponding thread on discourse:
https://discourse.llvm.org/t/are-symbolicregions-really-untyped/64406

---

In this patch, I'm eagerly wrapping each `SymbolicRegion` by an
`ElementRegion`; basically canonicalizing to this form.
It seems reasonable to do so since any object can be thought of as a single
array of that object; so this should not make much of a difference.

The tests also underpin this assumption, as only a few were broken by
this change; and actually fixed a FIXME along the way.

About the second example, which does the same copy operation - but on
the heap - it will be fixed by the next patch.

Reviewed By: martong

Differential Revision: https://reviews.llvm.org/D132142
2022-09-13 08:58:46 +02:00
Chuanqi Xu 79fa0ec8c4 [C++20] [Modules] Make member functions with a in-class definition in HU implicitly inline
According to [dcl.inline]p7/note4,

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

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

This fixes https://github.com/llvm/llvm-project/issues/57571.
2022-09-13 13:11:56 +08:00
Fangrui Song 6f9c4851ab [MinGW] Reject explicit hidden visibility applied to dllexport and hidden/protected applied to dllimport
Hidden visibility is incompatible with dllexport.
Hidden and protected visibilities are incompatible with dllimport.
(PlayStation uses dllexport protected.)

When an explicit visibility attribute applies on a dllexport/dllimport
declaration, report a Frontend error (Sema does not compute visibility).

Reviewed By: mstorsjo

Differential Revision: https://reviews.llvm.org/D133266
2022-09-12 15:56:36 -07:00
David Majnemer ab56719acd [clang, llvm] Add __declspec(safebuffers), support it in CodeView
__declspec(safebuffers) is equivalent to
__attribute__((no_stack_protector)).  This information is recorded in
CodeView.

While we are here, add support for strict_gs_check.
2022-09-12 21:15:34 +00:00
Ben Langmuir 4a72459ed6 Revert "[clang][test] Disallow using the default module cache path in lit tests"
This reverts commit d96f526196.

Some systems do not support `env -u`.
2022-09-12 13:10:22 -07:00
Richard Howell 3c1b42347b [clang] sort additional module maps when serializing
Sort additional module maps when serializing pcm files. This ensures
the `MODULE_MAP_FILE` record is deterministic across repeated builds.

Reviewed By: benlangmuir

Differential Revision: https://reviews.llvm.org/D133611
2022-09-12 12:00:43 -07:00
Corentin Jabot 7eead180b9 [Clang] NFC: Make UnqualifiedId::Kind private for consistency.
Differential Revision: https://reviews.llvm.org/D133703
2022-09-12 19:14:06 +02:00
Ben Langmuir d96f526196 [clang][test] Disallow using the default module cache path in lit tests
Make the default module cache path invalid when running lit tests so
that tests are forced to provide a cache path. This avoids accidentally
escaping to the system default location, and would have caught the
failure recently found in ClangScanDeps/multiple-commands.c.

Differential Revision: https://reviews.llvm.org/D133622
2022-09-12 09:54:56 -07:00
Jun Zhang 1d51bb824f
[Clang] Reword diagnostic for scope identifier with linkage
If the declaration of an identifier has block scope, and the identifier has
external or internal linkage, the declaration shall have no initializer for
the identifier.

Clang now gives a more suitable diagnosis for this case.
Fixes https://github.com/llvm/llvm-project/issues/57478

Signed-off-by: Jun Zhang <jun@junz.org>

 Differential Revision: https://reviews.llvm.org/D133088
2022-09-12 22:40:54 +08:00
Jonas Hahnfeld f0403c853b Fix build of Lex unit test with CLANG_DYLIB
If CLANG_LINK_CLANG_DYLIB, clang_target_link_libraries ignores all
indivial libraries and only links clang-cpp. As LLVMTestingSupport
is separate, pass it via target_link_libraries directly.
2022-09-12 13:49:57 +02:00
Muhammad Usman Shahid ea26ed1f9c Rewording note note_constexpr_invalid_cast
The diagnostics here are correct, but the note is really silly. It
talks about reinterpret_cast in C code. So rewording it for c mode by
using another %select{}.
```
int array[(long)(char *)0];
```
previous note:
```
cast that performs the conversions of a reinterpret_cast is not allowed in a constant expression
```
reworded note:
```
this conversion is not allowed in a constant expression
```

Differential Revision: https://reviews.llvm.org/D133194
2022-09-12 07:47:39 -04:00
owenca 5889ed83a0 [clang-format] Don't insert braces for loops with a null statement
This is a workaround for #57539.

Fixes #57509.

Differential Revision: https://reviews.llvm.org/D133635
2022-09-12 00:37:47 -07:00
Corentin Jabot 0e8afddaa1 [Clang] NFC: Remove duplicated variable def in CheckLValueConstantExpression 2022-09-10 19:10:23 +02:00
Rainer Orth 1e56821bac [Linux] Hack around Linux/sparc <bits/stdio-ldbl.h>
I've been using this hack to work around the Linux/sparc64 compile failure
described in Issue #47994
<https://github.com/llvm/llvm-project/issues/47994>, especially since the
underlying glibc PR build/27558
<https://sourceware.org/bugzilla/show_bug.cgi?id=27558> doesn't seem to be
making progress and some fix is required to have LLVM build on
`sparc64-unknown-linux-gnu` at all, as evidenced on the buildbot.

Tested on `sparc64-unknown-linux-gnu`.

Differential Revision: https://reviews.llvm.org/D133405
2022-09-10 09:37:35 +02:00
Mohammed Keyvanzadeh 467bb47c84
[clang][cmake] Remove extra brace
Remove the extra trailing brace from the local variable accessor.

Differential Revision: https://reviews.llvm.org/D133613
2022-09-10 05:00:23 +04:30
Bruno Cardoso Lopes f4a13c9c0a [Clang][ScanDeps] Change multiple-commands.c test to use -fmodules-cache-path on implicit builds
The module cache escapes the test output dirs in this test. Since its default location maybe
composed of system and user related path this can cause problems in some builders (e.g. not
accessible paths inherited in a chroot environment).

Clean the test a bit by passing `-fmodules-cache-path` inside the test output dirs.

Differential Revision: https://reviews.llvm.org/D133617
2022-09-09 16:20:04 -07:00
Xiang Li 71fae33f5e [NFC] Cleanup test for D132913 Preserve vec3 for HLSL
Support number for parameter test added in
https://reviews.llvm.org/D132913
2022-09-09 15:04:59 -07:00
Xiang Li c9d2b6b92d [HLSL] Preserve vec3 for HLSL.
Preserve vec3 for HLSL by set -fpreserve-vec3-type.

Reviewed By: beanz

Differential Revision: https://reviews.llvm.org/D132913
2022-09-09 10:55:45 -07:00
Jamie Schmeiser 5e3ac79690 Loop names used in reporting can grow very large
Summary:
The code for generating a name for loops for various reporting scenarios
created a name by serializing the loop into a string.  This may result in
a very large name for a loop containing many blocks.  Use the getName()
function on the loop instead.

Author: Jamie Schmeiser <schmeise@ca.ibm.com>
Reviewed By: Whitney (Whitney Tsang), aeubanks (Arthur Eubanks)
Differential Revision: https://reviews.llvm.org/D133587
2022-09-09 13:45:14 -04:00
Yitzhak Mandelbaum abc16c7a5b [NFC] Remove a FIXME fixed by an earlier patch.
Commit 28bd7945ea incidentally fixed the
associated FIXME, but didn't delete it.

Differential Revision: https://reviews.llvm.org/D133588
2022-09-09 17:13:52 +00:00
Steven Wu 493766e068 Frontend: Respect -working-directory when checking if output files can be written
Call `FixupRelativePath` when opening output files to ensure that
`-working-directory` is used when checking up front for write failures,
not just when finalizing the files at the end. This also moves the
temporary file into the same directory as the output file.

Reviewed By: benlangmuir

Differential Revision: https://reviews.llvm.org/D95497
2022-09-09 08:57:12 -07:00
mydeveloperday 28bd7945ea [clang-format] NFC remove incorrect whitespace causing documentation issue 2022-09-09 16:03:48 +01:00
Chris Bieneman d3c54a172d [HLSL] Call global constructors inside entry
HLSL doesn't have a runtime loader model that supports global
construction by a loader or runtime initializer. To allow us to leverage
global constructors with minimal code generation impact we put calls to
the global constructors inside the generated entry function.

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

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

Differential Revision: https://reviews.llvm.org/D132867
2022-09-09 16:28:51 +07:00
Vitaly Buka 7dc0734567 [msan] Insert simplification passes after instrumentation
This resolves TODO from D96406.
InstCombine issue is fixed with D133394.

Save 4.5% of .text on CTMark.
2022-09-09 00:33:04 -07:00
Alvin Wong a3a8bd00c8 [clang][MinGW] Add `-mguard=cf` and `-mguard=cf-nochecks`
This option can be used to enable Control Flow Guard checks and
generation of address-taken function table. They are equivalent to
`/guard:cf` and `/guard:cf,nochecks` in clang-cl. Passing this flag to
the Clang driver will also pass `--guard-cf` to the MinGW linker.

This feature is disabled by default. The option `-mguard=none` is also
available to explicitly disable this feature.

Reviewed By: rnk

Differential Revision: https://reviews.llvm.org/D132810
2022-09-09 09:55:40 +03:00
Vitaly Buka e261b03396 [sanitizers] Add experimental flag to insert sanitizers earlier 2022-09-08 19:05:17 -07:00
Fangrui Song d8c09b7bbc Revert D111509 "[clang] use getCommonSugar in an assortment of places"
This reverts commit d42122cd5d.

`clang++ gcc/libstdc++-v3/src/c++98/complex_io.cc` (all language modes) crashes.
Also see https://reviews.llvm.org/D111509#3777980
2022-09-08 17:09:18 -07:00
Fangrui Song 1f6a86b309 [cc1as] Support --compress-debug-sections=zstd
`clang -gz=zstd -c a.s` generates ELFCOMPRESS_ZSTD compressed debug info
sections if compression decreases size.
2022-09-08 16:31:45 -07:00
Joe Loser 1b3a78d1d5 [clang] Use std::size instead of llvm::array_lengthof
LLVM contains a helpful function for getting the size of a C-style
array: `llvm::array_lengthof`. This is useful prior to C++17, but not as
helpful for C++17 or later: `std::size` already has support for C-style
arrays.

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

Differential Revision: https://reviews.llvm.org/D133520
2022-09-08 17:20:25 -06:00
Fangrui Song 4d4ca6c9d0 [Driver] Rename Z to Zlib 2022-09-08 16:14:31 -07:00
Fangrui Song 781dea021a [Support] Rename DebugCompressionType::Z to Zlib
"Z" was so named when we had both gABI ELFCOMPRESS_ZLIB and the legacy .zdebug support.
Now we have just one zlib format, we should use the more descriptive name.
2022-09-08 16:11:29 -07:00
Fangrui Song 48203b327d Revert D130308 "[clang] extend getCommonSugaredType to merge sugar nodes"
This reverts commit 16e5d6d7f9.
There are multiple complaints on the review.

In addition, it may cause spurious
```
error: invalid operands to binary expression ('SinkPrinter' and 'char[cluster_name_length]')
note: candidate template ignored: substitution failure: variably modified type 'char *' cannot be used as a template argument SinkPrinter operator<<(const SinkPrinter &s, T) {
```
for some C++ code
2022-09-08 15:09:39 -07:00
Fangrui Song 2f23dc9127 [AST/Interp] Fix left shift overflow bug in D64146
Noticed by Dmitri Gribenko
2022-09-08 13:49:07 -07:00
Fangrui Song 49c289879c [AST/Interp] Fix latent unitialized use of memory bug in D64146
Exposed by D132727: clang/test/AST/Interp/arrays.cpp fails with --config=msan
2022-09-08 13:39:30 -07:00
Tom Honermann 8d03328e7b [clang] NFC: Add a missing const qualifier to Decl::isLocalExternDecl(). 2022-09-08 13:21:10 -07:00
Dominic Chen ac77b3fde1 [clang][ARM][NFC] Clean up signed conversion and undefined macros in builtin header
These warnings were identified while debugging modules with Wsystem-headers.

Differential Revision: https://reviews.llvm.org/D132003
2022-09-08 12:46:08 -07:00
Matheus Izvekov 16e5d6d7f9
[clang] extend getCommonSugaredType to merge sugar nodes
This continues D111283 by extending the getCommonSugaredType
implementation to also merge non-canonical type nodes.

We merge these nodes by going up starting from the canonical
node, calculating their merged properties on the way.

If we reach a pair that is too different, or which we could not
otherwise unify, we bail out and don't try to keep going on to
the next pair, in effect striping out all the remaining top-level
sugar nodes. This avoids mismatching 'companion' nodes, such as
ElaboratedType, so that they don't end up elaborating some other
unrelated thing.

Depends on D111509

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

Differential Revision: https://reviews.llvm.org/D130308
2022-09-08 19:17:53 +02:00
Matheus Izvekov d42122cd5d
[clang] use getCommonSugar in an assortment of places
For this patch, a simple search was performed for patterns where there are
two types (usually an LHS and an RHS) which are structurally the same, and there
is some result type which is resolved as either one of them (typically LHS for
consistency).

We change those cases to resolve as the common sugared type between those two,
utilizing the new infrastructure created for this purpose.

Depends on D111283

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

Differential Revision: https://reviews.llvm.org/D111509
2022-09-08 19:17:53 +02:00
Matheus Izvekov d200db3863
[clang] template / auto deduction deduces common sugar
After upgrading the type deduction machinery to retain type sugar in
D110216, we were left with a situation where there is no general
well behaved mechanism in Clang to unify the type sugar of multiple
deductions of the same type parameter.

So we ended up making an arbitrary choice: keep the sugar of the first
deduction, ignore subsequent ones.

In general, we already had this problem, but in a smaller scale.
The result of the conditional operator and many other binary ops
could benefit from such a mechanism.

This patch implements such a type sugar unification mechanism.

The basics:

This patch introduces a `getCommonSugaredType(QualType X, QualType Y)`
method to ASTContext which implements this functionality, and uses it
for unifying the results of type deduction and return type deduction.
This will return the most derived type sugar which occurs in both X and
Y.

Example:

Suppose we have these types:
```
using Animal = int;
using Cat = Animal;
using Dog = Animal;

using Tom = Cat;
using Spike = Dog;
using Tyke = Dog;
```
For `X = Tom, Y = Spike`, this will result in `Animal`.
For `X = Spike, Y = Tyke`, this will result in `Dog`.

How it works:

We take two types, X and Y, which we wish to unify as input.
These types must have the same (qualified or unqualified) canonical
type.

We dive down fast through top-level type sugar nodes, to the
underlying canonical node. If these canonical nodes differ, we
build a common one out of the two, unifying any sugar they had.
Note that this might involve a recursive call to unify any children
of those. We then return that canonical node, handling any qualifiers.

If they don't differ, we walk up the list of sugar type nodes we dived
through, finding the last identical pair, and returning that as the
result, again handling qualifiers.

Note that this patch will not unify sugar nodes if they are not
identical already. We will simply strip off top-level sugar nodes that
differ between X and Y. This sugar node unification will instead be
implemented in a subsequent patch.

This patch also implements a few users of this mechanism:
* Template argument deduction.
* Auto deduction, for functions returning auto / decltype(auto), with
  special handling for initializer_list as well.

Further users will be implemented in a subsequent patch.

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

Differential Revision: https://reviews.llvm.org/D111283
2022-09-08 19:17:48 +02:00
Kadir Cetinkaya abd2b1a9d0
[clang] Fix a crash in constant evaluation 2022-09-08 18:21:44 +02:00
Jonas Paulsson 906ea59d00 [SystemZ] Fix new test case
Add 'REQUIRES: systemz-registered-target'.
2022-09-08 18:05:17 +02:00
Jonas Paulsson de0e3117d4 [SystemZ] Improve handling of vector alignments.
Make the DataLayout string always hold a vector alignment of 8 bytes,
regardless of the vector ABI. This makes the datalayout depend only on the
target triple which is the general expectation (in assertions).

On older architectures where vectors use the natural alignment (16 bytes),
the front end will maintain the same behavior and produce an overalignment
compared to the datalayout.

Reviewed By: uweigand

Differential Revision: https://reviews.llvm.org/D131158
2022-09-08 17:33:05 +02:00
Thomas Lively ac3b8df8f2 [WebAssembly] Prototype `f32x4.relaxed_dot_bf16x8_add_f32`
As proposed in https://github.com/WebAssembly/relaxed-simd/issues/77. Only an
LLVM intrinsic and a clang builtin are implemented. Since there is no bfloat16
type, use u16 to represent the bfloats in the builtin function arguments.

Differential Revision: https://reviews.llvm.org/D133428
2022-09-08 08:07:49 -07:00
David Spickett e428baf001 [LLVM][ARM] Remove options for armv2, 2A, 3 and 3M
Fixes #57486

These pre v4 architectures are not specifically supported
by codegen. As demonstrated in the linked issue.

GCC has not supported 3M since GCC 9 and presumably
2 and 2A earlier than that. So we are aligned in that sense.

(see https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=2abd6e34fcf3bd9f9ffafcaa47cdc3ed443f9add)

This removes the options and associated testing.

The Pre_v4 build attribute remains mainly because its absence
would be more confusing. It will not be used other than to
complete the list of build attributes as shown in the ABI.

https://github.com/ARM-software/abi-aa/blob/main/addenda32/addenda32.rst#3352the-target-related-attributes

Reviewed By: nickdesaulniers, peter.smith, rengolin

Differential Revision: https://reviews.llvm.org/D133109
2022-09-08 09:49:48 +00:00
Fangrui Song a0365abad8 [Driver] Support -gz=zstd
The driver option translates to --compress-debug-sections=zstd cc1/cc1as/GNU
assembler/linker options.

`clang -g -gz=zstd -c a.c` generates ELFCOMPRESS_ZSTD compressed debug info
sections if compression decreases size.
2022-09-08 01:39:06 -07:00
Fangrui Song 3e99b8d947 C++/ObjC++: switch to gnu++17 as the default standard
Clang's default C++ standard is now `gnu++17` instead of `gnu++14`:
https://discourse.llvm.org/t/c-objc-switch-to-gnu-17-as-the-default-standard/64360

* CUDA/HIP are unchanged: C++14 from D103221.
* Sony PS4/PS5 are unchanged: https://discourse.llvm.org/t/c-objc-switch-to-gnu-17-as-the-default-standard/64360/6
* lit feature `default-std-cxx` is added to keep CLANG_DEFAULT_STD_CXX=xxx tests working.
  Whether the cmake variable should be retained is disccused in D133375.

Depends on D131464

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

Differential Revision: https://reviews.llvm.org/D131465
2022-09-08 08:22:04 +00:00
Timm Bäder 86271798e5 [clang][Interp] Only initialize initmaps for primitive arrays
As the comment states, this code should only run for primitive arrays.

This should fix the memory sanitize builds.
2022-09-08 10:03:06 +02:00
Nikita Popov fd2475049e Revert "C++/ObjC++: switch to gnu++17 as the default standard"
This reverts commit e321c8dd2c.

This causes many failures in llvm-test-suite, for example:

    /home/npopov/repos/llvm-test-suite/build-O3/tools/timeit --summary MultiSource/Applications/lambda-0.1.3/CMakeFiles/lambda.dir/token_stream.cc.o.time /home/npopov/repos/llvm-project/build/bin/clang++ -DNDEBUG -I/home/npopov/repos/llvm-test-suite/MultiSource/Applications/lambda-0.1.3 -O3   -w -Werror=date-time -MD -MT MultiSource/Applications/lambda-0.1.3/CMakeFiles/lambda.dir/token_stream.cc.o -MF MultiSource/Applications/lambda-0.1.3/CMakeFiles/lambda.dir/token_stream.cc.o.d -o MultiSource/Applications/lambda-0.1.3/CMakeFiles/lambda.dir/token_stream.cc.o -c /home/npopov/repos/llvm-test-suite/MultiSource/Applications/lambda-0.1.3/token_stream.cc
    /home/npopov/repos/llvm-test-suite/MultiSource/Applications/lambda-0.1.3/token_stream.cc:192:2: error: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
            register char chr;
            ^~~~~~~~~
2022-09-08 09:45:50 +02:00
Timm Bäder 651f4ce7b1 [clang][Interp][NFC] Use constexpr if when possible in Integral.h 2022-09-08 07:31:08 +02:00
Timm Bäder 0da7e409e0 [clang][Interp][NFC] Context::classify() can be const 2022-09-08 07:31:08 +02:00
Timm Bäder 3a7d476087 [clang][Interp] Implement array initializers and subscript expressions
Differential Revision: https://reviews.llvm.org/D132727
2022-09-08 07:31:07 +02:00
Timm Bäder aa7c5c9c4e [clang][Interp] Handle missing local initializers better
This is illegal in a constexpr context. We can already figure that out,
but we'd still run into an assertion later on when trying to visit the
missing initializer or run the invalid function.

Differential Revision: https://reviews.llvm.org/D132832
2022-09-08 07:31:07 +02:00
Timm Bäder 5c4dbff0b6 [clang][Interp] Handle SubstNonTypeTemplateParmExprs
Differential Revision: https://reviews.llvm.org/D132831
2022-09-08 07:31:07 +02:00
Timm Bäder 4d700ffe67 [clang][Interp] Implement ImplicitValueInitExprs
Take the existing Zero opcode and emit it.

Differential Revision: https://reviews.llvm.org/D132829
2022-09-08 07:31:07 +02:00
Timm Bäder 95e6a407d9 [clang][Interp] Implement IntegralToBoolean casts
Redo how we do IntegralCasts and implement IntegralToBoolean casts using
the already existing cast op.

Differential Revision: https://reviews.llvm.org/D132739
2022-09-08 07:31:07 +02:00
Timm Bäder 8e41e6a4ea [clang][Interp] Implement function calls
Add Call() and CallVoid() ops and use them to call functions. Only
FunctionDecls are supported for now.

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

Just always do it.

Differential Revision: https://reviews.llvm.org/D132136
2022-09-08 07:31:07 +02:00
Fangrui Song bc502d9c24 Revert D133266 "[MinGW] Reject explicit non-default visibility applied to dllexport/dllimport declaration"
This reverts commit 91d8324366.

The combo dllexport protected makes sense and is used by PlayStation.
Will change the patch to allow dllexport protected.
2022-09-07 16:06:19 -07:00
Volodymyr Sapsai 3e7350f317 [ODRHash diagnostics] Move `ODRDiagsEmitter` to libAST in separate files. NFC.
Intend to use `ODRDiagsEmitter` during parsing to diagnose a parsed
definition differing from a definition with the same name from a hidden
[sub]module.

Differential Revision: https://reviews.llvm.org/D128695
2022-09-07 14:40:37 -07:00
Fangrui Song e321c8dd2c C++/ObjC++: switch to gnu++17 as the default standard
Clang's default C++ standard is now `gnu++17` instead of `gnu++14`:
https://discourse.llvm.org/t/c-objc-switch-to-gnu-17-as-the-default-dialect/64360

* CUDA/HIP are unchanged: C++14 from D103221.
* Sony PS4/PS5 are unchanged: https://discourse.llvm.org/t/c-objc-switch-to-gnu-17-as-the-default-dialect/64360/6
* lit feature `default-std-cxx` is added to keep CLANG_DEFAULT_STD_CXX=xxx tests working.
  Whether the cmake variable should be retained is disccused in D133375.

Depends on D131464

Close https://github.com/llvm/llvm-project/issues/56946

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

Differential Revision: https://reviews.llvm.org/D131465
2022-09-07 14:17:52 -07:00
Marco Elver c4842bb2e9 [Clang] Introduce -fexperimental-sanitize-metadata=
Introduces the frontend flag -fexperimental-sanitize-metadata=, which
enables SanitizerBinaryMetadata instrumentation.

The first intended user of the binary metadata emitted will be a variant
of GWP-TSan [1]. The plan is to open source a stable and production
quality version of GWP-TSan. The development of which, however, requires
upstream compiler support.

[1] https://llvm.org/devmtg/2020-09/slides/Morehouse-GWP-Tsan.pdf

Until the tool has been open sourced, we mark this kind of
instrumentation as "experimental", and reserve the option to change
binary format, remove features, and similar.

Reviewed By: vitalybuka, MaskRay

Differential Revision: https://reviews.llvm.org/D130888
2022-09-07 21:25:40 +02:00
Craig Topper cc14e195e7 [RISCV] Remove space before colon in error message. 2022-09-07 11:34:33 -07:00
Craig Topper 9ea7e4f7c1 [RISCV] Remove unnecessary word from error message. 2022-09-07 10:31:48 -07:00
Argyrios Kyrtzidis aa484c90cf [Lex/DependencyDirectivesScanner] Keep track of the presence of tokens between the last scanned directive and EOF
Directive `dependency_directives_scan::tokens_present_before_eof` is introduced to indicate there were tokens present before
the last scanned dependency directive and EOF.
This is useful to ensure we correctly identify the macro guards when lexing using the dependency directives.

Differential Revision: https://reviews.llvm.org/D133357
2022-09-07 10:31:29 -07:00
yronglin 6ed21fc515 Avoid __builtin_assume_aligned crash when the 1st arg is array type
Avoid __builtin_assume_aligned crash when the 1st arg is array type (or
string literal).

Fixes Issue #57169

Differential Revision: https://reviews.llvm.org/D133202
2022-09-07 12:46:20 -04:00
Philip Reames a4a29438f4 [RISCV][MC] Add minimal support for Ztso extension
This is a minimalist implementation which simply adds the extension (in the experimental namespace since its not ratified), and wires up the setting of the required ELF header flag. Future changes will include codegen changes to exploit the stronger memory model.

This is intended to implement v0.1 of the proposed specification which can be found in Chapter 25 of https://github.com/riscv/riscv-isa-manual/releases/download/draft-20220723-10eea63/riscv-spec.pdf.

Differential Revision: https://reviews.llvm.org/D133239
2022-09-07 09:30:57 -07:00
Sam McCall 897f3ddc61 [Sema] Move Diags.isIgnored() checks off hot paths, it's not free. NFC
This speeds up clangd's buildAST() (i.e. parsing with a preamble) by 5% on
clangd/AST.cpp, by avoiding filling up the diagnostic state map with entries for
all the files where templates are being instantiated from.

(I would assume it has a similar effect on PCH and modules compiles).

This approach is obviously pretty fragile, and we should find ways to make
isIgnored() cheaper instead. But these changes in particular don't seem to make
the code worse in any case.

Differential Revision: https://reviews.llvm.org/D129683
2022-09-07 16:18:31 +02:00
Nikita Popov 98a3a340c3 [ConstantExpr] Don't create fneg expressions
Don't create fneg expressions unless explicitly requested by IR or
bitcode.
2022-09-07 11:27:25 +02:00
serge-sans-paille 1546df49f5 [clang][doc] Do not keep a copy of ClangCommandLineReference.rst in tree
This file is auto-generated, it's a bit confusing for the maintainers to have it
in tree while it shouldn't be modified *and* already have a rule to be
generated.

Differential Revision: https://reviews.llvm.org/D133349
2022-09-07 09:06:47 +02:00
Vitaly Buka 4c18670776 [NFC][sancov] Rename ModuleSanitizerCoveragePass 2022-09-06 20:55:39 -07:00
Vitaly Buka 5e38b2a456 [NFC][msan] Rename ModuleMemorySanitizerPass 2022-09-06 20:30:35 -07:00
Sinan Lin 73593145cb [cmake] do not set execution permission to regular files.
some regular files(e.g. files have no shebang and no execute
bit in source dir) are wrongly assigned an execution permission,
such as scanview.css and ear.c from libscanbuild, which is
unnecessary and introduces warnings in some envs.

Reviewed By: MaskRay, phosek

Differential Revision: https://reviews.llvm.org/D133308
2022-09-07 11:04:12 +08:00
Chuanqi Xu 5f571eeb3f [NFC] [Frontend] Correct the use of 'auto' in SemaCoroutine and CGCoroutine
We should only use 'auto' in case we can know the type from the right
hand side of the expression. Also we need keep '*' around if the type is
a pointer actually. Few uses of 'auto' in SemaCoroutine.cpp and
CGCoroutine.cpp violates the rule. This commit tries to fix it.
2022-09-07 10:45:01 +08:00
Joseph Huber 7354a73945 [CUDA] Actually fix the test correctly this time 2022-09-06 20:31:27 -05:00
Joseph Huber a6bb7c22fc [CUDA] Fix test failing when using the new driver
Summary:
Previously the new driver crashed when using `-fsyntax-only` which
required a work-around in one of the test files. This was not properly
updated when it was fixed for the new driver. This patch fixes the test
and also adjusts a missing boolean check.
2022-09-06 20:14:20 -05:00
Joseph Huber 2753eafe5a [Clang] Fix the new driver crashing when using '-fsyntax-only'
The new driver currently crashses when attempting to use the
'-fsyntax-only' option. This is because the option causes all output to
be given the `TY_Nothing' type which should signal the end of the
pipeline. The new driver was not treating this correctly and attempting
to use empty input. This patch fixes the handling so we do not attempt
to continue when the input is nothing.

One concession is that we must now check when generating the arguments
for Clang if the input is of 'TY_Nothing'. This is because the new
driver will only create code if the device code is a dependency on the
host, creating the output without the dependency would require a
complete rewrite of the logic as we do not maintain any state between
calls to 'BuildOffloadingActions' so I believe this is the most
straightforward method.

Reviewed By: tra

Differential Revision: https://reviews.llvm.org/D133161
2022-09-06 19:49:47 -05:00
Richard Smith a002063de3 Enforce module decl-use restrictions and private header restrictions in textual headers
Per the documentation, these restrictions were intended to apply to textual headers but previously this didn't work because we decided there was no requesting module when the `#include` was in a textual header.

A `-cc1` flag is provided to restore the old behavior for transitionary purposes.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D132779
2022-09-06 17:12:57 -07:00
Craig Topper d3b9970342 [RISCV] Use llvm::none_of to replace a loop. NFC 2022-09-06 16:24:23 -07:00
Vitaly Buka 93600eb50c [NFC][asan] Rename ModuleAddressSanitizerPass 2022-09-06 15:02:11 -07:00
Vitaly Buka e7bac3b9fa [msan] Convert Msan to ModulePass
MemorySanitizerPass function pass violatied requirement 4 of function
pass to do not insert globals. Msan nees to insert globals for origin
tracking, and paramereters tracking.

https://llvm.org/docs/WritingAnLLVMPass.html#the-functionpass-class

Reviewed By: kstoimenov, fmayer

Differential Revision: https://reviews.llvm.org/D133336
2022-09-06 15:01:04 -07:00
Craig Topper 7440e2274f [RISCV] Add '32bit' feature to rv32 only builtins.
The backend now has a 32bit feature as part of the recent mtune
patch. We can now use that make our rv32-only builtin error checking
work the same way as rv64-only errors.

Reviewed By: kito-cheng

Differential Revision: https://reviews.llvm.org/D132192
2022-09-06 14:46:35 -07:00
Aaron Ballman d3d334a625 Fix the Clang sphinx build bot; NFC
This should address the failure introduced in:
https://lab.llvm.org/buildbot/#/builders/92/builds/32377
2022-09-06 16:50:22 -04:00
Roy Jacobson 28bc410999 [DOC][Clang] Update cxx_status.html after the 15 release and fix a broken link in release notes 2022-09-06 21:59:27 +03:00
Joseph Huber 3a623999f3 [OpenMP] Fix logic error when building offloading applications
Summary:
A previous patch removed support for the `-fopenmp-new-driver` and
accidentally used the `isHostOffloading` flag instead of
`isDeviceOffloading` which lead to some build errors when compiling for
the offloading device. This patch addresses that.
2022-09-06 13:56:24 -05:00
Joseph Huber 57ef29f283 [OpenMP] Remove use of removed '-f[no-]openmp-new-driver' flag
The changes in D130020 removed all support for the old method of
compiling OpenMP offloading programs. This means that
`-fopenmp-new-driver` has no effect and `-fno-openmp-new-driver` does
not work. This patch removes the use and documentation of this flag.
Note that the `--offload-new-driver` flag still exists for using the new
driver optionally with CUDA and HIP.

Reviewed By: tra

Differential Revision: https://reviews.llvm.org/D133367
2022-09-06 13:40:05 -05:00
Matheus Izvekov 94c6dfbaeb
[clang] Implement setting crash_diagnostics_dir through env variable
This implements setting the equivalent of `-fcrash-diagnostics-dir`
through the environment variable `CLANG_CRASH_DIAGNOSTICS_DIR`.
If present, the flag still takes precedence.

This helps integration with test frameworks and pipelines.

With this feature, we change the libcxx bootstrapping build
pipeline to produce clang crash reproducers as artifacts.

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

Differential Revision: https://reviews.llvm.org/D133082
2022-09-06 19:27:37 +02:00
Matheus Izvekov acb767f5cd
[clang] fix profiling of template arguments of template and declaration kind
Template arguments of template and declaration kind were being profiled
only by their canonical properties, which would cause incorrect
uniquing of constrained AutoTypes, leading to a crash in some cases.

This exposed some places in CheckTemplateArgumentList where non-canonical
arguments where being pushed into the resulting converted list.

We also throw in some asserts to catch early and explain the crashes.

Note that the fix for the 'declaration' kind is untestable at this point,
because there should be no cases right now in the AST where we try
to unique a non-canonical converted template argument.

This fixes GH55567.

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

Differential Revision: https://reviews.llvm.org/D133072
2022-09-06 18:27:39 +02:00
Joseph Huber a69404c0a2 [OffloadPackager] Add ability to extract images from other file types
A previous patch added support for extracting images from offloading
binaries. Users may wish to extract these files from the file types they
are most commonly emebedded in, such as an ELF or bitcode. This can be
difficult for the user to do manually, as these could be stored in
different section names potentially. This patch addsp support for
extracting these file types.

Reviewed By: saiislam

Differential Revision: https://reviews.llvm.org/D132607
2022-09-06 08:55:17 -05:00
Joseph Huber 5dbc7cf7ca [Object] Refactor code for extracting offload binaries
We currently extract offload binaries inside of the linker wrapper.
Other tools may wish to do the same extraction operation. This patch
simply factors out this handling into the `OffloadBinary.h` interface.

Reviewed By: yaxunl

Differential Revision: https://reviews.llvm.org/D132689
2022-09-06 08:55:16 -05:00
Aaron Ballman e1ebe476e4 Fix Clang Sphinx docs build
The CodeOwners.rst file needs to live in the same directory as the rest
of the documentation. This copies the file to the correct place when
making a Sphinx build but continues to leave the .rst file at the root
directory where it's easier for developers to find. This also ensures
that local doc builds using `make html` work as expected.
2022-09-06 09:52:22 -04:00
Aaron Ballman 3c604e9f15 Update the clang and clang-tools-extra code owners files
This also converts the Clang code owners file from a flat text file to
an RST file that is linked in to the rest of our documentation.

The RFC for this can be found at:
https://discourse.llvm.org/t/rfc-proposed-changes-to-clangs-code-ownership/

Differential Revision: https://reviews.llvm.org/D132550
2022-09-06 08:28:03 -04:00
Animesh Kumar 0cecc6e8e2
[OpenMP] Add lit test for metadirective device arch inspired
from sollve

This lit test is added based upon the tests present in the
tests/5.0/metadirective directory of the SOLLVE repo
https://github.com/SOLLVE/sollve_vv

Reviewed By: saiislam

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

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

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

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

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

Differential Revision: https://reviews.llvm.org/D132295
2022-09-06 12:24:19 +02:00
Passw 2adf241592 [clang-format] [doc] Fix example of wrapping class definitions
Example of

BraceWrapping
  AfterClass
is wrong

Differential Revision: https://reviews.llvm.org/D133087
2022-09-06 12:24:18 +02:00
Sven van Haastregt f2c17a130a [OpenCL] Remove argument names from atomic/fence builtins
This simplifies completeness comparisons against OpenCLBuiltins.td and
also makes the header no longer "claim" the argument name identifiers.

Continues the direction set out in D119560.
2022-09-06 10:50:57 +01:00
Nikita Popov 71797797f7 [OpenMP] Mark -fopenmp-implicit-rpath as NoArgumentUnused
This matches the behavior for all the other -fopenmp options,
as well as -frtlib-add-rpath.

For context, Fedora passes this flag by default in case OpenMP is
used, and this results in a warning if it (usually) isn't, which
causes build failures for some programs with unnecessarily strict
build systems (like Ruby).

Differential Revision: https://reviews.llvm.org/D133316
2022-09-06 09:44:45 +02:00
Chuanqi Xu f65f06d63f [NFC] [Coroutines] Add tests for looking up deallocation
According to [dcl.fct.def.coroutine]p12, the program should be
ill-formed if the promise_type contains operator delete but none of them
are available. But this behavior was not tested before. This commit adds
the tests for it.
2022-09-06 14:57:01 +08:00
Chuanqi Xu 495419628b [NFC] Add test of sized deallocation for coroutines
[dcl.fct.def.coroutine]p12 says:

> If both a usual deallocation function with only a pointer parameter
> and a usual deallocation function with both a pointer parameter and a
> size parameter are found, then the selected deallocation function
> shall be the one with two parameters.

However, the sized deallocation function is disabled by default for ABI
reasons. This leads the sentence never get tested and covered. This
commit tries to add a test for it
2022-09-06 14:44:16 +08:00
Chuanqi Xu 7628f19262 [NFC] Remove invisible character in Diagnostic message and tests 2022-09-06 11:08:42 +08:00
Fangrui Song 91d8324366 [MinGW] Reject explicit non-default visibility applied to dllexport/dllimport declaration
dllimport/dllexport is incompatible with protected/hidden visibilities.
(Arguably dllexport semantics is compatible with protected but let's reject the
combo for simplicity.)

When an explicit visibility attribute applies on a dllexport/dllimport
declaration, report a Frontend error (Sema does not compute visibility).

Reviewed By: mstorsjo

Differential Revision: https://reviews.llvm.org/D133266
2022-09-05 10:17:19 -07:00
isuckatcs a11e51e91f [analyzer] Track trivial copy/move constructors and initializer lists in the BugReporter
If an object has a trivial copy/move constructor, it's not inlined
on invocation but a trivial copy is performed instead. This patch
handles trivial copies in the bug reporter by matching the field
regions of the 2 objects involved in the copy/move construction,
and tracking the appropriate region further. This patch also
introduces some support for tracking values in initializer lists.

Differential Revision: https://reviews.llvm.org/D131262
2022-09-05 17:06:27 +02:00
Amy Wang 8f4e6cfe73 [clang-format] Use utf-8 for JSON object load
From Python 3.6 and above, it should be able to automatically select a
decoding for json.loads. However, with a vim encoding that defaults
to utf-8, clang-format.py runs into the following error

    TypeError: the JSON object must be str, not 'bytes'

This patch explicitly specifies utf-8 decoding for the header.

Reviewed by: ldrumm, sammcall

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

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

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

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

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

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

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

Differential Revision: https://reviews.llvm.org/D132189
2022-09-05 12:35:39 +02:00
Ying Yi 5de4d97a00 Driver tests: remove `REQUIRES: x86-registered-target` and set `--sysroot=""` to support clang with `DEFAULT_SYSROOT`.
When testing clang that has been compiled with -DDEFAULT_SYSROOT set to some path, ps4-ps5-header-search.c would fail.

The test needs to be updated.

    1. Remove unnecessary REQUIRES: x86-registered-target.
    2. Override sysroot to be empty string for the test to succeed when clang is configured with DEFAULT_SYSROOT.
2022-09-05 09:59:47 +01:00
serge-sans-paille ab09043a19 [clang] Fix crash when parsing scanf format string with missing arguments
When parsing a format string with less argument than specified, one should check
argument access because there may be no such argument.

This fixes #57517

Differential Revision: https://reviews.llvm.org/D133197
2022-09-05 10:54:18 +02:00
Nathan Ridge c933453858 Fix build error in StmtPrinterTest.cpp 2022-09-05 03:48:46 -04:00
Nathan Ridge 898c421975 [clangd] Avoid crash when printing call to string literal operator template
Differential Revision: https://reviews.llvm.org/D132830
2022-09-05 03:42:08 -04:00
Krystian Kuzniarek 961fd77687 [clang-format][docs] Fix incorrect 'clang-format 4' option markers
Introduced by 23a5090c6, some style option markers indicated
'clang-format 4', though their respective options were available in
earlier releases.

Differential Revision: https://reviews.llvm.org/D129934
2022-09-05 09:38:22 +02:00
Chuanqi Xu 69e920d426 [Coroutines] Use LookupAllocationFunction to find allocation functions for coroutines consistently
Previously we may call Sema::FindAllocationFunctions directly to lookup
allocation functions directly instead of using our wrapped lambda
LookupAllocationFunction, which is slightly incosnsistent. It will be
helpful to refactor this for further changes.

Also previously, when we lookup 'operator new(std::size_t, std::nothrow_t)' in
case we found `get_­return_­object_­on_­allocation_­failure` in the
promise_type, the compiler will try to look at the allocation function
in promise_type. However, this is not wanted actually. According to
[dcl.fct.def.coroutine]p10:

> if a global allocation function is selected, the
> ::operator new(size_­t, nothrow_­t) form is used.

So we should only lookup for `::operator (size_t, nothrow_t)` for the
global allocation function. For the allocation function in the
promise_type, the requirement is that it shouldn't throw, which has
already been checked.

Given users generally include headers from standard libs so it will
generally include the <new> header, so this change should be a trivial
one and shouldn't affect almost any user.
2022-09-05 15:20:09 +08:00
Fangrui Song 36a1ca5835 [ASTReader] Fix -Wunused-private-field in non-assertion builds after D128490. NFC 2022-09-04 23:48:55 -07:00
Chuanqi Xu baa9eae279 [NFC] fix incorrect indentation in docs 2022-09-05 11:05:23 +08:00
isuckatcs a46154cb1c [analyzer] Warn if the size of the array in `new[]` is undefined
This patch introduces a new checker, called NewArraySize checker,
which detects if the expression that yields the element count of
the array in new[], results in an Undefined value.

Differential Revision: https://reviews.llvm.org/D131299
2022-09-04 23:06:58 +02:00
Kazu Hirata b7a7aeee90 [clang] Qualify auto in range-based for loops (NFC) 2022-09-03 23:27:27 -07:00
Fangrui Song 83ea47acd7 [test] Make tests pass regardless of gnu++14/gnu++17 default
GCC from 11 onwards defaults to -std=gnu++17 for C++ source files. We want to do the same
(https://discourse.llvm.org/t/c-objc-switch-to-gnu-17-as-the-default-dialect/64360).
Split RUN lines, adjust `-verify`, or add `__cplusplus < 201703L` or `-Wno-dynamic-exception-spec`,
so that tests will pass regardless of gnu++14/gnu++17 default.

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

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

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

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

Differential Revision: https://reviews.llvm.org/D131464
2022-09-04 05:29:32 +00:00
Vitaly Buka 9905dae5e1 Revert "[Clang][CodeGen] Avoid __builtin_assume_aligned crash when the 1st arg is array type"
Breakes windows bot.

This reverts commit 3ad2fe913a.
2022-09-03 13:12:49 -07:00
Kazu Hirata 89f1433225 Use llvm::lower_bound (NFC) 2022-09-03 11:17:37 -07:00
Kazu Hirata 3850edd9e0 Use llvm::count_if (NFC) 2022-09-03 11:17:35 -07:00
Fangrui Song 89df4e4825 [Driver] Remove unused -Ttext -Tdata -Tbss
They lead to -Wunused-command-line-argument and should be written as -Ttext=
instead, but the driver options end with a space. -Ttext=0 can be accepted by
the JoinedOrSeparate -T, so the JoinedOrSeparate -Ttext/etc are unneeded.
2022-09-03 10:57:29 -07:00
Fangrui Song a2ef7654ec [Driver] Change some cc1 only JoinedOrSeparate long options to Separate
They are error-prone as they do not end with `=`.
Note: for driver -isystem/etc, we have to support the Joined form.
2022-09-03 10:45:30 -07:00
yronglin 3ad2fe913a [Clang][CodeGen] Avoid __builtin_assume_aligned crash when the 1st arg is array type
Avoid __builtin_assume_aligned crash when the 1st arg is array type(or string literal).

Open issue: https://github.com/llvm/llvm-project/issues/57169

Reviewed By: rjmccall

Differential Revision: https://reviews.llvm.org/D133202
2022-09-03 23:26:01 +08:00
Junduo Dong 5e4f69edbc Revert "[Clang] change default storing path of `-ftime-trace`"
This reverts commit 38941da066.
2022-09-03 01:38:37 -07:00
Junduo Dong 4ff2250a22 Revert "[driver][clang] remove the check-time-trace test on the platform "PS4/PS5/Hexagon""
This reverts commit 39221ad557.
2022-09-03 01:37:55 -07:00
owenca 92d8738c38 [clang-format] Fix a bug in merging blocks with a wrapped l_brace
When the opening brace of a control statement block is wrapped, we
must check the previous line to determine whether to try to merge
the block.

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

Differential Revision: https://reviews.llvm.org/D133093
2022-09-02 21:38:36 -07:00
Junduo Dong 39221ad557 [driver][clang] remove the check-time-trace test on the platform "PS4/PS5/Hexagon"
One of the test cases in that test is designed to test the compiling
jobs with a linking stage, but the PS4/PS5/Hexagon platform requires
an external linker that isn't present.

So this test do not support the "PS4/PS5/Hexagon".
2022-09-02 20:27:35 -07:00
Richard Smith 632e1e9fd8 Work around Windows buildbot failure.
-fmodules-local-submodule-visibility and -fdelayed-template-parsing
don't work properly together because the template is parsed in the
visibility context of the wrong module.
2022-09-02 19:09:15 -07:00
Shafik Yaghmour 9f6b3199d3 [Clang] Fix lambda CheckForDefaultedFunction(...) so that it checks the CXXMethodDecl is not deleted before attempting to call DefineDefaultedFunction(...)
I discovered this additional bug at the end of working on D132906

In Sema::CheckCompletedCXXClass(...)  uses a lambda CheckForDefaultedFunction to
verify each CXXMethodDecl holds to the expected invariants before passing them
on to CheckForDefaultedFunction.

It is currently missing a check that it is not deleted, this adds that check and
a test that crashed without this check.

This fixes: https://github.com/llvm/llvm-project/issues/57516

Differential Revision: https://reviews.llvm.org/D133177
2022-09-02 18:59:15 -07:00
Junduo Dong 38941da066 [Clang] change default storing path of `-ftime-trace`
1. This implementation change the default storing behavior of -ftime-trace only.

That is, if the compiling job contains the linking action, the executable file' s directory may be seem as the main work directory.
Thus the time trace files would be stored in the same directory of linking result.

By this approach, the user can easily get the time-trace files in the main work directory. The improved demo results:

```
$ clang++ -ftime-trace -o main.out /demo/main.cpp
$ ls .
main.out   main-[random-string].json
```

2. In addition, the main codes of time-trace files' path inference have been refactored.

* The <path> of -ftime-trace=<path> is infered in clang driver
* After that, -ftime-trace=<path> can be added into clang's options

By this approach, the dirty work of path processing and judging can be implemented in driver layer, so that the clang may focus on its main work.

 #   $ clang -ftime-trace -o xxx.out xxx.cpp

Differential Revision: https://reviews.llvm.org/D131469
2022-09-02 18:49:11 -07:00
Richard Smith 220c2cb0a8 Attempt to make AIX bot happier. 2022-09-02 18:43:27 -07:00
Sheng a887d9efd6 [NFC][clang] LLVM_FALLTHROUGH => [[fallthrough] 2022-09-03 08:58:31 +08:00
Volodymyr Sapsai 246c5a994b [ODRHash diagnostics] Transform method `ASTReader::diagnoseOdrViolations` into a class `ODRDiagsEmitter`. NFC.
Preparing to use diagnostics about ODR hash mismatches outside of ASTReader.

Differential Revision: https://reviews.llvm.org/D128490
2022-09-02 16:20:05 -07:00
Richard Smith b484256f59 Add driver test for -fmodule-name and -fmodule-map-file use without -fmodules. 2022-09-02 16:08:30 -07:00
isuckatcs b5147937b2 [analyzer] Add more information to the Exploded Graph
This patch dumps every state trait in the egraph. Also
the empty state traits are no longer dumped, instead
they are treated as null by the egraph rewriter script,
which solves reverse compatibility issues.

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

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

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

Reviewed By: owenpan, MyDeveloperDay

Differential Revision: https://reviews.llvm.org/D132911
2022-09-03 05:56:49 +08:00
Chris Bieneman 00ecacca7d [HLSL] Generate buffer subscript operators
In HLSL buffer types support array subscripting syntax for loads and
stores. This change fleshes out the subscript operators to become array
accesses on the underlying handle pointer. This will allow LLVM
optimization passes to optimize resource accesses the same way any other
memory access would be optimized.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D131268
2022-09-02 14:55:43 -05:00
Fangrui Song 2f7da9d317 [Driver] Remove cc1 Separate form -fvisibility 2022-09-02 12:40:00 -07:00
Fangrui Song 74742147ee [test] Change cc1 -fvisibility to -fvisibility= 2022-09-02 12:36:44 -07:00
Chris Bieneman 5b5329bd41 [NFC] Make MultiplexExternalSemaSource own sources
This change refactors the MuiltiplexExternalSemaSource to take ownership
of the underlying sources. As a result it makes a larger cleanup of
external source ownership in Sema and the ChainedIncludesSource.

Reviewed By: aaron.ballman, aprantl

Differential Revision: https://reviews.llvm.org/D133158
2022-09-02 13:57:39 -05:00
Fangrui Song 1491282165 [clang] Change cc1 -fvisibility's canonical spelling to -fvisibility= 2022-09-02 11:49:38 -07:00
Chris Bieneman 10194a51a9 [HLSL] Restrict to supported targets
Someday we would like to support HLSL on a wider range of targets, but
today targeting anything other than `dxil` is likly to cause lots of
headaches. This adds an error and tests to validate that the expected
target is `dxil-?-shadermodel`.

We will continue to do a best effort to ensure the code we write makes
it easy to support other targets (like SPIR-V), but this error will
prevent users from hitting frustrating errors for unsupported cases.

Reviewed By: jcranmer-intel, Anastasia

Differential Revision: https://reviews.llvm.org/D132056
2022-09-02 13:36:23 -05:00
Fangrui Song 8899c3c4e1 [docs] -fivisibility= allows protected and internal 2022-09-02 10:49:10 -07:00
Fangrui Song a931eddd09 [docs] Regenerate clang/docs/ClangCommandLineReference.rst 2022-09-02 10:29:38 -07:00
Fangrui Song 1a4d851d27 [MinGW] Ignore -fvisibility/-fvisibility-inlines-hidden for dllexport
Similar to 123ce97fac for dllimport: dllexport
expresses a non-hidden visibility intention. We can consider it explicit and
therefore it should override the global visibility setting (see AST/Decl.cpp
"NamedDecl Implementation").

Adding the special case to CodeGenModule::setGlobalVisibility is somewhat weird,
but allows we to add the code in one place instead of many in AST/Decl.cpp.

Differential Revision: https://reviews.llvm.org/D133180
2022-09-02 09:59:16 -07:00
Fangrui Song e05edb19ad [Driver] Unsupport --print-multiarch
* If GCC is configured with `--disable-multi-arch`, `--print-multiarch` output is an empty line.
* If GCC is configured with `--enable-multi-arch`, `--print-multiarch` output may be a normalized triple or (on Debian, 'vendor' is omitted) `x86_64-linux-gnu`.

The Clang support D101400 just prints the Debian multiarch style triple
unconditionally, but the string is not really expected for non-Debian systems.

AIUI many Linux distributions and non-Linux OSes don't configure GCC with `--enable-multi-arch`.
Instead of getting us in the trouble of supporting all kinds of variants, drop the support as before D101400.

Close https://github.com/llvm/llvm-project/issues/51469

Reviewed By: phosek

Differential Revision: https://reviews.llvm.org/D133170
2022-09-02 09:51:02 -07:00
Luca Di Sera e7d9917a60 Expose QualType::getNonReferenceType in libclang
The method is now wrapped by clang_getNonReferenceType.

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

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

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

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

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

Differential Revision: https://reviews.llvm.org/D133195
2022-09-02 09:54:10 -04:00
Egor Zhdan 7c232b0867 [Clang][Comments] Fix `Index/comment-lots-of-unknown-commands.c`
This re-enables a test after it was disabled in https://reviews.llvm.org/D133009.

Fixes #57484.

Differential Revision: https://reviews.llvm.org/D133105
2022-09-02 12:34:38 +01:00
Muhammad Omair Javaid 18de7c6a3b Revert "[InstCombine] Treat passing undef to noundef params as UB"
This reverts commit c911befaec.

It has broken LLDB Arm/AArch64 Linux buildbots. I dont really understand
the underlying reason. Reverting for now make buildbot green.

https://reviews.llvm.org/D133036
2022-09-02 16:09:50 +05:00
Utkarsh Saxena e7eec38246 [clang] Skip re-building lambda expressions in parameters to consteval fns.
As discussed in this [comment](https://github.com/llvm/llvm-project/issues/56183#issuecomment-1224331699),
we end up building the lambda twice: once while parsing the function calls and then again while handling the immediate invocation.

This happens specially during removing nested immediate invocation.
Eg: When we have another consteval function as the parameter along with this lambda expression. Eg: `foo(bar([]{}))`, `foo(bar(), []{})`

While removing such nested immediate invocations, we should not rebuild this lambda. (IIUC, rebuilding a lambda would always generate a new type which will never match the original type from parsing)

Fixes: https://github.com/llvm/llvm-project/issues/56183
Fixes: https://github.com/llvm/llvm-project/issues/51695
Fixes: https://github.com/llvm/llvm-project/issues/50455
Fixes: https://github.com/llvm/llvm-project/issues/54872
Fixes: https://github.com/llvm/llvm-project/issues/54587

Differential Revision: https://reviews.llvm.org/D132945
2022-09-02 12:30:52 +02:00
Chuanqi Xu 085e8cd8d3 [NFC] Cleanup lookup for coroutine allocation/deallocation 2022-09-02 17:24:52 +08:00
Sinan Lin 1334e129a3 [cmake] Append CLANG_LIBDIR_SUFFIX to scan-build-py installation destination
met this issue when building llvm with config LLVM_LIBDIR_SUFFIX=64, and
the installation destination of scan-build-py does not respect the given
suffix.

Reviewed By: phosek

Differential Revision: https://reviews.llvm.org/D133160
2022-09-02 16:18:15 +08:00
Freddy Ye 66f332bc1a [X86] Add missing key feature for core2
Reviewed By: erichkeane

Differential Revision: https://reviews.llvm.org/D133094
2022-09-02 16:06:07 +08:00
Artem Belevich 54c47ff939 [CUDA] Allow using -o with -fsyntax-only
-fsyntax-only breaks down CUDA compilation pipeline and make it look like
multiple independent subcompilations and that trips the multiple arguments check
when -o is specified.

We do want to allow -fsyntax-only to be used with otherwise unmodified clang
options as it's commonly used by various tooling.

Differential Revision: https://reviews.llvm.org/D133133
2022-09-01 15:52:36 -07:00
Alex Brachet f6d6e33abc [clang] Give better message for unsupported no_sanitize on globals
Previously if you specified no_sanitize("known_sanitizer") on a global you
would yield a misleading error "'no_sanitize' attribute only applies to
functions and methods", but no_sanitize("unknown") would simply be a warning,
"unknown sanitizer 'unknown' ignored". This changes the former to a warning
"'no_sanitize' attribute argument not supported for globals: known_sanitizer".

Differential Revision: https://reviews.llvm.org/D133117
2022-09-01 22:35:42 +00:00
Arthur Eubanks c911befaec [InstCombine] Treat passing undef to noundef params as UB
Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D133036
2022-09-01 15:16:45 -07:00
Kevin Athey 0b509f2d1a [MSAN] removing redundant tests and parameters (NFC)
Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D117622
2022-09-01 14:03:55 -07:00
Wei Yi Tee 14757d5b84 [clang][dataflow] Refactor `TypeErasedDataflowAnalysisTest` - replace usage of the deprecated overload of `checkDataflow`.
Reviewed By: gribozavr2, sgatev

Differential Revision: https://reviews.llvm.org/D132756
2022-09-01 19:17:37 +00:00
Arthur Eubanks 9599393eeb Revert "[Pipelines] Introduce DAE after ArgumentPromotion"
This reverts commit b10a341aa5.

This commit exposes the pre-existing https://github.com/llvm/llvm-project/issues/56503 in some edge cases. Will fix that and then reland this.
2022-09-01 08:52:19 -07:00
Aaron Ballman fb38baef87 Removing an accidentally duplicated heading; NFC 2022-09-01 11:44:11 -04:00
Wei Yi Tee 8dd14c427a [clang][dataflow] Use `StringMap` for storing analysis states at annotated points instead of `vector<pair<string, StateT>>`.
Reviewed By: gribozavr2, sgatev, ymandel

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

Reviewed By: gribozavr2, sgatev, ymandel

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

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

Reviewed By: gribozavr2, sgatev

Differential Revision: https://reviews.llvm.org/D132147
2022-09-01 13:21:34 +00:00
serge-sans-paille e0746a8a8d [clang] cleanup -fstrict-flex-arrays implementation
This is a follow up to https://reviews.llvm.org/D126864, addressing some remaining
comments.

It also considers union with a single zero-length array field as FAM for each
value of -fstrict-flex-arrays.

Differential Revision: https://reviews.llvm.org/D132944
2022-09-01 15:06:21 +02:00
Egor Zhdan 0cb0809336 [Clang][Comments] Parse `<img src=""/>` in doc comments correctly
This is a valid HTML5 tag. Previously it triggered a Clang error (`HTML start tag prematurely ended, expected attribute name or '>'`) since Clang was treating `/>` as a text token. This was happening because after lexing the closing quote (`"`) the lexer state was reset to "Normal" while the tag was not actually closed yet: `>` was not yet parsed at that point.

rdar://91464292

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

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

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

Reviewed By: gribozavr2, sgatev

Differential Revision: https://reviews.llvm.org/D131616
2022-09-01 10:15:53 +00:00
Sam Clegg 849df8f6f0 [clang][WebAssembly] Pass `-Wa,--no-type-check` through to the MC layer
I took as an example the `-Wa,--noexecstack` clang flag that maps down
to `cc1 -mnoexecstack`.

Differential Revision: https://reviews.llvm.org/D131217
2022-09-01 02:56:58 -07:00