platform/upstream/llvm.git
2 years ago[randstruct] Add randomize structure layout support
Connor Kuehl [Sat, 9 Apr 2022 06:36:51 +0000 (23:36 -0700)]
[randstruct] Add randomize structure layout support

The Randstruct feature is a compile-time hardening technique that
randomizes the field layout for designated structures of a code base.
Admittedly, this is mostly useful for closed-source releases of code,
since the randomization seed would need to be available for public and
open source applications.

Why implement it? This patch set enhances Clang’s feature parity with
that of GCC which already has the Randstruct feature. It's used by the
Linux kernel in certain structures to help thwart attacks that depend on
structure layouts in memory.

This patch set is a from-scratch reimplementation of the Randstruct
feature that was originally ported to GCC. The patches for the GCC
implementation can be found here:

  https://www.openwall.com/lists/kernel-hardening/2017/04/06/14

Link: https://lists.llvm.org/pipermail/cfe-dev/2019-March/061607.html
Co-authored-by: Cole Nixon <nixontcole@gmail.com>
Co-authored-by: Connor Kuehl <cipkuehl@gmail.com>
Co-authored-by: James Foster <jafosterja@gmail.com>
Co-authored-by: Jeff Takahashi <jeffrey.takahashi@gmail.com>
Co-authored-by: Jordan Cantrell <jordan.cantrell@mail.com>
Co-authored-by: Nikk Forbus <nicholas.forbus@gmail.com>
Co-authored-by: Tim Pugh <nwtpugh@gmail.com>
Co-authored-by: Bill Wendling <isanbard@gmail.com>
Signed-off-by: Bill Wendling <isanbard@gmail.com>
Reviewed By: aaron.ballman

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

2 years ago[IRBuilder] Remove commented out include.
Florian Hahn [Sat, 9 Apr 2022 19:32:58 +0000 (21:32 +0200)]
[IRBuilder] Remove commented out include.

Looks like this was left over during some include optimizations. Remove
it.

2 years ago[X86] Remove cfi noise from splat-for-size.ll tests
Simon Pilgrim [Sat, 9 Apr 2022 16:53:21 +0000 (17:53 +0100)]
[X86] Remove cfi noise from splat-for-size.ll tests

2 years agoAdd some prototypes to fix -Wstrict-prototypes. NFC
Fangrui Song [Sat, 9 Apr 2022 16:46:39 +0000 (09:46 -0700)]
Add some prototypes to fix -Wstrict-prototypes. NFC

2 years ago[flang] Fix -Wunused-variable in -DLLVM_ENABLE_ASSERTIONS=off build
PeixinQiao [Sat, 9 Apr 2022 15:57:50 +0000 (23:57 +0800)]
[flang] Fix -Wunused-variable in -DLLVM_ENABLE_ASSERTIONS=off build

Fix the warning from D122483.

Reviewed By: kiranchandramohan

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

2 years ago[RISCV] Only try LUI+SH*ADD+ADDI for int materialization if LUI+ADDI+SH*ADD failed.
Craig Topper [Sat, 9 Apr 2022 15:32:42 +0000 (08:32 -0700)]
[RISCV] Only try LUI+SH*ADD+ADDI for int materialization if LUI+ADDI+SH*ADD failed.

There's an assert in LUI+SH*ADD+ADDI materialization that makes sure the
lower 12 bits aren't zero since that case should have been handled as
LUI+ADDI+SH*ADD. But nothing prevented the LUI+SH*ADD+ADDI checks from
running after the earlier code handled it.

The sequence would be the same length or longer so it wouldn't replace
the earlier sequence, but the assert happened before that was checked.

The vector holding the sequence also wasn't reset before the second
check so that guaranteed the sequence would never be found to be
shorter.

This patch fixes this by only trying the second expansion when the
earlier fails.

Fixes PR54812.

Reviewed By: benshi001

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

2 years ago[X86] Add original test coverage for Issue #54819
Simon Pilgrim [Sat, 9 Apr 2022 15:47:53 +0000 (16:47 +0100)]
[X86] Add original test coverage for Issue #54819

2 years ago[X86] Fold concat(pshufb(x,y),pshufb(z,w)) -> pshufb(concat(x,z),concat(y,w))
Simon Pilgrim [Sat, 9 Apr 2022 15:05:46 +0000 (16:05 +0100)]
[X86] Fold concat(pshufb(x,y),pshufb(z,w)) -> pshufb(concat(x,z),concat(y,w))

2 years ago[clang-format] Add execute permission to dump_format_help.py
owenca [Sat, 9 Apr 2022 14:55:38 +0000 (07:55 -0700)]
[clang-format] Add execute permission to dump_format_help.py

2 years agoAdd some prototypes to these functions; NFC
Aaron Ballman [Sat, 9 Apr 2022 14:51:06 +0000 (10:51 -0400)]
Add some prototypes to these functions; NFC

This is expected to fix the issues in this build bot:
https://lab.llvm.org/buildbot/#/builders/37/builds/12312

2 years ago[gn build] Port a96443eddedc
LLVM GN Syncbot [Sat, 9 Apr 2022 14:04:27 +0000 (14:04 +0000)]
[gn build] Port a96443eddedc

2 years ago[libc++] Implement P0401R6 (allocate_at_least)
Nikolas Klauser [Sat, 9 Apr 2022 07:41:19 +0000 (09:41 +0200)]
[libc++] Implement P0401R6 (allocate_at_least)

Reviewed By: ldionne, var-const, #libc

Spies: mgorny, libcxx-commits, arichardson

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

2 years ago[X86] lowerV64I8Shuffle - attempt to fold to SHUFFLE(ALIGNR(X,Y)) and OR(PSHUFB(X...
Simon Pilgrim [Sat, 9 Apr 2022 13:09:21 +0000 (14:09 +0100)]
[X86] lowerV64I8Shuffle - attempt to fold to SHUFFLE(ALIGNR(X,Y)) and OR(PSHUFB(X),PSHUFB(Y))

2 years agoAdd some prototypes to these checks; NFC
Aaron Ballman [Sat, 9 Apr 2022 12:35:15 +0000 (08:35 -0400)]
Add some prototypes to these checks; NFC

This should address a build bot failure:
https://lab.llvm.org/buildbot/#/builders/18/builds/4495

2 years ago[VPlan] Model pre-header explicitly.
Florian Hahn [Sat, 9 Apr 2022 12:19:47 +0000 (14:19 +0200)]
[VPlan] Model pre-header explicitly.

This patch extends the scope of VPlan to also model the pre-header.
The pre-header can be used to place recipes that should be code-gen'd
outside the loop, like SCEV expansion.

Depends on D121623.

Reviewed By: Ayal

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

2 years ago[X86][SSE] combineSelect - more aggressively create zero elements in the or(pshufb...
Simon Pilgrim [Sat, 9 Apr 2022 11:52:56 +0000 (12:52 +0100)]
[X86][SSE] combineSelect - more aggressively create zero elements in the or(pshufb(x), pshufb(y)) fold

When we fold vselect(cond, pshufb(x), pshufb(y)) -> or(pshufb(x), pshufb(y)), ensure we convert all undef elements to zero elements - this should help us expose more known zero elements for deeper chains of these cases.

Noticed while triaging Issue #54819

2 years ago[CUDA/HIP] Remove argument from module ctor/dtor signatures
Jonas Hahnfeld [Fri, 8 Apr 2022 08:30:30 +0000 (10:30 +0200)]
[CUDA/HIP] Remove argument from module ctor/dtor signatures

In theory, constructors can take arguments when called via .init_array
where at least glibc passes in (argc, argv, envp). This isn't used in
the generated code and if it was, the first argument should be an
integer, not a pointer. For destructors registered via atexit, the
function should never take an argument.

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

2 years ago[X86] Add v64i8 shuffle test coverage
Simon Pilgrim [Sat, 9 Apr 2022 10:33:15 +0000 (11:33 +0100)]
[X86] Add v64i8 shuffle test coverage

Legalized shuffle masks based on the test cases from Issue #54819

2 years ago[X86] Reduce some superfluous diffs between znver1/znver2 models. NFC
Simon Pilgrim [Sat, 9 Apr 2022 09:59:18 +0000 (10:59 +0100)]
[X86] Reduce some superfluous diffs between znver1/znver2 models. NFC

znver2 is a mainly a search+replace of the znver1 model, but for no reason some lines have been moved around - try to keep these in sync (no actual changes in the models).

2 years ago[LoopVectorize] Regenerate first-order-recurrence.ll
Simon Pilgrim [Sat, 9 Apr 2022 09:33:03 +0000 (10:33 +0100)]
[LoopVectorize] Regenerate first-order-recurrence.ll

2 years ago[AArch64] validateTargetOperandClass - early out from MCK_MPR case. NFCI.
Simon Pilgrim [Sat, 9 Apr 2022 08:26:58 +0000 (09:26 +0100)]
[AArch64] validateTargetOperandClass - early out from MCK_MPR case. NFCI.

If it didn't match a za register, there's nothing we can do.

Fixes static analyzer uninitialized variable warning.

2 years ago[PowerPC] Generate tests for 16-byte atomic load/store. NFC.
Kai Luo [Sat, 9 Apr 2022 08:36:57 +0000 (16:36 +0800)]
[PowerPC] Generate tests for 16-byte atomic load/store. NFC.

2 years ago[sanitizer] Disable new test on Android to fix a bot
Vitaly Buka [Sat, 9 Apr 2022 07:57:16 +0000 (00:57 -0700)]
[sanitizer] Disable new test on Android to fix a bot

2 years ago[gn build] Port 889302292bf6
LLVM GN Syncbot [Sat, 9 Apr 2022 07:40:37 +0000 (07:40 +0000)]
[gn build] Port 889302292bf6

2 years ago[libc++][format][4/6] Improve formatted_size.
Mark de Wever [Sun, 26 Sep 2021 14:48:25 +0000 (16:48 +0200)]
[libc++][format][4/6] Improve formatted_size.

Use a specialized "buffer" to count the number of insertions instead of
using a `string` as storage type.

Depends on D110497.

Reviewed By: ldionne, #libc

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

2 years ago[libc++][format][3/6] Adds a __container_buffer.
Mark de Wever [Sun, 26 Sep 2021 13:47:42 +0000 (15:47 +0200)]
[libc++][format][3/6] Adds a __container_buffer.

Instead of writing every character directly into the container by using
a `back_insert_iterator` the data is buffered in an `array`. This buffer
is then inserted to the container by calling its `insert` member function.

Since there's no guarantee every container's `insert` behaves properly
containers need to opt-in to this behaviour. The appropriate standard
containers opt-in to this behaviour.

This change improves the performance of the format functions that use a
`back_insert_iterator`.

Depends on D110495

Reviewed By: ldionne, vitaut, #libc

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

2 years agoReland "[Driver] Default CLANG_DEFAULT_PIE_ON_LINUX to ON""
Fangrui Song [Sat, 9 Apr 2022 06:40:18 +0000 (23:40 -0700)]
Reland "[Driver] Default CLANG_DEFAULT_PIE_ON_LINUX to ON""

(With C++ exceptions, `clang++ --target=mips64{,el}-linux-gnu -fpie -pie
-fuse-ld=lld` has link errors (lld does not implement some strange R_MIPS_64
.eh_frame handling in GNU ld). However, sanitizer-x86_64-linux-qemu used this to
build ScudoUnitTests. Pined ScudoUnitTests to -no-pie.)

Default the option introduced in D113372 to ON to match all(?) major Linux
distros. This matches GCC and improves consistency with Android and linux-musl
which always default to PIE.
Note: CLANG_DEFAULT_PIE_ON_LINUX may be removed in the future.

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

2 years ago[scudo][test] Link with -no-pie to be agnostic of CLANG_DEFAULT_PIE_ON_LINUX
Fangrui Song [Sat, 9 Apr 2022 06:30:07 +0000 (23:30 -0700)]
[scudo][test] Link with -no-pie to be agnostic of CLANG_DEFAULT_PIE_ON_LINUX

This keeps the test behavior unchanged when CLANG_DEFAULT_PIE_ON_LINUX switches
to ON by default.

Note: current clang --target=mips64el-linux-gnu -fpie -pie -fuse-ld=lld
does not link with C++ exceptions, using -pie would lead to

```
ld.lld: error: cannot preempt symbol: DW.ref.__gxx_personality_v0
...
ld.lld: error: relocation R_MIPS_64 cannot be used against local symbol; recompile with -fPIC
...
```

when linking `ScudoUnitTests`: https://lab.llvm.org/buildbot/#/builders/169/builds/7311/steps/18/logs/stdio

2 years ago[flang] Support export/import OpenMP Threadprivate Flag
Peixin-Qiao [Sat, 9 Apr 2022 05:52:31 +0000 (13:52 +0800)]
[flang] Support export/import OpenMP Threadprivate Flag

The information about OpenMP/OpenACC declarative directives in modules
should be carried in export mod files. This supports export OpenMP
Threadprivate directive and import OpenMP declarative directives.

Reviewed By: kiranchandramohan

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

2 years ago[clang][OpenMP5.1] Initial parsing/sema for has_device_addr
Jennifer Yu [Thu, 7 Apr 2022 03:30:44 +0000 (20:30 -0700)]
[clang][OpenMP5.1] Initial parsing/sema for has_device_addr

Added basic parsing/sema/ support for the 'has_device_addr' clause.

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

2 years ago[BOLT] Check MCContext errors
Amir Ayupov [Sat, 9 Apr 2022 04:07:27 +0000 (21:07 -0700)]
[BOLT] Check MCContext errors

Abort on emission errors to prevent a malformed binary being written.
Example:
```
<unknown>:0: error: Undefined temporary symbol .Ltmp26310
<unknown>:0: error: Undefined temporary symbol .Ltmp26311
<unknown>:0: error: Undefined temporary symbol .Ltmp26312
<unknown>:0: error: Undefined temporary symbol .Ltmp26313
<unknown>:0: error: Undefined temporary symbol .Ltmp26314
<unknown>:0: error: Undefined temporary symbol .Ltmp26315
BOLT-ERROR: Emission failed.
```

Reviewed By: yota9

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

2 years ago[lld-macho] Use fewer indirections in UnwindInfo implementation
Jez Ng [Sat, 9 Apr 2022 02:33:00 +0000 (22:33 -0400)]
[lld-macho] Use fewer indirections in UnwindInfo implementation

The previous implementation of UnwindInfoSection materialized
all the compact unwind entries & applied their relocations, then parsed
the resulting data to generate the final unwind info. This design had
some unfortunate conseqeuences: since relocations can only be applied
after their referents have had addresses assigned, operations that need
to happen before address assignment must contort themselves. (See
{D113582} and observe how this diff greatly simplifies it.)

Moreover, it made synthesizing new compact unwind entries awkward.
Handling PR50956 will require us to do this synthesis, and is the main
motivation behind this diff.

Previously, instead of generating a new CompactUnwindEntry directly, we
would have had to generate a ConcatInputSection with a number of
`Reloc`s that would then get "flattened" into a CompactUnwindEntry.

This diff introduces an internal representation of `CompactUnwindEntry`
(the former `CompactUnwindEntry` has been renamed to
`CompactUnwindLayout`). The new CompactUnwindEntry stores references to
its personality symbol and LSDA section directly, without the use of
`Reloc` structs.

In addition to being easier to work with, this diff also allows us to
handle unwind info whose personality symbols are located in sections
placed after the `__unwind_info`.

Reviewed By: #lld-macho, oontvoo

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

2 years agoRevert D121556 "[randstruct] Add randomize structure layout support"
Fangrui Song [Sat, 9 Apr 2022 01:37:26 +0000 (18:37 -0700)]
Revert D121556 "[randstruct] Add randomize structure layout support"

This reverts commit 3f0587d0c668202bb89d29a25432aa290e551a31.

Not all tests pass after a few rounds of fixes.

I spot one failure that std::shuffle (potentially different results with
different STL implementations) was misused and replaced it with llvm::shuffle,
but there appears to be another failure in a Windows build.

The latest failure is reported on https://reviews.llvm.org/D121556#3440383

2 years ago[gn build] Port 46b2a463bdef
LLVM GN Syncbot [Sat, 9 Apr 2022 01:14:57 +0000 (01:14 +0000)]
[gn build] Port 46b2a463bdef

2 years ago[randstruct] Use llvm::shuffle to avoid STL impl difference after D121556
Fangrui Song [Sat, 9 Apr 2022 01:14:21 +0000 (18:14 -0700)]
[randstruct] Use llvm::shuffle to avoid STL impl difference after D121556

This reverts commit 2a2149c754f96376ddf8fed248102dd8e6092a22.
This reverts commit 8d7595be1dd41d7f7470ec90867936ca5e4e0d82.
This reverts commit e2e6899452998932b37f0fa9e66d104a02abe3e5.

If this doesn't work, I'll revert the whole thing.

2 years ago[gn build] Port 2a2149c754f9
LLVM GN Syncbot [Sat, 9 Apr 2022 00:50:44 +0000 (00:50 +0000)]
[gn build] Port 2a2149c754f9

2 years ago[AMDGPU] Fix regression with vectorization limiting
Stanislav Mekhanoshin [Thu, 31 Mar 2022 23:17:01 +0000 (16:17 -0700)]
[AMDGPU] Fix regression with vectorization limiting

D67148 has removed TTI::getNumberOfRegisters(bool Vector) and
started to call TTI::getNumberOfRegisters(unsigned ClassID) from
the LoopVectorize. This has resulted in an unrestricted vectorization
on AMDGPU blowing up register pressure.

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

2 years agoAdapt the ObjC stepping algorithm to deal with "selector-stubs" in clang.
Jim Ingham [Fri, 8 Apr 2022 19:25:53 +0000 (12:25 -0700)]
Adapt the ObjC stepping algorithm to deal with "selector-stubs" in clang.

Clang is adding a feature to ObjC code generation, where instead of calling
objc_msgSend directly with an object & selector, it generates a stub that
gets passed only the object and the stub figures out the selector.

This patch adds support for following that dispatch method into the implementation
function.

2 years ago[randstruct] Remove RandstructTest.cpp from list
Bill Wendling [Sat, 9 Apr 2022 00:41:36 +0000 (17:41 -0700)]
[randstruct] Remove RandstructTest.cpp from list

2 years ago[randstruct] temporarily remove test that's failing
Bill Wendling [Sat, 9 Apr 2022 00:04:22 +0000 (17:04 -0700)]
[randstruct] temporarily remove test that's failing

2 years ago[PowerPC] Adjust `MaxAtomicSizeInBitsSupported` on PPC64
Kai Luo [Fri, 8 Apr 2022 23:42:06 +0000 (23:42 +0000)]
[PowerPC] Adjust `MaxAtomicSizeInBitsSupported` on PPC64

AtomicExpandPass uses this variable to determine emitting libcalls or not. The default value is 1024 and if we don't specify it for PPC64 explicitly, AtomicExpandPass won't emit `__atomic_*` libcalls for those target unable to inline atomic ops and finally the backend emits `__sync_*` libcalls. Thanks @efriedma for pointing it out.

Reviewed By: efriedma

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

2 years agoAdd some function prototypes; NFC
Aaron Ballman [Fri, 8 Apr 2022 23:54:35 +0000 (19:54 -0400)]
Add some function prototypes; NFC

(This file is compiled with -pedantic enabled in some two-stage builds)

2 years agounbreak Modules/cxx20-export-import.cpp with LLVM_APPEND_VC_REV after fa34951fbc9bde75
Nico Weber [Fri, 8 Apr 2022 23:43:37 +0000 (19:43 -0400)]
unbreak Modules/cxx20-export-import.cpp with LLVM_APPEND_VC_REV after fa34951fbc9bde75

See revision b8b7a9dcdcbc for prior art.

2 years agoFix bazel rule for __support_fputil_fma when using header modules.
Jorge Gorbe Moya [Fri, 8 Apr 2022 23:26:21 +0000 (16:26 -0700)]
Fix bazel rule for __support_fputil_fma when using header modules.

Putting __support/FPUtil/x86_64/FMA.h in `hdrs` will trigger a
compilation action for that header, and it will always `#error` out for
non-FMA targets. Move these platform-specific headers that are
conditionally included to `textual_hdrs` instead.

2 years ago[PowerPC] Support 16-byte lock free atomics on pwr8 and up
Kai Luo [Fri, 8 Apr 2022 22:50:45 +0000 (22:50 +0000)]
[PowerPC] Support 16-byte lock free atomics on pwr8 and up

Make 16-byte atomic type aligned to 16-byte on PPC64, thus consistent with GCC. Also enable inlining 16-byte atomics on non-AIX targets on PPC64.

Reviewed By: hubert.reinterpretcast

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

2 years agoTransforms: Fix code duplication between LowerAtomic and AtomicExpand
Matt Arsenault [Wed, 6 Apr 2022 00:22:12 +0000 (20:22 -0400)]
Transforms: Fix code duplication between LowerAtomic and AtomicExpand

2 years ago[randstruct] disable test for Windows for now.
Bill Wendling [Fri, 8 Apr 2022 23:00:15 +0000 (16:00 -0700)]
[randstruct] disable test for Windows for now.

2 years agoNo reason for these not to have prototypes; NFC
Aaron Ballman [Fri, 8 Apr 2022 22:52:06 +0000 (18:52 -0400)]
No reason for these not to have prototypes; NFC

This should speculatively fix build bots:

https://lab.llvm.org/buildbot#builders/19/builds/10294
https://lab.llvm.org/buildbot#builders/37/builds/12289

2 years agoSkip test on earlier clang versions
Adrian Prantl [Fri, 8 Apr 2022 22:40:57 +0000 (15:40 -0700)]
Skip test on earlier clang versions

2 years ago[MSAN] add __b64_pton and __b64_ntop intercepts
Kevin Athey [Fri, 8 Apr 2022 22:00:09 +0000 (15:00 -0700)]
[MSAN] add __b64_pton and __b64_ntop intercepts

Reviewed By: vitalybuka

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

2 years ago[RGT] Use GTEST_SKIP() in more places where we skip a test
Paul Robinson [Fri, 8 Apr 2022 22:18:50 +0000 (15:18 -0700)]
[RGT] Use GTEST_SKIP() in more places where we skip a test

Simply returning will report the test as PASSED when it didn't
really do anything. SKIPPED is the correct result for these.

Found by the Rotten Green Tests project.

2 years ago[clang-tidy] Deal with keyword tokens in preprocessor conditions
Richard [Fri, 8 Apr 2022 00:58:36 +0000 (18:58 -0600)]
[clang-tidy] Deal with keyword tokens in preprocessor conditions

When a "keyword" token like __restrict was present in a macro condition,
modernize-macro-to-enum would assert in non-release builds.  However,
even for a "keyword" token, calling getIdentifierInfo()->getName() would
retrieve the text of the token, which is what we want.  Our intention is
to scan names that appear in conditional expressions in potential enum
clusters and invalidate those clusters if they contain the name.

Also, guard against "raw identifiers" appearing as potential enums.
This shouldn't happen, but it doesn't hurt to generalize the code.

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

Fixes #54775

2 years ago[lldb] XFAIL tests that aren't passing remotely
Jonas Devlieghere [Fri, 8 Apr 2022 20:07:29 +0000 (13:07 -0700)]
[lldb] XFAIL tests that aren't passing remotely

XFAIL a series of tests that are failing remotely.

2 years ago[lldb] Skip more tests that don't make sense to run remotely
Jonas Devlieghere [Fri, 8 Apr 2022 20:07:08 +0000 (13:07 -0700)]
[lldb] Skip more tests that don't make sense to run remotely

Skip another batch of tests that don't really make sense to run
remotely.

2 years ago[randstruct] add expected output for WIN64
Bill Wendling [Fri, 8 Apr 2022 21:41:44 +0000 (14:41 -0700)]
[randstruct] add expected output for WIN64

This is an attempt to fix a test failure on one of the buildbot Windows
machines. It also turns all of the "ASSERT_" macros into "EXPECT_" to
catch all other failures.

Link: https://lab.llvm.org/buildbot/#/builders/216/builds/2647
2 years agoReland "[MTE] Add -fsanitize=memtag* and friends."
Mitch Phillips [Fri, 8 Apr 2022 20:22:27 +0000 (13:22 -0700)]
Reland "[MTE] Add -fsanitize=memtag* and friends."

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

2 years ago[libc][NFC] implement printf parser
Michael Jones [Mon, 4 Apr 2022 18:46:30 +0000 (11:46 -0700)]
[libc][NFC] implement printf parser

This patch adds the sequential mode implementation of the printf parser,
as well as unit tests for it. In addition it adjusts the surrounding
files to accomodate changes in the design found in the implementation
process.

Reviewed By: sivachandra

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

2 years ago[libc++] Add missing 'return 0;' to main() in test
Louis Dionne [Fri, 8 Apr 2022 21:10:58 +0000 (17:10 -0400)]
[libc++] Add missing 'return 0;' to main() in test

2 years ago[libcxx][NFC] Format sort.h
Nilay Vaish [Fri, 8 Apr 2022 21:02:25 +0000 (17:02 -0400)]
[libcxx][NFC] Format sort.h

This is to simplify the changes made in D122780.  This diff was generated using the command:

```
clang-format include/__algorithm/sort.h  -i
```

Reviewed By: #libc, ldionne

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

2 years ago[libc++] Rename PS() macro to avoid clashing with Xtensa register name
Gustavo Henrique Nihei [Fri, 8 Apr 2022 20:58:56 +0000 (16:58 -0400)]
[libc++] Rename PS() macro to avoid clashing with Xtensa register name

This patch addresses a clash with the PS register from Xtensa
defined in the <specreg.h> header file, which is commonly included in
OS implementation.

Issue identified while building libc++ port for Apache NuttX, targeting
Xtensa-based chips (e.g. Espressif's ESP32).

Signed-off-by: Gustavo Henrique Nihei <gustavo.nihei@espressif.com>
Differential Revision: https://reviews.llvm.org/D122479

2 years ago[gn build] Port 3f0587d0c668
LLVM GN Syncbot [Fri, 8 Apr 2022 20:26:24 +0000 (20:26 +0000)]
[gn build] Port 3f0587d0c668

2 years ago[gn build] Port 2aa575fd7f4b
LLVM GN Syncbot [Fri, 8 Apr 2022 20:26:23 +0000 (20:26 +0000)]
[gn build] Port 2aa575fd7f4b

2 years ago[C89/C2x] Improve diagnostics around strict prototypes in C
Aaron Ballman [Fri, 8 Apr 2022 20:19:58 +0000 (16:19 -0400)]
[C89/C2x] Improve diagnostics around strict prototypes in C

Functions without prototypes in C (also known as K&R C functions) were
introduced into C89 as a deprecated feature and C2x is now reclaiming
that syntax space with different semantics. However, Clang's
-Wstrict-prototypes diagnostic is off-by-default (even in pedantic
mode) and does not suffice to warn users about issues in their code.

This patch changes the behavior of -Wstrict-prototypes to only diagnose
declarations and definitions which are not going to change behavior in
C2x mode, and enables the diagnostic in -pedantic mode. The diagnostic
is now specifically about the fact that the feature is deprecated.

It also adds -Wdeprecated-non-prototype, which is grouped under
-Wstrict-prototypes and diagnoses declarations or definitions which
will change behavior in C2x mode. This diagnostic is enabled by default
because the risk is higher for the user to continue to use the
deprecated feature.

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

2 years agoRevert "[MTE] Add -fsanitize=memtag* and friends."
Aaron Ballman [Fri, 8 Apr 2022 20:15:58 +0000 (16:15 -0400)]
Revert "[MTE] Add -fsanitize=memtag* and friends."

This reverts commit 8aa1490513f111afd407d87c3f07d26f65c8a686.

Broke testing: https://lab.llvm.org/buildbot/#/builders/109/builds/36233

2 years ago[libc++] Avoid using anonymous struct with base classes (fixes GCC 12)
Azat Khuzhin [Fri, 8 Apr 2022 20:13:46 +0000 (16:13 -0400)]
[libc++] Avoid using anonymous struct with base classes (fixes GCC 12)

GCC 12 reports:

     libcxx/include/string:727:13: error: anonymous struct with base classes
     727 |             : __padding<value_type>

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

2 years ago[AMDGPU] Enable PreRARematerialize scheduling pass with multiple high RP regions
Vang Thao [Fri, 25 Mar 2022 18:36:34 +0000 (11:36 -0700)]
[AMDGPU] Enable PreRARematerialize scheduling pass with multiple high RP regions

Enable the PreRARematerialize pass when there are multiple high RP scheduling
regions present. Require the occupancy in all high RP regions be improved
before finalizing sinking. If any high RP region did not improve in occupancy
then un-do all sinking and restore the state to before the pass.

Reviewed By: rampitec

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

2 years agoAMDGPU: Add codegen test for ctpop(ballot(x))
Nicolai Hähnle [Fri, 8 Apr 2022 19:30:20 +0000 (14:30 -0500)]
AMDGPU: Add codegen test for ctpop(ballot(x))

Highlights a gap in DAG-based ISel where we unnecessarily choose vector
instructions. GlobalISel already looks good.

2 years ago[randstruct] Add randomize structure layout support
Connor Kuehl [Fri, 8 Apr 2022 19:47:11 +0000 (12:47 -0700)]
[randstruct] Add randomize structure layout support

The Randstruct feature is a compile-time hardening technique that
randomizes the field layout for designated structures of a code base.
Admittedly, this is mostly useful for closed-source releases of code,
since the randomization seed would need to be available for public and
open source applications.

Why implement it? This patch set enhances Clang’s feature parity with
that of GCC which already has the Randstruct feature. It's used by the
Linux kernel in certain structures to help thwart attacks that depend on
structure layouts in memory.

This patch set is a from-scratch reimplementation of the Randstruct
feature that was originally ported to GCC. The patches for the GCC
implementation can be found here:

  https://www.openwall.com/lists/kernel-hardening/2017/04/06/14

Link: https://lists.llvm.org/pipermail/cfe-dev/2019-March/061607.html
Co-authored-by: Cole Nixon <nixontcole@gmail.com>
Co-authored-by: Connor Kuehl <cipkuehl@gmail.com>
Co-authored-by: James Foster <jafosterja@gmail.com>
Co-authored-by: Jeff Takahashi <jeffrey.takahashi@gmail.com>
Co-authored-by: Jordan Cantrell <jordan.cantrell@mail.com>
Co-authored-by: Nikk Forbus <nicholas.forbus@gmail.com>
Co-authored-by: Tim Pugh <nwtpugh@gmail.com>
Co-authored-by: Bill Wendling <isanbard@gmail.com>
Signed-off-by: Bill Wendling <isanbard@gmail.com>
Reviewed By: aaron.ballman

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

2 years agoRevert D120327 "compiler-rt: Add udivmodei5 to builtins and add bitint library"
Fangrui Song [Fri, 8 Apr 2022 19:39:42 +0000 (12:39 -0700)]
Revert D120327 "compiler-rt: Add udivmodei5 to builtins and add bitint library"

It has several problems like not-compilable weak attribute with MSVC
(and the usage needs further scrutiny), and " different types for formal and actual parameter"
https://lab.llvm.org/buildbot/#/builders/127/builds/27760/steps/7/logs/stdio

This reverts commit 8843245ddd2daf8d6cecc94667c2af83a82284fa492c5c05e111b81e2e7f1faa69756082fb826085bf2dc4b37623e1b4f7d39570e1b5a6f3ef5db107.

2 years ago[RGT] Use GTEST_SKIP instead of just returning
Paul Robinson [Fri, 8 Apr 2022 19:19:51 +0000 (12:19 -0700)]
[RGT] Use GTEST_SKIP instead of just returning

2 years ago[flang] Do not fold fir.box_addr when it has a slice
Valentin Clement [Fri, 8 Apr 2022 19:16:08 +0000 (21:16 +0200)]
[flang] Do not fold fir.box_addr when it has a slice

This patch avoids to fold `fir.box_addr` when the defining `fir.embox` op
has a slice. If the op is folded the slice information are lost.

This kind of problem occurred with code like:

```
call check(y(half+1:))
```

where `y` is an array.

Reviewed By: jeanPerier

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

2 years ago[MTE] Add -fsanitize=memtag* and friends.
Mitch Phillips [Fri, 1 Apr 2022 21:24:15 +0000 (14:24 -0700)]
[MTE] Add -fsanitize=memtag* and friends.

Currently, enablement of heap MTE on Android is specified by an ELF note, which
signals to the linker to enable heap MTE. This change allows
-fsanitize=memtag-heap to synthesize these notes, rather than adding them
through the build system. We need to extend this feature to also signal the
linker to do special work for MTE globals (in future) and MTE stack (currently
implemented in the toolchain, but not implemented in the loader).

Current Android uses a non-backwards-compatible ELF note, called
".note.android.memtag". Stack MTE is an ABI break anyway, so we don't mind that
we won't be able to run executables with stack MTE on Android 11/12 devices.

The current expectation is to support the verbiage used by Android, in
that "SYNC" means MTE Synchronous mode, and "ASYNC" effectively means
"fast", using the Kernel auto-upgrade feature that allows
hardware-specific and core-specific configuration as to whether "ASYNC"
would end up being Asynchronous, Asymmetric, or Synchronous on that
particular core, whichever has a reasonable performance delta. Of
course, this is platform and loader-specific.

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

2 years ago[mlir][sparse] Moving <P,I,V>-invariant parts of SparseTensorStorage to base
wren romano [Thu, 7 Apr 2022 01:08:02 +0000 (18:08 -0700)]
[mlir][sparse] Moving <P,I,V>-invariant parts of SparseTensorStorage to base

This reorganization helps to clean up the changes needed for D122060.

Work towards fixing: https://github.com/llvm/llvm-project/issues/51652

Depends On D122625

Reviewed By: aartbik

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

2 years ago[LV] Set debug loc after setting insert point.
Florian Hahn [Fri, 8 Apr 2022 18:34:40 +0000 (20:34 +0200)]
[LV] Set debug loc after setting insert point.

This fixes the code to actually use the location of the instruction, if
available. Previously, SetInsertPoint would overwrite the insert point
set from the instruction.

2 years ago[LV] Add test case for wrong debug location with replicate recipe.
Florian Hahn [Fri, 8 Apr 2022 18:34:16 +0000 (20:34 +0200)]
[LV] Add test case for wrong debug location with replicate recipe.

2 years agolld/AMDGPU: Fix asserts if no object files are involved in link
Matt Arsenault [Fri, 8 Apr 2022 17:22:23 +0000 (13:22 -0400)]
lld/AMDGPU: Fix asserts if no object files are involved in link

Fixes issue 47690. The reproduction steps produced a shared object
from clang directly, and then fed the shared object back into
lld. With no regular object files, this assert was hit. I'm not sure
if we need to or should be looking for equivalent fields in shared
objects.

2 years ago[libc] Add support for x86-64 targets that do not have FMA instructions.
Tue Ly [Thu, 7 Apr 2022 20:02:10 +0000 (16:02 -0400)]
[libc] Add support for x86-64 targets that do not have FMA instructions.

Make FMA flag checks more accurate for x86-64 targets, and refactor
polyeval to use multiply and add instead when FMA instructions are not
available.

Reviewed By: michaelrj, sivachandra

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

2 years ago[libc++][test] Use the Japanese locale.
Mark de Wever [Wed, 30 Mar 2022 15:34:17 +0000 (17:34 +0200)]
[libc++][test] Use the Japanese locale.

This change is done to see whether all platforms have a CI with the
Japanese locale installed.

This wires in the locale in the tests and uses it in one test. This is
a preparation for the tests of the chrono formatters.

Reviewed By: ldionne, #libc

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

2 years agoUse writable temporary file for test compiler output instead of hardcoded name. NFCI.
Jorge Gorbe Moya [Fri, 8 Apr 2022 17:57:20 +0000 (10:57 -0700)]
Use writable temporary file for test compiler output instead of hardcoded name. NFCI.

2 years ago[lldb] Skip a bunch of tests that shouldn't run remotely
Jonas Devlieghere [Fri, 8 Apr 2022 17:36:16 +0000 (10:36 -0700)]
[lldb] Skip a bunch of tests that shouldn't run remotely

Skip a bunch of tests that don't really make sense to run remotely.

2 years ago[lldb] Fix TestQuoting when run remotely
Jonas Devlieghere [Fri, 8 Apr 2022 17:10:17 +0000 (10:10 -0700)]
[lldb] Fix TestQuoting when run remotely

2 years ago[lldb] Import Foundation in TestConflictingDefinition.py
Jonas Devlieghere [Fri, 8 Apr 2022 17:04:15 +0000 (10:04 -0700)]
[lldb] Import Foundation in TestConflictingDefinition.py

We need to import foundation to get a 'NSLog' declaration when building
against the iOS SDK. This doesn't appear necessary when building against
the macOS SDK, presumable because it gets transitively imported by
objc/NSObject.h

2 years agoUse portable formatting specified in test. NFCI.
Jorge Gorbe Moya [Fri, 8 Apr 2022 17:43:20 +0000 (10:43 -0700)]
Use portable formatting specified in test. NFCI.

2 years ago[Clang] [Docs] Add HLSLSupport page
Chris Bieneman [Thu, 7 Apr 2022 04:13:56 +0000 (23:13 -0500)]
[Clang] [Docs] Add HLSLSupport page

This document is a first-stab at addressing some of the questions about
HLSL support in Clang.

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

2 years ago[clang-offload-bundler] fix "no output file" issue with -outputs
Siu Chi Chan [Fri, 8 Apr 2022 17:09:31 +0000 (17:09 +0000)]
[clang-offload-bundler] fix "no output file" issue with -outputs

Fix backward compatibility issue due to D120662.

Change-Id: I7cd0f704aabbaac7dcf59fd4b73b4f0e0cdfa69f

Reviewed By: yaxunl, saiislam

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

2 years ago[CaptureTracking] Ignore ephemeral values in EarliestEscapeInfo
Arthur Eubanks [Thu, 7 Apr 2022 22:39:53 +0000 (15:39 -0700)]
[CaptureTracking] Ignore ephemeral values in EarliestEscapeInfo

And thread DSE's ephemeral values to EarliestEscapeInfo.

This allows more precise analysis in DSEState::isReadClobber() via BatchAA.

Followup to D123162.

Reviewed By: nikic

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

2 years ago[MC][ELF] Improve st_size propagation rule
Fangrui Song [Fri, 8 Apr 2022 17:06:43 +0000 (10:06 -0700)]
[MC][ELF] Improve st_size propagation rule

`.symver foo, foo@ver` creates the MCSymbolELF `foo@ver` whose almost all
attributes (including st_size) should inherit from `foo` (GNU as behavior).

a041ef1bd8905f0d58e301c6830b183002ff1847 added st_size propagation which works
for many cases but fails for the following one:

```
.set __GLIBC_2_12_sys_errlist, _sys_errlist_internal
.type   __GLIBC_2_12_sys_errlist,@object
.size   __GLIBC_2_12_sys_errlist, 1080
.symver __GLIBC_2_12_sys_errlist, sys_errlist@GLIBC_2.12
...
_sys_errlist_internal:
.size   _sys_errlist_internal, 1072
```

`sys_errlist@GLIBC_2.12`'s st_size is 1072 (incorrect), which does not match
`__GLIBC_2_12_sys_errlist`'s st_size: 1080.

The problem is that `Base` is (the final) `_sys_errlist_internal` while we want
to respect (the intermediate) `__GLIBC_2_12_sys_errlist`'s st_size.
Fix this by following the MCSymbolRefExpr assignment chain and finding
the closest non-null `getSize()`, which covers most needs. Notably MCBinaryExpr
is not handled, but it is rare enough to matter.

Reviewed By: peter.smith

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

2 years ago[MC][test] Improve offset.s
Fangrui Song [Fri, 8 Apr 2022 16:58:04 +0000 (09:58 -0700)]
[MC][test] Improve offset.s

2 years agoAdd one more definition for symbols in prctl unit test.
Kevin Athey [Fri, 8 Apr 2022 16:44:27 +0000 (09:44 -0700)]
Add one more definition for symbols in prctl unit test.

one more follow up to: https://reviews.llvm.org/D122851

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

2 years ago[clang][extract-api] Emit "navigator" property of "name" in SymbolGraph
Daniel Grumberg [Fri, 8 Apr 2022 14:58:14 +0000 (15:58 +0100)]
[clang][extract-api] Emit "navigator" property of "name" in SymbolGraph

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

2 years ago[flang] Fix semantic analysis for "forall" targeted by "label"
PeixinQiao [Fri, 8 Apr 2022 16:27:53 +0000 (00:27 +0800)]
[flang] Fix semantic analysis for "forall" targeted by "label"

As Fortran 2018 3.18 states, the branch target statement can be
`forall-construct-stmt`, but cannot be `forall-stmt`. `forall-stmt` is
wrapped by `Statement` in `action-stmt` and `action-stmt` can be one
branch target statement. Fix the semantic analysis and add two
regression test cases in lowering.

Reviewed By: Jean Perier

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

2 years ago[RISCV] Select unmasked FP setcc insts via ISel post-process
Fraser Cormack [Thu, 7 Apr 2022 08:32:32 +0000 (09:32 +0100)]
[RISCV] Select unmasked FP setcc insts via ISel post-process

Similar to D123217 but for the floating-point patterns. No change in
generated output, while reducing the generated table size.

Reviewed By: arcbbb

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

2 years ago[AMDGPU] Fix inline asm causing assert during PreRARematerialize stage in scheduler...
Vang Thao [Fri, 8 Apr 2022 00:51:47 +0000 (17:51 -0700)]
[AMDGPU] Fix inline asm causing assert during PreRARematerialize stage in scheduler pass

Reviewed By: foad

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

2 years ago[memprof] Deduplicate and outline frame storage in the memprof profile.
Snehasish Kumar [Tue, 22 Mar 2022 02:39:24 +0000 (19:39 -0700)]
[memprof] Deduplicate and outline frame storage in the memprof profile.

The current implementation of memprof information in the indexed profile
format stores the representation of each calling context fram inline.
This patch uses an interned representation where the frame contents are
stored in a separate on-disk hash table. The table is indexed via a hash
of the contents of the frame. With this patch, the compressed size of a
large memprof profile reduces by ~22%.

Reviewed By: tejohnson

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

2 years agoNFC: Avoid unused variable warning in UnwindLevel1.c
kristina [Fri, 8 Apr 2022 16:04:35 +0000 (17:04 +0100)]
NFC: Avoid unused variable warning in UnwindLevel1.c

2 years ago[RISCV] Always select (and (srl X, C), Mask) as (srli (slli X, C2), C3).
Craig Topper [Thu, 7 Apr 2022 23:10:30 +0000 (16:10 -0700)]
[RISCV] Always select (and (srl X, C), Mask) as (srli (slli X, C2), C3).

SLLI is always compressible to C.SLLI as long as the source and dest
register is the same.

ANDI and SRLI are only compressible if the register is x8-x15. By
using SLLI we have a better chance of generating shorter code.

I had to exclude one exclusion for the BEXTI case so that it's
pattern match could still fire.

Reviewed By: luismarques

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

2 years ago[InstCombine] Add sub(add(x,y),minmax(x,y)) -> maxmin(x,y) tests
Simon Pilgrim [Fri, 8 Apr 2022 15:55:44 +0000 (16:55 +0100)]
[InstCombine] Add sub(add(x,y),minmax(x,y)) -> maxmin(x,y) tests

Based on Issue #37628

2 years agoAdd definitions for symbols in unit test for prctl.
Kevin Athey [Fri, 8 Apr 2022 15:49:25 +0000 (08:49 -0700)]
Add definitions for symbols in unit test for prctl.

Follow up to: https://reviews.llvm.org/D122851

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

2 years ago[Loads] Check type size in bits during store to load forwarding
Nikita Popov [Fri, 8 Apr 2022 15:26:29 +0000 (17:26 +0200)]
[Loads] Check type size in bits during store to load forwarding

Rather than checking the rounded type store size, check the type
size in bits. We don't want to forward a store of i1 to a load
of i8 for example, even though they have the same type store size.
The padding bits have unspecified contents.

This is a partial fix for the issue reported at
https://reviews.llvm.org/D115924#inline-1179482,
the problem also needs to be addressed more generally in the
constant folding code.

2 years ago[VPlan] Preserve debug location when creating branch.
Florian Hahn [Fri, 8 Apr 2022 15:22:38 +0000 (17:22 +0200)]
[VPlan] Preserve debug location when creating branch.

Update createEmptyBasicBlock to preserve the debug location of the
previous terminator.