platform/upstream/llvm.git
2 years ago[clang-format] NFC use recently added Style.isJavaScript()
mydeveloperday [Tue, 21 Dec 2021 14:24:12 +0000 (14:24 +0000)]
[clang-format] NFC use recently added Style.isJavaScript()

Improve the readability of these if(Style==FormatStyle::LK_JavsScript) clauses

2 years agoAlignConsecutiveDeclarations not working for 'const' keyword in JavsScript
mydeveloperday [Tue, 21 Dec 2021 13:57:43 +0000 (13:57 +0000)]
AlignConsecutiveDeclarations not working for 'const' keyword in JavsScript

https://github.com/llvm/llvm-project/issues/49846

Fixes #49846

AlignConsecutiveDeclarations  is not working for "let" and "const" in JavaScript

let letVariable     = 5;
const constVariable = 10;

Reviewed By: owenpan, HazardyKnusperkeks, curdeius

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

2 years ago[CodeGen] Accept Address in CreateLaunderInvariantGroup
Nikita Popov [Tue, 21 Dec 2021 13:40:33 +0000 (14:40 +0100)]
[CodeGen] Accept Address in CreateLaunderInvariantGroup

Add an overload that accepts and returns an Address, as we
generally just want to replace the pointer with a laundered one,
while retaining remaining information.

2 years ago[libc++] Rename __s1/__s2 to __dest/__source in __copy_constexpr. NFC.
Arthur O'Dwyer [Tue, 21 Dec 2021 13:33:30 +0000 (08:33 -0500)]
[libc++] Rename __s1/__s2 to __dest/__source in __copy_constexpr. NFC.

This consistently completes the renaming started in D115986.

2 years ago[mlir][memref] ReinterpretCast: allow static sizes/strides/offset where affine map...
Butygin [Thu, 28 Oct 2021 16:04:35 +0000 (19:04 +0300)]
[mlir][memref] ReinterpretCast: allow static sizes/strides/offset where affine map expects dynamic

* There is no reason to forbid that case
* Also, user will get very unfriendly error like `expected result type with offset = -9223372036854775808 instead of 1`

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

2 years ago[clangd] Fix typo in test. NFC
Sam McCall [Tue, 21 Dec 2021 13:16:54 +0000 (14:16 +0100)]
[clangd] Fix typo in test. NFC

2 years ago[X86] getTargetVShiftNode - remove shift-by-constant handling.
Simon Pilgrim [Tue, 21 Dec 2021 13:16:41 +0000 (13:16 +0000)]
[X86] getTargetVShiftNode - remove shift-by-constant handling.

Move shift-by-constant handling and move it into its only user (VSHIFT intrinsics lowering).

This is some prep-work for getTargetVShiftNode to no longer take a scalar shift amount - we're introducing temporary ISD::EXTRACT_VECTOR_ELT nodes via SelectionDAG::getSplatValue to accommodate this which can cause various issues, including unnecessary scalarization and xmm->gpr->xmm transfers, and causes problems for 32-bit codegen if we fail to remove an (illegal) i64 scalar extracted from a (legal) vXi64 vector.

2 years ago[CodeGen] Avoid some pointer element type accesses
Nikita Popov [Mon, 20 Dec 2021 15:17:27 +0000 (16:17 +0100)]
[CodeGen] Avoid some pointer element type accesses

This avoids some pointer element type accesses when compiling
C++ code.

2 years ago[gn build] (semiautomatically) port 9b4f179bf8d3
Nico Weber [Fri, 17 Dec 2021 12:26:34 +0000 (07:26 -0500)]
[gn build] (semiautomatically) port 9b4f179bf8d3

2 years ago[libc++] Allow __move_constexpr to work with unrelated pointers
Nikolas Klauser [Tue, 21 Dec 2021 10:22:50 +0000 (11:22 +0100)]
[libc++] Allow __move_constexpr to work with unrelated pointers

Allow `__move_constexpr` to work with unrelated pointers and `_LIBCPP_ASSERT` that `__copy_constexpr`, `__move_constexpr` and `__assign_constexpr` are only run during constant evaluation

Reviewed By: ldionne, #libc

Spies: libcxx-commits

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

2 years ago[SVE] Reintroduce -scalable-vectorization=preferred as an alias to "on".
Paul Walker [Tue, 21 Dec 2021 12:51:40 +0000 (12:51 +0000)]
[SVE] Reintroduce -scalable-vectorization=preferred as an alias to "on".

Some buildbots still rely on the experimental flag, so let's keep
it until everything has been migrated to the new "on by default"
state.

2 years agotsan: always handle closing of file descriptors
Dmitry Vyukov [Tue, 21 Dec 2021 09:30:01 +0000 (10:30 +0100)]
tsan: always handle closing of file descriptors

If we miss both close of a file descriptor and a subsequent open
if the same file descriptor number, we report false positives
between operations on the old and on the new descriptors.

There are lots of ways to create new file descriptors, but for closing
there is mostly close call. So we try to handle at least it.
However, if the close happens in an ignored library, we miss it
and start reporting false positives.

Handle closing of file descriptors always, even in ignored libraries
(as we do for malloc/free and other critical functions).
But don't imitate memory accesses on close for ignored libraries.

FdClose checks validity of the fd (fd >= 0) itself,
so remove the excessive checks in the callers.

Reviewed By: melver

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

2 years ago[GlobalISel] Verify operand types for G_SHL, G_LSHR, G_ASHR
Jay Foad [Thu, 16 Dec 2021 09:52:48 +0000 (09:52 +0000)]
[GlobalISel] Verify operand types for G_SHL, G_LSHR, G_ASHR

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

2 years ago[X86] LowerRotate - enable vXi32 splat handling
Simon Pilgrim [Tue, 21 Dec 2021 11:19:15 +0000 (11:19 +0000)]
[X86] LowerRotate - enable vXi32 splat handling

Pull out the "rotl(x,y) --> (unpack(x,x) << zext(splat(y % bw))) >> bw" special case from vXi8 lowering so we can reuse it for vXi32 types as well.

There's still some regressions with vXi16 to handle before this becomes entirely general.

It also allows us to remove the now unnecessary hack for handling amount-modulo before splatting.

2 years ago[DAG] Constify SelectionDAG::isSplatValue()
Simon Pilgrim [Sun, 19 Dec 2021 17:03:53 +0000 (17:03 +0000)]
[DAG] Constify SelectionDAG::isSplatValue()

This doesn't generate any nodes so should be usable by methods with const SelectionDAG &.

2 years ago[FuncSpec] Rename internal option. NFC.
Sjoerd Meijer [Tue, 21 Dec 2021 10:19:49 +0000 (10:19 +0000)]
[FuncSpec] Rename internal option. NFC.

Rename option MaxConstantsThreshold to MaxClonesThreshold. Not only is this
more descriptive, this is also in preparation of introducing another threshold
to analyse more than just 1 constant argument as we currently do, and to better
distinguish these options/thresholds.

2 years ago[llvm-mca] Compare multiple files
Djordje Todorovic [Tue, 21 Dec 2021 10:53:21 +0000 (11:53 +0100)]
[llvm-mca] Compare multiple files

Script (llvm-mca-compare.py) uses llvm-mca tool to print
statistics in console for multiple files.
Script requires specified --llvm-mca-binary option (specified
relative path to binary of llvm-mca).
Options: --args [="-option1=<arg> -option2=<arg> ..."], -v or -h can also be used.

The script is used as follows:
$ llvm-project/llvm/utils/llvm-mca-compare.py file1.s --llvm-mca-binary=build/bin/llvm-mca

Patch by Milica Matic <Milica.Matic@syrmia.com>

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

2 years ago[mlir][Support] Avoid multiplication in floorDiv / ceilDiv
Stephan Herhut [Tue, 21 Dec 2021 10:31:28 +0000 (11:31 +0100)]
[mlir][Support] Avoid multiplication in floorDiv / ceilDiv

Using comparisons instead avoids potential overflow.

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

2 years ago[CodeGen] Avoid pointee type access during global var declaration
Nikita Popov [Tue, 21 Dec 2021 10:44:45 +0000 (11:44 +0100)]
[CodeGen] Avoid pointee type access during global var declaration

All callers pass in a GlobalVariable, so we can conveniently fetch
the type from there.

2 years ago[AArch64][SVE] Lower shuffles to permute instructions: zip1/2, uzp1/2, trn1/2
Andrew Wei [Tue, 21 Dec 2021 10:14:21 +0000 (18:14 +0800)]
[AArch64][SVE] Lower shuffles to permute instructions: zip1/2, uzp1/2, trn1/2

Attempt to lower a shuffle as a permute instruction(zip/uzp/trn) for fixed length SVE.

Reviewed By: paulwalker-arm

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

2 years agotsan: remove unused ReportMutex::destroyed
Dmitry Vyukov [Tue, 16 Nov 2021 08:02:59 +0000 (09:02 +0100)]
tsan: remove unused ReportMutex::destroyed

Depends on D113980.

Reviewed By: melver

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

2 years agotsan: change ReportMutex::id type to int
Dmitry Vyukov [Tue, 16 Nov 2021 08:09:14 +0000 (09:09 +0100)]
tsan: change ReportMutex::id type to int

We used to use u64 as mutex id because it was some
tricky identifier built from address and reuse count.
Now it's just the mutex index in the report (0, 1, 2...),
so use int to represent it.

Depends on D112603.

Reviewed By: melver

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

2 years agoRevert "[NFC] [C++20] [Modules] Add tests for template instantiation in transitively...
Chuanqi Xu [Tue, 21 Dec 2021 10:33:29 +0000 (18:33 +0800)]
Revert "[NFC] [C++20] [Modules] Add tests for template instantiation in transitively imported module"

This reverts commit 4f103e956157515dd800951f73ed550b1a0477f4.

The tests couldn't pass under windows.

2 years agotsan: optimize __tsan_read/write16
Dmitry Vyukov [Thu, 25 Nov 2021 14:44:19 +0000 (15:44 +0100)]
tsan: optimize __tsan_read/write16

These callbacks are used for SSE vector accesses.
In some computational programs these accesses dominate.
Currently we do 2 uninlined 8-byte accesses to handle them.
Inline and optimize them similarly to unaligned accesses.
This reduces the vector access benchmark time from 8 to 3 seconds.

Depends on D112603.

Reviewed By: melver

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

2 years ago[NFC] [C++20] [Modules] Add tests for template instantiation in transitively imported...
Chuanqi Xu [Tue, 21 Dec 2021 09:36:50 +0000 (17:36 +0800)]
[NFC] [C++20] [Modules] Add tests for template instantiation in transitively imported module

This commit adds two test about template class instantiation in
transitively imported module. They are used as pre-commit tests for
successive patches.

2 years ago[ELF] Remove unneeded SectionBase::repl indirection
Fangrui Song [Tue, 21 Dec 2021 08:39:16 +0000 (00:39 -0800)]
[ELF] Remove unneeded SectionBase::repl indirection

sec->repl equals sec after rL371216.

2 years ago[VE] FADD,FSUB,FMUL,FDIV v256f32|f64 isel and tests
Simon Moll [Tue, 21 Dec 2021 08:15:23 +0000 (09:15 +0100)]
[VE] FADD,FSUB,FMUL,FDIV v256f32|f64 isel and tests

Depends on D115940 for the `Binary_rv_vr_vv` pattern class op isel
fragment used for divisions.

Reviewed By: kaz7

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

2 years ago[ConstantFold][GlobalOpt] Don't create x86_mmx null value
Nikita Popov [Tue, 21 Dec 2021 08:11:41 +0000 (09:11 +0100)]
[ConstantFold][GlobalOpt] Don't create x86_mmx null value

This fixes the assertion failure reported at
https://reviews.llvm.org/D114889#3198921 with a straightforward
check, until the cleaner fix in D115924 can be reapplied.

2 years ago[InstCombine] Drop outdated alignment comment (NFC)
Nikita Popov [Tue, 21 Dec 2021 07:58:48 +0000 (08:58 +0100)]
[InstCombine] Drop outdated alignment comment (NFC)

Loads always have an alignment now, so this is no longer relevant.

2 years ago[VE] U|SDIV v256i32|64 isel and tests
Simon Moll [Tue, 21 Dec 2021 07:43:31 +0000 (08:43 +0100)]
[VE] U|SDIV v256i32|64 isel and tests

Reviewed By: kaz7

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

2 years ago[llvm] Construct SmallVector with iterator ranges (NFC)
Kazu Hirata [Tue, 21 Dec 2021 07:43:23 +0000 (23:43 -0800)]
[llvm] Construct SmallVector with iterator ranges (NFC)

2 years ago[ARM] Use range-based for loops (NFC)
Kazu Hirata [Tue, 21 Dec 2021 07:06:47 +0000 (23:06 -0800)]
[ARM] Use range-based for loops (NFC)

2 years ago[RISCV] Precommit tests for override hasAndNotCompare.
jacquesguan [Mon, 20 Dec 2021 03:44:09 +0000 (11:44 +0800)]
[RISCV] Precommit tests for override hasAndNotCompare.

Precommit tests for D115922.

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

2 years ago[AMDGPU][NFC] Update DWARF extension for locations on the stack
Tony Tye [Tue, 21 Dec 2021 04:47:26 +0000 (04:47 +0000)]
[AMDGPU][NFC] Update DWARF extension for locations on the stack

- Improve extension description.
- Rename "What is DWARF?" section to better reflect what it is
  describing.

Reviewed By: kzhuravl

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

2 years agoBPF: report better error message for BTF_TYPE_ID_REMOTE relo failure
Yonghong Song [Mon, 20 Dec 2021 00:58:12 +0000 (16:58 -0800)]
BPF: report better error message for BTF_TYPE_ID_REMOTE relo failure

Matteo Croce reported a bpf backend fatal error in
https://github.com/llvm/llvm-project/issues/52779

A simplified case looks like:
  $ cat bug.c
  extern int do_smth(int);
  int test() {
    return __builtin_btf_type_id(*(typeof(do_smth) *)do_smth, 1);
  }
  $ clang -target bpf -O2 -g -c bug.c
  fatal error: error in backend: Empty type name for BTF_TYPE_ID_REMOTE reloc
  ...

The reason for the fatal error is that the relocation is against
a DISubroutineType like type 13 below:
  !10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
  !11 = !{}
  !12 = !DILocation(line: 3, column: 10, scope: !7)
  !13 = !DISubroutineType(types: !14)
  !14 = !{!10, !10}

The DISubroutineType doesn't have a name and there is no way for
downstream bpfloader/kernel to do proper relocation for it.

But we can improve error message to be more specific for this case.
The patch improved the error message to be:
  fatal error: error in backend: SubroutineType not supported for BTF_TYPE_ID_REMOTE reloc

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

2 years ago[PowerPC][llvm-objdump] enable --symbolize-operands for PowerPC ELF/XCOFF.
Esme-Yi [Tue, 21 Dec 2021 04:17:57 +0000 (04:17 +0000)]
[PowerPC][llvm-objdump] enable --symbolize-operands for PowerPC ELF/XCOFF.

Summary: When disassembling, symbolize a branch target operand
to print a label instead of a real address.

Reviewed By: shchenz

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

2 years ago[tsan] Disable test from D115759 on Darwin
Vitaly Buka [Tue, 21 Dec 2021 03:37:34 +0000 (19:37 -0800)]
[tsan] Disable test from D115759 on Darwin

2 years ago[NFC] Fix clang-tidy issues in CalcSpillWeights.cpp
Mircea Trofin [Tue, 21 Dec 2021 03:21:31 +0000 (19:21 -0800)]
[NFC] Fix clang-tidy issues in CalcSpillWeights.cpp

2 years ago[memprof][NFC] Fix mismatched-new-delete in memprof tests
Xu Mingjie [Tue, 21 Dec 2021 02:35:08 +0000 (18:35 -0800)]
[memprof][NFC] Fix mismatched-new-delete in memprof tests

Fix mismatched-new-delete in memprof test_new_load_store.cpp and test_terse.cpp

Reviewed By: snehasish

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

2 years agoPort __sanitizer::StopTheWorld to Windows
Clemens Wasser [Tue, 21 Dec 2021 02:25:53 +0000 (18:25 -0800)]
Port __sanitizer::StopTheWorld to Windows

This also makes the sanitizer_stoptheworld_test cross-platform by using the STL, rather than pthread.

Reviewed By: vitalybuka

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

2 years ago[LTO] Fix incomplete optimization remarks for dead functions when PreOptModuleHook...
Xu Mingjie [Tue, 21 Dec 2021 02:16:09 +0000 (18:16 -0800)]
[LTO] Fix incomplete optimization remarks for dead functions when PreOptModuleHook or PostInternalizeModuleHook is defined

In 20a895c4be01769a37dfffb3c6b513a7bc9b8d17, we introduce `finalizeOptimizationRemarks()` to make sure we flush the diagnostic remarks file in case the linker doesn't call the global destructors before exiting.
In https://reviews.llvm.org/D73597, we add optimization remarks for removed functions for debugging or for detecting dead code.
But there is a case, if PreOptModuleHook or PostInternalizeModuleHook is defined (e.g. `--plugin-opt=emit-llvm` is passed to linker), we do not call `finalizeOptimizationRemarks()`, therefore we will get an incomplete optimization remarks file.
This patch make sure we flush the diagnostic remarks file when PreOptModuleHook or PostInternalizeModuleHook is defined.

Reviewed By: tejohnson, MaskRay

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

2 years ago[sanitizer] Fix compress_stack_depot.cpp test on Darwin
Vitaly Buka [Tue, 21 Dec 2021 02:13:27 +0000 (18:13 -0800)]
[sanitizer] Fix compress_stack_depot.cpp test on Darwin

All platforms which can start the thread should stop it as well.

2 years ago[DSE] Remove calls with known writes to dead memory
Philip Reames [Tue, 21 Dec 2021 02:10:23 +0000 (18:10 -0800)]
[DSE] Remove calls with known writes to dead memory

This is a reapply of a8a51fe5, which was reverted in 1ba99e due to a failing compiler-rt test.   That test was a false positive because it was checking asan failures not accounting for the fact the call could be validly optimized out.  I hopefully managed to stablize that test in 9b955f.  (That's a speculative fix due to disk consumption needed to build compiler-rt tests locally being absurd.)

Original commit message follows..

The majority of this change is sinking logic from instcombine into MemoryLocation such that it can be generically reused. If we have a call with a single analyzable write to an argument, we can treat that as-if it were a store of unknown size.

Merging the code in this was unblocks DSE in the store to dead memory code paths. In theory, it should also enable classic DSE of such calls, but the code appears to not know how to use object sizes to refine unknown access bounds (yet).

In addition, this does make the isAllocRemovable path slightly stronger by reusing the libfunc and additional intrinsics bits which are already in getForDest.

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

2 years agoAttempt to stablize compiler-rt/test/asan/TestCases/strncpy-overflow.cpp
Philip Reames [Tue, 21 Dec 2021 01:51:11 +0000 (17:51 -0800)]
Attempt to stablize compiler-rt/test/asan/TestCases/strncpy-overflow.cpp

This attempts to adjust the test to still exercise the expected codepath after D115904.  This test is fundementally rather fragile.

Unfortunately, I have not been able to confirm this workaround either does, or does not, work.  Attempting check-all with compiler-rt blows through an additional 30GB of disk space so my build config which exceeds my local disk space.

2 years agoRevert "[LTO] Add a function `LTOCodeGenerator::getMergedModule`"
Shilei Tian [Tue, 21 Dec 2021 01:34:04 +0000 (20:34 -0500)]
Revert "[LTO] Add a function `LTOCodeGenerator::getMergedModule`"

This reverts commit 75a5eaf7c6d60e95b11ea572b78fdb8788d15ddc.

2 years ago[tsan] Fix Darwin crash after D115759
Vitaly Buka [Mon, 20 Dec 2021 23:41:17 +0000 (15:41 -0800)]
[tsan] Fix Darwin crash after D115759

Remove global constructor which may or may not be needed for Android,
at it breaks Darwin now.

2 years agodocs: Clarify licensing rules for the project
Tom Stellard [Tue, 21 Dec 2021 01:03:06 +0000 (17:03 -0800)]
docs: Clarify licensing rules for the project

Reviewed By: lattner, kristof.beyls

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

2 years ago[LTO] Add a function `LTOCodeGenerator::getMergedModule`
Shilei Tian [Tue, 21 Dec 2021 01:01:37 +0000 (20:01 -0500)]
[LTO] Add a function `LTOCodeGenerator::getMergedModule`

One of the uses of `LTOCodeGenerator` is to take it as a middle+back end. Sometimes
it is very helpful to access, especially get information from the optimized module.
If the information can be changed in optimization, it cannot be get before the
module is added to `LTOCodeGenerator`. This patch adds a function
`LTOCodeGenerator::getMergedModule` to access the `MergedModule`.

Reviewed By: steven_wu

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

2 years agoFix clang-tidy issues in mlir/ (NFC)
Mehdi Amini [Fri, 17 Dec 2021 18:45:10 +0000 (18:45 +0000)]
Fix clang-tidy issues in mlir/ (NFC)

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

2 years agoAArch64/GlobalISel: Fix memory type in test
Matt Arsenault [Sat, 18 Dec 2021 19:32:39 +0000 (14:32 -0500)]
AArch64/GlobalISel: Fix memory type in test

2 years agoAMDGPU/GlobalISel: Stop using NarrowScalar/FewerElements for unaligned splitting
Matt Arsenault [Mon, 26 Jul 2021 21:22:01 +0000 (17:22 -0400)]
AMDGPU/GlobalISel: Stop using NarrowScalar/FewerElements for unaligned splitting

These actions should only be used for adjusting the register types
(and the memory type as needed to satisfy the register
type). Unaligned accesses should be split as a type of lowering.

This has the effect of improving the code in many cases since now we
produce zextloads instead of separate loads with ands. The load/store
legality rules still seem far more complicated than necessary though.

2 years ago[Analysis] fix cast in ValueTracking to allow constant expression
Sanjay Patel [Mon, 20 Dec 2021 21:13:55 +0000 (16:13 -0500)]
[Analysis] fix cast in ValueTracking to allow constant expression

The test would crash because a non-instruction negate op made it in here.

Fixes #51506

2 years ago[mlir][arith] Clean up ExpandOps pass
Mogball [Mon, 20 Dec 2021 21:58:39 +0000 (21:58 +0000)]
[mlir][arith] Clean up ExpandOps pass

2 years ago[docs]LLVM Tutorial: fix the typo in Cpu0 URL
Jinsong Ji [Mon, 20 Dec 2021 21:45:51 +0000 (21:45 +0000)]
[docs]LLVM Tutorial: fix the typo in Cpu0 URL

jonathan2251.github.com/lbd/ is 404. Update the URL to .io one according
to https://github.com/Jonathan2251/lbd/blob/master/README.md.

2 years ago[mlir] Add `mlir/unittests/BUILD.bazel`
Mogball [Mon, 20 Dec 2021 21:36:50 +0000 (21:36 +0000)]
[mlir] Add `mlir/unittests/BUILD.bazel`

Unit tests are not getting built as part of bazel runs.

Reviewed By: mehdi_amini, GMNGeoffrey

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

2 years ago[mlir][ods] FIx incorrect comments in PassGen (NFC)
Mogball [Mon, 20 Dec 2021 21:10:53 +0000 (21:10 +0000)]
[mlir][ods] FIx incorrect comments in PassGen (NFC)

And incorrect command option description for `-gen-pass-decls`.

2 years ago[Clang] Add __builtin_function_start
Sami Tolvanen [Tue, 10 Aug 2021 17:03:01 +0000 (10:03 -0700)]
[Clang] Add __builtin_function_start

Control-Flow Integrity (CFI) replaces references to address-taken
functions with pointers to the CFI jump table. This is a problem
for low-level code, such as operating system kernels, which may
need the address of an actual function body without the jump table
indirection.

This change adds the __builtin_function_start() builtin, which
accepts an argument that can be constant-evaluated to a function,
and returns the address of the function body.

Link: https://github.com/ClangBuiltLinux/linux/issues/1353
Depends on D108478

Reviewed By: pcc, rjmccall

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

2 years ago[llvm][IR] Add no_cfi constant
Sami Tolvanen [Tue, 10 Aug 2021 17:02:17 +0000 (10:02 -0700)]
[llvm][IR] Add no_cfi constant

With Control-Flow Integrity (CFI), the LowerTypeTests pass replaces
function references with CFI jump table references, which is a problem
for low-level code that needs the address of the actual function body.

For example, in the Linux kernel, the code that sets up interrupt
handlers needs to take the address of the interrupt handler function
instead of the CFI jump table, as the jump table may not even be mapped
into memory when an interrupt is triggered.

This change adds the no_cfi constant type, which wraps function
references in a value that LowerTypeTestsModule::replaceCfiUses does not
replace.

Link: https://github.com/ClangBuiltLinux/linux/issues/1353
Reviewed By: nickdesaulniers, pcc

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

2 years agoFix clang-tidy issues in mlir/ (NFC)
Mehdi Amini [Mon, 20 Dec 2021 19:45:05 +0000 (19:45 +0000)]
Fix clang-tidy issues in mlir/ (NFC)

Reviewed By: ftynse

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

2 years agoSilence warning with MSVC2019
Alexandre Ganea [Mon, 20 Dec 2021 00:28:31 +0000 (19:28 -0500)]
Silence warning with MSVC2019

This prevents "warning C4551: function call missing argument list"

2 years ago[lit] Support relative path arguments
Geoffrey Martin-Noble [Fri, 10 Dec 2021 01:17:00 +0000 (17:17 -0800)]
[lit] Support relative path arguments

Currently the behavior with relative paths is pretty broken. It differs
between external shell and internal shell because the path resolution
is done with a different working directory. With the internal shell,
it's resolved relative to the directory from which lit is executed,
whereas with the external shell it's resolved relative to where the
test case is executed. To make matters worse, using the internal shell
the filepath to binaries looked up with `which` is returned relative
to the directory from which lit is executed, but then executed from
the test execution directory. That means that relative paths with the
internal shell give a `[Errno 2] No such file or directory` error
instead of the expected `command not found`.

To address these issues this patch makes lit interpret relative paths
as relative to the directory from which lit was invoked and modifies
`which` to return absolute paths, matching the behavior of its
namesake unix function.

See https://groups.google.com/g/llvm-dev/c/KzMWlOXR98Y/m/QJoqn0U5HAAJ

Reviewed By: yln

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

2 years ago[OpenMP][libomp] Add use-all syntax to KMP_HW_SUBSET
Jonathan Peyton [Wed, 15 Dec 2021 20:36:44 +0000 (14:36 -0600)]
[OpenMP][libomp] Add use-all syntax to KMP_HW_SUBSET

This patch allows the user to request all resources of a particular
layer (or core-attribute). The syntax of KMP_HW_SUBSET is modified
so the number of units requested is optional or can be replaced with an
'*' character.

e.g., KMP_HW_SUBSET=c:intel_atom@3 will use all the cores after offset 3
e.g., KMP_HW_SUBSET=*c:intel_core will use all the big cores
e.g., KMP_HW_SUBSET=*s,*c,1t will use all the sockets, all cores per
      each socket and 1 thread per core.

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

2 years ago[flang] Add a semantics test for co_max
Damian Rouson [Wed, 1 Dec 2021 23:55:06 +0000 (15:55 -0800)]
[flang] Add a semantics test for co_max

Test a range of acceptable forms of co_max calls, including
combinations of keyword and non-keyword actual arguments of
numeric types.  Also test that several invalid forms of
co_max call generate the correct error messages.

Reviewed By: ktras

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

2 years ago[Support] Revert posix_fallocate in resize_file
Fangrui Song [Mon, 20 Dec 2021 19:16:03 +0000 (11:16 -0800)]
[Support] Revert posix_fallocate in resize_file

This reverts 3816c53f040cc6aa06425978dd504b0bd5b7899c and removes follow-up
fixups.

The original intention was to show error earlier (posix_fallocate time) than
later for ld.lld but it appears to cause some problems which make it not free.

* FreeBSD ZFS: EINVAL, not too bad.
* FreeBSD UFS: according to khng "devastatingly slow on freebsd because UFS on freebsd does not have preallocation support like illumos. It zero-fills."
* NetBSD: maybe EOPNOTSUPP
* Linux tmpfs: unless tmpfs is set up to use huge pages (requires CONFIG_TRANSPARENT_HUGE_PAGECACHE=y), I can consistently demonstrate ~300ms delay for a 1.4GiB output.
* Linux ext4: I don't measure any benefit, either backed by a hard disk or by a file in tmpfs.
* The current code organization of `defined(HAVE_POSIX_FALLOCATE)` costs us a macro dispatch for AIX.

I think we should just remove it. I think if posix_fallocate ever finds demonstrable benefit,
it is likely Linux specific and will not need HAVE_POSIX_FALLOCATE, and possibly opt-in by some specific programs.

In a filesystem with CoW and compression, the ENOSPC benefit may be lost as well.

Reviewed By: khng300

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

2 years ago[flang] Add a semantics test for co_min
Damian Rouson [Wed, 1 Dec 2021 23:18:36 +0000 (15:18 -0800)]
[flang] Add a semantics test for co_min

Test various acceptable forms of co_min calls, including
combinations of keyword and non-keyword actual arguments of
integer, real, and character types.  Also test that several
invalid forms of co_min call generate the correct error messages.

Reviewed By: ktras

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

2 years ago[mlir][scf] Canonicalize nested scf.if's to scf.if + arith.and
Butygin [Thu, 28 Oct 2021 16:04:35 +0000 (19:04 +0300)]
[mlir][scf] Canonicalize nested scf.if's to scf.if + arith.and

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

2 years agoRevert "[ARM] Use range-based for loops (NFC)"
Kazu Hirata [Mon, 20 Dec 2021 18:51:36 +0000 (10:51 -0800)]
Revert "[ARM] Use range-based for loops (NFC)"

This reverts commit 93d79cac2ede436e1e3e91b5aff702914cdfbca7.

This patch seems to break
llvm/test/CodeGen/ARM/constant-islands-cfg.mir under asan.

2 years ago[ELF] --time-trace: Trace "Write sections"
Fangrui Song [Mon, 20 Dec 2021 18:51:24 +0000 (10:51 -0800)]
[ELF] --time-trace: Trace "Write sections"

writeSections is typically a bottleneck.
This was used to track down the following bottlenecks:

* Output section .rela.dyn (9115d75117b57115fe45153e5f38f2c444c0cd91)
* Output section .debug_str (3aae04c744b03eb3eec7376f9d34fa3e42f8d108)
* posix_fallocate is slow for Linux tmpfs: D115957

Reviewed By: ikudrin

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

2 years ago[flang] Add a semantics test for co_reduce
Damian Rouson [Thu, 2 Dec 2021 01:33:26 +0000 (17:33 -0800)]
[flang] Add a semantics test for co_reduce

Test a range of acceptable forms of co_reduce calls, including
combinations of keyword and non-keyword actual arguments of
numeric types.  Also test that several invalid forms of
co_reduce call generate the correct error messages.

Reviewed By: kiranchandramohan, ktras, ekieri

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

2 years ago[libcxx] Add deprecation notices to macros deprecated in P0883R2
Raul Tambre [Sat, 18 Dec 2021 20:19:37 +0000 (22:19 +0200)]
[libcxx] Add deprecation notices to macros deprecated in P0883R2

When P0883R2 was initially implemented in D103769 #pragma clang deprecated didn't exist yet.
We also forgot to cleanup usages in libc++ itself.

This takes care of both.

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

2 years ago[mlir][Linalg] Move named op conversions out of canonicalizations.
MaheshRavishankar [Mon, 20 Dec 2021 17:34:41 +0000 (09:34 -0800)]
[mlir][Linalg] Move named op conversions out of canonicalizations.

These conversions are better suited to be applied at whole tensor
level. Applying these as canonicalizations end up triggering such
canonicalizations at all levels of the stack which might be
undesirable. For example some of the resulting code patterns wont
bufferize in-place and need additional stack buffers. Best is to be
more deliberate in when these canonicalizations apply.

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

2 years ago[ELF] #undef PPC to support GCC powerpc32 build
Fangrui Song [Mon, 20 Dec 2021 18:12:50 +0000 (10:12 -0800)]
[ELF] #undef PPC to support GCC powerpc32 build

GCC's powerpc32 port predefines `PPC` as a macro in GNU C++ mode in some configurations (Linux,
FreeBSD, and some others. See `builtin_define_std ("PPC"); ` in gcc/config/rs6000).

```
% powerpc-linux-gnu-g++ -E -dM -xc++ /dev/null -o - | grep -w PPC
#define PPC 1
```

Fixes https://bugs.gentoo.org/829599

Reviewed By: thesamesam

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

2 years agotsan: fix NULL deref in TraceSwitchPart
Dmitry Vyukov [Mon, 20 Dec 2021 16:19:42 +0000 (17:19 +0100)]
tsan: fix NULL deref in TraceSwitchPart

There is a small chance that the slot may be not queued in TraceSwitchPart.
This can happen if the slot has kEpochLast epoch and another thread
in FindSlotAndLock discovered that it's exhausted and removed it from
the slot queue. kEpochLast can happen in 2 cases: (1) if TraceSwitchPart
was called with the slot locked and epoch already at kEpochLast,
or (2) if we've acquired a new slot in SlotLock in the beginning
of the function and the slot was at kEpochLast - 1, so after increment
in SlotAttachAndLock it become kEpochLast.

If this happens we crash on ctx->slot_queue.Remove(thr->slot).
Skip the requeueing if the slot is not queued.
The slot is exhausted, so it must not be ctx->slot_queue.

The existing stress test triggers this with very small probability.
I am not sure how to make this condition more likely to be triggered,
it evaded lots of testing.

Depends on D116040.

Reviewed By: melver

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

2 years agotsan: fix deadlock during race reporting
Dmitry Vyukov [Mon, 20 Dec 2021 13:03:13 +0000 (14:03 +0100)]
tsan: fix deadlock during race reporting

SlotPairLocker calls SlotLock under ctx->multi_slot_mtx.
SlotLock can invoke global reset DoReset if we are out of slots/epochs.
But DoReset locks ctx->multi_slot_mtx as well, which leads to deadlock.

Resolve the deadlock by removing SlotPairLocker/multi_slot_mtx
and only lock one slot for which we will do RestoreStack.
We need to lock that slot because RestoreStack accesses the slot journal.
But it's unclear why we need to lock the current slot.
Initially I did it just to be on the safer side (but at that time
we dit not lock the second slot, so it was easy just to lock the current slot).

Reviewed By: melver

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

2 years ago[InstrProf] Don't profile merge by default in lightweight mode
Ellis Hoag [Mon, 20 Dec 2021 17:47:32 +0000 (09:47 -0800)]
[InstrProf] Don't profile merge by default in lightweight mode

Profile merging is not supported when using debug info profile
correlation because the data section won't be in the binary at runtime.
Change the default profile name in this mode to `default_%p.proflite` so
we don't use profile merging.

Reviewed By: kyulee

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

2 years ago[AMDGPU] Enable divergence predicates for ctlz/cttz
alex-t [Mon, 20 Dec 2021 16:03:13 +0000 (19:03 +0300)]
[AMDGPU] Enable divergence predicates for ctlz/cttz

ctlz/cttz get lowered to the set of target opcodes
This change enables the ISel to select SALU or VALU form according to the SDNode divergence.
CTLZ - S_FLBIT_I32_B32 if uniform and V_FFBH_U32_e64 if divergent
CTTZ - S_FF1_I32_B32   if uniform and V_FFBL_B32_e64 if divergent
Also @llvm.amdgcn.sffbh.i32 gets lowered to S_FLBIT_I32 if uniform and V_FFBH_I32_e64 if divergent
NOTE: 64bit versions S_FF1_I32_B64 and S_FLBIT_I32_B64 are not currently supported by the DAG ISel.
ctlz/cttz with i64 input are split into two 32bit instructions. Nevertheless, they already have the patterns
and were equipped with the divergence predicates to make sure they will be selected correctly when enabled.

Reviewed By: rampitec

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

2 years ago[mlir] Address compiler warning (NFC)
Jacques Pienaar [Mon, 20 Dec 2021 17:33:30 +0000 (09:33 -0800)]
[mlir] Address compiler warning (NFC)

Mark overridden virtual function.

2 years ago[NFC][mlgo] Rename some TensorFlowCompile internal vars
Mircea Trofin [Mon, 20 Dec 2021 17:24:55 +0000 (09:24 -0800)]
[NFC][mlgo] Rename some TensorFlowCompile internal vars

They were referring to 'inlining' albeit being generic

2 years ago[gn build] Port 37e6bd8bc8da
LLVM GN Syncbot [Mon, 20 Dec 2021 17:19:51 +0000 (17:19 +0000)]
[gn build] Port 37e6bd8bc8da

2 years agoFix buildbot failure caused by D115651
Sander de Smalen [Mon, 20 Dec 2021 17:17:24 +0000 (17:17 +0000)]
Fix buildbot failure caused by D115651

I somehow missed updating the RUN line of this test.

2 years agoReland "[AST] Add UsingType: a sugar type for types found via UsingDecl"
Sam McCall [Mon, 20 Dec 2021 17:01:33 +0000 (18:01 +0100)]
Reland "[AST] Add UsingType: a sugar type for types found via UsingDecl"

This reverts commit cc56c66f27e131b914082d3bd21180646e842e9a.
Fixed a bad assertion, the target of a UsingShadowDecl must not have
*local* qualifiers, but it can be a typedef whose underlying type is qualified.

2 years agoRevert "[AST] Add UsingType: a sugar type for types found via UsingDecl"
Sam McCall [Mon, 20 Dec 2021 16:53:56 +0000 (17:53 +0100)]
Revert "[AST] Add UsingType: a sugar type for types found via UsingDecl"

This reverts commit e1600db19d6303f84b995acb9340459694e06ea9.

Breaks sanitizer tests, at least on windows:
https://lab.llvm.org/buildbot/#/builders/127/builds/21592/steps/4/logs/stdio

2 years ago[clang] Adjust coroutine namespace diagnostics
Nathan Sidwell [Fri, 17 Dec 2021 20:38:04 +0000 (12:38 -0800)]
[clang] Adjust coroutine namespace diagnostics

The diagnostics concerning mixing std::experimental and std are
somewhat wordy and have some typographical errors.  Diagnostics do not
start with a capital letter nor end with a fullstop.  Usually we try
and link clauses with a semicolon, rather than start a new sentence.
So that's what this patch does.  Along with avoiding repetition about
std::experimental going away.

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

2 years ago[clang] p2085 out-of-class comparison operator defaulting
Nathan Sidwell [Wed, 16 Jun 2021 17:43:43 +0000 (10:43 -0700)]
[clang] p2085 out-of-class comparison operator defaulting

Commit 5fbe21a7748f missed committing the correct checking of
out-of-class comparision operator argument types.  These are they,
from the originally posted diff.

Reviewed By: mizvekov

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

2 years ago[mlir][vim] Add comment for markdown highlighting
Jacques Pienaar [Mon, 20 Dec 2021 16:20:54 +0000 (08:20 -0800)]
[mlir][vim] Add comment for markdown highlighting

Useful for local editing.

2 years ago[libc++][NFC] Bump Dockerfile to get latest nightly Clang
Louis Dionne [Mon, 20 Dec 2021 16:25:00 +0000 (11:25 -0500)]
[libc++][NFC] Bump Dockerfile to get latest nightly Clang

2 years ago[LV] Enable scalable vectorization by default for SVE cores.
Sander de Smalen [Mon, 13 Dec 2021 16:52:35 +0000 (16:52 +0000)]
[LV] Enable scalable vectorization by default for SVE cores.

The availability of SVE should be sufficient to enable scalable
auto-vectorization.

This patch adds a new TTI interface to query the target what style of
vectorization it wants when scalable vectors are available. For other
targets than AArch64, this currently defaults to 'FixedWidthOnly'.

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

2 years ago[clangd] Don't trim xrefs references if we overran the limit
Kadir Cetinkaya [Mon, 20 Dec 2021 14:51:09 +0000 (15:51 +0100)]
[clangd] Don't trim xrefs references if we overran the limit

This preserves all the results we've processed already rather than
throwing them away in the end.
It has some performance implications on the edge cases, in the worst case we
might issue 1 relations and 2 xrefs requests in extra to deduce `HasMore`
correctly.

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

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

2 years ago[libc++] Add a helper class to write code with the strong exception guarantee
Louis Dionne [Tue, 14 Dec 2021 15:18:19 +0000 (10:18 -0500)]
[libc++] Add a helper class to write code with the strong exception guarantee

__transaction is a helper class that allows rolling back code in case an
exception is thrown. The main goal is to reduce the clutter when code
needs to be guarded with `#if _LIBCPP_NO_EXCEPTIONS`.

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

2 years ago[AST] Add UsingType: a sugar type for types found via UsingDecl
Sam McCall [Fri, 19 Nov 2021 16:20:58 +0000 (17:20 +0100)]
[AST] Add UsingType: a sugar type for types found via UsingDecl

Currently there's no way to find the UsingDecl that a typeloc found its
underlying type through. Compare to DeclRefExpr::getFoundDecl().

Design decisions:
- a sugar type, as there are many contexts this type of use may appear in
- UsingType is a leaf like TypedefType, the underlying type has no TypeLoc
- not unified with UnresolvedUsingType: a single name is appealing,
  but being sometimes-sugar is often fiddly.
- not unified with TypedefType: the UsingShadowDecl is not a TypedefNameDecl or
  even a TypeDecl, and users think of these differently.
- does not cover other rarer aliases like objc @compatibility_alias,
  in order to be have a concrete API that's easy to understand.
- implicitly desugared by the hasDeclaration ASTMatcher, to avoid
  breaking existing patterns and following the precedent of ElaboratedType.

Scope:
- This does not cover types associated with template names introduced by
  using declarations. A future patch should introduce a sugar TemplateName
  variant for this. (CTAD deduced types fall under this)
- There are enough AST matchers to fix the in-tree clang-tidy tests and
  probably any other matchers, though more may be useful later.

Caveats:
- This changes a fairly common pattern in the AST people may depend on matching.
  Previously, typeLoc(loc(recordType())) matched whether a struct was
  referred to by its original scope or introduced via using-decl.
  Now, the using-decl case is not matched, and needs a separate matcher.
  This is similar to the case of typedefs but nevertheless both adds
  complexity and breaks existing code.

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

2 years agoRevert "[DAGCombiner] Avoid combining adjacent stores at -O0 to improve debug experience"
Shivam Gupta [Mon, 20 Dec 2021 16:13:40 +0000 (21:43 +0530)]
Revert "[DAGCombiner] Avoid combining adjacent stores at -O0 to improve debug experience"

This reverts commit 731bde1ed30fcd8474ea6b88c3a9fc3072d2dca4.

2 years ago[PowerPC] Support hwsync extended mnemonic
Nemanja Ivanovic [Mon, 20 Dec 2021 15:52:11 +0000 (09:52 -0600)]
[PowerPC] Support hwsync extended mnemonic

This mnemonic has been supported by GAS for years and
it was added to the PowerPC ISA as of ISA 3.1. We will
support the mnemonic to be compatible with GAS.

2 years ago[mlir] Switching accessors to prefixed form (NFC)
Jacques Pienaar [Mon, 20 Dec 2021 16:03:43 +0000 (08:03 -0800)]
[mlir] Switching accessors to prefixed form (NFC)

Makes eventual prefixing flag flip smaller change.

2 years ago[HIPSPV][3/4] Enable SPIR-V emission for HIP
Yaxun (Sam) Liu [Fri, 17 Dec 2021 16:01:51 +0000 (11:01 -0500)]
[HIPSPV][3/4] Enable SPIR-V emission for HIP

This patch enables SPIR-V binary emission for HIP device code via the
HIPSPV tool chain.

‘--offload’ option, which is envisioned in [1], is added for specifying
offload targets. This option is used to override default device target
(amdgcn-amd-amdhsa) for HIP compilation for emitting device code as
SPIR-V binary. The option is handled in getHIPOffloadTargetTriple().

getOffloadingDeviceToolChain() function (based on the design in the
SYCL repository) is added to select HIPSPVToolChain when HIP offload
target is ‘spirv64’.

The HIPActionBuilder is modified to produce LLVM IR at the backend
phase. HIPSPV tool chain expects to receive HIP device code as LLVM
IR so it can run external LLVM passes over them. HIPSPV TC is also
responsible for emitting the SPIR-V binary.

A Cuda GPU architecture ‘generic’ is added. The name is picked from
the LLVM SPIR-V Backend. In the HIPSPV code path the architecture
name is inserted to the bundle entry ID as target ID. Target ID is
expected to be always present so a component in the target triple
is not mistaken as target ID.

Tests are added for checking the HIPSPV tool chain.

[1]: https://lists.llvm.org/pipermail/cfe-dev/2020-December/067362.html

Patch by: Henry Linjamäki

Reviewed by: Yaxun Liu, Artem Belevich, Alexey Bader

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

2 years agoPrevent copy of AttrBuilder
Serge Guelton [Mon, 20 Dec 2021 15:31:55 +0000 (10:31 -0500)]
Prevent copy of AttrBuilder

It's a relatively heavy data structure, make sure it's not copied.

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

2 years ago[llvm-readobj] Check ELFType value first when checking for OpenBSD notes.
Frederic Cambus [Mon, 20 Dec 2021 15:22:01 +0000 (16:22 +0100)]
[llvm-readobj] Check ELFType value first when checking for OpenBSD notes.

Checking ELFType == ELF::ET_CORE first skips string comparison for the
majority of cases.

Suggested by Fangrui Song in D114635 for a similar construct.

2 years ago[SLP]Fix PR52756: SLPVectorizer crashes with assertion VecTy == FinalVecTy.
Alexey Bataev [Fri, 17 Dec 2021 13:46:10 +0000 (05:46 -0800)]
[SLP]Fix PR52756: SLPVectorizer crashes with assertion VecTy == FinalVecTy.

Need to check for the number of the unique non-constant values since the
unique values may include several constants.

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

2 years agoRevert "[SLP]Fix PR52756: SLPVectorizer crashes with assertion VecTy == FinalVecTy."
Alexey Bataev [Mon, 20 Dec 2021 13:52:17 +0000 (05:52 -0800)]
Revert "[SLP]Fix PR52756: SLPVectorizer crashes with assertion VecTy == FinalVecTy."

This reverts commit fcaf290d0278bb83387e1a1d972c55e08b8c40e3 to fix test
mismatch reported in https://lab.llvm.org/buildbot#builders/117/builds/3531

2 years ago[VPlan] Add Debugloc to VPInstruction.
Florian Hahn [Mon, 20 Dec 2021 15:03:46 +0000 (15:03 +0000)]
[VPlan] Add Debugloc to VPInstruction.

Upcoming changes require attaching debug locations to VPInstructions,
e.g. adding induction increment recipes in D113223.

Reviewed By: Ayal

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

2 years ago[clang-include-fixer] Fix incorrect ranking because of dangling references
Danila Kutenin [Mon, 20 Dec 2021 14:56:56 +0000 (15:56 +0100)]
[clang-include-fixer] Fix incorrect ranking because of dangling references

SymbolAndSignals stores SymbolInfo which stores two std::strings. Then
the values are stored in a llvm::DenseMap<llvm::StringRef, double>. When
the sorting is happening, SymbolAndSignals are swapped and thus because
of small string optimization some strings may become invalid. This
results in incorrect ranking.

This was detected when running new std::sort algorithm against llvm
toolchain. This could have been prevented with running llvm::sort and
EXPENSIVE_CHECKS. Unfortunately, no sanitizer yelled.

I don't have commit rights, kutdanila@yandex.ru Danila Kutenin

Reviewed By: bkramer

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