platform/upstream/llvm.git
9 months ago[OpenMP] Use the more appropriate function to retrieve the thread id on OpenBSD ...
Brad Smith [Fri, 8 Sep 2023 01:05:25 +0000 (21:05 -0400)]
[OpenMP] Use the more appropriate function to retrieve the thread id on OpenBSD (#65553)

Use the getthrid() function instead of a syscall.

(cherry picked from commit 7e31b45d6a2571ff17426930dcbb784473a965b4)

9 months ago[libc++] Encode additional ODR-affecting properties in the ABI tag (#69669)
Louis Dionne [Thu, 26 Oct 2023 13:05:16 +0000 (09:05 -0400)]
[libc++] Encode additional ODR-affecting properties in the ABI tag (#69669)

As explained in `__config`, we have an ABI tag that we use to ensure
that we don't run into ODR issues when mixing different versions of
libc++ in multiple TUs. However, the reasoning behind that extends not
only to different versions of libc++, but also to different
configurations of the same version of libc++. In fact, we've been aware
of this for a while but never really bothered to make the change because
ODR issues are often thought to be benign.

Well, it turns out that I just spent over an hour banging my head
against an issue that boils down to our lack of encoding of some ODR
properties in the ABI tag, so here's the patch we should have done a
long time ago.

For now, the ODR properties we encode in the ABI tag are:
- library version
- exceptions vs no-exceptions
- hardening mode

Those are all things that we support different values for on a per-TU
basis and they definitely affect ODR in a meaningful way. We can add
more properties later as we see fit.

(cherry picked from commit bc792a284362696c91599f9ab01f74eda4b9108f)

9 months ago[AArch64] Prevent argument promotion of vector with size > 128 bits (#70034)
KAWASHIMA Takahiro [Thu, 26 Oct 2023 05:51:20 +0000 (14:51 +0900)]
[AArch64] Prevent argument promotion of vector with size > 128 bits (#70034)

This patch prevents argument promotion from promoting pointers to
fixed-length vector types larger than 128 bits like `<8 x float>` into
the values of the pointees.

Such vector types are used for SVE VLS but there is no ABI for SVE VLS
arguments and the backend cannot lower such value arguments.

Fixes #69147

(cherry picked from commit 926173c614784149889b2c975adccf52bcece75b)

9 months ago[LoongArch] Implement COPY instruction between CFRs (#69300)
wanglei [Thu, 19 Oct 2023 01:20:27 +0000 (09:20 +0800)]
[LoongArch] Implement COPY instruction between CFRs (#69300)

With this patch, all CFRs can be used for register allocation.

(cherry picked from commit 271087e3a0875672b26c185a28b3552d5600d2fb)

9 months agoRevert "[clang-format] Fix align consecutive declarations over function pointers"
Owen Pan [Tue, 24 Oct 2023 09:13:14 +0000 (02:13 -0700)]
Revert "[clang-format] Fix align consecutive declarations over function pointers"

This reverts commit a84e0b4bdc9999872adbdaafbade8164b197784b.

Fixes #68079.

(cherry picked from commit 7bc1031c474ebb2216a5432273dafe4d1490fbce)

9 months agoFix tests for c23 <-> c2x
Aaron Ballman [Wed, 25 Oct 2023 15:57:17 +0000 (11:57 -0400)]
Fix tests for c23 <-> c2x

9 months agoFix a c23 -> c2x think-o
Aaron Ballman [Wed, 25 Oct 2023 13:10:34 +0000 (09:10 -0400)]
Fix a c23 -> c2x think-o

9 months ago[C23] Use thread_local semantics (#70107)
Aaron Ballman [Wed, 25 Oct 2023 11:51:28 +0000 (07:51 -0400)]
[C23] Use thread_local semantics (#70107)

When implementing thread_local as a keyword in C23, we accidentally
started using C++11 thread_local semantics when using that keyword
instead of using C11 _Thread_local semantics.

This oversight is fixed by pretending the user wrote _Thread_local
instead. This doesn't have the best behavior in terms of diagnostics,
but it does correct the semantic behavior.

Fixes https://github.com/llvm/llvm-project/issues/70068
Fixes https://github.com/llvm/llvm-project/issues/69167

9 months ago[clangd] Disable crashy unchecked-optional-access tidy check (#69427)
kadir çetinkaya [Thu, 19 Oct 2023 07:24:22 +0000 (09:24 +0200)]
[clangd] Disable crashy unchecked-optional-access tidy check (#69427)

Fixes https://github.com/llvm/llvm-project/issues/69369.
Fixes https://github.com/clangd/clangd/issues/1700.

(cherry picked from commit e63ab13c82e78f65baca48d5b5e4f6ea8d55dbc7)

9 months ago[ConstraintElim] Don't decompose values wider than 64 bits (#68803)
Nikita Popov [Mon, 16 Oct 2023 10:03:49 +0000 (12:03 +0200)]
[ConstraintElim] Don't decompose values wider than 64 bits (#68803)

Our coefficients are 64-bits, so adding/multiplying them can wrap in
64-bits even if there would be no wrapping the full bit width.

The alternative would be to check for overflows during all adds/muls in
decomposition. I assume that we don't particularly care about handling
wide integers here, so I've opted to bail out.

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

(cherry picked from commit 1d43096e16ff7288c7feac1ae81fd4f745ce10bb)

9 months ago[ConstraintElim] Add test for #68751 (NFC)
Nikita Popov [Wed, 11 Oct 2023 13:52:18 +0000 (15:52 +0200)]
[ConstraintElim] Add test for #68751 (NFC)

(cherry picked from commit 2b74db6c9bff757ce016d62a7086617e2b9e43b3)

9 months ago[mlir] Avoid including <alloca.h> on DragonFly
Brad Smith [Sat, 21 Oct 2023 05:18:36 +0000 (01:18 -0400)]
[mlir] Avoid including <alloca.h> on DragonFly

(cherry picked from commit a157a82b1e7a8d4be34cc862db4b42fa9db363d0)

9 months ago[LVI][CVP] Treat undef like a full range on abs(x, false) (#68711)
DianQK [Sun, 15 Oct 2023 22:25:23 +0000 (06:25 +0800)]
[LVI][CVP] Treat undef like a full range on abs(x, false) (#68711)

Fixes #68682.

(cherry picked from commit 2ad9a658005e6a4204d7ee617c3949632a707aa5)

9 months ago[libcxx] [test] Add a test parameter for disabling memory intensive tests (#68214)
Martin Storsjö [Tue, 17 Oct 2023 19:49:52 +0000 (22:49 +0300)]
[libcxx] [test] Add a test parameter for disabling memory intensive tests (#68214)

Specifically, the test std/input.output/string.streams/stringstream/stringstream.members/gcount.pass.cpp
allocates a std::string with INT_MAX-1 elements, and then writes this to
a std::stringstream. On Linux, running this test consumes around 5.0 GB
of memory; on Windows, it ends up using up to 6.8 GB of memory.

This limits whether such tests can run on e.g. GitHub Actions runners,
where the free runners are limited to 8 GB of memory.

This is somewhat similar to, but still notably different, from the
existing test parameter long_tests.

(cherry picked from commit 122064a6303eb9c06e0af231f5a4ce145d9a2e67)

9 months agoworkflows/release-tasks: Fix release note artifact upload (#69522)
Tom Stellard [Thu, 19 Oct 2023 21:02:23 +0000 (14:02 -0700)]
workflows/release-tasks: Fix release note artifact upload (#69522)

(cherry picked from commit afdad4fd402d1e8917375960df7104bc16f4cba9)

9 months agoBump version to 17.0.4
Tobias Hieta [Mon, 23 Oct 2023 07:39:40 +0000 (09:39 +0200)]
Bump version to 17.0.4

9 months agoworkflows/release-lit: Pass correct build directory to pypa/gh-action-pypi-publish...
Tom Stellard [Wed, 18 Oct 2023 21:02:05 +0000 (14:02 -0700)]
workflows/release-lit: Pass correct build directory to pypa/gh-action-pypi-publish (#69438)

(cherry picked from commit 1db8abf21a7c025d850624b487b5b792c562094e)

9 months agoworkflows/release-lit: Fix dev suffix removal (#69397)
Tom Stellard [Wed, 18 Oct 2023 21:01:53 +0000 (14:01 -0700)]
workflows/release-lit: Fix dev suffix removal (#69397)

This was broken by b71edfaa4ec3c998aadb35255ce2f60bba2940b0.

(cherry picked from commit 6a7f0b9d9fb533abeb14a7b5af03205688b3786a)

9 months ago[asan] Ensure __asan_register_elf_globals is called in COMDAT asan.module_ctor (...
Fangrui Song [Wed, 11 Oct 2023 16:23:56 +0000 (09:23 -0700)]
[asan] Ensure __asan_register_elf_globals is called in COMDAT asan.module_ctor (#67745)

On ELF platforms, when there is no global variable and the unique module ID is
non-empty, COMDAT asan.module_ctor is created with no
`__asan_register_elf_globals` calls. If this COMDAT is the prevailing copy
selected by the linker, the linkage unit will have no
`__asan_register_elf_globals` call: the redzone will not be poisoned and ODR
violation checker will not work (#67677).

This behavior is benign for -fno-sanitize-address-globals-dead-stripping because
asan.module_ctor functions that call `__asan_register_globals`
(`InstrumentGlobalsWithMetadataArray`) do not use COMDAT.

To fix #67677:

* Use COMDAT for -fsanitize-address-globals-dead-stripping on ELF platforms.
* Call `__asan_register_elf_globals` even if there is no global variable.
* If the unique module ID is empty, don't call SetComdatForGlobalMetadata:
  placing `@.str` in a COMDAT would incorrectly discard internal COMDAT `@.str`
  in other compile units.

Alternatively, when there is no global variable, asan.module_ctor is not COMDAT
and does not call `__asan_register_elf_globals`. However, the asan.module_ctor
function cannot be eliminated by the linker.

Tested the following script. Only ELF -fsanitize-address-globals-dead-stripping has changed behaviors.
```
echo > a.cc  # no global variable, empty uniqueModuleId
echo 'void f() {}' > b.cc  # with global variable, with uniqueModuleId
echo 'int g;' > c.cc  # with global variable
for t in x86_64-linux-gnu arm64-apple-macosx x86_64-windows-msvc; do
  for gc in -f{,no-}sanitize-address-globals-dead-stripping; do
    for f in a.cc b.cc c.cc; do
      echo /tmp/Rel/bin/clang -S --target=$t -fsanitize=address $gc $f -o -
      /tmp/Rel/bin/clang -S --target=$t -fsanitize=address $gc $f -o - | sed -n '/asan.module_ctor/,/ret/p'
    done
  done
done
```

---

Identical to commit 16eed8c906875e748c3cb610f3dc4b875f3882aa.
6420d3301cd4f0793adcf11f59e8398db73737d8 is an incorrect revert for genuine
purely internal issues.

9 months ago[clang-format][doc] Update the Linux kernel coding style URL
Owen Pan [Thu, 5 Oct 2023 08:12:27 +0000 (01:12 -0700)]
[clang-format][doc] Update the Linux kernel coding style URL

(cherry picked from commit 8902f12e61aa2d3053ad4d536e36569fc8bc9512)

9 months ago[clang-format] Fix a serious bug in git-clang-format (#65723)
Owen Pan [Fri, 8 Sep 2023 22:05:22 +0000 (15:05 -0700)]
[clang-format] Fix a serious bug in git-clang-format (#65723)

When applying format changes to staged files, git-clang-format
erroneously checks out all files in the index and thus may overwrite
unstaged changes.

Fixes #65643.

(cherry picked from commit 743659be87daff4cc8861c525d4a6229d787ef14)

9 months ago[LSan] Mark create_thread_leak.cpp as UNSUPPORTED: darwin.
Artem Dergachev [Thu, 31 Aug 2023 23:36:38 +0000 (16:36 -0700)]
[LSan] Mark create_thread_leak.cpp as UNSUPPORTED: darwin.

It started to fail in a flaky manner a few days ago on GreenDragon buildbots
(i.e. x86_64-darwin). I didn't track down the root cause but LSan isn't
actually supported on darwin anyway, so UNSUPPORTED seems appropriate.

Prior art: 3ff080b5.

(cherry picked from commit 0a3519d5a27b9400250b5f6656b50148021e7496)

9 months ago[PowerPC] Use zext instead of anyext in custom and combine (#68784)
Nikita Popov [Thu, 12 Oct 2023 07:32:17 +0000 (09:32 +0200)]
[PowerPC] Use zext instead of anyext in custom and combine (#68784)

This custom combine currently converts `and(anyext(x),c)` into
`anyext(and(x,c))`. This is not correct, because the original expression
guaranteed that the high bits are zero, while the new one sets them to
undef.

Emit `zext(and(x,c))` instead.

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

(cherry picked from commit 127ed9ae266ead58aa525f74f4c86841f6674793)

9 months ago[PowerPC] Add test for #68783 (NFC)
Nikita Popov [Wed, 11 Oct 2023 10:14:31 +0000 (12:14 +0200)]
[PowerPC] Add test for #68783 (NFC)

(cherry picked from commit 0ead1faef0bfaea499c3b2d13ab417f6bf3f67e1)

9 months ago[clang-format] Fix a bug in RemoveParentheses: ReturnStatement (#67911)
Owen Pan [Mon, 2 Oct 2023 07:15:49 +0000 (00:15 -0700)]
[clang-format] Fix a bug in RemoveParentheses: ReturnStatement (#67911)

Don't remove the outermost parentheses surrounding a return statement
expression when inside a function/lambda that has the decltype(auto)
return type.

Fixed #67892.

(cherry picked from commit 75441a684273268ce91036aa2c770e669d39f501)

9 months ago[X86] Fix logic for optimizing movmsk(bitcast(shuffle(x))); PR67287
Noah Goldstein [Sun, 8 Oct 2023 16:40:15 +0000 (11:40 -0500)]
[X86] Fix logic for optimizing movmsk(bitcast(shuffle(x))); PR67287

Prior logic would remove the shuffle iff all of the elements in `x`
where used. This is incorrect.

The issue is `movmsk` only cares about the highbits, so if the width
of the elements in `x` is smaller than the width of the elements
for the `movmsk`, then the shuffle, even if it preserves all the elements,
may change which ones are used by the highbits.

For example:
`movmsk64(bitcast(shuffle32(x, (1,0,3,2))))`

Even though the shuffle mask `(1,0,3,2)` preserves all the elements, it
flips which will be relevant to the `movmsk64` (x[1] and x[3]
before and x[0] and x[2] after).

The fix here, is to ensure that the shuffle mask can be scaled to the
element width of the `movmsk` instruction. This ensure that the
"high" elements stay "high". This is overly conservative as it
misses cases like `(1,1,3,3)` where the "high" elements stay
intact despite not be scalable, but for an relatively edge-case
optimization that should generally be handled during
simplifyDemandedBits, it seems okay.

(cherry picked from commit 1684c65bc997a8ce0ecf96a493784fe39def75de)

9 months ago[X86] Add tests for incorrectly optimizing out shuffle used in `movmsk`; PR67287
Noah Goldstein [Fri, 6 Oct 2023 00:54:57 +0000 (19:54 -0500)]
[X86] Add tests for incorrectly optimizing out shuffle used in `movmsk`; PR67287

(cherry picked from commit 65a576e27be814bd23f39b31a8074e9850b0fe26)

9 months ago[clang] [MinGW] Explicitly always pass the -fno-use-init-array (#68571)
Martin Storsjö [Tue, 10 Oct 2023 06:55:56 +0000 (09:55 +0300)]
[clang] [MinGW] Explicitly always pass the -fno-use-init-array (#68571)

On MinGW targets, the .ctors section is always used for constructors.

When using the .ctors section, the constructors need to be emitted in
reverse order to get them execute in the right order. (Constructors with
a specific priority are sorted separately by the linker later.) In LLVM,
in CodeGen/AsmPrinter/AsmPrinter.cpp, there's code that reverses them
before writing them out, executed when using the .ctors section. This
logic is done whenever TM.Options.UseInitArray is set to false. Thus,
make sure to set UseInitArray to false for this target.

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

(cherry picked from commit a2b8c49c1839076b540c542c024fcfe2361a3e47)

9 months ago[LVI][CVP] Treat undef like a full range (#68190)
DianQK [Tue, 10 Oct 2023 08:03:24 +0000 (16:03 +0800)]
[LVI][CVP] Treat undef like a full range (#68190)

When converting to ConstantRange, we should treat undef like a full range.
Fixes #68381.

(cherry picked from commit 81857940f278e21f7957a2833d4b6ec72819e79f)

9 months ago[X86] combineConcatVectorOps - only concatenate single-use subops
Simon Pilgrim [Sun, 1 Oct 2023 13:27:55 +0000 (14:27 +0100)]
[X86] combineConcatVectorOps - only concatenate single-use subops

We could maybe extend this by allowing the lowest subop to have multiple uses and extract the lowest subvector result of the concatenated op, but let's just get the fix in first.

Fixes #67333

9 months agoBump version to 17.0.3
Tobias Hieta [Tue, 10 Oct 2023 06:47:40 +0000 (08:47 +0200)]
Bump version to 17.0.3

9 months ago[clang] Correct behavior of `LLVM_UNREACHABLE_OPTIMIZE=OFF` for `Release` builds...
Arvind Mukund [Thu, 5 Oct 2023 19:01:56 +0000 (12:01 -0700)]
[clang] Correct behavior of `LLVM_UNREACHABLE_OPTIMIZE=OFF` for `Release` builds (#68284)

```c++
AArch64SVEPcsAttr *AArch64SVEPcsAttr::CreateImplicit(ASTContext &Ctx, SourceRange Range, Spelling S) {
  AttributeCommonInfo I(Range, NoSemaHandlerAttribute, (
    S == GNU_aarch64_sve_pcs ? AttributeCommonInfo::Form{AttributeCommonInfo::AS_GNU, GNU_aarch64_sve_pcs, false /*IsAlignas*/, false /*IsRegularKeywordAttribute*/} :
    S == CXX11_clang_aarch64_sve_pcs ? AttributeCommonInfo::Form{AttributeCommonInfo::AS_CXX11, CXX11_clang_aarch64_sve_pcs, false /*IsAlignas*/, false /*IsRegularKeywordAttribute*/} :
    S == C23_clang_aarch64_sve_pcs ? AttributeCommonInfo::Form{AttributeCommonInfo::AS_C23, C23_clang_aarch64_sve_pcs, false /*IsAlignas*/, false /*IsRegularKeywordAttribute*/} :
    (llvm_unreachable("Unknown attribute spelling!"),  AttributeCommonInfo::Form{AttributeCommonInfo::AS_GNU, 0, false /*IsAlignas*/, false /*IsRegularKeywordAttribute*/})));
  return CreateImplicit(Ctx, I);
}
```

```c++
AArch64SVEPcsAttr *AArch64SVEPcsAttr::CreateImplicit(ASTContext &Ctx, SourceRange Range, Spelling S) {
  AttributeCommonInfo I(Range, NoSemaHandlerAttribute, [&]() {
    switch (S) {
    case GNU_aarch64_sve_pcs:
      return AttributeCommonInfo::Form{AttributeCommonInfo::AS_GNU, GNU_aarch64_sve_pcs, false /*IsAlignas*/, false /*IsRegularKeywordAttribute*/};
    case CXX11_clang_aarch64_sve_pcs:
      return AttributeCommonInfo::Form{AttributeCommonInfo::AS_CXX11, CXX11_clang_aarch64_sve_pcs, false /*IsAlignas*/, false /*IsRegularKeywordAttribute*/};
    case C23_clang_aarch64_sve_pcs:
      return AttributeCommonInfo::Form{AttributeCommonInfo::AS_C23, C23_clang_aarch64_sve_pcs, false /*IsAlignas*/, false /*IsRegularKeywordAttribute*/};
    default:
      llvm_unreachable("Unknown attribute spelling!");
      return AttributeCommonInfo::Form{AttributeCommonInfo::AS_GNU, 0, false /*IsAlignas*/, false /*IsRegularKeywordAttribute*/};
    }
  }());
  return CreateImplicit(Ctx, I);
}
```

Fixes https://github.com/llvm/llvm-project/issues/68237
Conflicts:
clang/docs/ReleaseNotes.rst

9 months ago[LLD] [COFF] Fix handling of comdat .drectve sections (#68116)
Martin Storsjö [Wed, 4 Oct 2023 07:54:50 +0000 (10:54 +0300)]
[LLD] [COFF] Fix handling of comdat .drectve sections (#68116)

This can happen when manually emitting strings into .drectve sections
with `__attribute__((section(".drectve")))`, which is a way to emulate
`#pragma comment(linker, "...")` for mingw compilers, without requiring
building with -fms-extensions.

Normally, this doesn't generate any comdat, but if compiled with
-fsanitize=address, this section does get turned into a comdat section.

This fixes #67261. This issue can be seen as a regression; a change in
the "lli" tool in 17.x triggers this case, if compiled with ASAN
enabled, triggering this unsupported corner case in LLD. With this
change, LLD can handle it.

(cherry picked from commit 503bc5f66111f7e4fc79972bb9bfec8bb5606bab)

9 months agoworkflows/release-binaries: Use more cores to avoid the 6 hour timeout (#67874)
Tom Stellard [Tue, 3 Oct 2023 18:40:41 +0000 (11:40 -0700)]
workflows/release-binaries: Use more cores to avoid the 6 hour timeout (#67874)

(cherry picked from commit 95b2c6b3d6dc5f8b6ee5eb4f8dbc96dea0f50cac)

9 months ago[AArch64] Disable loop alignment for Windows targets (#67894)
Martin Storsjö [Mon, 2 Oct 2023 20:55:23 +0000 (23:55 +0300)]
[AArch64] Disable loop alignment for Windows targets (#67894)

This should fix #66912. When emitting SEH unwind info, we need to be
able to calculate the exact length of functions before alignments are
fixed. Until that limitation is overcome, just disable all loop
alignment on Windows targets.

(cherry picked from commit 6ae36c012728a274a78a771e4506681732f85a6d)

9 months ago[Sema] Use underlying type of scoped enum for -Wformat diagnostics (#67378)
Shoaib Meenai [Mon, 2 Oct 2023 18:32:54 +0000 (11:32 -0700)]
[Sema] Use underlying type of scoped enum for -Wformat diagnostics (#67378)

Right now, `-Wformat` for a scoped enum will suggest a cast based on the
format specifier being used. This can lead to incorrect results, e.g.
attempting to format a scoped enum with `%s` would suggest casting to
`char *` instead of fixing the specifier. Change the logic to treat the
scoped enum's underlying type as the intended type to be printed, and
suggest format specifier changes and casts based on that.

(cherry picked from commit 0b07b06effe5fdf779b75bb5ac6cf15e477cb0be)

10 months agoFix release/export.sh to export runtimes tarball, too (#67404)
René Rebe [Thu, 28 Sep 2023 14:37:24 +0000 (16:37 +0200)]
Fix release/export.sh to export runtimes tarball, too (#67404)

This addresses missing cmake files needed to build some sub-projects
like libstdcxx.

Co-authored-by: René Rebe <rene@exactcode.de>
10 months ago[libc++] Fix `std::pair`'s pair-like constructor's incorrect assumption (#66585)
Hui [Mon, 18 Sep 2023 18:01:19 +0000 (19:01 +0100)]
[libc++] Fix `std::pair`'s  pair-like constructor's incorrect assumption (#66585)

The helper function `__pair_like_explicit_wknd` is only SFINAE-ed with
`tuple_size<remove_cvref_t<_PairLike>>::value == 2`, but its function
body assumes `std::get` being valid.

Fixes #65620

(cherry picked from commit 054f9c55c6b4520d3feb8b4354b9b942026b5124)

10 months ago[CodeGen] Don't treat thread local globals as large data (#67764)
Arthur Eubanks [Fri, 29 Sep 2023 19:56:53 +0000 (12:56 -0700)]
[CodeGen] Don't treat thread local globals as large data (#67764)

Otherwise they may mistakenly get the large section flag.

(cherry picked from commit b915f60678c3033c466611be1119a46ba4b0869c)
(fix was slightly different since cherry-pick didn't apply well)

10 months ago[workflow] Fix abi checker in llvm-tests. Same fix as in 99fb0af80d16b0ff886f03244139...
Tobias Hieta [Mon, 2 Oct 2023 16:14:02 +0000 (18:14 +0200)]
[workflow] Fix abi checker in llvm-tests. Same fix as in 99fb0af80d16b0ff886f032441392219e1cac452 (#67957)

Fixes #67651

10 months ago[clang] [MinGW] Tolerate mingw specific linker options during compilation (#67891)
Martin Storsjö [Sun, 1 Oct 2023 20:42:16 +0000 (23:42 +0300)]
[clang] [MinGW] Tolerate mingw specific linker options during compilation (#67891)

Prior to 591c4b64b3650884c2c68eb47d755ebb62981b99, the mingw specific
linker options -mthreads, -mconsole, -mwindows and -mdll would be
tolerated also at compile time, but generating a warning about being
unused.

After that commit, they were marked as target specific, which means that
it's an error if they're unused (which would consider them used for the
wrong target). These specific options are only relevant when linking,
but we want to tolerate them at compile time too, like before.

This was fixed for -mthreads in
a79995ca6004082774a87f7a58ab6be5343364b7, while the other options didn't
seem to be commonly used during compilation.

After the 17.x release, we've got more reports about this actually being
an issue, in #64464. Therefore, apply the same fix for them; marking
them as tolerated for mingw targets during compilation, even if they're
unused. Also add a testcase for -mthreads which was already handled.

Thus, this fixes #64464.

(cherry picked from commit e39de2b8862ae43459324da84279366997265078)

Adapted from the original commit; the test in the original commit
depended on f39c399d9d15efe8309d8aa3d0ecf62205e6c474. Instead of
using -###, when we're not actually using the printed output of
-###, instead use -fdriver-only.

10 months ago[LLD] [COFF] Restore the current dir as the first entry in the search path (#67857)
Martin Storsjö [Mon, 2 Oct 2023 10:47:30 +0000 (13:47 +0300)]
[LLD] [COFF] Restore the current dir as the first entry in the search path (#67857)

Before af744f0b84e2b6410be65277068b9033124c73b2, the first entry
among the search paths was the empty string, indicating searching
in (or starting from) the current directory. After
af744f0b84e2b6410be65277068b9033124c73b2, the toolchain/clang
specific lib directories were added at the head of the search path.

This would cause lookups of literal file names or relative paths
to match paths in the toolchain, if there are coincidental files
with similar names there, even if they would be find in the current
directory as well.

Change addClangLibSearchPaths to append to the list like all other
operations on searchPaths - but move the invocation of the
function to the right place in the sequence.

This fixes #67779.

(cherry picked from commit f906fd53b5ce12f07aec394ddf900c7f9f583405)

10 months ago[LLD] [COFF] Clarify -print-search-path for the empty string element (#67856)
Martin Storsjö [Mon, 2 Oct 2023 10:43:56 +0000 (13:43 +0300)]
[LLD] [COFF] Clarify -print-search-path for the empty string element (#67856)

Also switch the test case to use -NEXT to strictly match all lines.

(cherry picked from commit 7d7d9e462a8983d71e01786c9ad61a976ff10e8a)

10 months ago[NFC] clang-format lld/COFF/Driver.cpp and lld/Common/Filesystem.cpp
Matheus Izvekov [Thu, 21 Sep 2023 11:16:11 +0000 (13:16 +0200)]
[NFC] clang-format lld/COFF/Driver.cpp and lld/Common/Filesystem.cpp

In order to reduce noise for a MR.

(cherry picked from commit a5e280bc6bda10607e0e7c864e4d23fac02d00aa)

10 months ago[compiler-rt] Reinstate removal of CRT choice flags from CMAKE_*_FLAGS* (#67935)
Martin Storsjö [Mon, 2 Oct 2023 10:22:23 +0000 (13:22 +0300)]
[compiler-rt] Reinstate removal of CRT choice flags from CMAKE_*_FLAGS* (#67935)

This reverts one part of commit
9f4dfcb795bb0ecf9944553f49371164801cd83f, with a modified comment added
about the code.

Ideally, this would only be reinstated temporarily - but given the
situation in vcpkg, it looks likely that they would keep passing the
duplicate options for quite some time. The conflicting CRT choice
usually are benign but only would cause warnings about one option
overriding the other, if passing e.g. "/MDd /MT".

However when vcpkg currently sets these options in CMAKE_*_FLAGS_DEBUG,
it passes the redundant option /D_DEBUG; thus the compiler finally ends
up with e.g. "/D_DEBUG /MDd /MT", which has the effect of defining
_DEBUG while using a release mode CRT, which allegedly breaks the build.

There's a PR up for removing this redundant /D_DEBUG option in vcpkg in
https://github.com/microsoft/vcpkg/pull/34123. With that in place, this
change wouldn't be strictly needed.

(cherry picked from commit 7bc09a471fbc274d8632d1379d4134bec63fecc4)

10 months ago[MemCpyOpt] Merge alias metadatas when replacing arguments (#67539)
DianQK [Thu, 28 Sep 2023 08:13:21 +0000 (16:13 +0800)]
[MemCpyOpt] Merge alias metadatas when replacing arguments (#67539)

Alias metadata may no longer be valid after replacing the call argument.
Fix this by merging it with the memcpy alias metadata.

This fixes a miscompilation encountered in
https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Failing.20tests.20when.20rustc.20is.20compiled.20with.201.20CGU.

(cherry picked from commit 4e6e476329a8359cb381517864ed6f88a152e37b)

10 months ago[MemCpyOpt] Add test for #67539 (NFC)
Nikita Popov [Thu, 28 Sep 2023 07:43:22 +0000 (09:43 +0200)]
[MemCpyOpt] Add test for #67539 (NFC)

(cherry picked from commit d5c8b23b1ee1dcb6922e8226143410840edabe50)

10 months ago[DependencyScanningFilesystem] Make sure the local/shared cache filename lookups...
Argyrios Kyrtzidis [Wed, 20 Sep 2023 01:18:23 +0000 (18:18 -0700)]
[DependencyScanningFilesystem] Make sure the local/shared cache filename lookups use only absolute paths (#66122)

Previously a relative path would be used as a key for cache lookup and
if the same relative path was used from another compiler invocation with
a different working directory then the first cache entry was erroneously
returned.

(cherry picked from commit 36b37c775c285bbff9b57630e7ea9d00b918cc91)

10 months ago[Sema] Fix fixit cast printing inside macros (#66853)
Shoaib Meenai [Thu, 21 Sep 2023 00:32:35 +0000 (17:32 -0700)]
[Sema] Fix fixit cast printing inside macros (#66853)

`Lexer::getLocForEndOfToken` is documented as returning an invalid
source location when the end of the token is inside a macro expansion.
We don't want that for this particular application, so just calculate
the end location directly instead.

Before this, format fix-its would omit the closing parenthesis (thus
producing invalid code) for macros, e.g.:

```
$ cat format.cpp
extern "C" int printf(const char *, ...);
enum class Foo { Bar };
#define LOG(...) printf(__VA_ARGS__)
void f(Foo foo) { LOG("%d\n", foo); }

$ clang -fsyntax-only format.cpp
format.cpp:4:29: warning: format specifies type 'int' but the argument has type 'Foo' [-Wformat]
    4 | void f(Foo f) { LOG("%d\n", f); }
      |                      ~~     ^
      |                             static_cast<int>(
format.cpp:3:25: note: expanded from macro 'LOG'
    3 | #define LOG(...) printf(__VA_ARGS__)
      |                         ^~~~~~~~~~~
1 warning generated.
```

We now emit a valid fix-it:

```
$ clang -fsyntax-only format.cpp
format.cpp:4:31: warning: format specifies type 'int' but the argument has type 'Foo' [-Wformat]
    4 | void f(Foo foo) { LOG("%d\n", foo); }
      |                        ~~     ^~~
      |                               static_cast<int>( )
format.cpp:3:25: note: expanded from macro 'LOG'
    3 | #define LOG(...) printf(__VA_ARGS__)
      |                         ^~~~~~~~~~~
1 warning generated.
```

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

(cherry picked from commit 61c5ad8857a71510e4393680a1e42740da4ba6fa)

10 months agoWork around two more instances of __noinline__ conflicts. (#66138)
Artem Belevich [Tue, 12 Sep 2023 20:35:07 +0000 (13:35 -0700)]
Work around two more instances of __noinline__ conflicts. (#66138)

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

(cherry picked from commit 588023ddafb4b0cd11914ab068c6d07187374d69)

10 months ago[lldb] Fix building LLDB standlone without framework
Alex Langford [Mon, 31 Jul 2023 23:30:17 +0000 (16:30 -0700)]
[lldb] Fix building LLDB standlone without framework

In a809720102fae8d1b5a7073f99f9dae9395c5f41 I refactored some logic to
deal with the clang resource directory in standalone LLDB builds.
However, this logic escaped me because it only runs when you do not
build LLDB.framework.

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

(cherry picked from commit 6888de118707e6392b46073fc35738804f9f1d80)

10 months ago[lldb][NFCI] Change logic to find clang resource dir in standalone builds
Alex Langford [Tue, 25 Jul 2023 22:38:04 +0000 (15:38 -0700)]
[lldb][NFCI] Change logic to find clang resource dir in standalone builds

As of 0beffb854209a41f31beb18f9631258349a99299 there is a CMake
function to actually calculate the relative path to the clang resource
directory. Currently we have some bespoke logic that looks in a few
places, but with this new function we should be able to eliminate some
complexity here.

Also, I moved the functionality from LLDBConfig to LLDBStandalone since
it is only used in standalone builds.

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

(cherry picked from commit a809720102fae8d1b5a7073f99f9dae9395c5f41)

10 months ago[XCOFF] Do not generate the special .ref for zero-length sections (#66805)
Wael Yehia [Thu, 28 Sep 2023 05:33:41 +0000 (01:33 -0400)]
[XCOFF] Do not generate the special .ref for zero-length sections (#66805)

Co-authored-by: Wael Yehia <wyehia@ca.ibm.com>
(cherry picked from commit da55b1b52fbce80093eee8dd4185df4861a44ba5)

10 months agoFix buildbot failure caused by D157623
duk [Thu, 10 Aug 2023 20:33:43 +0000 (16:33 -0400)]
Fix buildbot failure caused by D157623

GCC doesn't like the implicit conversion here.

(cherry picked from commit f11f90d5f4ebfab2b44bf3c98b2d2162acf81e2c)

10 months ago[lld][COFF] Remove incorrect flag from EHcont table
namazso [Thu, 10 Aug 2023 20:00:58 +0000 (16:00 -0400)]
[lld][COFF] Remove incorrect flag from EHcont table

Fixes EHCont implementation in LLD. Closes #64570

Reviewed By: rnk

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

(cherry picked from commit e335c78ec2848e24b10e32e015a84347c69c8130)

10 months agoworkflows/release-tasks: Setup FileCheck and not for release-lit (#66799)
Tulio Magno Quites Machado Filho [Mon, 25 Sep 2023 17:03:34 +0000 (14:03 -0300)]
workflows/release-tasks: Setup FileCheck and not for release-lit (#66799)

lit tests require commands FileCheck and not. They must be available in
the PATH.

This also guarantees that python3-psutil is installed in order to enable
more tests.

Fixes #64892.

(cherry picked from commit b2247f85dc4b187dd0ebc93059a0aa42f35dd64a)

10 months ago[StackColoring] Handle fixed object index
Nikita Popov [Fri, 22 Sep 2023 10:25:56 +0000 (12:25 +0200)]
[StackColoring] Handle fixed object index

This is a followup to #66988. The implementation there did not
account for the possibility of the catch object frame index
referrring to a fixed object, which is the case on win64.

(cherry picked from commit aa70f4d8cf8f09a2997773156289b16d6a16ec01)

10 months ago[StackColoring] Handle SEH catch object stack slots conservatively
Nikita Popov [Thu, 21 Sep 2023 07:13:27 +0000 (09:13 +0200)]
[StackColoring] Handle SEH catch object stack slots conservatively

The write to the SEH catch object happens before cleanuppads are
executed, while the first reference to the object will typically
be in a catchpad.

If we make use of first-use analysis, we may end up allocating
an alloca used inside the cleanuppad and the catch object at the
same stack offset, which would be incorrect.

https://reviews.llvm.org/D86673 was a previous attempt to fix it.
It used the heuristic "a slot loaded in a WinEH pad and never
written" to detect catch objects. However, because it checks
for more than one load (while probably more than zero was
intended), the fix does not actually work.

The general approach also seems dubious to me, so this patch
reverts that change entirely, and instead marks all catch object
slots as conservative (i.e. excluded from first-use analysis)
based on the WinEHFuncInfo. As far as I can tell we don't need
any heuristics here, we know exactly which slots are affected.

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

(cherry picked from commit b3cb4f069c2cb99bdae68d6906156af20e76314f)

10 months ago[X86] Add test for #66984 (NFC)
Nikita Popov [Thu, 21 Sep 2023 07:13:27 +0000 (09:13 +0200)]
[X86] Add test for #66984 (NFC)

(cherry picked from commit 8b4e29b35d21b079e8b30244cbbfc4d4bc4a29d4)

10 months ago[SimpleLoopUnswitch] Fix exponential unswitch
Nikita Popov [Wed, 20 Sep 2023 09:41:42 +0000 (11:41 +0200)]
[SimpleLoopUnswitch] Fix exponential unswitch

When unswitching via invariant condition injection, we currently
mark the condition in the old loop, so that it does not get
unswitched again. However, if there are multiple branches for
which conditions can be injected, then we can do that for both
the old and new loop. This means that the number of unswitches
increases exponentially.

Change the handling to be more similar to partial unswitching,
where we instead mark the whole loop, rather than a single
condition. This means that we will only generate a linear number
of loops.

TBH I think even that is still highly undesirable, and we should
probably be unswitching all candidates at the same time, so that
we end up with only two loops. But at least this mitigates the
worst case.

The test case is a reduced variant that generates 1700 lines of IR
without this patch and 290 with it.

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

(cherry picked from commit 8362cae71b80bc43c8c680cdfb13c495705a622f)

10 months ago[SimpleLoopUnswitch] Fix reversed branch during condition injection
Nikita Popov [Wed, 20 Sep 2023 08:46:25 +0000 (10:46 +0200)]
[SimpleLoopUnswitch] Fix reversed branch during condition injection

The in-loop successor is only on the left after a potential condition
inversion. As we re-use the old condition as-is, we should also
reuse the old successors as-is.

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

(cherry picked from commit afd7db48c55cb87566758e961f1ebac8af16b8bc)

10 months ago[clang] Include `expected-no-diagnostics` in newly-added test (NFC)
Antonio Frighetto [Thu, 14 Sep 2023 07:16:01 +0000 (09:16 +0200)]
[clang] Include `expected-no-diagnostics` in newly-added test (NFC)

(cherry picked from commit c990d9444350ef583c6d53e84d9c10cebbf65532)

10 months ago[clang] Bail out when handling union access with virtual inheritance
Antonio Frighetto [Wed, 13 Sep 2023 16:44:19 +0000 (18:44 +0200)]
[clang] Bail out when handling union access with virtual inheritance

An assertion issue that arose when handling union member access with
virtual base class has been addressed. As pointed out by @zygoloid,
there is no need for further derived-to-base analysis in this instance,
so we can bail out upon encountering a virtual base class. Minor
refinement on the function name as we might not be handling a union.

Reported-By: ormris
Fixes: https://github.com/llvm/llvm-project/issues/65982
(cherry picked from commit 660876a4019b81b5a7427a3dcec5ce8c39cd1ee0)

10 months ago[clang][Diagnostics] Fix wrong line number display (#65238)
Takuya Shimizu [Tue, 5 Sep 2023 03:12:42 +0000 (12:12 +0900)]
[clang][Diagnostics] Fix wrong line number display (#65238)

When the caret location is lower than the lowest source range, clang is
printing wrong line numbers. The first line number should consider caret
location line even when there are source ranges provided.

Current wrong line example: https://godbolt.org/z/aj4qEjzs4

(cherry picked from commit ef5217b3c0dcbb58927fe43400b6d1faa677bf98)

10 months agoRevert "[InlineCost] Check for conflicting target attributes early"
Kazu Hirata [Thu, 21 Sep 2023 17:29:46 +0000 (10:29 -0700)]
Revert "[InlineCost] Check for conflicting target attributes early"

This reverts commit d6f994acb3d545b80161e24ab742c9c69d4bbf33.

Several people have reported breakage resulting from this patch:

- https://github.com/llvm/llvm-project/issues/65152
- https://github.com/llvm/llvm-project/issues/65205

(cherry picked from commit b4301df61fc77a9d54ac236bc88742a731285f1c)

10 months ago[GVN] Also remove phi nodes from VN table (PR65447)
Nikita Popov [Fri, 15 Sep 2023 09:42:59 +0000 (11:42 +0200)]
[GVN] Also remove phi nodes from VN table (PR65447)

Followup to D158849: We also need to remove the phi node from the
VN table, which is not handled by removeInstruction().

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

(cherry picked from commit 18e77760ce5e42d9057f69c3e64a8300d01a48ac)

10 months ago[GVN] Invalidate MDA when deduplicating phi nodes
Nikita Popov [Thu, 17 Aug 2023 14:37:32 +0000 (16:37 +0200)]
[GVN] Invalidate MDA when deduplicating phi nodes

Duplicate phi nodes were being directly removed, without
invalidating MDA. This could result in a new phi node being
allocated at the same address, incorrectly reusing a cache entry.

Fix this by optionally allowing EliminateDuplicatePHINodes() to
collect phi nodes to remove into a vector, which allows GVN to
handle removal itself.

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

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

(cherry picked from commit 7c229f6e85478bb0626a5e598f47b7be94bb50b0)

10 months agoBump version to 17.0.2
Tobias Hieta [Mon, 25 Sep 2023 11:03:29 +0000 (13:03 +0200)]
Bump version to 17.0.2

10 months ago[SVE] Ensure SVE call operands passed via memory are correctly initialised. (#66070)
paulwalker-arm [Thu, 14 Sep 2023 11:58:58 +0000 (12:58 +0100)]
[SVE] Ensure SVE call operands passed via memory are correctly initialised. (#66070)

The stores created when passing operands via memory don't typically
maintain the chain, because they can be done in any order. Instead,
a new chain is created based on all collated stores. SVE parameters
passed via memory don't follow this idiom and try to maintain the
chain, which unfortunately can result in them being incorrectly
deadcoded when the chain is recreated.

This patch brings the SVE side in line with the non-SVE side to
ensure no stores become lost whilst also allowing greater flexibility
when ordering the stores.

10 months ago[SVE] Precommit test to show missing initialisation of call operand.
Paul Walker [Fri, 8 Sep 2023 16:14:58 +0000 (16:14 +0000)]
[SVE] Precommit test to show missing initialisation of call operand.

When calling func_f8_and_v0_passed_via_memory the memory used to
hold the first vector operand is allocated but not initialised.

10 months agoBump version to 17.0.1
Tobias Hieta [Tue, 19 Sep 2023 09:05:13 +0000 (11:05 +0200)]
Bump version to 17.0.1

10 months agoRemove RC suffix
Tobias Hieta [Tue, 19 Sep 2023 07:44:33 +0000 (09:44 +0200)]
Remove RC suffix

10 months agoRevert "[C++20] [Coroutines] Mark await_suspend as noinline if the awaiter is not...
Chuanqi Xu [Mon, 28 Aug 2023 05:32:27 +0000 (13:32 +0800)]
Revert "[C++20] [Coroutines] Mark await_suspend as noinline if the awaiter is not empty"

This reverts commit f05226d7e38c36efe029a0eb4201b0843f81b5e8.

10 months agoRevert "[NFC] [C++20] [Coroutines] Mention the side effect of a fix may bring regress...
Chuanqi Xu [Mon, 28 Aug 2023 05:32:23 +0000 (13:32 +0800)]
Revert "[NFC] [C++20] [Coroutines] Mention the side effect of a fix may bring regressions"

This reverts commit 6998ecd330f2b028bf4678edd4f53b5489c5e6df.

10 months ago[SimplifyCFG] handle monotonic wrapped case for D150943 (#65882)
Kohei Asano [Thu, 14 Sep 2023 12:26:11 +0000 (21:26 +0900)]
[SimplifyCFG] handle monotonic wrapped case for D150943 (#65882)

(cherry picked from commit fef82492209b24fd0b36a199657f3ed822e601a6)

10 months ago[lli] Make sure the exported __chkstk functions are included when exporting them
Martin Storsjö [Tue, 29 Aug 2023 08:31:53 +0000 (11:31 +0300)]
[lli] Make sure the exported __chkstk functions are included when exporting them

The trick we use (since cbc2a0623a39461b56bd9eeb308ca535f03793f8)
for exporting the __chkstk function (with various per-arch names)
that is defined in a different object file, relies on the function
already being linked in (by some function referencing it).

This function does end up referenced if there's a function that
allocates more than 4 KB on the stack. In most cases, it's referenced
somewhere, but in the case of builds with LLVM_LINK_LLVM_DYLIB
enabled (so most of the code resides in a separate libLLVM-<ver>.dll)
the only code in lli.exe is the lli tool specific code and the
mingw-w64 crt startup code. In the case of GCC based MinGW i386
builds with LLVM_LINK_LLVM_DYLIB, nothing else references it though.

Manually add a reference to the function to make sure it is linked
in (from libgcc or compiler-rt builtins) so that it can be exported.

This fixes one build issue encountered in
https://github.com/msys2/MINGW-packages/pull/18002.

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

(cherry picked from commit 4bba12f7226228221d1fa4bad7732e25647ecb87)

10 months ago[ARM] Change CRC predicate to just HasCRC
David Green [Fri, 8 Sep 2023 08:02:15 +0000 (09:02 +0100)]
[ARM] Change CRC predicate to just HasCRC

This removes the backend requirement for crc instructions on HasV8, relying on
just HasCRC instead. This should allow them to be selected with ArmV7 + crc,
making them more usable whilst hopefully not making them incorrectly generated
(they only come from intrinsics, and HasCRC usually requires HasV8). This is
how most other instructions are specified.

(cherry picked from commit a82c106e571c6991a95c38a936a466895122d713)

10 months ago[flang] Allow runtime build with AVOID_NATIVE_INT128_T=1
Peter Klausler [Thu, 6 Jul 2023 22:03:05 +0000 (15:03 -0700)]
[flang] Allow runtime build with AVOID_NATIVE_INT128_T=1

This patch enables the Fortran runtime support library to be
built without native 128-bit integer support in the C++ compiler.

Experimental: do not merge yet.

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

(cherry picked from commit 1c35c1a73907a95ce54b5a0edca513591e2bc069)

10 months ago[Clang] Fix JIT test on 32-bit systems
Sam James [Tue, 5 Sep 2023 15:02:04 +0000 (16:02 +0100)]
[Clang] Fix JIT test on 32-bit systems

As reported by mgorny at https://reviews.llvm.org/D159115#4638037, the
unsigned long long cast fails on 32-bit systems at least with GCC.

It looks like a pointer provenance/aliasing issue rather than a bug in GCC.

Acked by Vassil Vassilev on the original revision.

(cherry picked from commit 3403686b72507e3fdbcd69f21fb9235ffa0ca169)

10 months ago[builtins][AArch64] Implement _sync out-of-line atomics
Jessica Clarke [Mon, 4 Sep 2023 00:46:00 +0000 (01:46 +0100)]
[builtins][AArch64] Implement _sync out-of-line atomics

Whilst Clang does not use these, recent GCC does, and so on systems such
as FreeBSD that wish to use compiler-rt as the system runtime library
but also wish to support building programs with GCC these interfaces are
needed.

This is a light adaptation of the code committed to GCC by Sebastian Pop
<spop@amazon.com>, relicensed with permission for use in compiler-rt.

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

Reviewed By: sebpop, MaskRay

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

(cherry picked from commit 4bb2416d42eb593c44bbeb765e1b8641a58f853c)

10 months agoFix AIX OS requirements for ThinLTO to 7.2.5 SP7
Wael Yehia [Wed, 6 Sep 2023 14:17:45 +0000 (14:17 +0000)]
Fix AIX OS requirements for ThinLTO to 7.2.5 SP7

10 months ago[SCEV] Fix potentially empty set for unsigned ranges
Tejas Joshi [Mon, 4 Sep 2023 09:46:52 +0000 (10:46 +0100)]
[SCEV] Fix potentially empty set for unsigned ranges

The following commit enabled the analysis of ranges for heap allocations:
22ca38da25e19a7c5fcfeb3f22159aba92ec381e

The range turns out to be empty in cases such as the one in test (which
is [1,1)), leading to an assertion failure. This patch fixes for the
same case.

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

Reviewed By: fhahn

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

(cherry picked from commit 0609b65aaf03b083d282a4ffe8bf660351dac461)

10 months ago[CodeGen] Fix incorrect insertion point selection for reduction nodes in ComplexDeint...
Igor Kirillov [Wed, 30 Aug 2023 14:52:28 +0000 (14:52 +0000)]
[CodeGen] Fix incorrect insertion point selection for reduction nodes in ComplexDeinterleavingPass

When replacing ComplexDeinterleavingPass::ReductionOperation, we can do it
either from the Real or Imaginary part. The correct way is to take whichever
is later in the BasicBlock, but before the patch, we just always took the
Real part.

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

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

(cherry picked from commit e2cb07c322e85604dc48f9caec52b3570db0e1d8)

10 months ago[CodeGen][AArch64] Commit test for #65044
Danila Malyutin [Tue, 29 Aug 2023 15:05:01 +0000 (18:05 +0300)]
[CodeGen][AArch64] Commit test for #65044

(cherry picked from commit 2fce8f74b3c04bbf7e941cfed7604edae2b573b6)

10 months ago[libc++][hardening] Remove hardening from release notes, undeprecate safe mode
Konstantin Varlamov [Wed, 30 Aug 2023 06:29:33 +0000 (23:29 -0700)]
[libc++][hardening] Remove hardening from release notes, undeprecate safe mode

This patch effectively maintains the status quo, making sure that the
safe mode keeps working the same way as before. Hardening will target
the next major release, allowing it to go through RFC and for the
implementation to stabilize and mature.

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

10 months ago[LoopVectorize] Fix incorrect order of invariant stores when there are multiple reduc...
Igor Kirillov [Thu, 10 Aug 2023 15:38:27 +0000 (15:38 +0000)]
[LoopVectorize] Fix incorrect order of invariant stores when there are multiple reductions.

When a loop has multiple reductions, each with an intermediate invariant
store, the order in which those reductions are processed is not considered.
This can result in the invariant stores outside the loop not preserving the
original order.
This patch sorts VPReductionPHIRecipes by the order in which they have
stores in the original loop before running
`InnerLoopVectorizer::fixReduction` function, and it helps to maintain
the correct order of stores.

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

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

(cherry picked from commit ac65fb869977185b44757b94dc5130bd08c6f7e2)

10 months ago[LoopVectorize] Pre-commit tests for D157631
Igor Kirillov [Thu, 10 Aug 2023 15:35:39 +0000 (15:35 +0000)]
[LoopVectorize] Pre-commit tests for D157631

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

(cherry picked from commit 2df9ed11c51ebf6d19f7cb22c3794d1bd460ddf8)

11 months ago[RelNotes] Add more details on the removal of the legacy optimization pipeline
Arthur Eubanks [Wed, 6 Sep 2023 18:28:38 +0000 (11:28 -0700)]
[RelNotes] Add more details on the removal of the legacy optimization pipeline

11 months ago[mlir][nfc] Allow ops to have operands/attributes named `context`.
Christian Sigg [Wed, 30 Aug 2023 10:23:25 +0000 (12:23 +0200)]
[mlir][nfc] Allow ops to have operands/attributes named `context`.

This is probably a bad idea, but it's only become a problem with properties and is easy to fix.

Reviewed By: mehdi_amini

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

11 months ago[JumpThreading] Invalidate LVI after `combineMetadataForCSE`.
DianQK [Sun, 3 Sep 2023 04:23:33 +0000 (12:23 +0800)]
[JumpThreading] Invalidate LVI after `combineMetadataForCSE`.

(cherry picked from commit 7ded71b1e43fff0be3acb74038bfea87f38d5cfa)

11 months ago[JumpThreading][NFC] Pre-commit for invalid LVI.
DianQK [Sun, 3 Sep 2023 04:18:57 +0000 (12:18 +0800)]
[JumpThreading][NFC] Pre-commit for invalid LVI.

(cherry picked from commit 5855a4be9cbc3c4584d8a1632886c347044dfbef)

11 months agoRevert "[clang][Docs] Added release note for D142609"
Takuya Shimizu [Mon, 4 Sep 2023 02:19:46 +0000 (11:19 +0900)]
Revert "[clang][Docs] Added release note for D142609"

The associated commit was reverted and backported in a93ca35, so this
release note line should also be removed.

This reverts commit 061e855767dbe0821d81a8d47158f468dd00ae5f.

11 months ago[clang][clangd] Ensure the stack bottom before building AST
Younan Zhang [Mon, 28 Aug 2023 06:51:59 +0000 (14:51 +0800)]
[clang][clangd] Ensure the stack bottom before building AST

`clang::runWithSufficientStackSpace` requires the address of the
initial stack bottom to prevent potential stack overflows.

In addition, add a fallback to ASTFrontendAction in case any client
forgets to call it when not through CompilerInstance::ExecuteAction,
which is rare.

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

Reviewed By: sammccall

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

(cherry picked from commit e257c0a9190637e44e292271103a13d70bec4b03)

11 months ago[clang] Construct ExprRequirement with SubstitutionDiagnostic on SubstFailure
Younan Zhang [Wed, 16 Aug 2023 07:33:58 +0000 (15:33 +0800)]
[clang] Construct ExprRequirement with SubstitutionDiagnostic on SubstFailure

We're expecting a SubstitutionDiagnostic in diagnoseUnsatisfiedRequirement
if the status of ExprRequirement is SubstFailure. Previously, the Requirement
was created with Expr on SubstFailure by mistake, which could lead to the
assertion failure in the subsequent diagnosis.

Fixes https://github.com/clangd/clangd/issues/1726
Fixes https://github.com/llvm/llvm-project/issues/64723
Fixes https://github.com/llvm/llvm-project/issues/64172

In addition, this patch also fixes an invalid test from D129499.

Reviewed By: erichkeane

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

11 months ago[NFC][Clang] Fix static analyzer concern about null value dereference
Elizabeth Andrews [Mon, 14 Aug 2023 19:01:14 +0000 (12:01 -0700)]
[NFC][Clang] Fix static analyzer concern about null value dereference

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

11 months ago[sanitizer] scanf interceptor: fix write size for %mc/%mC/%mS
Fangrui Song [Mon, 28 Aug 2023 05:19:31 +0000 (22:19 -0700)]
[sanitizer] scanf interceptor: fix write size for %mc/%mC/%mS

When the optional assignment-allocation character 'm' (Extension to the
ISO C standard) is present, we currently use internal_strlen(buf)+1 for
all of cCsS[ (D85350). Fix cCS to use the correct size.

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

Reviewed By: #sanitizers, vitalybuka

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

(cherry picked from commit beeb37a8f3275281be305d2d1afe35ca053e21c0)

11 months ago[CodeGen] First check the kind and then the llvm::Function properties.
Vassil Vassilev [Fri, 1 Sep 2023 19:50:54 +0000 (19:50 +0000)]
[CodeGen] First check the kind and then the llvm::Function properties.

This patch fixes valgrind reports from downstream consumers about conditional
jump over uninitialised memory.

The original report:

```[ RUN      ] ScopeReflectionTest.IsComplete
==987150== Conditional jump or move depends on uninitialised value(s)
==987150==    at 0x1E1128F: clang::CodeGen::CodeGenModule::SetLLVMFunctionAttributesForDefinition(clang::Decl const*, llvm::Function*) (CodeGenModule.cpp:2391)
==987150==    by 0x1E4F181: clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (CodeGenModule.cpp:5669)
==987150==    by 0x1E4A194: clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (CodeGenModule.cpp:3909)
==987150==    by 0x1E4A752: clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (CodeGenModule.cpp:3649)
==987150==    by 0x1E532F5: clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) [clone .part.0] (CodeGenModule.cpp:6563)
==987150==    by 0x1B0BEDD: (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) (ModuleBuilder.cpp:190)
==987150==    by 0x1AEA47B: clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (CodeGenAction.cpp:235)
==987150==    by 0x101B02F: clang::IncrementalASTConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (IncrementalParser.cpp:52)
==987150==    by 0x101ED93: clang::IncrementalParser::ParseOrWrapTopLevelDecl() (IncrementalParser.cpp:276)
==987150==    by 0x101FBBC: clang::IncrementalParser::Parse(llvm::StringRef) (IncrementalParser.cpp:342)
==987150==    by 0x100E104: clang::Interpreter::Parse(llvm::StringRef) (Interpreter.cpp:360)
==987150==    by 0xE734C0: Cpp::Interpreter::Parse(llvm::StringRef) (CppInterOpInterpreter.h:172)
==987150==  Uninitialised value was created by a heap allocation
==987150==    at 0x844BE63: operator new(unsigned long) (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==987150==    by 0x1B0C882: StartModule (ModuleBuilder.cpp:139)
==987150==    by 0x1B0C882: clang::CodeGenerator::StartModule(llvm::StringRef, llvm::LLVMContext&) (ModuleBuilder.cpp:360)
==987150==    by 0x101C4AF: clang::IncrementalParser::GenModule() (IncrementalParser.cpp:372)
==987150==    by 0x101FC0E: clang::IncrementalParser::Parse(llvm::StringRef) (IncrementalParser.cpp:362)
==987150==    by 0x100E104: clang::Interpreter::Parse(llvm::StringRef) (Interpreter.cpp:360)
==987150==    by 0x100E243: clang::Interpreter::create(std::unique_ptr<clang::CompilerInstance, std::default_delete<clang::CompilerInstance> >) (Interpreter.cpp:279)
==987150==    by 0xF2131A: compat::createClangInterpreter(std::vector<char const*, std::allocator<char const*> >&) (Compatibility.h:123)
==987150==    by 0xF22AB9: Cpp::Interpreter::Interpreter(int, char const* const*, char const*, std::vector<std::shared_ptr<clang::ModuleFileExtension>, std::allocator<std::shared_ptr<clang::ModuleFileExtension> > > const&, void*, bool) (CppInterOpInterpreter.h:146)
==987150==    by 0xF1827A: CreateInterpreter (CppInterOp.cpp:2494)
==987150==    by 0xECFA0E: TestUtils::GetAllTopLevelDecls(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::vector<clang::Decl*, std::allocator<clang::Decl*> >&, bool) (Utils.cpp:23)
==987150==    by 0xE9CB85: ScopeReflectionTest_IsComplete_Test::TestBody() (ScopeReflectionTest.cpp:71)
==987150==    by 0xF0ED0C: void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) (in /home/vvassilev/workspace/builds/scratch/cppyy/InterOp/build-with-clang-repl-release/unittests/CppInterOp/CppInterOpTests)
==987150==
```

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

(cherry picked from commit 92246a9be0ba47788ada9621bef58ce7819be526)

11 months ago[Driver] Report warnings for unclaimed TargetSpecific options for assembler input
Fangrui Song [Fri, 1 Sep 2023 06:26:46 +0000 (23:26 -0700)]
[Driver] Report warnings for unclaimed TargetSpecific options for assembler input

This patch amends D151590 to not error for unlaimed TargetSpecific
options for `-x assembler` input files. This input type causes Driver to
construct tools::ClangAs (-fintegrated-as) or other assemblers (e.g.
tools::gnutools::Assembler) Their ConstructJobs methods, unlike
Clang::ConstructJobs, claim very few options. If an option is unclaimed,
it either leads to a -Wunused-command-line-argument warning or an error
(if `TargetSpecific` is set):
```
% clang '-###' --target=aarch64 -mbranch-protection=bti -c a.s
clang: error: unsupported option '-mbranch-protection=' for target 'aarch64'
```

It seems that downgrading the diagnostic to warning is most useful as
many users use CFLAGS even for `.s` files:
```
clang --target=aarch64 -mbranch-protection=bti -S a.c
clang --target=aarch64 -mbranch-protection=bti -c a.s
```

I decide not to suppress the warning so that
-Wunused-command-line-argument lovers still get a warning, and help
projects use proper ASFLAGS/CFLAGS/etc.

Note: `-mbranch-protection=bti a.S` currently has no warning as `-x assembler-with-cpp`
instructs clangDriver to select tools::Clang and claim most options.

Revert D159010 to demonstrate that we emit a warning for -mfpmath= for
`-x assembler` input.

Modify my AIX cleanup cd18efb61d759405956dbd30e4b5f2720d8e1783 to
add an err_drv_unsupported_opt_for_target.

Reviewed By: thesamesam

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

(cherry picked from commit e9d454d1c195958645fb0948f8b97262e7f8b33a)

11 months ago[AArch64] Fix arm neon vstx lane memVT size
hstk30 [Thu, 31 Aug 2023 16:54:57 +0000 (17:54 +0100)]
[AArch64] Fix arm neon vstx lane memVT size

StN lane memory size set too big lead to alias analysis goes wrong.

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

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

(cherry picked from commit db8f6c009e5a17d304be7404e50eb20b2dd0c75b)

11 months ago[llvm-windres] Implement the windres flag --use-temp-file
Martin Storsjö [Wed, 30 Aug 2023 20:29:15 +0000 (23:29 +0300)]
[llvm-windres] Implement the windres flag --use-temp-file

Whether a temp file or a pipe is used for preprocessing is an
internal detail, this flag has a notable effect on the preprocessing
in GNU windres. Without this flag, GNU windres passes command
arguments as-is to popen(), which means they get evaluated by a
shell without being re-escaped for this case. To mimic this,
llvm-windres has manually tried to unescape arguments.

When GNU windres is given the --use-temp-file flag, it uses a
different API for invoking the preprocessor, and this API takes care
of preserving special characters in the command line arguments.
For users of GNU windres, this means that by using --use-temp-file,
they don't need to do the (quite terrible) double escaping of
quotes/spaces etc.

The xz project uses the --use-temp-file flag when invoking
GNU windres, see
https://github.com/tukaani-project/xz/commit/6b117d3b1fe91eb26d533ab16a2e552f84148d47.
However as llvm-windres didn't implement this flag and just
assumed the GNU windres popen() behaviour, they had to use a
different codepath for llvm-windres.

That separate codepath for llvm-windres broke later when llvm-windres
got slightly more accurate unescaping of lone quotes in
0f4c6b120f21d582ab7c5c4f2b2a475086c34938 /
https://reviews.llvm.org/D146848 (fixing a discrepancy to GNU
windres as found in https://github.com/llvm/llvm-project/issues/57334),
and this was reported in
https://github.com/mstorsjo/llvm-mingw/issues/363.

Not touching the implementation of the --preprocessor option
with respect to the --use-temp-file flag; that option is doubly
tricky as GNU windres changed its behaviour in a backwards incompatible
way recently (and llvm-windres currently matches the old behaviour).
(See
https://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff;h=21c33bcbe36377abf01614fb1b9be439a3b6de20,
https://sourceware.org/bugzilla/show_bug.cgi?id=27594 and
https://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff;h=5edb8e3f5ad8d74a83fc0df7f6e4514eed0aa77f;hp=3abbafc2aacc6706fea3e3e326e2f08d107c3672
for the behaviour change.)

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

(cherry picked from commit 2bcc0fdc58a220cb9921b47ec8a32c85f2511a47)