51309 Commits

Author SHA1 Message Date
Fangrui Song
e8fe4de64f
[CodeGen] -fsanitize=alignment: add cl::opt sanitize-alignment-builtin to disable memcpy instrumentation (#69240)
Deploying #67766 to a large internal codebase uncovers many bugs (many
are
probably benign but need cleaning up). There are also issues in
high-profile
open-source projects like v8. Add a cl::opt to disable builtin
instrumentation
for -fsanitize=alignment to help large codebase users.

In the long term, this cl::opt option may still be useful to debug
-fsanitize=alignment instrumentation on builtins, so we probably want to
keep it around.
2023-10-18 11:43:36 -07:00
vabridgers
708808e853
[Sema] Add check for bitfield assignments to integral types (#69049)
This change introduces the bitfield conversion check after fixes to the
test case. The original submission unfortunately did not comprehend
differences in architecture for the diagnostic messages, leading to
unanticipated failures in the arm build bots.

Original PR: https://github.com/llvm/llvm-project/pull/68276

Clang does not check for bitfield assignment widths, while gcc checks
this.

gcc produced a warning like so for it's -Wconversion flag:
```
$ gcc -Wconversion -c test.c
test.c: In function 'foo':
test.c:10:15: warning: conversion from 'int' to 'signed char:7' may
change value [-Wconversion]
   10 |      vxx.bf = x; // no warning
      |               ^
```

This change simply adds this check for integral types under the
-Wbitfield-conversion compiler option.
2023-10-18 11:40:07 -05:00
Erich Keane
98191d7c16
[CONCEPTS]Corrected comparison of constraints with out of line CTD (#69244)
Out of line class template declaration specializations aren't created at
the time they have their template arguments checked, so we previously
weren't doing any amount of work to substitute the constraints before
comparison. This resulted in the out of line definition's difference in
'depth' causing the constraints to compare differently.

This patch corrects that. Additionally, it handles ClassTemplateDecl
when collecting template arguments.

Fixes: #61763
2023-10-18 09:10:30 -07:00
Caroline Concatto
1b93e15bcd [Clang][SVE2p1] Add svpsel builtins
As described in: https://github.com/ARM-software/acle/pull/257

Patch by : Sander de Smalen<sander.desmalen@arm.com>

Reviewed By: kmclaughlin

Differential Revision: https://reviews.llvm.org/D151197
2023-10-18 15:05:26 +00:00
Dmitry Chernenkov
a3a0f59a1e Revert "Correctly compute conversion seq for args to fn with reversed param order (#68999)"
This reverts commit e6d0b126c824222fca2f31a2ba571c2ee2bb4760.

See PR for reason

https://github.com/llvm/llvm-project/pull/68999#issuecomment-1768541660
2023-10-18 14:13:48 +00:00
VitaNuo
00f34eefe4
[clang] Bail out if the result of function template instantiation is not a function type. (#69459) 2023-10-18 15:22:40 +02:00
Timm Bäder
66c99154a1 [clang][Interp][NFC] Remove from(Boolean) overload
This code is unused now that we have special casts from/to IntAP(S).
2023-10-18 14:23:29 +02:00
Paul Walker
9322a0c2f3 [Clang] Run update_cc_test_checks across SVE acle tests. 2023-10-18 11:17:36 +00:00
pvanhout
868abf0961 Revert "[AMDGPU] Remove Code Object V3 (#67118)"
This reverts commit 544d91280c26fd5f7acd70eac4d667863562f4cc.
2023-10-18 12:55:36 +02:00
Paul Walker
675231eb09
[SVE ACLE] Allow default zero initialisation for svcount_t. (#69321)
This matches the behaviour of the other SVE ACLE types.
2023-10-18 10:40:07 +01:00
kadir çetinkaya
48a53509e8
[clang][USR] Encode full decl-context also for anon namespaces (#68325)
Otherwise we create collisions, e.g. a struct named Foo inside an
anonymous
namespace will get the same USR no matter what the surrounding
decl-context is.
2023-10-18 10:51:31 +02:00
Utkarsh Saxena
e6d0b126c8
Correctly compute conversion seq for args to fn with reversed param order (#68999)
We associated conversion seq for args (when reversed) to the wrong
index.
This lead to clang believing reversed `operator==` a worse overload
candidate than the `operator==` without reversed args when both these
candidate were ambiguous.

Fixes https://github.com/llvm/llvm-project/issues/53954
2023-10-17 20:53:42 +02:00
Caroline Concatto
7cad5a9eb4 [Clang][SVE2.1] Add svpext builtins
As described in: https://github.com/ARM-software/acle/pull/257

Reviewed By: hassnaa-arm

Differential Revision: https://reviews.llvm.org/D151081
2023-10-17 16:15:22 +00:00
AdityaK
20af0e5e8d
Enable v for RISCV64 Android (#69261)
Android has already enabled V by default for aosp:
https://android-review.googlesource.com/c/platform/build/soong/+/2752805
four weeks back.
2023-10-17 08:52:55 -07:00
Sam Tebbs
4b8f23e93d
[AArch64][SME] Remove immediate argument restriction for svldr and svstr (#68908)
The svldr_vnum_za and svstr_vnum_za builtins/intrinsics currently
require that the vnum argument be an immediate, but since vnum is used
to modify the base register via a mul and add, that restriction is not
necessary. This patch removes that restriction.
2023-10-17 16:02:36 +01:00
Alex Voicu
791b890c46 [HIP][Clang][CodeGen] Simplify test for hipstdpar
Fixes build failures for cases where there's no additional visibility / linkage spec.

Differential Revision: https://reviews.llvm.org/D155850
2023-10-17 15:42:28 +01:00
Caroline Concatto
81d8fa5a1d [Clang][SVE2.1] Add svcntp prototype
As described in: https://github.com/ARM-software/acle/pull/257

Patch by : David Sherwood <david.sherwood@arm.com>

Reviewed By: sdesmalen

Differential Revision: https://reviews.llvm.org/D150961
2023-10-17 14:14:45 +00:00
Yaxun (Sam) Liu
fc53b1abf7
[CUDA][HIP] Fix init var diag in temmplate (#69081)
Currently clang diagnoses the following code:
(https://godbolt.org/z/s8zK3E5P5) but nvcc
does not.

`
struct A {
   constexpr A(){}
};

struct  B {
  A a;
  int b;
};

template<typename T>
__global__ void kernel( )
{
   __shared__ B x;
}
`

Clang generates an implicit trivial ctor for struct B, which should be
allowed for initializing a shared variable.

However, the body of the ctor is defined only if the template kernel is
instantiated. Clang checks the initialization of variable in
non-instantiated templates, where it cannot find the body of the ctor,
therefore diagnoses it.

This patch skips the check for non-instantiated templates.
2023-10-17 10:00:32 -04:00
Alex Voicu
dd5d65adb6 [HIP][Clang][CodeGen] Add CodeGen support for hipstdpar
This patch adds the CodeGen changes needed for enabling HIP parallel algorithm offload on AMDGPU targets. This change relaxes restrictions on what gets emitted on the device path, when compiling in `hipstdpar` mode:

1. Unless a function is explicitly marked `__host__`, it will get emitted, whereas before only `__device__` and `__global__` functions would be emitted;
2. Unsupported builtins are ignored as opposed to being marked as an error, as the decision on their validity is deferred to the `hipstdpar` specific code selection pass;
3. We add a `hipstdpar` specific pass to the opt pipeline, independent of optimisation level:
    - When compiling for the host, iff the user requested it via the `--hipstdpar-interpose-alloc` flag, we add a pass which replaces canonical allocation / deallocation functions with accelerator aware equivalents.

A test to validate that unannotated functions get correctly emitted is added as well.

Reviewed by: yaxunl, efriedma

Differential Revision: https://reviews.llvm.org/D155850
2023-10-17 11:41:36 +01:00
Timm Bäder
11f5e5eb90 [clang][Interp][NFC] Add thread_local tests 2023-10-17 10:37:28 +02:00
刘雨培
4b8b70a52f
[Clang] Fix dependence handling of nttp for variable templates (#69075)
The dependence of a template argument is not only determined by the
argument itself, but also by the type of the template parameter:

> Furthermore, a non-type
[template-argument](https://eel.is/c++draft/temp.names#nt:template-argument)
is dependent if the corresponding non-type
[template-parameter](https://eel.is/c++draft/temp.param#nt:template-parameter)
is of reference or pointer type and the
[template-argument](https://eel.is/c++draft/temp.names#nt:template-argument)
designates or points to a member of the current instantiation or a
member of a dependent
type[.](https://eel.is/c++draft/temp.dep#temp-3.sentence-1)

For example:

```cpp
struct A{};

template <const A& T>
const A JoinStringViews = T;

template <int V>
class Builder {
public:
    static constexpr A Equal{};
    static constexpr auto Val = JoinStringViews<Equal>;
};
```

The constant expression `Equal` is not dependent, but because the type
of the template parameter is a reference type and `Equal` is a member of
the current instantiation, the template argument of
`JoinStringViews<Equal>` is actually dependent, which makes
`JoinStringViews<Equal>` dependent.

When a template-id of a variable template is dependent,
`CheckVarTemplateId` will return an `UnresolvedLookupExpr`, but
`UnresolvedLookupExpr` calculates dependence by template arguments only
(the `ConstantExpr` `Equal` here), which is not dependent. This causes
type deduction to think that `JoinStringViews<Equal>` is `OverloadTy`
and treat it as a function template, which is clearly wrong.

This PR adds a `KnownDependent` parameter to the constructor of
`UnresolvedLookupExpr`. After canonicalization, if `CanonicalConverted`
contains any dependent argument, `KnownDependent` is set to `true`. This
fixes the dependence calculation of `UnresolvedLookupExpr` for dependent
variable templates.

Fixes #65153 .
2023-10-16 22:23:28 -07:00
Timm Baeder
7bc793a692
[clang][Interp] Check pointer inc/dec ops for null (#69168) 2023-10-17 06:53:33 +02:00
Antonio Abbatangelo
ce9eaf0360
Revert "[clang][Sema] Use original template pattern when declaring implicit deduction guides for nested template classes (#68379)"
This reverts commit dd0fba11690f9fef304d5f48cde646e5eca8d3c0.

It fails on nested classes that have both an explicit deduction guide and
a constructor that has an argument of the same type as the class (i.e. a copy constructor).
2023-10-16 22:16:09 -04:00
zijunzhao
3694697003 [clang] Implement C23 <stdckdint.h>
https://github.com/llvm/llvm-project/issues/62248

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

Differential Revision: https://reviews.llvm.org/D157331
2023-10-17 00:51:21 +00:00
antangelo
dd0fba1169
[clang][Sema] Use original template pattern when declaring implicit deduction guides for nested template classes (#68379)
When a nested template is instantiated, the template pattern of the
inner class is not copied into the outer class
ClassTemplateSpecializationDecl. The specialization contains a
ClassTemplateDecl with an empty record that points to the original
template pattern instead.

As a result, when looking up the constructors of the inner class, no
results are returned. This patch finds the original template pattern and
uses that for the lookup instead.

Based on CWG2471 we must also substitute the known outer template
arguments when creating deduction guides for the inner class.

Fixes #46200
Fixes #57812
2023-10-16 15:17:36 -04:00
Balázs Kéri
c202a17d02
[clang][analyzer] Move checker alpha.unix.StdCLibraryFunctions out of alpha. (#66207) 2023-10-16 14:51:05 +02:00
Timm Baeder
de9b3c5eba
[clang][Interp] Handle delegating constructors (#67823) 2023-10-16 14:11:25 +02:00
Gábor Spaits
c68bc1726c
[analyzer] Fix note for member reference (#68691)
In the following code:
```cpp
int main() {
    struct Wrapper {char c; int &ref; };
    Wrapper w = {.c = 'a', .ref = *(int *)0 };
    w.ref = 1;
}
```

The clang static analyzer will produce the following warnings and notes:
```
test.cpp:12:11: warning: Dereference of null pointer [core.NullDereference]
   12 |     w.ref = 1;
      |     ~~~~~~^~~
test.cpp:11:5: note: 'w' initialized here
   11 |     Wrapper w = {.c = 'a', .ref = *(int *)0 };
      |     ^~~~~~~~~
test.cpp:12:11: note: Dereference of null pointer
   12 |     w.ref = 1;
      |     ~~~~~~^~~
1 warning generated.
```
In the line where `w` is created, the note gives information about the
initialization of `w` instead of `w.ref`. Let's compare it to a similar
case where a null pointer dereference happens to a pointer member:

```cpp
int main() {
     struct Wrapper {char c; int *ptr; };
     Wrapper w = {.c = 'a', .ptr = nullptr };
     *w.ptr = 1;
}
```

Here the following error and notes are seen:
```
test.cpp:18:12: warning: Dereference of null pointer (loaded from field 'ptr') [core.NullDereference]
   18 |     *w.ptr = 1;
      |        ~~~ ^
test.cpp:17:5: note: 'w.ptr' initialized to a null pointer value
   17 |     Wrapper w = {.c = 'a', .ptr = nullptr };
      |     ^~~~~~~~~
test.cpp:18:12: note: Dereference of null pointer (loaded from field 'ptr')
   18 |     *w.ptr = 1;
      |        ~~~ ^
1 warning generated.
```
Here the note that shows the initialization the initialization of
`w.ptr` in shown instead of `w`.

This commit is here to achieve similar notes for member reference as the
notes of member pointers, so the report looks like the following:

```
test.cpp:12:11: warning: Dereference of null pointer [core.NullDereference]
   12 |     w.ref = 1;
      |     ~~~~~~^~~
test.cpp:11:5: note: 'w.ref' initialized to a null pointer value
   11 |     Wrapper w = {.c = 'a', .ref = *(int *)0 };
      |     ^~~~~~~~~
test.cpp:12:11: note: Dereference of null pointer
   12 |     w.ref = 1;
      |     ~~~~~~^~~
1 warning generated.
```
Here the initialization of `w.ref` is shown instead of `w`.

---------

Authored-by: Gábor Spaits <gabor.spaits@ericsson.com>
Reviewed-by: Donát Nagy <donat.nagy@ericsson.com>
2023-10-16 10:55:31 +02:00
Pierre van Houtryve
544d91280c
[AMDGPU] Remove Code Object V3 (#67118)
V3 has been deprecated for a while as well, so it can safely be removed
like V2 was removed.

- [Clang] Set minimum code object version to 4
- [lld] Fix tests using code object v3
- Remove code object V3 from the AMDGPU backend, and delete or port v3
tests to v4.
- Update docs to make it clear V3 can no longer be emitted.
2023-10-16 08:21:48 +02:00
Freddy Ye
819ac45d1c
[X86] Add USER_MSR instructions. (#68944)
For more details about this instruction, please refer to the latest ISE
document:
https://www.intel.com/content/www/us/en/develop/download/intel-architecture-instruction-set-extensions-programming-reference.html
2023-10-16 10:12:53 +08:00
Fangrui Song
993e839480
[Driver] Don't pass -Z to ld for ELF platforms (#69120)
-Z is an Apple ld64 option. ELF linkers don't recognize -Z, except
OpenBSD which patched GNU ld to add -Z for zmagic (seems unused)

> -Z Produce 'Standard' executables, disables Writable XOR Executable
features in resulting binaries.

Some `ToolChain`s have -Z due to copy-and-paste mistakes.
2023-10-15 19:12:35 -07:00
Min-Yih Hsu
fd4f96290a [Clang][M68k] Add Clang support for the new M68k_RTD CC
This patch adds `CC_M68kRTD`, which will be used on function if either
`__attribute__((m68k_rtd))` is presented or `-mrtd` flag is given.

Differential Revision: https://reviews.llvm.org/D149867
2023-10-15 16:13:43 -07:00
Ben Shi
169f60f7c7
[clang][driver] Add avr-libc's default linker script to lld (#68507)
If `-fuse-ld=lld` is specified but no user linker script is offered, we
try to use avr-libc's default one for lld. (not needed for GNU ld)
2023-10-15 13:47:56 +08:00
Matt Arsenault
2dc6579f6f clang: Switch SYCL test to generated checks 2023-10-15 11:44:40 +09:00
Aaron Ballman
343bed8d3a Canonically identical types are allowed in compound expressions in C
We did not have a catch-all for when the two operand types are
identical after canonicalization. Instead, we handled that on a case by
case basis. Thus, we would diagnose code like:
```
mat4 test(int a) {
  typedef float mat4 __attribute((matrix_type(4, 4)));
  mat4 transform;
  return (a > 0) ? transform : transform;
}
```
This simplifies the logic and will be more forwards
compatible with other extended datatypes.

Fixes https://github.com/llvm/llvm-project/issues/69008
2023-10-14 11:03:35 -04:00
Carlos Galvez
e7a6171c4c
[clang] Enable Wenum-constexpr-conversion also in system headers and … (#67528)
…macros

As per review comments on https://reviews.llvm.org/D150226, we should
allow for one more release before turning this warning into a hard
error, by making it visible in system headers and macros, so that people
are aware of it and can work on it.
2023-10-14 14:19:20 +02:00
Bill Wendling
769bc11f68
[Clang] Implement the 'counted_by' attribute (#68750)
The 'counted_by' attribute is used on flexible array members. The
argument for the attribute is the name of the field member in the same
structure holding the count of elements in the flexible array. This
information can be used to improve the results of the array bound
sanitizer and the '__builtin_dynamic_object_size' builtin.

This example specifies the that the flexible array member 'array' has
the number of elements allocated for it in 'count':

  struct bar;
  struct foo {
    size_t count;
     /* ... */
    struct bar *array[] __attribute__((counted_by(count)));
  };

This establishes a relationship between 'array' and 'count',
specifically that 'p->array' must have *at least* 'p->count' number of
elements available. It's the user's responsibility to ensure that this
relationship is maintained through changes to the structure.

In the following, the allocated array erroneously has fewer elements
than what's specified by 'p->count'. This would result in an
out-of-bounds access not not being detected:

  struct foo *p;

  void foo_alloc(size_t count) {
    p = malloc(MAX(sizeof(struct foo),
                   offsetof(struct foo, array[0]) + count *
                       sizeof(struct bar *)));
    p->count = count + 42;
  }

The next example updates 'p->count', breaking the relationship
requirement that 'p->array' must have at least 'p->count' number of
elements available:

  struct foo *p;

  void foo_alloc(size_t count) {
    p = malloc(MAX(sizeof(struct foo),
                   offsetof(struct foo, array[0]) + count *
                       sizeof(struct bar *)));
    p->count = count + 42;
  }

  void use_foo(int index) {
    p->count += 42;
    p->array[index] = 0; /* The sanitizer cannot properly check this access */
  }

Reviewed By: nickdesaulniers, aaron.ballman

Differential Revision: https://reviews.llvm.org/D148381
2023-10-14 04:18:02 -07:00
Timm Baeder
a653749aca
[clang][Interp] Implement compound assign operators on bitfields (#67306) 2023-10-14 09:17:35 +02:00
Amy Huang
e220398cc3
[MSVC, ARM64] Add __prefetch intrinsic (#67174)
Implement __prefetch intrinsic. 

MSVC docs:
https://learn.microsoft.com/en-us/cpp/intrinsics/arm64-intrinsics?view=msvc-170

Bug: https://github.com/llvm/llvm-project/issues/65405
2023-10-13 13:34:15 -07:00
Timm Baeder
3efa4794ec
[clang][Interp] Support AddOffset with 128bit offsets (#68679)
We do a similar thing a few lines above for `Index`:

```c++
  // Get a version of the index comparable to the type.
  T Index = T::from(Ptr.getIndex(), Offset.bitWidth());
```
2023-10-13 14:47:46 +02:00
vabridgers
2e955c0504
Revert "[Sema] Add check for bitfield assignments to integral types" (#68963)
This reverts commit 47e36266e93de9c34ba3028951a58124864bb2b4.

This change broke some arm8/arm7 build bots because int and void * have
the same size.

Co-authored-by: einvbri <vince.a.bridgers@ericsson.com>
2023-10-13 05:03:38 -05:00
Brad Smith
8da1e3dd24
[Driver] Have -rdynamic be a no-op on Haiku (#67872)
Do the same as the Haiku GCC patches.

46afdec057
2023-10-12 18:05:49 -04:00
Leonard Chan
ef388334ee Revert "Reapply "InstCombine: Introduce SimplifyDemandedUseFPClass""
This reverts commit 5a36904c515b.

Reverted because this breaks some floating point operations. See the
comment on https://github.com/llvm/llvm-project/commit/5a36904c515b.
2023-10-12 20:23:39 +00:00
vabridgers
dd0f642e6e
[Sema] Add check for bitfield assignments to larger integral types (#68276)
We noticed that clang does not check for bitfield assignment widths,
while gcc does check this.

gcc produced a warning like so for it's -Wconversion flag:
```
$ gcc -Wconversion -c test.c
test.c: In function 'foo':
test.c:10:15: warning: conversion from 'int' to 'signed char:7' may change value [-Wconversion]
   10 |      vxx.bf = x; // no warning
      |               ^
```

This change simply adds this check for integral types under the
-Wbitfield-conversion compiler option.
2023-10-12 13:14:20 -05:00
Nikita Popov
e44c9fd197 [Clang] Regenerate test checks (NFC)
Avoid extra diffs on future change.
2023-10-12 14:24:26 +02:00
Chen Zheng
c661c4f576
[AIX] recognize vsr in inline asm for AIX (#68476)
Extend `PPCTargetInfo::getGCCAddlRegNames()` to aix as well. The
definition should be common between Linux PPC and AIX PPC.
2023-10-12 08:54:45 +08:00
Amirreza Ashouri
4313351c13
[clang] __is_trivially_equality_comparable for types containing lambdas (#68506)
Lambdas (closure types) are trivially equality-comparable iff they are
non-capturing, because non-capturing lambdas are convertible to function
pointers: if (lam1 == lam2) compiles, then lam1 and lam2 must have
the same type, and be always-equal, and be empty.
2023-10-11 17:12:15 +02:00
Aaron Ballman
ac2722873b Revert "Diagnose problematic uses of constructor/destructor attribute (#67673)"
This reverts commit 27ecb63c260400dd20b8c5dc16d0dfd2d0e7122e.

Still fails compiler-rt:
https://lab.llvm.org/buildbot/#/builders/109/builds/75364
2023-10-11 09:02:24 -04:00
Aaron Ballman
27ecb63c26 Diagnose problematic uses of constructor/destructor attribute (#67673)
Functions with these attributes will be automatically called before
main() or after main() exits gracefully. In glibc environments, the
constructor function is passed the same arguments as main(), so that
signature is allowed. In all other environments, we require the function
to accept no arguments and either return `void` or `int`. The functions
must use the C calling convention. In C++ language modes, the functions
cannot be a nonstatic member function, or a consteval function.

Additionally, these reuse the same priority logic as the init_priority
attribute which explicitly reserved priorty values <= 100 or > 65535. So
we now diagnose use of reserved priorities the same as we do for the
init_priority attribute, but we downgrade the error to be a warning
which defaults to an error to ease use for implementers like compiler-rt
or libc.

This relands a633a3761fcbd0799426cbf5fbd7794961080e43 with fixes.
2023-10-11 08:55:33 -04:00
Aaron Ballman
0cb6c413b1 Revert "Diagnose problematic uses of constructor/destructor attribute (#67673)"
This reverts commit a633a3761fcbd0799426cbf5fbd7794961080e43.

Still breaking compiler-rt bots:
https://lab.llvm.org/buildbot/#/builders/109/builds/75360
2023-10-11 08:31:13 -04:00