101799 Commits

Author SHA1 Message Date
eopXD
bafedb1c2c [Clang][RISCV] Remove RVV intrinsics vread_csr,vwrite_csr
As proposed in riscv-non-isa/rvv-intrinsic-doc#249, removing the interface.

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D156321
2023-07-29 08:40:39 +02:00
Joseph Huber
aff99b1a12 [OpenMP] Do not always emit unused extern variables
Currently, the precense of the OpenMP target declare metadata requires
that we always codegen a global declaration. This is undesirable in the
case that we could defer or omit this declaration as is common with
unused extern variables. This is important as it allows us, in the
runtime, to rely on static linking semantics to omit unused symbols so
they are not included when the user links it in.

This patch changes the check for always emitting these variables.
Because of this we also need to extend this logic to the generation of
the offloading entries. This has the result of derring the offload entry
generation to the canonical definitoin. So we are effectively assuming
whoever owns the storage for this variable will perform that operation.
This makes an exception for `link` attributes as those require their own
special handling.

Let me know if this is sound in the implementation, I do not have the
largest view of the standards here.

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

Reviewed By: tianshilei1992

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

(cherry picked from commit 141c4e7a9403fed46d84c7f0429295bd28c89368)
2023-07-29 08:40:22 +02:00
Richard Smith
8ea504be36 Add release node for exact dynamic_cast optimization. 2023-07-29 08:40:05 +02:00
Brian Cain
991cbe12b5 [hexagon] restore library path arguments
Before applying this fix, clang would not include the specified library
path arguments:

    $ ./bin/clang --target=hexagon-unknown-linux-musl  -o tprog tprog.o -L/tmp -###
    ...
    clang: warning: argument unused during compilation: '-L/tmp' [-Wunused-command-line-argument]
     "/local/mnt/workspace/install/clang-latest/bin/ld.lld" "-z" "relro" "-o" "tprog" "-dynamic-linker=/lib/ld-musl-hexagon.so.1" "/usr/lib/crt1.o" "-L/usr/lib" "tprog.o" "-lclang_rt.builtins-hexagon" "-lc"

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

(cherry picked from commit 96832a6bf7e0e7f1e8d634d38c44a1b32d512923)
2023-07-28 09:10:13 +02:00
eopXD
726f698ac5 [Clang][RISCV] Bump rvv intrinsics version to v0.12
The LLVM now supports v0.12 of the RVV intrinsics. Users can use the macro
riscv_v_intrinsic to distinguish what kind of intrinsics is supported in
the compiler.

Please refer to tag descriptions under

https://github.com/riscv-non-isa/rvv-intrinsic-doc/tags

Reviewed By: kito-cheng

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

(cherry picked from commit 20e87e2f794173deebd1cf8c86684452bb0c989b)
2023-07-28 09:08:15 +02:00
Rainer Orth
88ce4e85f2 [Driver] Link shared asan runtime lib with -z now on Solaris/x86
As detailed in Issue #64126, several asan tests `FAIL` due to a cycle in
`AsanInitInternal`.  This can by avoided by disabling lazy binding with `ld
-z now`.

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

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

(cherry picked from commit 6b5149aa442efc10afa00e8864e58a24a9cf5c9f)
2023-07-28 09:08:02 +02:00
Richard Smith
313de9dbf6 For #64088: mark vtable as used if we might emit a reference to it.
(cherry picked from commit b6847edfc235829b37dd6d734ef5bbfa0a58b6fc)
2023-07-27 15:50:46 +02:00
Matt Arsenault
52647ad027 HIP: Fix broken version check for deprecated macro
Remove test hack that was accidentally pushed.

(cherry picked from commit 73105a54725ec11165dd8c90ca3b7a0b1b9cd6e3)
2023-07-27 15:28:30 +02:00
Weining Lu
ce53e91738 Reland "[LoongArch] Support -march=native and -mtune="
As described in [1][2], `-mtune=` is used to select the type of target
microarchitecture, defaults to the value of `-march`. The set of
possible values should be a superset of `-march` values. Currently
possible values of `-march=` and `-mtune=` are `native`, `loongarch64`
and `la464`.

D136146 has supported `-march={loongarch64,la464}` and this patch adds
support for `-march=native` and `-mtune=`.

A new ProcessorModel called `loongarch64` is defined in LoongArch.td
to support `-mtune=loongarch64`.

`llvm::sys::getHostCPUName()` returns `generic` on unknown or future
LoongArch CPUs, e.g. the not yet added `la664`, leading to
`llvm::LoongArch::isValidArchName()` failing to parse the arch name.
In this case, use `loongarch64` as the default arch name for 64-bit
CPUs.

And these two preprocessor macros are defined:
- __loongarch_arch
- __loongarch_tune

[1]: https://github.com/loongson/LoongArch-Documentation/blob/2023.04.20/docs/LoongArch-toolchain-conventions-EN.adoc
[2]: https://github.com/loongson/la-softdev-convention/blob/v0.1/la-softdev-convention.adoc

Reviewed By: xen0n, wangleiat

Differential Revision: https://reviews.llvm.org/D155824
2023-07-26 19:27:39 +02:00
Kai Stierand
d0b54bb50e [Clang] use unsigned integer constants in unit-test | fixes build error on ppc64le-lld-multistage-test
Fixes:
    /home/buildbots/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project/third-party/unittest/googletest/include/gtest/gtest.h:1526:11: warning: comparison of integer expressions of different signedness: ‘const unsigned int’ and ‘const int’ [-Wsign-compare]
    /home/buildbots/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project/third-party/unittest/googletest/include/gtest/gtest.h:1526:11: warning: comparison of integer expressions of different signedness: ‘const long unsigned int’ and ‘const int’ [-Wsign-compare]

Reviewed By: cor3ntin

Differential Revision: https://reviews.llvm.org/D156224
2023-07-25 13:58:30 +02:00
Aaron Ballman
0d12683046 Revert "[OpenMP] Add the ompx_attribute clause for target directives"
This reverts commit ef9ec4bbcca2fa4f64df47bc426f1d1c59ea47e2.

The changes broke several bots:
https://lab.llvm.org/buildbot/#/builders/176/builds/3408
https://lab.llvm.org/buildbot/#/builders/198/builds/4028
https://lab.llvm.org/buildbot/#/builders/197/builds/8491
https://lab.llvm.org/buildbot/#/builders/197/builds/8491
2023-07-25 07:57:36 -04:00
Matt Arsenault
e7ab6982de HIP: Directly call nearbyint builtins 2023-07-25 07:56:31 -04:00
Matt Arsenault
71be91eba9 HIP: Directly call rint builtins 2023-07-25 07:54:11 -04:00
John Brawn
d031ff3877 [Sema] Fix handling of functions that hide classes
When a function is declared in the same scope as a class with the same
name then the function hides that class. Currently this is done by a
single check after the main loop in LookupResult::resolveKind, but
this can give the wrong result when we have a using declaration in
multiple namespace scopes in two different ways:

 * When the using declaration is hidden in one namespace but not the
   other we can end up considering only the hidden one when deciding
   if the result is ambiguous, causing an incorrect "not ambiguous"
   result.

 * When two classes with the same name in different namespace scopes
   are both hidden by using declarations this can result in
   incorrectly deciding the result is ambiguous. There's currently a
   comment saying this is expected, but I don't think that's correct.

Solve this by checking each Decl to see if it's hidden by some other
Decl in the same scope. This means we have to delay removing anything
from Decls until after the main loop, in case a Decl is hidden by
another that is removed due to being non-unique.

Differential Revision: https://reviews.llvm.org/D154503
2023-07-25 12:30:41 +01:00
Podchishchaeva, Mariya
c5a13e2c7e [NFC][clang] Fix static analyzer concerns
EHScopeStack doesn't seem to be intended for copy. It frees memory in
the destructor and doesn't have user-written copy c'tor and assignment
operator, so delete them to avoid using default ones which would do
wrong.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D156133
2023-07-25 02:43:41 -07:00
Daniel Krupp
4dbe2db02d [clang][analyzer] Improved documentation for TaintPropagation Checker
The usage of the taint analysis is described through a command injection attack example.
It is explained how to make a variable sanitized through configuration.

Differential Revision: https://reviews.llvm.org/D145229
2023-07-25 11:34:11 +02:00
Simon Pilgrim
3d83912c0c Revert rGfae7b98c221b5b28797f7b56b656b6b819d99f27 "[Support] Change SetVector's default template parameter to SmallVector<*, 0>"
This is failing on Windows MSVC builds:
llvm\unittests\Support\ThreadPool.cpp(380): error C2440: 'return': cannot convert from 'Vector' to 'std::vector<llvm::BitVector,std::allocator<llvm::BitVector>>'
        with
        [
            Vector=llvm::SmallVector<llvm::BitVector,0>
        ]
2023-07-25 10:22:08 +01:00
Weining Lu
6223050db8 [docs] Add llvm & clang release notes for LoongArch
Differential Revision: https://reviews.llvm.org/D156195
2023-07-25 17:06:12 +08:00
David Sherwood
4cf11d8a65 [Clang][SVE] Permit specific predicate-as-counter registers in inline assembly
This patch adds the predicate-as-counter registers pn0-pn15 to the
list of supported registers used when writing inline assembly.

Tests added to

  clang/test/CodeGen/aarch64-sve-inline-asm.c

Differential Revision: https://reviews.llvm.org/D156115
2023-07-25 08:55:45 +00:00
Kai Stierand
86da763ab6 [Clang] Fix crash in CIndex, when visiting a static_assert without message
After implementation of "[Clang] Implement P2741R3 - user-generated static_assert messages"  (47ccfd7a89e2a9a747a7114db18db1376324799c) the c indexer crashes when handling a `static_assert` w/o any message.
This is caused by using `dyn_cast` to get the literal string, which isn't working on `nullptr`.

Reviewed By: cor3ntin

Differential Revision: https://reviews.llvm.org/D156053
2023-07-25 10:53:14 +02:00
Simi Pallipurath
9dcd232f4a [clang][driver][NFC] Call IsARMBigEndain function only for isARM and isThumb.
IsARMBIgEndian function returns true only if:
  1. The triples are either arm or thumb and the
     commandline has the  option -mbig-endian
  2. The triples are either armeb or thumbeb.

Missing the checking of arm or thumb triples in the
first case pass through the --be8 endian flag to
linker For AArch64 as well which is not expected.
This is the regression happened from the previous
patch https://reviews.llvm.org/D154786.

It is better to refactor to only call IsARMBigEndian
for isARM and isthumb satisfying conditions which
keeps ARM and AArch64 separate.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D155808
2023-07-25 09:20:59 +01:00
Fangrui Song
fae7b98c22 [Support] Change SetVector's default template parameter to SmallVector<*, 0>
Similar to D156016 for MapVector.
2023-07-25 00:39:17 -07:00
Freddy Ye
6d23a3faa4 [X86] Support -march=graniterapids-d and update -march=graniterapids
Reviewed By: pengfei, RKSimon, skan

Differential Revision: https://reviews.llvm.org/D155798
2023-07-25 13:48:31 +08:00
Richard Smith
6cf8179661 Don't perform dynamic_cast optimization at -O0.
It seems preferable to avoid this optimization under -O0, and we're not
set up to emit speculative references to vtables at -O0 in general
anyway.

For #64088.
2023-07-24 22:24:33 -07:00
Johannes Doerfert
ef9ec4bbcc [OpenMP] Add the ompx_attribute clause for target directives
CUDA and HIP have kernel attributes to tune the code generation (in the
backend). To reuse this functionality for OpenMP target regions we
introduce the `ompx_attribute` clause that takes these kernel
attributes and emits code as if they had been attached to the kernel
fuction (which is implicitly generated).

To limit the impact, we only support three kernel attributes:
`amdgpu_waves_per_eu`, for AMDGPU
`amdgpu_flat_work_group_size`, for AMDGPU
`launch_bounds`, for NVPTX

The existing implementations of those attributes are used for error
checking and code generation. `ompx_attribute` can be attached to any
executable target region and it can hold more than one kernel attribute.

Differential Revision: https://reviews.llvm.org/D156184
2023-07-24 22:04:45 -07:00
Chuanqi Xu
8a86f85ab1 Revert "[C++20] [Modules] Use CanonicalType for base classes"
Close https://github.com/llvm/llvm-project/issues/64091

This reverts commit f82df0b285acd8a7115f0bfc55ce44474251c2d1 and add a
test from https://github.com/llvm/llvm-project/issues/64091
2023-07-25 11:03:57 +08:00
Freddy Ye
5cc4b1059b [X86] Update features for sierraforest, grandridge
Reviewed By: pengfei

Differential Revision: https://reviews.llvm.org/D155784
2023-07-25 11:00:41 +08:00
Zheng Qian
cead1497ae Add new option -fkeep-persistent-storage-variables to Clang release notes
This patch updates the Clang release notes with the new option
-fkeep-persistent-storage-variables added in bb6ab91b1dcd.

Reviewed By: hubert.reinterpretcast

Differential Revision: https://reviews.llvm.org/D155501
2023-07-24 22:56:18 -04:00
Gedare Bloom
c669541c96 [clang-format] Add SpacesInParens with SpacesInParensOptions
This is a refactoring of:
- SpacesInConditionalStatement
- SpacesInCStyleCastParentheses
- SpaceInEmptyParentheses
- SpacesInParentheses

These are now options under the new Style Option: SpacesInParens. The
existing options are maintained for backward compatibility.

Within SpacesInParens, there are currently options for:
- Never
- Custom

The currently available options for Custom are:
- InConditionalStatements
- InCStyleCasts
- InEmptyParentheses
- Other

Setting InConditionalStatements and Other to true enables the same space
additions as SpacesInParentheses.

This refactoring does not add or remove any existing features, but it makes
it possible to more easily extend and maintain the addition of spaces within
parentheses.

Related to #55428.

Differential Revision: https://reviews.llvm.org/D155239
2023-07-24 19:27:23 -07:00
Galen Elias
74720d1b33 [clang-format] Add AlignConsecutiveShortCaseStatements
This adds a new AlignConsecutiveShortCaseStatements option in line with the
existing AlignConsecutive* options , which when
AllowShortCaseLabelsOnASingleLine is enabled will align the tokens after the
case statement's colon. This also adds a AlignCaseColons option to allow
aligning the case label colon itself rather than the token after it.

Fixes #55475.

Differential Revision: https://reviews.llvm.org/D151761
2023-07-24 18:39:25 -07:00
Owen Pan
87ad34ffdc Revert "[clang-format] Add AlignConsecutiveShortCaseStatements"
This reverts commit 4ba00844174db562d2bd8b15dab6aac605eddf57.
2023-07-24 18:37:42 -07:00
Owen Pan
ac6e55146f Revert "Revert "[clang-format] Add AlignConsecutiveShortCaseStatements""
This reverts commit 4f093b31669a4f8e417259583141159586a05b28.
2023-07-24 18:24:30 -07:00
Owen Pan
4f093b3166 Revert "[clang-format] Add AlignConsecutiveShortCaseStatements"
This reverts commit 4ba00844174db562d2bd8b15dab6aac605eddf57 due to missing
authorship.
2023-07-24 18:19:38 -07:00
Weining Lu
983f248832 Revert "[Clang][LoongArch] Fix ABI handling of empty structs in C++ to match GCC behaviour"
This reverts commit c299efbf284fae92bb8d7d29110f76912f089daf.

Reason to revert: D142327 has been reverted which is depended by this
change.
2023-07-25 09:18:06 +08:00
Owen Pan
4ba0084417 [clang-format] Add AlignConsecutiveShortCaseStatements
This adds a new AlignConsecutiveShortCaseStatements option in line with the
existing AlignConsecutive* options , which when
AllowShortCaseLabelsOnASingleLine is enabled will align the tokens after the
case statement's colon. This also adds a AlignCaseColons option to allow
aligning the case label colon itself rather than the token after it.

Fixes #55475.

Differential Revision: https://reviews.llvm.org/D151761
2023-07-24 18:16:21 -07:00
chenli
d25c79dc70 [LoongArch] Support InlineAsm for LSX and LASX
The author of the following files is licongtian <licongtian@loongson.cn>:
- clang/lib/Basic/Targets/LoongArch.cpp
- llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp
- llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp

The files mentioned above implement InlineAsm for LSX and LASX as follows:
- Enable clang parsing LSX/LASX register name, such as $vr0.
- Support the case which operand type is 128bit or 256bit when the
  constraints is 'f'.
- Support the way of specifying LSX/LASX register by using constraint,
  such as "={$xr0}".
- Support the operand modifiers 'u' and 'w'.
- Support and legalize the data types and register classes involved in
  LSX/LASX in the lowering process.

Reviewed By: xen0n, SixWeining

Differential Revision: https://reviews.llvm.org/D154931
2023-07-25 09:02:29 +08:00
Weining Lu
c299efbf28 [Clang][LoongArch] Fix ABI handling of empty structs in C++ to match GCC behaviour
GCC doesn't ignore non-zero-length array of empty structures in C++
while clang does. What this patch did is to match GCC's behaviour
although this rule is not documented in psABI.

Similar to D142327 for RISCV.

Reviewed By: xry111, xen0n

Differential Revision: https://reviews.llvm.org/D156116
2023-07-25 08:59:40 +08:00
Weining Lu
669d2bbc83 [Clang][LoongArch] Pre-commit test for D156116
Differential Revision: https://reviews.llvm.org/D156114
2023-07-25 08:59:40 +08:00
Joshua Batista
3a98e73169 clang: Add elementwise pow builtin
Add codegen for llvm pow elementwise builtin
The pow elementwise builtin is necessary for HLSL codegen.
Tests were added to make sure that the expected errors are encountered when these functions are given inputs of incompatible types, or too many inputs.
The new builtin is restricted to floating point types only.

Reviewed By: arsenm

Differential Revision: https://reviews.llvm.org/D153310
2023-07-24 14:03:58 -07:00
Nick Desaulniers
b54294e2c9 [clang][ConstantEmitter] have tryEmitPrivate[ForVarInit] try ConstExprEmitter fast-path first
As suggested by @efriedma in:
https://reviews.llvm.org/D76096#4370369

This should speed up evaluating whether an expression is constant or
not, but due to the complexity of these two different implementations,
we may start getting different answers for edge cases for which we do
not yet have test cases in-tree (or perhaps even performance regressions
for some cases). As such, contributors have carte blanche to revert if
necessary.

For additional historical context about ExprConstant vs CGExprConstant,
here's snippets from a private conversation on discord:

  ndesaulniers:
  why do we have clang/lib/AST/ExprConstant.cpp and
  clang/lib/CodeGen/CGExprConstant.cpp? Does clang constant fold during
  ast walking/creation AND during LLVM codegen?
  efriedma:
  originally, clang needed to handle two things: integer constant
  expressions (the "5" in "int x[5];"), and constant global initializers
  (the "5" in "int x = 5;").  pre-C++11, the two could be handled mostly
  separately; so we had the code for integer constants in AST/, and the
  code for globals in CodeGen/.  C++11 constexpr sort of destroyed that
  separation, though. so now we do both kinds of constant evaluation on
  the AST, then CGExprConstant translates the result of that evaluation
  to LLVM IR.  but we kept around some bits of the old cgexprconstant to
  avoid performance/memory usage regressions on large arrays.

Reviewed By: efriedma

Differential Revision: https://reviews.llvm.org/D151587
2023-07-24 13:50:45 -07:00
Anton Dukeman
2f0630f8bc [clang-tidy] Add folly::Optional to unchecked-optional-access
The unchecked-optional-access check identifies attempted value
unwrapping without checking if the value exists. These changes extend
that support to checking folly::Optional.

Reviewed By: gribozavr2

Differential Revision: https://reviews.llvm.org/D155890
2023-07-24 19:42:19 +00:00
Fangrui Song
05c2c09bb1 [Driver][test] Remove XRay/lit.local.cfg
This was needed when XRay/* tests relied on the default target triple.
Now that we set a default target triple for every test we can remove
this customization.

This cleanup is intrigued by D156090.
2023-07-24 12:27:14 -07:00
Reid Kleckner
47d178939e Add Adrian and David as owners for debug info
Reviewed By: aprantl, probinson

Differential Revision: https://reviews.llvm.org/D156143
2023-07-24 11:11:35 -07:00
Paul Robinson
7abb5fc618 [DWARF] Make sure file entry for artificial functions has an MD5 checksum
The DIFile cache was keyed on a string pointer instead of string content,
which was causing misses and resulted in an entry without a checksum.
In DWARF v5 if any checksum is missing, we can't write any to the output
file, so this had consequences.

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

Differential revision: https://reviews.llvm.org/D155991
2023-07-24 10:53:10 -07:00
Paul Robinson
69593aa5c0 [Headers][doc] Add misc non-AVX2 intrinsic descriptions
Adds descriptions for adxintrin.h, bmi2intrin.h, clflushoptintrin.h,
clzerointrin.h, rdseedintrin.h, and xsavecintrin.h.

Differential revision: https://reviews.llvm.org/D155859
2023-07-24 10:51:18 -07:00
Po-yao Chang
bed75faf7d [Clang] Reject programs declaring namespace std to be inline
Fixes #64041

Differential Revision: https://reviews.llvm.org/D156063
2023-07-25 01:30:23 +08:00
Fangrui Song
841ff7c6ca [Driver][test] Clean up some xray tests
Add explicit --target= so that the tests run on all targets, not some
that support XRay, similar to commit e1051414a16e970c2e36c2ab7dfe2b17353c4751.
For option testing, we often use a placeholder architecture (e.g., x86_64).

Fix https://github.com/llvm/llvm-project/issues/64028
2023-07-24 10:05:34 -07:00
Podchishchaeva, Mariya
dcb8911316 [clang] Fix specialization of non-templated member classes of class templates
Explicit specialization doesn't increase depth of template parameters,
so need to be careful when gathering template parameters for
instantiation.
For the case:
```
template<typename T>
struct X {
  struct impl;
};

template <>
struct X<int>::impl {
    template<int ct>
    int f() { return ct; };
};
```
instantiation of `f` used to crash because type template parameter
`int` of explicit specialization was taken into account, but non-type
template parameter `ct` had zero depth and index so wrong parameter
ended up inside of a wrong handler.

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

Reviewed By: aaron.ballman, shafik

Differential Revision: https://reviews.llvm.org/D155705
2023-07-24 09:36:58 -07:00
Owen Pan
2f6b2dafb7 [clang-format] Insert namespace comments with leading spaces
Insert missing namespace comments with SpacesBeforeTrailingComments
leading spaces.

Fixes #64051.

Differential Revision: https://reviews.llvm.org/D156065
2023-07-24 09:22:51 -07:00
Corentin Jabot
8698262a43 [Clang] Fix consteval propagation for aggregates and defaulted constructors
This patch does a few things:

* Fix aggregate initialization.
  When an aggregate has an initializer that is immediate-escalating,
  the context in which it is used automatically becomes an immediate function.
  The wording does that by rpretending an aggregate initialization is itself
  an invocation which is not really how clang works, so my previous attempt
  was... wrong.

* Fix initialization of defaulted constructors with immediate escalating
  default member initializers.
  The wording was silent about that case and I did not handled it fully
  https://cplusplus.github.io/CWG/issues/2760.html

* Fix diagnostics
  In some cases clang would produce additional and unhelpful
  diagnostics by listing the invalid references to consteval
  function that appear in immediate escalating functions

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

Reviewed By: aaron.ballman, #clang-language-wg, Fznamznon

Differential Revision: https://reviews.llvm.org/D155175
2023-07-24 18:15:38 +02:00