1698 Commits

Author SHA1 Message Date
Bogdan Graur
821dfc392a Revert "[X86] Change target of __builtin_ia32_cmp[p|s][s|d] from avx into sse/sse2 (#67410)"
Does not respect `__attribute__((target("avx"))`.

This reverts commit ccd5b8db48a4cfa9e6868301cbab5fe033434e46.
2023-10-05 10:33:44 +00:00
cor3ntin
c72d3a0966
[Clang] Handle consteval expression in array bounds expressions (#66222)
The bounds of a c++ array is a _constant-expression_. And in C++ it is
also a constant expression.

But we also support VLAs, ie arrays with non-constant bounds.

We need to take care to handle the case of a consteval function (which
are specified to be only immediately called in non-constant contexts)
that appear in arrays bounds.

This introduces `Sema::isAlwayConstantEvaluatedContext`, and a flag in
ExpressionEvaluationContextRecord, such that immediate functions in
array bounds are always immediately invoked.

Sema had both `isConstantEvaluatedContext` and
`isConstantEvaluated`, so I took the opportunity to cleanup that.

The change in `TimeProfilerTest.cpp` is an unfortunate manifestation of
the problem that #66203 seeks to address.

Fixes #65520
2023-10-05 11:36:27 +02:00
Shoaib Meenai
0b07b06eff
[Sema] Use underlying type of scoped enum for -Wformat diagnostics (#67378)
Right now, `-Wformat` for a scoped enum will suggest a cast based on the
format specifier being used. This can lead to incorrect results, e.g.
attempting to format a scoped enum with `%s` would suggest casting to
`char *` instead of fixing the specifier. Change the logic to treat the
scoped enum's underlying type as the intended type to be printed, and
suggest format specifier changes and casts based on that.
2023-10-02 11:32:54 -07:00
Corentin Jabot
af4751738d [C++] Implement "Deducing this" (P0847R7)
This patch implements P0847R7 (partially),
CWG2561 and CWG2653.

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

Differential Revision: https://reviews.llvm.org/D140828
2023-10-02 14:33:02 +02:00
Sam McCall
880fa7faa9 Revert "[clang][SemaCXX] Diagnose tautological uses of consteval if and is_constant_evaluated"
This reverts commit 491b2810fb7fe5f080fa9c4f5945ed0a6909dc92.

This change broke valid code and generated incorrect diagnostics, see
https://reviews.llvm.org/D155064
2023-09-27 18:58:01 +02:00
Freddy Ye
ccd5b8db48
[X86] Change target of __builtin_ia32_cmp[p|s][s|d] from avx into sse/sse2 (#67410) 2023-09-27 21:24:22 +08:00
Takuya Shimizu
491b2810fb [clang][SemaCXX] Diagnose tautological uses of consteval if and is_constant_evaluated
This patch makes clang diagnose extensive cases of consteval if and is_constant_evaluated usage that are tautologically true or false.
This introduces a new IsRuntimeEvaluated boolean flag to Sema::ExpressionEvaluationContextRecord that means the immediate appearance of if consteval or is_constant_evaluated are tautologically false(e.g. inside if !consteval {} block or non-constexpr-qualified function definition body)
This patch also pushes new expression evaluation context when parsing the condition of if constexpr and initializer of constexpr variables so that Sema can be aware that the use of consteval if and is_consteval are tautologically true in if constexpr condition and constexpr variable initializers.
BEFORE this patch, the warning for is_constant_evaluated was emitted from constant evaluator. This patch moves the warning logic to Sema in order to diagnose tautological use of is_constant_evaluated in the same way as consteval if.

This patch separates initializer evaluation context from InitializerScopeRAII.
This fixes a bug that was happening when user takes address of function address in initializers of non-local variables.

Fixes https://github.com/llvm/llvm-project/issues/43760
Fixes https://github.com/llvm/llvm-project/issues/51567

Reviewed By: cor3ntin, ldionne
Differential Revision: https://reviews.llvm.org/D155064
2023-09-27 09:26:06 +09:00
Takuya Shimizu
56c3b8e997
[clang][Sema] Make format size estimator aware of %p's existence in format string (#65969)
This change introduces `-Wformat-overflow` and `-Wformat-truncation` warning flags that were formerly diagnosed from `-Wfortify-source` warning group.
This also introduces `-Wformat-overflow-non-kprintf` and `-Wformat-truncation-non-kprintf`, both of which will be used when the format string contains `%p` format string.

The rationale for this is that Linux kernel has its own extension for `%p` format specifier, and we need some way to suppress false positives in kernel codebase.
The approach of this patch aims NOT to affect non-kernel codebases.
Note that GCC stops format size estimation upon `%p` format specifier.

As requested in https://github.com/llvm/llvm-project/issues/64871
2023-09-25 10:03:46 +09:00
Shoaib Meenai
61c5ad8857
[Sema] Fix fixit cast printing inside macros (#66853)
`Lexer::getLocForEndOfToken` is documented as returning an invalid
source location when the end of the token is inside a macro expansion.
We don't want that for this particular application, so just calculate
the end location directly instead.

Before this, format fix-its would omit the closing parenthesis (thus
producing invalid code) for macros, e.g.:

```
$ cat format.cpp
extern "C" int printf(const char *, ...);
enum class Foo { Bar };
#define LOG(...) printf(__VA_ARGS__)
void f(Foo foo) { LOG("%d\n", foo); }

$ clang -fsyntax-only format.cpp
format.cpp:4:29: warning: format specifies type 'int' but the argument has type 'Foo' [-Wformat]
    4 | void f(Foo f) { LOG("%d\n", f); }
      |                      ~~     ^
      |                             static_cast<int>(
format.cpp:3:25: note: expanded from macro 'LOG'
    3 | #define LOG(...) printf(__VA_ARGS__)
      |                         ^~~~~~~~~~~
1 warning generated.
```

We now emit a valid fix-it:

```
$ clang -fsyntax-only format.cpp
format.cpp:4:31: warning: format specifies type 'int' but the argument has type 'Foo' [-Wformat]
    4 | void f(Foo foo) { LOG("%d\n", foo); }
      |                        ~~     ^~~
      |                               static_cast<int>( )
format.cpp:3:25: note: expanded from macro 'LOG'
    3 | #define LOG(...) printf(__VA_ARGS__)
      |                         ^~~~~~~~~~~
1 warning generated.
```

Fixes https://github.com/llvm/llvm-project/issues/63462
2023-09-20 17:32:35 -07:00
Takuya Shimizu
72f6abb9bc [clang][Sema] Fix format size estimator's handling of %o, %x, %X with alternative form
The wrong handling of %x specifier with alternative form causes a false positive in linux kernel (https://github.com/ClangBuiltLinux/linux/issues/1923#issuecomment-1696075886)

The kernel code: 651a00bc56/drivers/media/pci/cx18/cx18-mailbox.c (L99)

This patch fixes this handling, and also adds some standard wordings as comments to clarify the reason.

Reviewed By: nickdesaulniers
Differential Revision: https://reviews.llvm.org/D159138
2023-09-12 12:22:26 +09:00
Yueh-Ting (eop) Chen
77b7b1ad42
[Clang][RISCV] Use Decl for checkRVVTypeSupport (#65778)
Using ValueDecl will cause error for OpenMP. Decl should do the work.
2023-09-11 14:19:34 +08:00
Serge Pavlov
9fd57e4d48 [clang] Support vectors in __builtin_isfpclass
Builtin function `__builtin_isfpclass` now can be called for a vector
of floating-point values. In this case it is applied to the vector
elementwise and produces vector of integer values.

Differential Revision: https://reviews.llvm.org/D153339
2023-09-02 11:52:43 +07:00
Takuya Shimizu
0c9c9dd9a2 [clang][Sema] Add truncation warning on fortified snprintf
This patch warns on snprintf calls whose n argument is known to be smaller than the size of the formatted string like

```
char buf[5];
snprintf(buf, 5, "Hello");
```
This is a counterpart of gcc's Wformat-truncation
Fixes https://github.com/llvm/llvm-project/issues/64871

Reviewed By: aaron.ballman, nickdesaulniers
Differential Revision: https://reviews.llvm.org/D158562
2023-08-26 14:41:05 +09:00
Jianjian GUAN
654fa9a7e8 [RISCV] Add Zvfhmin extension for clang
This patch adds the Zvfhmin extension for clang.

Reviewed By: craig.topper, michaelmaitland

Differential Revision: https://reviews.llvm.org/D150253
2023-08-23 17:08:39 +08:00
Kazu Hirata
abed823dfe [Sema] Modernize UsageInfo (NFC) 2023-08-20 22:07:58 -07:00
Kazu Hirata
4d434f7696 [Sema] Modernize Usage (NFC) 2023-08-20 09:43:04 -07:00
Jianjian GUAN
28741a23c9 [clang][SVE] Rename isVLSTBuiltinType, NFC
Since we also have VLST for rvv now, it is not clear to keep using `isVLSTBuiltinType`, so I added prefix SVE to it.

Reviewed By: paulwalker-arm

Differential Revision: https://reviews.llvm.org/D158045
2023-08-17 14:18:32 +08:00
Craig Topper
ee6befe264 [RISCV] Rewrite CheckInvalidVLENandLMUL to avoid floating point.
This avoids needing an FP value to represent LMUL.

Reviewed By: 4vtomat

Differential Revision: https://reviews.llvm.org/D157651
2023-08-12 11:14:51 -07:00
Matt Arsenault
9e3d9c9eae clang: Add __builtin_elementwise_sqrt
This will be used in the opencl builtin headers to provide direct
intrinsic access with proper !fpmath metadata.

https://reviews.llvm.org/D156737
2023-08-11 19:32:39 -04:00
dingfei
0f73a2406a [clang][Sema] Skip access check on arrays of zero-length element
Bound check on array of zero-sized element isn't meaningful.

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

Reviewed By: jacquesguan

Differential Revision: https://reviews.llvm.org/D157584
2023-08-11 22:05:04 +08:00
Aaron Ballman
9c4ade0623 [C23] Rename C2x->C23 in diagnostics
This renames C2x to C23 in diagnostic identifiers and messages. The
changes were made mechanically.
2023-08-11 08:42:01 -04:00
Aaron Ballman
0ce056a814 [C23] Rename C2x -> C23; NFC
This does the rename for most internal uses of C2x, but does not rename
or reword diagnostics (those will be done in a follow-up).

I also updated standards references and citations to the final wording
in the standard.
2023-08-11 07:43:43 -04:00
Sander de Smalen
453c30e9e6 [Clang][AArch64] Add diagnostic for calls from non-ZA to shared-ZA functions.
The caller is required to have ZA state if it wants to share it with a callee.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D157270
2023-08-09 12:37:41 +00:00
Sander de Smalen
ecb7b9c5c5 [Clang][AArch64] Diagnostics for SME attributes when target doesn't have 'sme'
This patch adds error diagnostics to Clang when code uses the AArch64 SME
attributes without specifying 'sme' as available target attribute.

* Function definitions marked as '__arm_streaming', '__arm_locally_streaming',
  '__arm_shared_za' or '__arm_new_za' will by definition use or require SME
  instructions.
* Calls from non-streaming functions to streaming-functions require
  the compiler to enable/disable streaming-SVE mode around the call-site.

In some cases we can accept the SME attributes without having 'sme' enabled:
* Function declaration can have the SME attributes.
* Definitions can be __arm_streaming_compatible since the generated
  code should execute on processing elements without SME.

Reviewed By: paulwalker-arm

Differential Revision: https://reviews.llvm.org/D157269
2023-08-09 12:31:02 +00:00
wanglei
ea8d3b1f9f [Clang][LoongArch] Use the ClangBuiltin class to automatically generate support for CBE and CFE
Fixed the type modifier (L->W), removed redundant feature checking code
since the feature has already been checked in `EmitBuiltinExpr`. And
Cleaned up unused diagnostic information.

Reviewed By: SixWeining

Differential Revision: https://reviews.llvm.org/D156866
2023-08-09 16:04:09 +08:00
4vtomat
2a05a5215f [RISCV] Support vector crypto extension C intrinsics
Depends on D141672, D138809

Differential Revision: https://reviews.llvm.org/D138810
2023-08-08 17:09:49 -07:00
Piyou Chen
2df05cd01c [RISCV] Support overloaded version ntlh intrinsic function
Here is the proposal https://github.com/riscv-non-isa/riscv-c-api-doc/pull/47.

The version that omit the domain argument imply domain=__RISCV_NTLH_ALL.

```
type __riscv_ntl_load (type *ptr);
void __riscv_ntl_store (type *ptr, type val);
```

Reviewed By: kito-cheng, craig.topper

Differential Revision: https://reviews.llvm.org/D156221
2023-08-04 00:39:25 -07:00
Joshua Batista
57f879cdd4 clang: Add elementwise bitreverse builtin
Add codegen for llvm bitreverse elementwise builtin
The bitreverse 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 integer types only.

Reviewed By: arsenm

Differential Revision: https://reviews.llvm.org/D156357
2023-07-31 10:59:13 -07: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
Bryan Chan
578b0bd4e6 [Clang][AArch64][SME] Add ZA zeroing intrinsics
This patch adds support for the following SME ACLE intrinsics (as defined
 in https://arm-software.github.io/acle/main/acle.html):

   - svzero_mask_za
   - svzero_za

Co-authored-by: Sagar Kulkarni <sagar.kulkarni1@huawei.com>

Reviewed By: sdesmalen

Differential Revision: https://reviews.llvm.org/D134677
2023-07-20 06:06:34 -04:00
Freddy Ye
c6f66de21a [X86] Add SM3 instructions.
For more details about these instructions, 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

Reviewed By: pengfei

Differential Revision: https://reviews.llvm.org/D155147
2023-07-20 10:24:16 +08:00
Craig Topper
3055c5815a [RISCV] Upgrade Zvfh version to 1.0 and move out of experimental state.
This has been ratified according to https://wiki.riscv.org/display/HOME/Recently+Ratified+Extensions

Differential Revision: https://reviews.llvm.org/D155668
2023-07-19 10:03:57 -07:00
eopXD
28c3a74a5c [Clang][RISCV] Improve diagnostic message for full multiply intrinsics
The full multiply intrinsics are not included for EEW=64 in Zve64*.
They require the V extension to be enabled.

This commit improves diagnostic message from

```
<source>:4:10: error: call to undeclared function '__riscv_vsmul_vv_i64m1';
    4 |   return __riscv_vsmul_vv_i64m1(op1, op2, __RISCV_VXRM_RNU, vl);
```

to

```
test.c:5:10: error: builtin requires: v
    5 |   return __riscv_vsmul_vv_i64m1(op1, op2, __RISCV_VXRM_RNU, vl);
```

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D155416
2023-07-18 19:39:46 -07:00
eopXD
c4a5b58497 [Clang][RISCV] Guard RVV intrinsics types that is not available when ELEN < 64
(ELEN, LMUL) pairs of (8, mf8), (16, mf4), (32, mf2), (64, m1)
requires at least `zve64x`.

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D155414
2023-07-18 18:57:33 -07:00
Craig Topper
8e6482115c [RISCV] Remove unnecessary _32 and _64 suffixes from some scalar crypto builtins.
The names of these builtins aren't ambiguous so they don't need the suffix.
2023-07-18 12:56:01 -07:00
Alex Brachet
563a23c824 [clang][Sema] Add fixit for scoped enum format error
This helps transition code bases to handle the new warning added in 3632e2f5179

Before:
```
clang/test/FixIt/format.cpp:10:16: warning: format specifies type 'int' but the argument has type 'N::E' [-Wformat]
   10 |   printf("%d", N::E::One); // expected-warning{{format specifies type 'int' but the argument has type 'N::E'}}
      |           ~~   ^~~~~~~~~
      |           %d
```
After:
```
clang/test/FixIt/format.cpp:10:16: warning: format specifies type 'int' but the argument has type 'N::E' [-Wformat]
   10 |   printf("%d", N::E::One); // expected-warning{{format specifies type 'int' but the argument has type 'N::E'}}
      |           ~~   ^~~~~~~~~
      |                static_cast<int>( )
```

Differential Revision: https://reviews.llvm.org/D153623
2023-07-14 16:23:22 +00:00
Alex Brachet
3c0a136ce4 [clang][Sema] Suggest static_cast in C++ code
This patch changes the -Wformat diagnostic to suggest static_cast over
a C-style cast for {,Objective}C++ when recommending the argument be
casted rather than changing the format string.

Before:
```
clang/test/FixIt/format.mm:11:16: warning: format specifies type 'unichar' (aka 'unsigned short') but the argument has type 'wchar_t' [-Wformat]
   11 |   NSLog(@"%C", wchar_data);  // expected-warning{{format specifies type 'unichar' (aka 'unsigned short') but the argument has type 'wchar_t'}}
      |           ~~   ^~~~~~~~~~
      |                (unsigned short)
```
After:
```
clang/test/FixIt/format.mm:11:16: warning: format specifies type 'unichar' (aka 'unsigned short') but the argument has type 'wchar_t' [-Wformat]
   11 |   NSLog(@"%C", wchar_data);  // expected-warning{{format specifies type 'unichar' (aka 'unsigned short') but the argument has type 'wchar_t'}}
      |           ~~   ^~~~~~~~~~
      |                static_cast<unsigned short>( )
```

Differential Revision: https://reviews.llvm.org/D153622
2023-07-14 16:22:06 +00:00
Jim Lin
8fe0449ac9 [RISCV] Fix required features checking with empty string
In our downstream, we define some intrinsics that don't require any
extra extension enabled. Such as

TARGET_BUILTIN(__builtin_riscv_xxx, "LiLi", "nc", "")

But `split` function's `KeepEmpty` argument is True. Got the error message

error: builtin requires at least one of the following extensions support to be enabled : ''

when we use our customized intrinsic.

Reviewed By: craig.topper, wangpc

Differential Revision: https://reviews.llvm.org/D154596
2023-07-14 16:09:11 +08:00
eopXD
dd158c1b4f [Clang][RISCV] Align RVV intrinsic builtin names with the C intrinsics
Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D155102
2023-07-13 02:47:47 -07:00
eopXD
2c38d63323 [8/8][RISCV] Add rounding mode control variant for vfredosum, vfredusum, vfwredosum, vfwredusum
Depends on D154635

For the cover letter of the patch-set, please checkout D154628.

This is the 8th patch of the patch-set.

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D154636
2023-07-13 00:55:10 -07:00
eopXD
5d18d43f26 [7/8][RISCV] Add rounding mode control variant for conversion intrinsics between floating-point and integer
Depends on D154634

For the cover letter of the patch-set, please checkout D154628.

This is the 7th patch of the patch-set. This patch includes change to
vfcvt_x_f, vfcvt_xu_f, vfwcvt_x_f, vfwcvt_xu_f, vfncvt_x_f, vfncvt_xu_f
vfcvt_f_x, vfcvt_f_xu, vfncvt_f_x vfncvt_f_xu, vfncvt_f_f

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D154635
2023-07-13 00:54:07 -07:00
eopXD
51b9e33661 [6/8][RISCV] Add rounding mode control variant for vfsqrt, vfrec7
Depends on D154633

For the cover letter of the patch-set, please checkout D154628.

This is the 6th patch of the patch-set.

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D154634
2023-07-13 00:51:51 -07:00
eopXD
4085b23609 [5/8][RISCV] Add rounding mode control variant for vfwmacc, vfwnmacc, vfwmsac, vfwnmsac
Depends on D154632

For the cover letter of the patch-set, please checkout D154628.

This is the 5th patch of the patch-set.

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D154633
2023-07-13 00:49:59 -07:00
eopXD
e1f224a647 [4/8][RISCV] Add rounding mode control variant for vfmacc, vfnmacc, vfmsac, vfnmsac, vfmadd, vfnmadd, vfmsub, vfnmsub
Depends on D154631

For the cover letter of the patch-set, please checkout D154628.

This is the 4th patch of the patch-set.

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D154632
2023-07-13 00:47:27 -07:00
eopXD
1a905e8238 [3/8][RISCV] Add rounding mode control variant for vfmul, vfdiv, vfrdiv, vfwmul
Depends on D154629

For the cover letter of the patch-set, please checkout D154628.

This is the 3rd patch of the patch-set.

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D154631
2023-07-13 00:43:54 -07:00
eopXD
00093667b1 [2/8][RISCV] Add rounding mode control variant for vfwadd, vfwsub
Depends on D154628

For the cover letter of the patch-set, please checkout D154628.

This is the 2nd patch of the patch-set.

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D154629
2023-07-13 00:42:00 -07:00
eopXD
474e37c113 [1/8][RISCV] Add rounding mode control variant for vfsub, vfrsub
Depends on D152996.

This patch-set aims to add a variant for the RVV floating-point
intrinsics that controls the rounding mode (`frm`). The rounding mode
variant appends `_rm` before the policy suffix to distinguish from
those without them.

Specification PR: riscv-non-isa/rvv-intrinsic-doc#226

This is the 1st patch of the patch-set.

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D154628
2023-07-13 00:35:36 -07:00
eopXD
76482078cd [RISCV][POC] Model frm control for vfadd
Depends on D152879.

Specification PR: riscv-non-isa/rvv-intrinsic-doc#226

This patch adds variant of `vfadd` that models the rounding mode control.
The added variant has suffix `_rm` appended to differentiate from the
existing ones that does not alternate `frm` and uses whatever is inside.

The value `7` is used to indicate no rounding mode change. Reusing the
semantic from the rounding mode encoding for scalar floating-point
instructions.

Additional data member `HasFRMRoundModeOp` is added so we can append
`_rm` suffix for the fadd variants that models rounding mode control.

Additional data member `IsRVVFixedPoint` is added so we can define
pseudo instructions with rounding mode operand and distinguish the
instructions between fixed-point and floating-point.

Reviewed By: craig.topper, kito-cheng

Differential Revision: https://reviews.llvm.org/D152996
2023-07-13 00:34:00 -07:00
eopXD
5704630ec4 [RISCV] Remove redundant _ta suffix in RVV intrinsics builtins. NFC
Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D154693
2023-07-09 08:40:36 -07:00
Timm Bäder
381e8052d0 [clang][Sema][NFC] Make worklist in CheckForIntOverflow const 2023-07-02 06:49:55 +02:00