platform/upstream/llvm.git
18 months ago[cmake] Add missing CMakePushCheckState include to FindLibEdit.cmake
Michał Górny [Mon, 7 Nov 2022 13:46:58 +0000 (14:46 +0100)]
[cmake] Add missing CMakePushCheckState include to FindLibEdit.cmake

Add the missing include to fix an error when `cmake_push_check_state()`
is called and incidentally the CMakePushCheckState module is not loaded
by any other check running prior to `FindLibEdit.cmake`:

    CMake Error at /var/no-tmpfs/portage/dev-util/lldb-15.0.4/work/cmake/Modules/FindLibEdit.cmake:24 (cmake_push_check_state):
      Unknown CMake command "cmake_push_check_state".
    Call Stack (most recent call first):
      cmake/modules/LLDBConfig.cmake:52 (find_package)
      cmake/modules/LLDBConfig.cmake:59 (add_optional_dependency)
      CMakeLists.txt:28 (include)

Gentoo Bug: https://bugs.gentoo.org/880065

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

(cherry picked from commit 3676a86a4322e8c2b9c541f057b5d3704146b8f3)

18 months agoReenable POSIX builtin library functions in gnu2x mode
Aaron Ballman [Wed, 2 Nov 2022 11:56:43 +0000 (07:56 -0400)]
Reenable POSIX builtin library functions in gnu2x mode

gnu17 and earlier modes automatically expose several POSIX C APIs, and
this was accidentally disabled for gnu2x in
7d644e1215b376ec5e915df9ea2eeb56e2d94626.

This restores the behavior for gnu2x mode (without changing the
behavior in C standards modes instead of GNU modes).

Fixes #56607

18 months ago[CMake] Fix -Wstrict-prototypes
Sam James [Tue, 8 Nov 2022 01:36:43 +0000 (01:36 +0000)]
[CMake] Fix -Wstrict-prototypes

Fixes warnings (or errors, if someone injects -Werror in their build system,
which happens in fact with some folks vendoring LLVM too) with Clang 16:
```
+/var/tmp/portage.notmp/portage/sys-devel/llvm-15.0.4/work/llvm_build-abi_x86_64.amd64/CMakeFiles/CMakeTmp/src.c:3:9: warning: a function declaration without a prototype
is deprecated in all versions of C [-Wstrict-prototypes]
-/var/tmp/portage.notmp/portage/sys-devel/llvm-14.0.4/work/llvm_build-abi_x86_64.amd64/CMakeFiles/CMakeTmp/src.c:3:9: error: a function declaration without a prototype is
deprecated in all versions of C [-Werror,-Wstrict-prototypes]
 int main() {return 0;}
         ^
          void
```

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

(cherry picked from commit 32a2af44e1e882f13d1cc2817f0a8d4d8b375d4d)

19 months agoAMDGPU: Make various vector undefs legal
Matt Arsenault [Tue, 27 Sep 2022 03:07:49 +0000 (23:07 -0400)]
AMDGPU: Make various vector undefs legal

Surprisingly these were getting legalized to something
zero initialized.

This fixes an infinite loop when combining some vector types.
Also fixes zero initializing some undef values.

SimplifyDemandedVectorElts / SimplifyDemandedBits are not checking
for the legality of the output undefs they are replacing unused
operations with. This resulted in turning vectors into undefs
that were later re-legalized back into zero vectors.

(cherry picked from commit 7a84624079a2656c684bed6100708544500c5a32)

19 months ago[clang][Sema] Fix a clang crash with btf_type_tag
Yonghong Song [Wed, 26 Oct 2022 23:15:02 +0000 (16:15 -0700)]
[clang][Sema] Fix a clang crash with btf_type_tag

For the following program,
  $ cat t.c
  struct t {
   int (__attribute__((btf_type_tag("rcu"))) *f)();
   int a;
  };
  int foo(struct t *arg) {
    return arg->a;
  }
Compiling with 'clang -g -O2 -S t.c' will cause a failure like below:
  clang: /home/yhs/work/llvm-project/clang/lib/Sema/SemaType.cpp:6391: void {anonymous}::DeclaratorLocFiller::VisitParenTypeLoc(clang::ParenTypeLoc):
         Assertion `Chunk.Kind == DeclaratorChunk::Paren' failed.
  PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
  Stack dump:
  ......
  #5 0x00007f89e4280ea5 abort (/lib64/libc.so.6+0x21ea5)
  #6 0x00007f89e4280d79 _nl_load_domain.cold.0 (/lib64/libc.so.6+0x21d79)
  #7 0x00007f89e42a6456 (/lib64/libc.so.6+0x47456)
  #8 0x00000000045c2596 GetTypeSourceInfoForDeclarator((anonymous namespace)::TypeProcessingState&, clang::QualType, clang::TypeSourceInfo*) SemaType.cpp:0:0
  #9 0x00000000045ccfa5 GetFullTypeForDeclarator((anonymous namespace)::TypeProcessingState&, clang::QualType, clang::TypeSourceInfo*) SemaType.cpp:0:0
  ......

The reason of the failure is due to the mismatch of TypeLoc and D.getTypeObject().Kind. For example,
the TypeLoc is
  BTFTagAttributedType 0x88614e0 'int  btf_type_tag(rcu)()' sugar
  |-ParenType 0x8861480 'int ()' sugar
  | `-FunctionNoProtoType 0x8861450 'int ()' cdecl
  |   `-BuiltinType 0x87fd500 'int'
while corresponding D.getTypeObject().Kind points to DeclaratorChunk::Paren, and
this will cause later assertion.

To fix the issue, similar to AttributedTypeLoc, let us skip BTFTagAttributedTypeLoc in
GetTypeSourceInfoForDeclarator().

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

19 months ago[SPARC] Make calls to function with big return values work
Koakuma [Tue, 18 Oct 2022 00:01:55 +0000 (00:01 +0000)]
[SPARC] Make calls to function with big return values work

Implement CanLowerReturn and associated CallingConv changes for SPARC/SPARC64.

In particular, for SPARC64 there's new `RetCC_Sparc64_*` functions that handles the return case of the calling convention.
It uses the same analysis as `CC_Sparc64_*` family of funtions, but fails if the return value doesn't fit into the return registers.

This makes calls to functions with big return values converted to an sret function as expected, instead of crashing LLVM.

Reviewed By: MaskRay

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

(cherry picked from commit d3fcbee10d893b9e01e563c3840414ba89283484)

19 months agoTake memset_inline into account in analyzeLoadFromClobberingMemInst
Guillaume Chatelet [Wed, 26 Oct 2022 09:34:34 +0000 (09:34 +0000)]
Take memset_inline into account in analyzeLoadFromClobberingMemInst

This appeared in https://reviews.llvm.org/D126903#3884061

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

(cherry picked from commit 1a726cfa83667585dd87a9955ed5e331cad45d18)

19 months ago[lld-macho] Canonicalize personality pointers in EH frames
Jez Ng [Wed, 12 Oct 2022 03:50:46 +0000 (23:50 -0400)]
[lld-macho] Canonicalize personality pointers in EH frames

We already do this for personality pointers referenced from compact
unwind entries; this patch extends that behavior to personalities
referenced via EH frames as well.

This reduces the number of distinct personalities we need in the final
binary, and helps us avoid hitting the "too many personalities" error.

I renamed `UnwindInfoSection::prepareRelocations()` to simply `prepare`
since we now do some non-reloc-specific stuff within.

Fixes #58277.

Reviewed By: #lld-macho, oontvoo

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

(cherry picked from commit 7b45dfc6811a52ff4e9a6054dc276d70d77fddaf)

19 months ago[clang][driver] Remove dynamic gcc-toolset/devtoolset logic
Timm Bäder [Fri, 21 Oct 2022 09:36:37 +0000 (11:36 +0200)]
[clang][driver] Remove dynamic gcc-toolset/devtoolset logic

This breaks when the newest available devtoolset directory is not a
complete toolset: https://github.com/llvm/llvm-project/issues/57843

Remove this again in favor or just adding the two new directories for
devtoolset/gcc-toolset 12.

This reverts commit 35aaf548237a4f213ba9d95de53b33c5ce1eadce.
This reverts commit 9f97720268911abae2ad9d90e270358db234a1c1.

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

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

19 months ago[clangd] Return earlier when snippet is empty
Tom Praschan [Sun, 18 Sep 2022 16:48:11 +0000 (18:48 +0200)]
[clangd] Return earlier when snippet is empty

Fixes github.com/clangd/clangd/issues/1216

If the Snippet string is empty, Snippet.front() would trigger a crash.
Move the Snippet->empty() check up a few lines to avoid this. Should not
break any existing behavior.

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

(cherry picked from commit 60528c690a4c334d2a3a2c22eb97af9e67d7a91d)

19 months ago[lldb] Automatically unwrap parameter packs in template argument accessors
Jonas Devlieghere [Wed, 17 Aug 2022 00:53:34 +0000 (17:53 -0700)]
[lldb]  Automatically unwrap parameter packs in template argument accessors

When looking at template arguments in LLDB, we usually care about what
the user passed in his code, not whether some of those arguments where
passed as a variadic parameter pack.

This patch extends all the C++ APIs to look at template parameters to
take an additional 'expand_pack' boolean that automatically unwraps the
potential argument packs. The equivalent SBAPI calls have been changed
to pass true for this parameter.

A byproduct of the patch is to also fix the support for template type
that have only a parameter pack as argument (like the OnlyPack type in
the test). Those were not recognized as template instanciations before.

The added test verifies that the SBAPI is able to iterate over the
arguments of a variadic template.

The original patch was written by Fred Riss almost 4 years ago.

Differential revision: https://reviews.llvm.org/D51387

(cherry picked from commit b706f56133a77f9d7c55270ac24ff59e6fce3fa4)

19 months ago[SystemZ] Relase notes for LLVM 15
Tom Stellard [Mon, 24 Oct 2022 21:48:32 +0000 (14:48 -0700)]
[SystemZ] Relase notes for LLVM 15

Unfortunately these notes were compiled until now, but these are the release notes for SystemZ.

(Did not find anything under clang)

@tstellar Should I push this patch onto release/15.x once approved, or will you apply it?

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

19 months ago[ELF] Suppress "duplicate symbol" when resolving STB_WEAK and STB_GNU_UNIQUE in diffe...
Fangrui Song [Fri, 21 Oct 2022 16:43:25 +0000 (09:43 -0700)]
[ELF] Suppress "duplicate symbol" when resolving STB_WEAK and STB_GNU_UNIQUE in different COMDATs

```
template <typename T> struct A {
  A() {}
  int value = 0;
};

template <typename Value> struct B {
  static A<int> a;
};

template <typename Value> A<int> B<Value>::a;

inline int foo() {
  return B<int>::a.value;
}
```

```
clang++ -c -fno-pic a.cc -o weak.o
g++ -c -fno-pic a.cc -o unique.o  # --enable-gnu-unique-object

# Duplicate symbol error. In postParse, we do not check `sym.binding`
ld.lld -e 0 weak.o unique.o
```

Mixing GCC and Clang object files in this case is not ideal. .bss._ZGVN1BIiE1aE
has different COMDAT groups. It appears to work in practice because the guard
variable prevents harm due to double initialization.

For the linker, we just stick with the rule that a weak binding does not cause
"duplicate symbol" errors.

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

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

(cherry picked from commit 0051b6bb78772b0658f28e5f31ddf91c1589aab5)

19 months ago[AutoUpgrade] Fix remangling when upgrading struct return type
Nikita Popov [Fri, 21 Oct 2022 09:05:53 +0000 (11:05 +0200)]
[AutoUpgrade] Fix remangling when upgrading struct return type

This was remangling the old function rather than the new one, and
could result in failures when we were performing both a struct
return upgrade and an opaque pointer upgrade.

(cherry picked from commit c8938809d155682ef5eec170897b8c26b8cbf3ea)

19 months agoBump version to 15.0.4
Tobias Hieta [Mon, 24 Oct 2022 11:45:36 +0000 (13:45 +0200)]
Bump version to 15.0.4

19 months ago[InstCombine] Bail out of casting calls when a conversion from/to byval is involved.
Mike Hommey [Sun, 23 Oct 2022 07:49:16 +0000 (09:49 +0200)]
[InstCombine] Bail out of casting calls when a conversion from/to byval is involved.

Fixes #58307

Reviewed By: nikic

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

(cherry picked from commit 86e57e66da9380eaa90a9d0830d7f2c5fe87af99)

19 months ago[SROA] Don't speculate phis with different load user types
Arthur Eubanks [Tue, 18 Oct 2022 00:03:35 +0000 (17:03 -0700)]
[SROA] Don't speculate phis with different load user types

Fixes an SROA crash.

Fallout from opaque pointers since with typed pointers we'd bail out at the bitcast.

Reviewed By: nikic

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

(cherry picked from commit 6219ec07c6f8d1ead51beca7cf21fbf2323c51d7)

19 months ago[test] Make Linux/sem_init_glibc.cpp robust
Fangrui Song [Sun, 2 Oct 2022 07:47:10 +0000 (00:47 -0700)]
[test] Make Linux/sem_init_glibc.cpp robust

and fix it for 32-bit ports defining sem_init@GLIBC_2.0 (i386, mips32, powerpc32) for glibc>=2.36.

Fix https://github.com/llvm/llvm-project/issues/58079

Reviewed By: mgorny

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

(cherry picked from commit 6f46ff3765dcdc178b9cf52ebd8c03437806798a)

19 months ago[ARM] Fix for MVE i128 vector icmp costs.
David Green [Fri, 14 Oct 2022 17:49:25 +0000 (18:49 +0100)]
[ARM] Fix for MVE i128 vector icmp costs.

We were hitting an assert as the legalied type needn't be a vector.

Fixes #58364

(cherry picked from commit de6dfbbb300e552efa1cd86a023063a39d408b06)

19 months ago[clangd] Block clang-tidy misc-const-correctness check
Sam McCall [Wed, 12 Oct 2022 23:43:49 +0000 (01:43 +0200)]
[clangd] Block clang-tidy misc-const-correctness check

This check performs an extremely large amount of work (for each variable, it
runs very many full matcher-driven traversals of the whole scope the variable
is defined in).

When (inadvertently) enabled for Fuchsia, it regressed BuildAST times by >10x
(400ms -> 7s on my machine).

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

(cherry picked from commit e78165f0ba1e2fbf72b36a36c8560645b69a168a)

19 months ago[libc++] Fix std::function's handling of blocks under Objc ARC
Louis Dionne [Tue, 11 Oct 2022 18:53:14 +0000 (14:53 -0400)]
[libc++] Fix std::function's handling of blocks under Objc ARC

Previously, some uses of std::function with blocks would crash when ARC was enabled.

rdar://100907096

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

(cherry picked from commit 0e4802bf45952b1120c52d4d1bf6bfa2800fd102)

19 months ago[CMake] Provide Findzstd module
Petr Hosek [Fri, 30 Sep 2022 20:33:13 +0000 (20:33 +0000)]
[CMake] Provide Findzstd module

This module is used to find the system zstd library. The imported
targets intentionally use the same name as the generate zstd config
CMake file so these can be used interchangeably.

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

(cherry picked from commit 2d4fd0b6d5d5582ebb8b521d807104235d67aee4)

19 months ago[llvm] [test] Add missing canonicalization of LLVM_ENABLE_ZSTD
Michał Górny [Thu, 6 Oct 2022 12:41:52 +0000 (14:41 +0200)]
[llvm] [test] Add missing canonicalization of LLVM_ENABLE_ZSTD

Add LLVM_ENABLE_ZSTD to llvm_canonicalize_cmake_booleans().  This is
needed to ensure that the substitutions in lit.site.cfg.py resolve
to correct Python booleans.

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

(cherry picked from commit bc4bcbcfc820b324f680e8f260691c38052eedc9)

19 months ago[llvm] [lit] Fix use_lld() to respect llvm_shlib_dir
Michał Górny [Thu, 6 Oct 2022 14:41:04 +0000 (16:41 +0200)]
[llvm] [lit] Fix use_lld() to respect llvm_shlib_dir

Fix the use_lld() to use llvm_shlib_dir similarly to how use_clang()
does it.  This fixes use_lld() wrongly prepending llvm_libs_dir,
i.e. the directory with system-installed LLVM libraries before
the build directory of standalone build.  As a result, the shared
libraries from an earlier version of clang end up being used instead of
the newly built version when running the test suite prior to installing.

To reproduce the problem, build and install LLVM with dylibs first,
e.g.:

    cmake ../llvm -G Ninja -DCMAKE_BUILD_TYPE=MinSizeRel \
      -DCMAKE_INSTALL_PREFIX="${HOME}"/llvm-test \
      -DLLVM_BUILD_LLVM_DYLIB=ON -DLLVM_LINK_LLVM_DYLIB=ON \
      -DLLVM_INSTALL_UTILS=ON
    ninja install

Then build clang against that installation and run tests:

    export LD_LIBRARY_PATH=~/llvm-test/lib
    export PATh=~/llvm-test/bin:"${PATH}"
    cmake ../clang -G Ninja -DCMAKE_BUILD_TYPE=MinSizeRel \
      -DCMAKE_INSTALL_PREFIX="${HOME}"/llvm-test \
      -DCLANG_LINK_CLANG_DYLIB=ON -DLLVM_BUILD_TESTS=ON \
      -DLLVM_EXTERNAL_LIT="${PWD}"/bin/llvm-lit
    ninja check-clang

The tests will be run with LD_LIBRARY_PATH of:

    /home/${USER}/llvm-test/lib:/home/${USER}/llvm-project/build-clang/lib

As a result, installed libclang-cpp will take precedence over the one
from build dir.  With the patch, the correct path is used, i.e.:

    /home/${USER}/llvm-project/build-clang/lib:/home/${USER}/llvm-test/lib

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

(cherry picked from commit a64ea173d7b152678780d5443407d1071277642b)

19 months ago[clang-tidy] Fix a false positive in readability-simplify-boolean-expr
Nathan James [Sat, 24 Sep 2022 17:29:17 +0000 (18:29 +0100)]
[clang-tidy] Fix a false positive in readability-simplify-boolean-expr

Reviewed By: LegalizeAdulthood

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

(cherry picked from commit 8c783b8ec78ec857e446a89a35463baed8026f40)

19 months ago[AArch64][SVE] Fix AArch64_SVE_VectorCall calling convention
Matt Devereau [Thu, 8 Sep 2022 11:22:11 +0000 (11:22 +0000)]
[AArch64][SVE] Fix AArch64_SVE_VectorCall calling convention

This fixes the case where callees with SVE arguments outside of the z0-z7
range were incorrectly deduced as SVE calling convention functions

19 months agoRevert "Recommit "[SCEV] Look through single value PHIs." (take 3)"
Martin Storsjö [Wed, 5 Oct 2022 11:44:21 +0000 (14:44 +0300)]
Revert "Recommit "[SCEV] Look through single value PHIs." (take 3)"

This reverts commit 20d798bd47ec5191de1b2a8a031da06a04e612e1.

This commit caused crashes in some cases, see github issue #58152.
This is fixed on main, but backporting it requires multiple
nontrivial cherrypicks.

Updating llvm/test/Transforms/LoopVectorize/create-induction-resume.ll
with update_test_checks.py, so this isn't an exact automatic revert,
as that test case was added after the reverted commit.

This fixes #58152 for the release branch.

19 months agoFix LLDB build on old Linux kernels (pre-4.1)
David Spickett [Wed, 5 Oct 2022 07:31:03 +0000 (07:31 +0000)]
Fix LLDB build on old Linux kernels (pre-4.1)

These fields are guarded elsewhere, but were missing here.

Reviewed By: wallace

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

(chery picked from a9ffb473453519bae158e5d9c72431aa0f6aac2b)

19 months ago[Syntax] avoid using c++17 features on 15.x branch
Sam McCall [Mon, 10 Oct 2022 15:08:10 +0000 (17:08 +0200)]
[Syntax] avoid using c++17 features on 15.x branch

19 months agoBump version to 15.0.3
Tobias Hieta [Mon, 10 Oct 2022 06:53:34 +0000 (08:53 +0200)]
Bump version to 15.0.3

19 months ago[Syntax] Fix macro-arg handling in TokenBuffer::spelledForExpanded
Sam McCall [Mon, 26 Sep 2022 01:22:09 +0000 (03:22 +0200)]
[Syntax] Fix macro-arg handling in TokenBuffer::spelledForExpanded

A few cases were not handled correctly. Notably:
  #define ID(X) X
  #define HIDE a ID(b)
  HIDE
spelledForExpanded() would claim HIDE is an equivalent range of the 'b' it
contains, despite the fact that HIDE also covers 'a'.

While trying to fix this bug, I found findCommonRangeForMacroArgs hard
to understand (both the implementation and how it's used in spelledForExpanded).
It relies on details of the SourceLocation graph that are IMO fairly obscure.
So I've added/revised quite a lot of comments and made some naming tweaks.

Fixes https://github.com/clangd/clangd/issues/1289

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

(cherry picked from commit 67268ee11c220b1dfdf84afb10a12371c5ae6400)

19 months ago[clangd] Improve inlay hints of things expanded from macros
Sam McCall [Thu, 15 Sep 2022 22:41:32 +0000 (00:41 +0200)]
[clangd] Improve inlay hints of things expanded from macros

When we aim a hint at some expanded tokens, we're only willing to attach it
to spelled tokens that exactly corresponde.

e.g.
int zoom(int x, int y, int z);
int dummy = zoom(NUMBERS);

Here we want to place a hint "x:" on the expanded "1", but we shouldn't
be willing to place it on NUMBERS, because it doesn't *exactly*
correspond (it has more tokens).

Fortunately we don't even have to implement this algorithm from scratch,
TokenBuffer has it.

Fixes https://github.com/clangd/clangd/issues/1289
Fixes https://github.com/clangd/clangd/issues/1118
Fixes https://github.com/clangd/clangd/issues/1018

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

(cherry picked from commit 924974a3a13b03090d04860f209ce11b3d9d00a6)

19 months ago[X86] Remove AVX512VP2INTERSECT from Sapphire Rapids.
Freddy Ye [Sat, 8 Oct 2022 06:27:06 +0000 (14:27 +0800)]
[X86] Remove AVX512VP2INTERSECT from Sapphire Rapids.

For more details, please refer to the latest ISE document: https://www.intel.com/content/www/us/en/develop/download/intel-architecture-instruction-set-extensions-programming-reference.html

Reviewed By: pengfei

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

(cherry picked from commit 566c277c64f8f76d8911aa5fd931903a357ed7be)

19 months ago[clangd] Avoid scanning up to end of file on each comment!
Sam McCall [Wed, 5 Oct 2022 20:23:10 +0000 (22:23 +0200)]
[clangd] Avoid scanning up to end of file on each comment!

Assigning char* (pointing at comment start) to StringRef was causing us
to scan the rest of the source file looking for the null terminator.

This seems to be eating about 8% of our *total* CPU!

While fixing this, factor out the common bits from the two places we're
parsing IWYU pragmas.

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

(cherry picked from commit 5d2d527c32da2081b814ef8b446bc3e037f74b0a)

19 months ago[LoopVersioning] Invalidate SCEV for phi if new values are added.
Florian Hahn [Fri, 23 Sep 2022 10:53:29 +0000 (11:53 +0100)]
[LoopVersioning] Invalidate SCEV for phi if new values are added.

After 20d798bd47ec5191d, SCEV looks through PHIs with a single incoming
value. This means adding a new incoming value may change the SCEV for a
phi. Add missing invalidation when an existing PHI is reused during
LoopVersioning. New incoming values will be added later from the
versioned loop.

Similar issues have been fixed by also adding missing invalidation.

Fixes #57825.

Note that the test case unfortunately requires running loop-vectorize
followed by loop-load-elimination, which does the actual versioning. I
don't think it is possible to reproduce the failure without that
combination.

(cherry picked from commit 623c4a7a55f716b96070a5c2f83fe0096cb38d38)

19 months ago[clang-tools-extra] [clangd] Respect llvm_shlib_dir in tests
Michał Górny [Mon, 3 Oct 2022 07:59:34 +0000 (09:59 +0200)]
[clang-tools-extra] [clangd] Respect llvm_shlib_dir in tests

Add llvm_shlib_dir to variables used in clangd test suite, consistently
to how it is used in the test suites of clang, clang-tools-extra
and a few other components.  This is necessary to ensure that
the correct shared libraries are used when building clang standalone --
otherwise, use_clang() sets LD_LIBRARY_PATH to the directory containing
the earlier system installation of clang rather than the just-built
library.

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

(cherry picked from commit 77945a344c3dee3f9735744c8d4151ef2cec6a8d)

20 months agouse LLVM_USE_STATIC_ZSTD
Cole [Fri, 2 Sep 2022 21:00:07 +0000 (21:00 +0000)]
use LLVM_USE_STATIC_ZSTD

removes LLVM_PREFER_STATIC_ZSTD in favor of using a LLVM_USE_STATIC_ZSTD

Reviewed By: phosek

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

(cherry picked from commit fc1da043f4f9198303abd6f643cf23439115ce73)

20 months agotweak zstd behavior in cmake and llvm config for better testing
Cole Kissane [Thu, 1 Sep 2022 14:49:42 +0000 (07:49 -0700)]
tweak zstd behavior in cmake and llvm config for better testing

add LLVM_PREFER_STATIC_ZSTD (default TRUE) cmake config flag
(compression test seems to fail for shared zstd on windows, note that zstd multithread is by default disabled in the static build so it may be a hidden variable)
propagate variable zstd_DIR in LLVMConfig.cmake.in
fix llvm-config CMakeLists.txt behavior for absolute libs windows
get zstd lib name

Reviewed By: phosek

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

(cherry picked from commit c0b4f248df79f184adba856f13a950a53c881f3f)

20 months ago[clang][DebugInfo] Emit debuginfo for non-constant case value
Yonghong Song [Mon, 26 Sep 2022 14:08:24 +0000 (07:08 -0700)]
[clang][DebugInfo] Emit debuginfo for non-constant case value

Currently, clang does not emit debuginfo for the switch stmt
case value if it is an enum value. For example,
  $ cat test.c
  enum { AA = 1, BB = 2 };
  int func1(int a) {
    switch(a) {
    case AA: return 10;
    case BB: return 11;
    default: break;
    }
    return 0;
  }
  $ llvm-dwarfdump test.o | grep AA
  $
Note that gcc does emit debuginfo for the same test case.

This patch added such a support with similar implementation
to CodeGenFunction::EmitDeclRefExprDbgValue(). With this patch,
  $ clang -g -c test.c
  $ llvm-dwarfdump test.o | grep AA
                  DW_AT_name    ("AA")
  $

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

(cherry picked from commit 75be0482a2e2a78fae83f1ca604f4ee20d673796)

20 months ago[gn build] (manually) port 18b4a8bcf35 more
Nico Weber [Thu, 28 Jul 2022 11:14:43 +0000 (07:14 -0400)]
[gn build] (manually) port 18b4a8bcf35 more

(cherry picked from commit dd428a571c69621d5b6eb2e0e3ce5497c304fb2c)

20 months ago[LV] Update handling of scalable pointer inductions after b73d2c8.
Florian Hahn [Fri, 23 Sep 2022 17:23:01 +0000 (18:23 +0100)]
[LV] Update handling of scalable pointer inductions after b73d2c8.

The dependent code has been changed quite a lot since 151c144 which
b73d2c8 effectively reverts. Now we run into a case where lowering
didn't expect/support the behavior pre 151c144 any longer.

Update the code dealing with scalable pointer inductions to also check
for uniformity in combination with isScalarAfterVectorization. This
should ensure scalable pointer inductions are handled properly during
epilogue vectorization.

Fixes #57912.

(cherry picked from commit 2c692d891ed639779b1c4b504ca63037bbacc0e8)

20 months ago[LV] Add test for #57912.
Florian Hahn [Fri, 23 Sep 2022 10:44:13 +0000 (11:44 +0100)]
[LV] Add test for #57912.

Add test showing miscompilation during epilogue vectorization with SVE.

(cherry picked from commit 17167005d532dce35ade3a47a0403ffaa7fff6ff)

20 months ago[LV] Convert sve-epilog-vect.ll to use opaque pointers.
Florian Hahn [Fri, 23 Sep 2022 09:24:18 +0000 (10:24 +0100)]
[LV] Convert sve-epilog-vect.ll to use opaque pointers.

(cherry picked from commit 05b3493819fa8aba1eb7510afbcb80a64148beb6)

20 months ago[Clang] Fix variant crashes from GH58028, GH57370
Roy Jacobson [Thu, 29 Sep 2022 15:38:46 +0000 (18:38 +0300)]
[Clang] Fix variant crashes from GH58028, GH57370

Fixes a null dereference in some diagnostic issuing code.

Closes https://github.com/llvm/llvm-project/issues/57370
Closes https://github.com/llvm/llvm-project/issues/58028

Reviewed By: shafik

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

(cherry picked from commit 9415aad6a40fec74296008a25f34164a95c857f4)

20 months ago[ValueTracking] Fix CannotBeOrderedLessThanZero() for fdiv (PR58046)
Nikita Popov [Thu, 29 Sep 2022 13:51:05 +0000 (15:51 +0200)]
[ValueTracking] Fix CannotBeOrderedLessThanZero() for fdiv (PR58046)

When checking the RHS of fdiv, we should set the SignBitOnly flag,
because a negative zero can become -Inf, which is ordered less
than zero.

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

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

20 months ago[InstSimplify] Add test for PR58046 (NFC)
Nikita Popov [Thu, 29 Sep 2022 13:21:57 +0000 (15:21 +0200)]
[InstSimplify] Add test for PR58046 (NFC)

20 months ago[libcxx] Make stdatomic.h work when included from a C source file
Gergely Nagy [Tue, 27 Sep 2022 11:59:55 +0000 (07:59 -0400)]
[libcxx] Make stdatomic.h work when included from a C source file

If a C source file includes the libc++ stdatomic.h, compilation will
break because (a) the C++ standard check will fail (which is expected),
and (b) `_LIBCPP_COMPILER_CLANG_BASED` won't be defined because the
logic defining it in `__config` is guarded by a `__cplusplus` check, so
we'll end up with a blank header. Move the detection logic outside of
the `__cplusplus` check to make the second check pass even in a C context
when you're using Clang. Note that `_LIBCPP_STD_VER` is not defined when
in C mode, hence stdatomic.h needs to check if in C++ mode before using
that macro to avoid a warning.

In an ideal world, a C source file wouldn't be including the libc++
header directory in its search path, so we'd never have this issue.
Unfortunately, certain build environments make this hard to guarantee,
and in this case it's easy to tweak this header to make it work in a C
context, so I'm hoping this is acceptable.

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

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

(cherry picked from commit afec0f0ec38a72bcc6a697c1cefb1dac0bbd02fb)

20 months ago[docs] improve documentation for misc-const-correctness
Jonas Toth [Mon, 29 Aug 2022 09:19:16 +0000 (11:19 +0200)]
[docs] improve documentation for misc-const-correctness

Improve the documentation for 'misc-const-correctness' to:

- include better examples
- improve the english
- fix links to other checks that were broken due to the directory-layout changes
- mention the limitation that the check does not run on `C` code.

Addresses #56749, #56958

Reviewed By: njames93

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

(cherry picked from commit b5b750346346bfe95c7c6b1cceacc6cfccc8f4f4)

20 months ago[clang-tidy] adjust treating of array-of-pointers when 'AnalyzePointers' is deactivated
Jonas Toth [Sun, 25 Sep 2022 17:26:32 +0000 (19:26 +0200)]
[clang-tidy] adjust treating of array-of-pointers when 'AnalyzePointers' is deactivated

'misc-const-correctness' previously considered arrays as 'Values' independent of the type of the elements.
This is inconsistent with the configuration of the check to disable treating pointers as values.
This patch rectifies this inconsistency.

Fixes #56749

Reviewed By: njames93

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

(cherry picked from commit e66345d54d5f5e803f54c1ace487d57bb11ee884)

20 months agoFix build error in StmtPrinterTest.cpp
Nathan Ridge [Mon, 5 Sep 2022 07:48:17 +0000 (03:48 -0400)]
Fix build error in StmtPrinterTest.cpp

(cherry picked from commit c933453858307d060a1b79e257feb99c9ac828d7)

20 months ago[clangd] Avoid crash when printing call to string literal operator template
Nathan Ridge [Mon, 29 Aug 2022 08:19:19 +0000 (04:19 -0400)]
[clangd] Avoid crash when printing call to string literal operator template

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

(cherry picked from commit 898c421975ed36b99ec2047589384539bd29a40b)

20 months ago[ELF] Rewrite R_RISCV_ALIGN nops when r.addend%4 != 0
Fangrui Song [Mon, 26 Sep 2022 21:20:27 +0000 (14:20 -0700)]
[ELF] Rewrite R_RISCV_ALIGN nops when r.addend%4 != 0

For RVC, GNU assembler and LLVM integrated assembler add c.nop followed by a
sequence of 4-byte nops. Even if remove % 4 == 0, we have to split one 4-byte
nop and therefore need to write the code sequence, otherwise we create an
incorrect c.unimp.

(cherry picked from commit 78084d9e77b9a2017e2215491b71b37c2671c292)

20 months agoBump version to 15.0.2
Tobias Hieta [Mon, 26 Sep 2022 06:22:40 +0000 (08:22 +0200)]
Bump version to 15.0.2

20 months agoExclude check-polly-unittests and check-polly-isl from check-all
Eli Friedman [Wed, 24 Aug 2022 19:52:17 +0000 (12:52 -0700)]
Exclude check-polly-unittests and check-polly-isl from check-all

The unittests are already included in check-polly, so check-all was
running them twice.  Running them twice causes a race on the output
files, which led to intermittent failures on the reverse-iteration
buildbot.

(cherry picked from commit 2c29268bfcc84c3b94bcb0aa34b7ef9c9bd9af01)

20 months ago[Hexagon] Add defaulted operator= to classes with defaulted copy ctor
Krzysztof Parzyszek [Thu, 18 Aug 2022 20:50:20 +0000 (13:50 -0700)]
[Hexagon] Add defaulted operator= to classes with defaulted copy ctor

This avoids deprecation warning:
```
warning: definition of implicit copy assignment operator for 'AddrInfo'
is deprecated because it has a user-declared copy constructor
[-Wdeprecated-copy]
```

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

(cherry picked from commit 252cea037bcad6e1e7236756bcbb4e4ed73e328d)

20 months ago[MachineCycle][NFC] add a cache for block and its top level cycle
Chen Zheng [Fri, 16 Sep 2022 05:48:44 +0000 (01:48 -0400)]
[MachineCycle][NFC] add a cache for block and its top level cycle

This solves https://github.com/llvm/llvm-project/issues/57664

Reviewed By: sameerds

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

(cherry picked from commit c941d925b0e47ec166364178edac75cf1cb1ee1a)

20 months ago[libc++] Keep unary_function and binary_function in C++17 for one more release
Louis Dionne [Thu, 22 Sep 2022 20:17:31 +0000 (16:17 -0400)]
[libc++] Keep unary_function and binary_function in C++17 for one more release

In LLVM 15, we added the deprecation markup for unary_function and
binary_function for >= C++11, and we also removed it for >= C++17.
While this is in accordance with the Standard, it's also a bit quick
for our users, since there was no release in which the classes were
marked as deprecated before their removal.

We noticed widespread breakage due to this, and after months of trying
to fix downstream failures, I am coming to the conclusion that users
will be better served if we give them one release where unary_function
is deprecated but still provided even in >= C++17.

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

20 months agoSPIRV: Fix compilation in NDEBUG.
James Y Knight [Thu, 11 Aug 2022 22:41:22 +0000 (22:41 +0000)]
SPIRV: Fix compilation in NDEBUG.

(cherry picked from commit 59351fe340f20a605bae53260ed30a8e0fd95cb6)

20 months ago[LV] Keep track of cost-based ScalarAfterVec in VPWidenPointerInd.
Florian Hahn [Mon, 19 Sep 2022 17:14:34 +0000 (18:14 +0100)]
[LV] Keep track of cost-based ScalarAfterVec in VPWidenPointerInd.

Epilogue vectorization uses isScalarAfterVectorization to check if
widened versions for inductions need to be generated and bails out in
those cases.

At the moment, there are scenarios where isScalarAfterVectorization
returns true but VPWidenPointerInduction::onlyScalarsGenerated would
return false, causing widening.

This can lead to widened phis with incorrect start values being created
in the epilogue vector body.

This patch addresses the issue by storing the cost-model decision in
VPWidenPointerInductionRecipe and restoring the behavior before 151c144.
This effectively reverts 151c144, but the long-term fix is to properly
support widened inductions during epilogue vectorization

Fixes #57712.

20 months ago[LV] Move new epilog-vectorization-widen-inductions.ll to AArch64 dir.
Florian Hahn [Mon, 19 Sep 2022 16:12:31 +0000 (17:12 +0100)]
[LV] Move new epilog-vectorization-widen-inductions.ll to AArch64 dir.

The test requires the AArch64 backend, so move it to the right subdir.

20 months ago[LV] Add tests for epilogue vectorization with widened inductions.
Florian Hahn [Mon, 19 Sep 2022 16:10:40 +0000 (17:10 +0100)]
[LV] Add tests for epilogue vectorization with widened inductions.

Includes a test for the miscompile in #57712.

20 months ago[libc++] Always query the compiler to find whether a type is always lockfree
Louis Dionne [Tue, 6 Sep 2022 21:07:18 +0000 (17:07 -0400)]
[libc++] Always query the compiler to find whether a type is always lockfree

In https://llvm.org/D56913, we added an emulation for the __atomic_always_lock_free
compiler builtin when compiling in Freestanding mode. However, the emulation
did (and could not) give exactly the same answer as the compiler builtin,
which led to a potential ABI break for e.g. enum classes.

After speaking to the original author of D56913, we agree that the correct
behavior is to instead always use the compiler builtin, since that provides
a more accurate answer, and __atomic_always_lock_free is a purely front-end
builtin which doesn't require any runtime support. Furthermore, it is
available regardless of the Standard mode (see https://godbolt.org/z/cazf3ssYY).

However, this patch does constitute an ABI break. As shown by https://godbolt.org/z/1eoex6zdK:
- In LLVM <= 11.0.1, an atomic<enum class with 1 byte> would not contain a lock byte.
- In LLVM >= 12.0.0, an atomic<enum class with 1 byte> would contain a lock byte.

This patch breaks the ABI again to bring it back to 1 byte, which seems
like the correct thing to do.

Fixes #57440

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

(cherry picked from commit f1a601fe88f99d52ca80617266897b217bcd4d64)

20 months ago[docs] Fix build-docs.sh
Tobias Hieta [Mon, 19 Sep 2022 19:42:42 +0000 (21:42 +0200)]
[docs] Fix build-docs.sh

If libcxxabi is not included CMake will error out:

Cannot find target libcxxabi-SHARED

I ran into this doing the 15.0.0 release

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

20 months ago[libcxx] Bump libc++ version to 15.0.1
Tobias Hieta [Mon, 19 Sep 2022 17:47:45 +0000 (19:47 +0200)]
[libcxx] Bump libc++ version to 15.0.1

20 months ago[CodeGen] Don't zero callee-save registers with zero-call-used-regs (PR57692)
Nikita Popov [Thu, 15 Sep 2022 15:00:55 +0000 (17:00 +0200)]
[CodeGen] Don't zero callee-save registers with zero-call-used-regs (PR57692)

Callee save registers must be preserved, so -fzero-call-used-regs
should not be zeroing them. The previous implementation only did
not zero callee save registers that were saved&restored inside the
function, but we need preserve all of them.

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

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

(cherry picked from commit b4309800e9dc53a84222a6b57c8615d4a3084988)

20 months ago[lit] Set shlibpath_var on OpenBSD
Brad Smith [Fri, 16 Sep 2022 01:43:01 +0000 (21:43 -0400)]
[lit] Set shlibpath_var on OpenBSD

(cherry picked from commit 3eca0b395ff07d0428f4179e33a6ae295e608f47)

20 months ago[clang(d)] Include/Exclude CLDXC options properly
Kadir Cetinkaya [Thu, 15 Sep 2022 18:57:07 +0000 (20:57 +0200)]
[clang(d)] Include/Exclude CLDXC options properly

This handles the new CLDXC options that was introduced in
https://reviews.llvm.org/D128462 inside clang-tooling to make sure cl driver
mode is not broken.

Fixes https://github.com/clangd/clangd/issues/1292.

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

(cherry picked from commit 23ace26e0d1aa2283d65d192c37592fb0eef1b1f)

20 months ago[Libomptarget] Revert changes to AMDGPU plugin destructors
Joseph Huber [Thu, 15 Sep 2022 23:28:52 +0000 (18:28 -0500)]
[Libomptarget] Revert changes to AMDGPU plugin destructors

These patches exposed a lot of problems in the AMD toolchain. Rather
than keep it broken we should revert it to its old semi-functional
state. This will prevent us from using device destructors but should
remove some new bugs. In the future this interface should be changed
once these problems are addressed more correctly.

This reverts commit ed0f21811544320f829124efbb6a38ee12eb9155.

This reverts commit 2b7203a35972e98b8521f92d2791043dc539ae88.

Fixes #57536

Reviewed By: jdoerfert

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

20 months ago[llvm-objdump] Change printSymbolVersionDependency to use ELFFile API
Fangrui Song [Wed, 14 Sep 2022 19:30:34 +0000 (12:30 -0700)]
[llvm-objdump] Change printSymbolVersionDependency to use ELFFile API

When .gnu.version_r is empty (allowed by readelf but warned by objdump),
llvm-objdump -p may decode the next section as .gnu.version_r and may crash due
to out-of-bounds C string reference. ELFFile<ELFT>::getVersionDependencies
handles 0-entry .gnu.version_r gracefully. Just use it.

Fix https://github.com/llvm/llvm-project/issues/57707

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

(cherry picked from commit 25394c9d10e73b666f4fa1dff2426824894cce58)

20 months ago[llvm-objdump][test] Add verneed-invalid.test
Fangrui Song [Wed, 14 Sep 2022 19:27:30 +0000 (12:27 -0700)]
[llvm-objdump][test] Add verneed-invalid.test

(cherry picked from commit 55a72dae1f996e4fb1528c1b6b1bff8550fec303)

20 months ago[compiler-rt] Handle non-canonical triples with new runtime lib layout
Rainer Orth [Sun, 11 Sep 2022 09:25:53 +0000 (11:25 +0200)]
[compiler-rt] Handle non-canonical triples with new runtime lib layout

As described in Issue #54196
<https://github.com/llvm/llvm-project/issues/54196>, the ideas of `clang`
and `compiler-rt` where runtime libs are located with
`-DLLVM_ENABLE_RUNTIMES` can differ.  This is the `compiler-rt` side of the
patch I've used to get them in sync for the `amd64-pc-solaris2.11` and
`sparc64-unknown-linux-gnu` release builds.

Tested on  `amd64-pc-solaris2.11` and `sparc64-unknown-linux-gnu`.

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

(cherry picked from commit cadc9cdedfef892b00b17658a823e4846a71e3ac)

20 months ago[NFC] Fix exception in version-check.py script
Tobias Hieta [Thu, 15 Sep 2022 11:32:32 +0000 (13:32 +0200)]
[NFC] Fix exception in version-check.py script

20 months agoBump version to 15.0.1
Tobias Hieta [Thu, 15 Sep 2022 08:16:56 +0000 (10:16 +0200)]
Bump version to 15.0.1

20 months agoDowngrade implicit int and implicit function declaration to warning only
Aaron Ballman [Wed, 14 Sep 2022 14:10:56 +0000 (10:10 -0400)]
Downgrade implicit int and implicit function declaration to warning only

The changes in Clang 15.0.0 which enabled these diagnostics as a
warning which defaulted to an error caused disruption for people
working on distributions such as Gentoo. There was an explicit request
to downgrade these to be warning-only in Clang 15.0.1 with the
expectation that Clang 16 will default the diagnostics to an error.

See
https://discourse.llvm.org/t/configure-script-breakage-with-the-new-werror-implicit-function-declaration/65213
for more details on the discussion.

See https://reviews.llvm.org/D133800 for the public review of these
changes.

20 months ago[MachO] Don't fold compact unwind entries with LSDA
Shoaib Meenai [Sun, 28 Aug 2022 20:09:56 +0000 (01:09 +0500)]
[MachO] Don't fold compact unwind entries with LSDA

Folding them will cause the unwinder to compute the incorrect function
start address for the folded entries, which in turn will cause the
personality function to interpret the LSDA incorrectly and break
exception handling.

You can verify the end-to-end flow by creating a simple C++ file:
```
void h();
int main() { h(); }
```

and then linking this file against the liblsda.dylib produced by the
test case added here. Before this change, running the resulting program
would result in a program termination with an uncaught exception.
Afterwards, it works correctly.

Reviewed By: #lld-macho, thevinster

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

(cherry picked from commit 56bd3185cdd8d79731acd6c75bf41869284a12ed)

20 months ago[MachO] Fix dead-stripping __eh_frame
Shoaib Meenai [Mon, 22 Aug 2022 19:55:41 +0000 (22:55 +0300)]
[MachO] Fix dead-stripping __eh_frame

This section is marked S_ATTR_LIVE_SUPPORT in input files, which meant
that on arm64, we were unnecessarily preserving FDEs if we e.g. had
multiple weak definitions for a function. Worse, we would actually
produce an invalid `__eh_frame` section in that case, because the CIE
associated with the unnecessary FDE would still get dead-stripped and
we'd end up with a dangling FDE. We set up associations from functions
to their FDEs, so dead-stripping will just work naturally, and we can
clear S_ATTR_LIVE_SUPPORT from our input `__eh_frame` sections to fix
dead-stripping.

Reviewed By: #lld-macho, int3

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

(cherry picked from commit a745e47900dde15c180d5caea7a1d292ca809eb1)

20 months ago[libc++][format] Updates feature-test macros.
Mark de Wever [Sun, 4 Sep 2022 11:56:36 +0000 (13:56 +0200)]
[libc++][format] Updates feature-test macros.

During the discussion on the SG-10 mailinglist regarding the format
feature-test macros voted in during the last plenary it turns out libc++
can't mark the format feature-test macro as implemented.

According to
  https://isocpp.org/std/standing-documents/sd-6-sg10-feature-test-recommendations#__cpp_lib_format
the not yet implemented paper
  P1361R2 Integration of chrono with text formatting
affects the feature test macro.

Note that P1361R2 doesn't mention the feature-test macro nor is there an
LWG-issue to address the issue. The reporter of the issue didn't recall
where this requirement exactly has been decided.

Reviewed By: ldionne, #libc

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

20 months ago[LLD][COFF] Fix writing a map file when range extension thunks are inserted
Jan Ole Hüser [Wed, 7 Sep 2022 06:17:10 +0000 (09:17 +0300)]
[LLD][COFF] Fix writing a map file when range extension thunks are inserted

Bug: An assertion fails:

    Assertion failed: isa<To>(Val) && "cast<Ty>() argument of incompatible type!",
    file C:\Users\<user>\prog\llvm\llvm-git-lld-bug\llvm\include\llvm/Support/Casting.h, line 578

Bug is triggered, if

    - a map file is requested with /MAP, and
    - Architecture is ARMv7, Thumb, and
    - a relative jump (branch instruction) is greater than 16 MiB (2^24)

The reason for the Bug is:

    - a Thunk is created for the jump
    - a Symbol for the Thunk is created
        - of type `DefinedSynthetic`
        - in file `Writer.cpp`
        - in function `getThunk`
    - the Symbol has no name
    - when creating the map file, the name of the Symbol is queried
    - the function `Symbol::computeName` of the base class `Symbol`
      casts the `this` pointer to type `DefinedCOFF` (a derived type),
      but the acutal type is `DefinedSynthetic`
    - The in the llvm::cast an assertion fails

Changes:

- Modify regression test to trigger this bug
- Give the symbol pointing to the thunk a name, to fix the bug
- Add assertion, that only DefinedCOFF symbols are allowed to have an
  empty name, when the constructor of the base class Symbol is executed

Reviewed By: rnk

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

(cherry picked from commit 4e5a59a3839f54d928d37d49d4c4ddbb3f339b76)

20 months ago[mlir] Fix building CRunnerUtils on OpenBSD with 15.x
Brad Smith [Sat, 10 Sep 2022 00:33:30 +0000 (20:33 -0400)]
[mlir] Fix building CRunnerUtils on OpenBSD with 15.x

CRunnerUtils builds as C++11. 9c1d133c3a0256cce7f40e2e06966f84e8b99ffe broke
the build on OpenBSD. aligned_alloc() was only introduced in C++17.

20 months ago[DwarfEhPrepare] Assign dummy debug location for inserted _Unwind_Resume calls (PR57469)
Nikita Popov [Thu, 1 Sep 2022 08:13:35 +0000 (10:13 +0200)]
[DwarfEhPrepare] Assign dummy debug location for inserted _Unwind_Resume calls (PR57469)

DwarfEhPrepare inserts calls to _Unwind_Resume into landing pads.
If _Unwind_Resume happens to be defined in the same module and
debug info is used, then this leads to a verifier error:

  inlinable function call in a function with debug info must
    have a !dbg location
  call void @_Unwind_Resume(ptr %exn.obj) #0

Fix this by assigning a dummy location to the call. (As this
happens in the backend, inlining is not actually relevant here.)

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

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

(cherry picked from commit 5134bd432f8c35c87f4c4dc3bb744d396adcab58)

20 months ago[Clang] Fix crash in coverage of if consteval.
Corentin Jabot [Fri, 26 Aug 2022 08:20:12 +0000 (10:20 +0200)]
[Clang] Fix crash in coverage of if consteval.

Clang crashes when encountering an `if consteval` statement.
This is the minimum fix not to crash.
The fix is consistent with the current behavior of if constexpr,
which does generate coverage data for the discarded branches.
This is of course not correct and a better solution is
needed for both if constexpr and if consteval.
See https://github.com/llvm/llvm-project/issues/54419.

Fixes #57377

Reviewed By: aaron.ballman

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

20 months ago[clang] Skip re-building lambda expressions in parameters to consteval fns.
Utkarsh Saxena [Tue, 30 Aug 2022 14:57:07 +0000 (16:57 +0200)]
[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

(cherry picked from commit e7eec38246560781e0a4020b19c7eb038a8c5655)

20 months ago[DAG] extractShiftForRotate - replace assertion for shift opcode with an early-out
Simon Pilgrim [Wed, 31 Aug 2022 13:39:32 +0000 (14:39 +0100)]
[DAG] extractShiftForRotate - replace assertion for shift opcode with an early-out

We feed the result from the first extractShiftForRotate call into the second, and that result might no longer be a shift op (usually due to constant folding).

NOTE: We REALLY need to stop creating nodes on the fly inside extractShiftForRotate!

Fixes Issue #57474

(cherry picked from commit eaede4b5b7cfc13ca0e484b4cb25b2f751d86fd9)

20 months ago[clang-format] Distinguish logical and after bracket from reference
jackh [Sat, 13 Aug 2022 03:12:10 +0000 (11:12 +0800)]
[clang-format] Distinguish logical and after bracket from reference

Fix commit `b646f0955574` and remove redundant code.

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

(cherry picked from commit ef71383b0cfbacdbebf495015f6ead5294bf7759)

20 months ago[compiler-rt] [test] Handle missing ld.gold gracefully
Michał Górny [Tue, 6 Sep 2022 13:40:10 +0000 (15:40 +0200)]
[compiler-rt] [test] Handle missing ld.gold gracefully

Fix the is_binutils_lto_supported() function to handle missing
executables gracefully.  Currently, the function does not catch
exceptions from subprocess.Popen() and therefore causes lit to crash
if config.gold_executable does not specify a valid executable:

```
lit: /usr/lib/python3.11/site-packages/lit/TestingConfig.py:136: fatal: unable to parse config file '/tmp/portage/sys-libs/compiler-rt-
15.0.0/work/compiler-rt/test/lit.common.cfg.py', traceback: Traceback (most recent call last):
  File "/usr/lib/python3.11/site-packages/lit/TestingConfig.py", line 125, in load_from_path
    exec(compile(data, path, 'exec'), cfg_globals, None)
  File "/tmp/portage/sys-libs/compiler-rt-15.0.0/work/compiler-rt/test/lit.common.cfg.py", line 561, in <module>
    if is_binutils_lto_supported():
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/portage/sys-libs/compiler-rt-15.0.0/work/compiler-rt/test/lit.common.cfg.py", line 543, in is_binutils_lto_supported
    ld_cmd = subprocess.Popen([exe, '--help'], stdout=subprocess.PIPE, env={'LANG': 'C'})
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/subprocess.py", line 1022, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib/python3.11/subprocess.py", line 1899, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'GOLD_EXECUTABLE-NOTFOUND'
```

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

(cherry picked from commit ea953b9d9a65c202985a79f1f95da115829baef6)

21 months ago[Symbolizer] Handle {{{bt}}} symbolizer markup element.
Daniel Thornburgh [Fri, 5 Aug 2022 21:58:44 +0000 (14:58 -0700)]
[Symbolizer] Handle {{{bt}}} symbolizer markup element.

This adds support for backtrace generation to the llvm-symbolizer markup
filter, which is likely the largest use case.

Reviewed By: peter.smith

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

(cherry picked from commit ea99225521cba6dec1ad4ca70a8665829e772fa9)

21 months ago[Symbolizer] Fix symbolizer-filter-markup-pc.test on Windows
Daniel Thornburgh [Mon, 8 Aug 2022 18:39:44 +0000 (11:39 -0700)]
[Symbolizer] Fix symbolizer-filter-markup-pc.test on Windows

(cherry picked from commit 0d6cf1e8b5fa8590f816d5330cb7c2dcc449ec24)

21 months ago[Symbolizer] Implement pc element in symbolizing filter.
Daniel Thornburgh [Mon, 1 Aug 2022 21:35:25 +0000 (14:35 -0700)]
[Symbolizer] Implement pc element in symbolizing filter.

Implements the pc element for the symbolizing filter, including it's
"ra" and "pc" modes. Return addresses ("ra") are adjusted by
decrementing one. By default, {{{pc}}} elements are assumed to point to
precise code ("pc") locations. Backtrace elements will adopt the
opposite convention.

Along the way, some minor refactors of value printing and colorization.

Reviewed By: peter.smith

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

(cherry picked from commit bf48b128b02813e53e0c8f6585db837d14c9358f)

21 months ago[Symbolizer] Implement data symbolizer markup element.
Daniel Thornburgh [Tue, 19 Jul 2022 21:20:12 +0000 (14:20 -0700)]
[Symbolizer] Implement data symbolizer markup element.

This connects the Symbolizer to the markup filter and enables the first
working end-to-end flow using the filter.

Reviewed By: peter.smith

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

(cherry picked from commit 22df238d4a642a4553ebf7b91325189be48b139d)

21 months agoAMDGPU: mbcnt allow for non-zero src1 for known-bits
David Stuttard [Tue, 9 Aug 2022 07:46:55 +0000 (08:46 +0100)]
AMDGPU: mbcnt allow for non-zero src1 for known-bits

Src1 for mbcnt can be a non-zero literal or register. Take this into account
when calculating known bits.

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

(cherry picked from commit 1d1cc05539e275ae7666fc4b44bf725ec335078a)

21 months ago[RISCV][ReleaseNotes] Added LLVM and Clang release notes for RISC-V 15.0.0
Alex Bradbury [Mon, 5 Sep 2022 09:48:03 +0000 (10:48 +0100)]
[RISCV][ReleaseNotes] Added LLVM and Clang release notes for RISC-V 15.0.0

21 months ago[DOCS] Minor fixes and removals of WIP warnings
Tobias Hieta [Sun, 4 Sep 2022 14:48:01 +0000 (16:48 +0200)]
[DOCS] Minor fixes and removals of WIP warnings

21 months ago[RLEV] Pick a correct insert point when incoming instruction is itself a phi node
Philip Reames [Mon, 29 Aug 2022 18:37:42 +0000 (11:37 -0700)]
[RLEV] Pick a correct insert point when incoming instruction is itself a phi node

This fixes https://github.com/llvm/llvm-project/issues/57336. It was exposed by a recent SCEV change, but appears to have been a long standing issue.

Note that the whole insert into the loop instead of a split exit edge is slightly contrived to begin with; it's there solely because IndVarSimplify preserves the CFG.

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

(cherry picked from commit c37b1a5f764380f83ba08ae0cebca2b162123eb6)

21 months ago[clang] Add __is_target_variant_{os,environment} builtins
Nico Weber [Fri, 26 Aug 2022 18:40:59 +0000 (14:40 -0400)]
[clang] Add __is_target_variant_{os,environment} builtins

Xcode 13's clang has them. For the included testcase, Xcode's clang
behaves like the implementation in this patch.

Availability.h in the macOS 12.0 SDK (part of Xcode 13, and the current
stable version of the macOS SDK) does something like:

   #if defined(__has_builtin)
     ...
     #if __has_builtin(__is_target_os)
      #if __has_builtin(__is_target_environment)
       #if __has_builtin(__is_target_variant_os)
        #if __has_builtin(__is_target_variant_environment)
         #if (... && ((__is_target_os(ios) && __is_target_environment(macabi)) || (__is_target_variant_os(ios) && __is_target_variant_environment(macabi))))
           #define __OSX_AVAILABLE_STARTING(_osx, _ios) ...
           #define __OSX_AVAILABLE_BUT_DEPRECATED(_osxIntro, _osxDep, _iosIntro, _iosDep) ...
           #define __OSX_AVAILABLE_BUT_DEPRECATED_MSG(_osxIntro, _osxDep, _iosIntro, _iosDep, _msg) ...

So if __has_builtin(__is_target_variant_os) or
__has_builtin(__is_target_variant_environment) are false, these defines are not
defined.

Most of the time, this doesn't matter. But open-source clang currently fails
to commpile a file containing only `#include <Security/cssmtype.h>` when
building for catalyst by adding a `-target arm64-apple-ios13.1-macabi` triple,
due to those __OSX_AVAILABLE macros not being set correctly.

If a potential future SDK version were to include cssmtype.h transitively
from a common header such as `<Foundation/Foundation.h>`, then it would become
close to impossible to build Catalyst binaries with open-source clang.

To fix this for normal catalyst builds, it's only necessary that
__has_builtin() evaluates to true for these two built-ins -- the implementation
of them doesn't matter. But as a courtesy, a correct (at least on the test
cases I tried) implementation is provided. (This should also help people who
try to build zippered code, where having the correct implementation does
matter.)

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

21 months ago[SystemZ][z/OS] Account for renamed parameter name (libc++)
Muiez Ahmed [Tue, 30 Aug 2022 18:18:44 +0000 (14:18 -0400)]
[SystemZ][z/OS] Account for renamed parameter name (libc++)

The following patch (https://reviews.llvm.org/D129051) broke z/OS builds by renaming the parameter name. This patch accounts for that change.

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

(cherry picked from commit e1e9961f7692cfb84c4b3bb213d515d4c80332a4)

21 months ago[Docs][OpenCL][SPIR-V] Release 15 notes for Clang.
Anastasia Stulova [Thu, 1 Sep 2022 09:04:50 +0000 (10:04 +0100)]
[Docs][OpenCL][SPIR-V] Release 15 notes for Clang.

21 months ago[Frontend] Restore Preprocessor::getPredefines()
Roy Jacobson [Wed, 31 Aug 2022 19:27:09 +0000 (22:27 +0300)]
[Frontend] Restore Preprocessor::getPredefines()

https://reviews.llvm.org/rG6bbf51f3ed59ae37f0fec729f25af002111c9e74 from May removed Preprocessor::getPredefines() from Clang's API, presumably as a cleanup because this method is unused in the LLVM codebase.

However, it was/is used by a small number of third-party tools and is pretty harmless, so this patch adds it back and documents why it's here.

The issue was raised in https://github.com/llvm/llvm-project/issues/57483, it would be nice to be able to land it into Clang 15 as it breaks those third-party tools and we can't easily add it back in bug fix releases.

Reviewed By: brad.king, thieta

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

(cherry picked from commit bb9dedce5d01f5608acd784942481f386c710c0d)

21 months ago[docs] Add "Standard C++ Modules"
Chuanqi Xu [Wed, 31 Aug 2022 03:09:46 +0000 (11:09 +0800)]
[docs] Add "Standard C++ Modules"

We get some standard C++ module things done in clang15.x. But we lack a
user documentation for it. The implementation of standard C++ modules
share a big part of codes with clang modules. But they have very
different semantics and user interfaces, so I think it is necessary to
add a document for Standard C++ modules. Previously, there were also
some people ask the document for standard C++ Modules and I couldn't
offer that time.

Reviewed By: iains, Mordante, h-vetinari, ruoso, dblaikie, JohelEGP,
aaronmondal

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

(cherry picked from commit b1d5af81249dc7e5697faf9ee33f86012ccd8668)

21 months ago[SLP]Fix PR57447: Assertion `!getTreeEntry(V) && "Scalar already in tree!"' failed.
Alexey Bataev [Tue, 30 Aug 2022 15:09:31 +0000 (08:09 -0700)]
[SLP]Fix PR57447: Assertion `!getTreeEntry(V) && "Scalar already in tree!"' failed.

The pointer operands for the ScatterVectorize node may contain
non-instruction values and they are not checked for "already being
vectorized". Need to check that such pointers are already vectorized and
gather them instead of trying to build vectorize node to avoid compiler
crash.

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

(cherry picked from commit ec06df9459136ed538c07d32db16163999c350fe)

21 months ago[MCContext] Reverse order of DebugPrefixMap sort for generated assembly debug info
Dan McGregor [Thu, 25 Aug 2022 04:43:40 +0000 (21:43 -0700)]
[MCContext] Reverse order of DebugPrefixMap sort for generated assembly debug info

Match Clang's sorting, so that longer (more specific) prefix paths will match
before less specific paths.

Reviewed By: MaskRay, raj.khem, #debug-info

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

(cherry picked from commit 3922ec46b84a877a9ac6ce4cfa765c4c847d097d)