platform/upstream/llvm.git
6 months ago[CMake] Support building shared library for NetBSD
Brad Smith [Wed, 22 Nov 2023 23:42:56 +0000 (18:42 -0500)]
[CMake] Support building shared library for NetBSD

(cherry picked from commit 51c5d74940c3a6682ccd44491cb40c7e26fb83e5)

6 months agoworkflows/release-binaries: Do a preliminary build to fill ccache (#72576)
Tom Stellard [Tue, 21 Nov 2023 20:29:20 +0000 (12:29 -0800)]
workflows/release-binaries: Do a preliminary build to fill ccache (#72576)

Build clang with the host compiler and ccache enabled in order to speed
up the phase 1 builds. This helps reduce the amount of time spent
running on the non-free builders.

(cherry picked from commit e746b56c98f6180cffd4cad9ebdd249bdaa17283)

6 months agoAdd RV64 constraint to SRLIW (#69416)
Shao-Ce SUN [Wed, 18 Oct 2023 07:01:17 +0000 (15:01 +0800)]
Add RV64 constraint to SRLIW (#69416)

Fixes #69408

(cherry picked from commit f48dab523784252448dbd42e72f0048ee0463368)

6 months ago[runtimes] Add missing test dependencies to check-all (#72955)
Tom Stellard [Wed, 22 Nov 2023 21:57:48 +0000 (13:57 -0800)]
[runtimes] Add missing test dependencies to check-all (#72955)

The test-depends target contained all the dependencies needed to run the
runtimes tests, but it was never added as a dependency of check-all.
This caused some of the tsan tests to fail, since the custom libcxx
build the tests were looking for was never built. Besides the tsan
failures, this fixes all the other test failures I was seeing with:
cmake -G Ninja -B release-build -S llvm \
        -DCMAKE_POSITION_INDEPENDENT_CODE=ON \
        -DCMAKE_BUILD_TYPE=Release \
        -DLLVM_ENABLE_ASSERTIONS=OFF \
        -DLLVM_ENABLE_PROJECTS="clang;lld" \
        -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind;compiler-rt"

This is the same configuration the test-release.sh script uses, so I'm
hoping this will also fix all the test failures we've been seeing when
building the releases.

Fixes #58680

(cherry picked from commit 7f215b1380da49dccbf57da3040a40d25ed898f4)

6 months ago[clang-format] Fix a bug in aligning comments above PPDirective (#72791)
Owen Pan [Sun, 19 Nov 2023 22:59:53 +0000 (14:59 -0800)]
[clang-format] Fix a bug in aligning comments above PPDirective (#72791)

Fixed #72785.

(cherry picked from commit 5860d248a780aaef860db3d54184b49fc758c3c1)

6 months ago[clangd] Avoid null result in FindRecordTypeAt()
Nathan Ridge [Fri, 25 Aug 2023 15:16:04 +0000 (11:16 -0400)]
[clangd] Avoid null result in FindRecordTypeAt()

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

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

(cherry picked from commit 1994e1173b64b61c07f8acf107f29c2c015575b4)

6 months agoBump version to 17.0.6
Tobias Hieta [Mon, 20 Nov 2023 08:56:48 +0000 (09:56 +0100)]
Bump version to 17.0.6

6 months agoremove tests from bad merge
Utkarsh Saxena [Wed, 15 Nov 2023 12:21:09 +0000 (13:21 +0100)]
remove tests from bad merge

6 months agoUse the correct namespace for looking up matching operator!= (#68922)
Utkarsh Saxena [Mon, 23 Oct 2023 12:10:06 +0000 (14:10 +0200)]
Use the correct namespace for looking up matching operator!= (#68922)

`S.getScopeForContext` determins the **active** scope associated with
the given `declContext`.
This fails to find the matching `operator!=` if candidate `operator==`
was found via ADL since that scope is not active.

Instead, just directly lookup using the namespace decl of `operator==`

Fixes #68901

(cherry picked from commit 9330261143ccbe947ef0687fd20747ba47f26879)

6 months ago[libc++] Use correct size for deallocation of arrays in shared_ptr (#68233)
Ilya Biryukov [Thu, 5 Oct 2023 13:27:58 +0000 (15:27 +0200)]
[libc++] Use correct size for deallocation of arrays in shared_ptr (#68233)

Fixes #68051.

Current implementation passes the number of `_AlignedStorage` objects
when it calls to `allocate` and the number of **bytes** on `deallocate`.
This only applies to allocations that allocate control block and the
storage together, i.e. `make_shared` and `allocate_shared`.

Found by ASan under Clang combined with `-fsized-deallocation`.

(cherry picked from commit f722db02d359e29ca001b78197ee1a275f8c3d7c)

6 months agoRevert "Reland [clang] Canonicalize system headers in dependency file when -canonical...
Arthur Eubanks [Wed, 8 Nov 2023 19:43:35 +0000 (11:43 -0800)]
Revert "Reland [clang] Canonicalize system headers in dependency file when -canonical-prefixes" (#71697)

This reverts commit 578a4716f549167165a2ec3bac89c86706136d4e.

This causes multiple issues. Compile time slowdown due to more path
canonicalization, and weird behavior on Windows.

Will reland under a separate flag `-f[no-]canonical-system-headers` to
match gcc in the future and further limit when it's passed by default.

Fixes #70011.

6 months ago[clang][WebAssembly] Link crt1 even in case of -shared
YAMAMOTO Takashi [Mon, 14 Aug 2023 16:18:34 +0000 (09:18 -0700)]
[clang][WebAssembly] Link crt1 even in case of -shared

This allows -mexec-model=reactor -shared produces a library module
with _initialize entrypoint, which is preferrable over __wasm_call_ctors.

This partially reverts https://reviews.llvm.org/D153293

Discussion: https://github.com/dicej/component-linking-demo/issues/3

Reviewed By: sbc100

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

(cherry picked from commit 989ce069a4638fd561bebc95f478ca9e45154fec)

6 months ago[BranchFolding] Remove dubious assert from operator< (#71639)
Nikita Popov [Thu, 9 Nov 2023 09:23:10 +0000 (10:23 +0100)]
[BranchFolding] Remove dubious assert from operator< (#71639)

`MergePotentialElts::operator<` asserts that the two elements being
compared are not equal. However, sorting functions are allowed to invoke
the comparison function with equal arguments (though they usually don't
for efficiency reasons).

There is an existing special-case that disables the assert if
_GLIBCXX_DEBUG is used, which may invoke the comparator with equal args
to verify strict weak ordering. I believe libc++ also has strict weak
ordering checks under some options nowadays.

Recently, #71312 was reported, where a change to glibc's qsort_r
implementation can also result in comparison between equal elements.
From what I understood, this is an inefficiency that will be fixed on
the glibc side as well, but I think at this point we should just remove
this assertion.

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

(cherry picked from commit 74a76a288562c486f377121855ef7db0386e0e43)

6 months ago[GlobalOpt] Cache whether CC is changeable (#71381)
Nikita Popov [Tue, 7 Nov 2023 09:36:45 +0000 (10:36 +0100)]
[GlobalOpt] Cache whether CC is changeable (#71381)

The hasAddressTaken() call in hasOnlyColdCalls() has quadratic
complexity if there are many cold calls to a function: We're going to
visit each call of the function, and then for each of them iterate all
the users of the function.

We've recently encountered a case where GlobalOpt spends more than an
hour in these hasAddressTaken() checks when full LTO is used.

Avoid this by moving the hasAddressTaken() check into hasChangeableCC()
and caching its result, so it is only computed once per function.

(cherry picked from commit e360a16fee2dc3cb632ace556fb715832f488a90)

6 months ago[libc++] Fix UB in <expected> related to "has value" flag (#68552) (#68733)
Jan Kokemüller [Mon, 30 Oct 2023 18:56:03 +0000 (19:56 +0100)]
[libc++] Fix UB in <expected> related to "has value" flag (#68552) (#68733)

The calls to std::construct_at might overwrite the previously set
__has_value_ flag in the case where the flag is overlapping with
the actual value or error being stored (since we use [[no_unique_address]]).
To fix this issue, this patch ensures that we initialize the
__has_value_ flag after we call std::construct_at.

Fixes #68552

(cherry picked from commit 134c91595568ea1335b22e559f20c1a488ea270e)

6 months ago[clang] fix test PR69717.cpp (#72134)
antoine moynault [Mon, 13 Nov 2023 17:39:25 +0000 (18:39 +0100)]
[clang] fix test PR69717.cpp (#72134)

Test still fail on ARM machine (no float_control support)

(cherry picked from commit 5fdb70be7b0a1340a7ebdeb94ab073e466fc4aa6)

6 months ago[clang] Run test on x86 only
Serge Pavlov [Mon, 13 Nov 2023 12:16:29 +0000 (19:16 +0700)]
[clang] Run test on x86 only

The test Sema/PR69717.cpp fails on platforms that do not support
pragma float_control. So run this test on x86 only.

(cherry picked from commit 93ae26331592f41bf2b1d10b048743d80c468385)

6 months ago[clang] Do not clear FP pragma stack when instantiating functions (#70646)
Serge Pavlov [Mon, 13 Nov 2023 10:24:46 +0000 (17:24 +0700)]
[clang] Do not clear FP pragma stack when instantiating functions (#70646)

When instantiation function, a call to Sema::resetFPOption was used to
set the FP options associated with AST node. However this function also
cleared FP pragma stack, and it is incorrect. Template instantiation
takes place on AST representation and semantic information like the FP
pragma stack should not affect it. This was a reason for miscompilation
in some cases.

To make the Sema interface more consistent, now `resetFPOptions` does
not clear FP pragma stack anymore. It is cleared in
`FpPragmaStackSaveRAII`, which is used in parsing only.

This change must fix https://github.com/llvm/llvm-project/issues/69717
(Problems with float_control pragma stack in Clang 17.x).

(cherry picked from commit f6f625f4c6c3cbeb8cf6b889cdafc848dd4cb117)

6 months ago[SLP]Fix PR70004: Do not change insert point for reduction gather nodes.
Alexey Bataev [Tue, 24 Oct 2023 15:58:50 +0000 (08:58 -0700)]
[SLP]Fix PR70004: Do not change insert point for reduction gather nodes.

No need to change the insert point for reduction gather node, we can use
the ReductionRoot as insert point instead to avoid possible crashes.

(cherry picked from commit d79051f894129428ec36dedc6bbfdfdcc1bd0c17)

6 months ago[DAG] WidenVectorOperand - add basic handling for *_EXTEND_VECTOR_INREG nodes
Simon Pilgrim [Wed, 25 Oct 2023 15:52:00 +0000 (16:52 +0100)]
[DAG] WidenVectorOperand - add basic handling for *_EXTEND_VECTOR_INREG nodes

Fixes Issue #70208

(cherry picked from commit c9c9bf0f20fd820b86fac35113bbd8049ff4e72a)

6 months ago[Mips] In LowerShift*Parts, xor with bits-1 instead of -1. (#71149)
Craig Topper [Fri, 3 Nov 2023 17:08:00 +0000 (10:08 -0700)]
[Mips] In LowerShift*Parts, xor with bits-1 instead of -1. (#71149)

If we start with an i128 shift, the initial shift amount would usually
have zeros in bit 8 and above. xoring the shift amount with -1 will set
those upper bits to 1. If DAGCombiner is able to prove those bits are
now 1, then the shift that uses the xor will be replaced with undef.
Which we don't want.

Reduce the xor constant to VT.bits-1 where VT is half the size of the
larger shift type. This avoids toggling the upper bits. The hardware
shift instruction only uses the lower bits of the shift amount. I assume
the code used NOT because the hardware doesn't use the upper bits, but
that isn't compatible with the LLVM poison semantics.

Fixes #71142.

(cherry picked from commit 8d24d3900ec3f28902b2fad4a2c2c2b789257424)

6 months ago[clang-format] Correctly annotate keyword operator function name (#66904)
Owen Pan [Wed, 27 Sep 2023 20:12:55 +0000 (13:12 -0700)]
[clang-format] Correctly annotate keyword operator function name (#66904)

Fixes #66890.

(cherry picked from commit 67b99fa8ba638edddd5ce38b4d379eab8e339e4a)

6 months agoBump version to 17.0.5
Tobias Hieta [Mon, 13 Nov 2023 07:29:19 +0000 (08:29 +0100)]
Bump version to 17.0.5

6 months ago[Driver] Fix linking with -lm on Solaris (#65632)
Rainer Orth [Thu, 7 Sep 2023 17:14:55 +0000 (19:14 +0200)]
[Driver] Fix linking with -lm on Solaris (#65632)

As noticed in D158846, the Solaris driver deviates from other targets in
that it links every executable with `-lm`, but doesn't for shared
objects. For C code, this is unnecessary, while for C++ `libm` is always
needed, even for shared objects.

This patch fixes this by following the `Gnu.cpp` precedent. It adjusts
the `solaris-ld.c` test accordingly, adding some more tests.

Tested on `amd64-pc-solaris2.11`, `sparcv9-sun-solaris2.11`, and
`x86_64-pc-linux-gnu`.

(cherry picked from commit 1e6b0df3503567488e7df2d574c90f8f31a001a2)

6 months ago[clang-repl] Fix BUILD_SHARED_LIBS symbols from libclangInterpreter on MinGW (#71393)
Martin Storsjö [Tue, 7 Nov 2023 09:48:12 +0000 (11:48 +0200)]
[clang-repl] Fix BUILD_SHARED_LIBS symbols from libclangInterpreter on MinGW (#71393)

A few symbols within libclangInterpreter have got explicit dllexport
attributes, in order to make them exported (and thus visible at runtime)
in any build, not only when they are part of e.g. a DLL libclang-cpp,
but also when they are part of a plain .exe.

Due to the explicit dllexports, these symbols would sidestep the regular
MinGW logic of exporting all symbols if there are no dllexports.
Therefore, for libclang-cpp, a separate fix was made in
592e935e115ffb451eb9b782376711dab6558fe0, to pass --export-all-symbols
to the build of libclang-cpp.

If building with BUILD_SHARED_LIBS enabled, then the same issue appears
in libclangInterpreter; pass the same flag --export-all-symbols there as
well, to make sure all symbols are visible, not only the ones that are
explicitly marked as dllexport.

(cherry picked from commit 0d3eeac8c0f45410398a87f72ae38ea6ae1c3073)

6 months ago[CGExprConstant] stop calling into ConstExprEmitter for Reference type destinations...
Nick Desaulniers [Mon, 30 Oct 2023 15:48:31 +0000 (08:48 -0700)]
[CGExprConstant] stop calling into ConstExprEmitter for Reference type destinations (#70366)

Fixes a bug introduced by
commit b54294e2c959 ("[clang][ConstantEmitter] have
tryEmitPrivate[ForVarInit] try ConstExprEmitter fast-path first")

In the added test case, the QualType is a LValueReferenceType.

    LValueReferenceType 0x558412998d90 'const char (&)[41]'
    `-ParenType 0x558412998d30 'const char[41]' sugar
      `-ConstantArrayType 0x558412998cf0 'const char[41]' 41
        `-QualType 0x55841294c271 'const char' const
          `-BuiltinType 0x55841294c270 'char'

Fixes: #69979
(cherry picked from commit d9b15b068d19089f72fc0d7dc59ed1d6d77125dc)

7 months ago[AArch64][GlobalISel] Fix incorrect ABI when tail call not supported (#70215)
Nikita Popov [Mon, 30 Oct 2023 14:01:01 +0000 (15:01 +0100)]
[AArch64][GlobalISel] Fix incorrect ABI when tail call not supported (#70215)

The check for whether a tail call is supported calls
determineAssignments(), which may modify argument flags. As such, even
though the check fails and a non-tail call will be emitted, it will not
have a different (incorrect) ABI.

Fix this by operating on a separate copy of the arguments.

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

(cherry picked from commit 292f34b0d3cb2a04be5ebb85aaeb838b29f71323)

7 months ago[AArch64] Add test for #70207 (NFC)
Nikita Popov [Wed, 25 Oct 2023 13:43:02 +0000 (15:43 +0200)]
[AArch64] Add test for #70207 (NFC)

(cherry picked from commit d9cfb82207035fc7382ad02ec827c0dbed96565c)

7 months ago[GVN] Fix use-after-free in load PRE with select available value (#69314)
Nikita Popov [Thu, 19 Oct 2023 07:08:59 +0000 (09:08 +0200)]
[GVN] Fix use-after-free in load PRE with select available value (#69314)

replaceValuesPerBlockEntry() only handled simple and coerced load
values, however the load may also be referenced by a select value.

Additionally, I suspect that the previous code might have been incorrect
if a load had an offset, as it always constructed the AvailableValue
from scratch.

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

(cherry picked from commit 7f1733a252cbbad74445bd54dc95aeec52bb3199)

7 months ago[clang-tidy] Fix crash in modernize-use-trailing-return-type (#70709)
Piotr Zegar [Tue, 31 Oct 2023 05:52:40 +0000 (06:52 +0100)]
[clang-tidy] Fix crash in modernize-use-trailing-return-type (#70709)

Resolved the crash that occurred during the use of a user-defined
C-style string literal. The fix entails checking whether the identifier
is non-empty before attempting to read its name.

(cherry picked from commit a396fb247e0719f56a830a9e4aab0449be7f843a)

7 months ago[OpenMP] Fix building for 32-bit DragonFly, NetBSD, OpenBSD (#70527)
Brad Smith [Sat, 28 Oct 2023 02:53:24 +0000 (22:53 -0400)]
[OpenMP] Fix building for 32-bit DragonFly, NetBSD, OpenBSD (#70527)

Fixing ```#error "Unknown or unsupported OS"```

(cherry picked from commit 223852aecf3f01cea21c40ea128a26f6a194345d)

7 months ago[OpenMP] record-replay use static-cast (#70516)
Konstantinos Parasyris [Fri, 27 Oct 2023 23:46:34 +0000 (16:46 -0700)]
[OpenMP] record-replay use static-cast  (#70516)

[OpenMP] Fixes #69905

(cherry picked from commit 01828c4323172db5901ac3e959d52553b2bd74e5)

7 months ago[flang] Add comdats to functions with linkonce linkage (#66516)
David Truby [Tue, 19 Sep 2023 14:00:04 +0000 (15:00 +0100)]
[flang] Add comdats to functions with linkonce linkage (#66516)

This fixes a bug where functions generated by the MLIR Math dialect, for
example ipowi, would fail to link with link.exe on Windows due to having
linkonce linkage but no associated comdat. Adding the comdat on ELF also
allows linkers to perform better garbage collection in the binary.

Simply adding comdats to all functions with this linkage type should
also cover future cases where linkonce or linkonce_odr functions might
be necessary.

(cherry picked from commit 5f476b80e3d472f672f5f6a719eebe2c0aadf52c)

7 months ago[mlir] Add pass to add comdat to all linkonce functions (#65270)
David Truby [Wed, 13 Sep 2023 12:05:05 +0000 (13:05 +0100)]
[mlir] Add pass to add comdat to all linkonce functions (#65270)

This adds a new pass to add an Any comdat to each linkonce
and linkonce_odr function in the LLVM dialect. These comdats are
necessary on Windows
to allow the default system linker to link binaries containing these
functions.

(cherry picked from commit a6857156df9a73720fbd9633067d1a61c32dd74e)

7 months agoUpdate release note for the fix
Takuya Shimizu [Fri, 27 Oct 2023 09:15:47 +0000 (18:15 +0900)]
Update release note for the fix

7 months ago[clang][ExprConst] Fix crash on uninitialized array subobject (#67817)
Takuya Shimizu [Fri, 27 Oct 2023 05:11:27 +0000 (14:11 +0900)]
[clang][ExprConst] Fix crash on uninitialized array subobject (#67817)

https://reviews.llvm.org/D146358 was assuming that all subobjects have
their own name (`SubobjectDecl`), but it was not true for array
elements.

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

7 months ago[RISCV] Correct copyPhysReg for GPRPF64. (#70419)
Craig Topper [Fri, 27 Oct 2023 06:54:46 +0000 (23:54 -0700)]
[RISCV] Correct copyPhysReg for GPRPF64. (#70419)

GPRF64 represents a pair of registers. We were only copying the even
part. We need to copy the odd part too.

7 months ago[SVE] Fix incorrect offset calculation when rewriting an instruction's frame index...
Paul Walker [Fri, 27 Oct 2023 15:53:30 +0000 (16:53 +0100)]
[SVE] Fix incorrect offset calculation when rewriting an instruction's frame index. (#70315)

When partially packing an offset into an SVE load/store instruction we
are incorrectly calculating the remainder.

(cherry picked from commit 7c90be2857fc4c6a2e67f203ca289ed7773fae03)

7 months ago[MemCpyOpt] Combine alias metadatas when replacing byval arguments (#70580)
DianQK [Sun, 29 Oct 2023 08:07:55 +0000 (16:07 +0800)]
[MemCpyOpt] Combine alias metadatas when replacing byval arguments (#70580)

Fixes #70578.

(cherry picked from commit 0c4f326d8bc97a2fdb0533a68dbe1a7164da3911)

7 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)

7 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)

7 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)

7 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)

7 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)

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

7 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

7 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

7 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)

7 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)

7 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)

7 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)

7 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)

7 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)

7 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)

7 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

7 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)

7 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)

7 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.

7 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)

7 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)

7 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)

7 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)

7 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)

7 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)

7 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)

7 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)

7 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)

7 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)

7 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

7 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

7 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

7 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)

7 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)

7 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)

7 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)

8 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>
8 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)

8 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)

8 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

8 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.

8 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)

8 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)

8 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)

8 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)

8 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)

8 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)

8 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)

8 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)

8 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)

8 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)

8 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)

8 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)

8 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)

8 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)

8 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)

8 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)

8 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)

8 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)

8 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)

8 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)