376 Commits

Author SHA1 Message Date
Matt Arsenault
2a488b4443 clang: Add __builtin_elementwise_round 2023-06-19 11:32:56 -04:00
Serge Pavlov
112fa9aa70 [Doc] Fix table layout 2023-06-18 23:46:08 +07:00
Serge Pavlov
7dd387d297 [clang] Add __builtin_isfpclass
A new builtin function __builtin_isfpclass is added. It is called as:

    __builtin_isfpclass(<floating point value>, <test>)

and returns an integer value, which is non-zero if the floating point
argument falls into one of the classes specified by the second argument,
and zero otherwise. The set of classes is an integer value, where each
value class is represented by a bit. There are ten data classes, as
defined by the IEEE-754 standard, they are represented by bits:

    0x0001 (__FPCLASS_SNAN)         - Signaling NaN
    0x0002 (__FPCLASS_QNAN)         - Quiet NaN
    0x0004 (__FPCLASS_NEGINF)       - Negative infinity
    0x0008 (__FPCLASS_NEGNORMAL)    - Negative normal
    0x0010 (__FPCLASS_NEGSUBNORMAL) - Negative subnormal
    0x0020 (__FPCLASS_NEGZERO)      - Negative zero
    0x0040 (__FPCLASS_POSZERO)      - Positive zero
    0x0080 (__FPCLASS_POSSUBNORMAL) - Positive subnormal
    0x0100 (__FPCLASS_POSNORMAL)    - Positive normal
    0x0200 (__FPCLASS_POSINF)       - Positive infinity

They have corresponding builtin macros to facilitate using the builtin
function:

    if (__builtin_isfpclass(x, __FPCLASS_NEGZERO | __FPCLASS_POSZERO) {
      // x is any zero.
    }

The data class encoding is identical to that used in llvm.is.fpclass
function.

Differential Revision: https://reviews.llvm.org/D152351
2023-06-18 22:53:32 +07:00
Paulo Matos
55aeb23fe0 [clang][WebAssembly] Implement support for table types and builtins
This commit implements support for WebAssembly table types and
respective builtins. Table tables are WebAssembly objects to store
reference types. They have a large amount of semantic restrictions
including, but not limited to, only being allowed to be declared
at the top-level as static arrays of zero-length. Not being arguments
or result of functions, not being stored ot memory, etc.

This commit introduces the __attribute__((wasm_table)) to attach to
arrays of WebAssembly reference types. And the following builtins to
manage tables:

* ref   __builtin_wasm_table_get(table, idx)
* void  __builtin_wasm_table_set(table, idx, ref)
* uint  __builtin_wasm_table_size(table)
* uint  __builtin_wasm_table_grow(table, ref, uint)
* void  __builtin_wasm_table_fill(table, idx, ref, uint)
* void  __builtin_wasm_table_copy(table, table, uint, uint, uint)

This commit also enables reference-types feature at bleeding-edge.

This is joint work with Alex Bradbury (@asb).

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D139010
2023-06-10 15:53:13 +02:00
Aaron Ballman
12728e1449 [C] Support _Generic expressions with a type operand
_Generic accepts an expression operand whose type is matched against a
list of associations. The expression operand is unevaluated, but the
type matched is the type after lvalue conversion. This conversion loses
type information, which makes it more difficult to match against
qualified or incomplete types.

This extension allows _Generic to accept a type operand instead of an
expression operand. The type operand form does not undergo any
conversions and is matched directly against the association list.

This extension is also supported in C++ as we already supported
_Generic selection expressions there.

The RFC for this extension can be found at:
https://discourse.llvm.org/t/rfc-generic-selection-expression-with-a-type-operand/70388

Differential Revision: https://reviews.llvm.org/D149904
2023-06-05 11:09:58 -04:00
Kazu Hirata
a82f2b2db3 Fix typos in documentation 2023-05-28 13:13:12 -07:00
M. Zeeshan Siddiqui
dd2e681612 [Docs] Fix Sphinx documentation formatting issues in LanguageExtensions.rst
Fix indentation and spacing.

Reviewed By: pengfei

Differential Revision: https://reviews.llvm.org/D151610
2023-05-27 16:45:21 +08:00
M. Zeeshan Siddiqui
e621757365 [Clang][BFloat16] Upgrade __bf16 to arithmetic type, change mangling, and extend excess precision support
Pursuant to discussions at
https://discourse.llvm.org/t/rfc-c-23-p1467r9-extended-floating-point-types-and-standard-names/70033/22,
this commit enhances the handling of the __bf16 type in Clang.
- Firstly, it upgrades __bf16 from a storage-only type to an arithmetic
  type.
- Secondly, it changes the mangling of __bf16 to DF16b on all
  architectures except ARM. This change has been made in
  accordance with the finalization of the mangling for the
  std::bfloat16_t type, as discussed at
  https://github.com/itanium-cxx-abi/cxx-abi/pull/147.
- Finally, this commit extends the existing excess precision support to
  the __bf16 type. This applies to hardware architectures that do not
  natively support bfloat16 arithmetic.
Appropriate tests have been added to verify the effects of these
changes and ensure no regressions in other areas of the compiler.

Reviewed By: rjmccall, pengfei, zahiraam

Differential Revision: https://reviews.llvm.org/D150913
2023-05-27 13:33:50 +08:00
Aaron Ballman
09841d792f Add WG14 N2607 to the list of backported features
Arrays and their element types are identically qualified as of C2x,
and we support that behavior as far back as C89.

As a drive-by, this adds the paper number for designated initializers
so that all the WG14 features can be uniquely identified despite the
lack of a feature testing macro.
2023-05-22 08:16:32 -04:00
Jakub Mazurkiewicz
78d8312ace [Clang][clang-cl] Implement __builtin_FUNCSIG
This patch implements __builtin_FUNCSIG intrinsic which returns the same string as __FUNCSIG__.

Fixes https://github.com/llvm/llvm-project/issues/58951
Differential Revision: https://reviews.llvm.org/D150183
2023-05-19 12:02:44 -04:00
Kazu Hirata
2db0812882 [clang] Fix typos in documentation 2023-05-12 23:19:17 -07:00
jinge90
2ed77846a9 This patch adds doc for __builtin_flt_rounds and __builtin_set_flt_rounds
and also adds description for default fp environment.

Reviewed By:rjmccall, sepavloff
Differential Revision: https://reviews.llvm.org/D146188
2023-05-12 11:12:36 +08:00
Nikolas Klauser
b09fad7f8e [clang] Document extensions from later standards
Reviewed By: aaron.ballman

Spies: H-G-Hristov, cfe-commits

Differential Revision: https://reviews.llvm.org/D150321
2023-05-11 11:54:46 -07:00
Nikolas Klauser
e98776a180 [clang] Add __is_trivially_equality_comparable
This patch adds a new trait to allow standard libraries to forward `std::equal` calls to `memcmp` in more cases.

Reviewed By: aaron.ballman

Spies: Mordante, shafik, xbolva00, libcxx-commits, cfe-commits, ldionne

Differential Revision: https://reviews.llvm.org/D147175
2023-04-17 15:36:21 +02:00
Vlad Serebrennikov
467ed27987 [clang] Extend pragma dump to support expressions
Extend `#pragma clang __debug dump` to support not only single identifier, but an expression as well. This makes it possible to test ADL and overload resolution directly, without being creative to make them observable via diagnostics (e.g. when [[ http://eel.is/c++draft/over.match.best | over.match.best ]] is involved). This implementation has a known limitation of not supporting dependent expressions properly, but it's quite useful even without such support.

Differential Revision: https://reviews.llvm.org/D144115
2023-03-24 17:35:35 +03:00
Aaron Ballman
ef310c6d49 Fix Clang sphinx build
This addresses the issues found in:
https://lab.llvm.org/buildbot/#/builders/92/builds/41772
2023-03-24 07:27:07 -04:00
Bruno Cardoso Lopes
07ef7b1ff2 [Builtins] Add __builtin_assume_separate_storage
Plumbing from the language level to the assume intrinsics with
separate_storage operand bundles.

Patch by David Goldblatt (davidtgoldblatt)

Differential Revision: https://reviews.llvm.org/D136515
2023-03-23 16:35:30 -07:00
Ilya Karapsin
2147e940e8 Add __builtin_FILE_NAME()
Add '__builtin_FILE_NAME()', which expands to the filename because the
full path is not always needed. It corresponds to the '__FILE_NAME__'
predefined macro and is consistent with the other '__builin' functions
added for predefined macros.

Differential Revision: https://reviews.llvm.org/D144878
2023-03-17 09:52:41 -04:00
Joshua Batista
4c82050c56 Add codegen for llvm exp/exp2 elementwise builtins
Add codegen for llvm exp/exp2 elementwise builtin
The exp/exp2 elementwise builtins are 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.
The new builtins are restricted to floating point types only.

Reviewed By: fhahn

Differential Revision: https://reviews.llvm.org/D145270
2023-03-09 12:14:59 -08:00
Matt Arsenault
8709bcacfb clang: Add __builtin_elementwise_fma
I didn't understand why the other builtins have promotion logic,
or how it would apply for a ternary operation. Implicit conversions
are evil to begin with,  and even more so when the purpose is to get
an exact IR intrinsic. This checks all the arguments have the same type.
2023-02-24 21:55:08 -04:00
Fangrui Song
44b391fc47 LanguageExtensions.rst: fix a typo in the #pragma clang deprecated example 2023-02-24 12:41:49 -08:00
Nick Desaulniers
54186d33c3 [clang] add __has_extension(gnu_asm_goto_with_outputs_full)
Also move the line about __has_extension(gnu_asm_goto_with_outputs) so
that it is more generally about asm goto, not the paragraph on symbolic
references.

Reviewed By: efriedma, void

Differential Revision: https://reviews.llvm.org/D143205
2023-02-16 17:58:35 -08:00
Nick Desaulniers
329ef60f3e [Clang] support for outputs along indirect edges of asm goto
Initial support for asm goto w/ outputs (D69876) only supported outputs
along the "default" (aka "fallthrough") edge.

We can support outputs along all edges by repeating the same pattern of
stores along the indirect edges that we allready do for the default
edge.  One complication is that these indirect edges may be critical
edges which would need to be split. Another issue is that mid-codgen of
LLVM IR, the control flow graph might not reflect the control flow of
the final function.

To avoid this "chicken and the egg" problem assume that any given
indirect edge may become a critical edge, and pro-actively split it.
This is unnecessary if the edge does not become critical, but LLVM will
optimize such cases via tail duplication.

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

Reviewed By: void

Differential Revision: https://reviews.llvm.org/D136497
2023-02-16 17:58:34 -08:00
KAWASHIMA Takahiro
e8d44841c5 [docs] Update the ACLE URL 2023-02-14 19:14:04 +09:00
KAWASHIMA Takahiro
6240627cfd [docs] Fix bullet list formatting
reST requires an empty line before a bullet list.
2023-02-14 19:14:03 +09:00
Roy Jacobson
b6259eca16 [Clang] Export CanPassInRegisters as a type trait
While working on D140664, I thought it would be nice to be able to write tests
for parameter passing ABI. Currently we test this by dumping the AST and
matching the results which makes it hard to write new tests.
Adding this builtin will allow writing better ABI tests which
can help improve our coverage in this area.

While less useful, maybe some users would also find it useful for asserting
against pessimisations for their classes.

Reviewed By: erichkeane

Differential Revision: https://reviews.llvm.org/D141775
2023-02-13 19:16:23 +02:00
Joshua Batista
836249b1c2 Add codegen for llvm log2/log10 elementwise builtins
Add codegen for llvm log2 / log10 elementwise builtin
The log2/log10 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.
The new builtins are restricted to floating point types only.

Reviewed By: fhahn

Differential Revision: https://reviews.llvm.org/D143207
2023-02-07 12:23:48 -08:00
ManuelJBrito
450a4612c3 [Clang] Add builtin_nondeterministic_value
Differential Revision: https://reviews.llvm.org/D142388
2023-02-03 09:47:46 +00:00
Joshua Batista
26eb70820f Add builtin_elementwise_log
Add codegen for llvm log elementwise builtin
The log 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.
The new builtin is restricted to floating point types only.

Reviewed By: beanz

Differential Revision: https://reviews.llvm.org/D140489
2023-02-02 11:36:22 -08:00
Nico Weber
adf7ffd51e Revert "[Clang] Add builtin_nondeterministic_value"
This reverts commit 4a1832a5c801a61bf4c30891aaebe63993712fd9.
Test fail on (at least) macOS and Windows, see
https://reviews.llvm.org/D142388#4099441
2023-02-02 08:59:27 -05:00
ManuelJBrito
4a1832a5c8 [Clang] Add builtin_nondeterministic_value
Differential Revision: https://reviews.llvm.org/D142388
2023-02-02 11:14:17 +00:00
Aaron Ballman
9367bd0591 Improve example documentation for __builtin_offsetof; NFC
This implements some post-commit feedback from D142723
2023-01-30 14:54:59 -05:00
Aaron Ballman
63d6b8be6c Stop diagnosing member and array access in offsetof as an extension
This was a mistake from e7300e75b51a7e7d4e81975b4be7a6c65f9a8286
(https://reviews.llvm.org/D133574) caused by us accidentally tracking
an older copy of the C DR list for DR496. The text in
https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2396.htm#dr_496 makes
it clear that subobjects are allowed, which means member and array
access expressions are allowed.

This backs out the changes from the previous commit that relate to this
diagnostic.
2023-01-27 11:01:58 -05:00
Alexander Shaposhnikov
31b0be4eba [Clang] Add lifetimebound attribute to std::move/std::forward
Clang now automatically adds [[clang::lifetimebound]] to the parameters of
std::move, std::forward et al, this enables Clang to diagnose more cases
where the returned reference outlives the object.
Associated GitHub issue: https://github.com/llvm/llvm-project/issues/60020

Test plan: ninja check-clang check-all

Differential revision: https://reviews.llvm.org/D141744
2023-01-19 20:57:24 +00:00
Aaron Ballman
e7300e75b5 Diagnose extensions in 'offsetof'
https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2350.htm made very
clear that it is an UB having type definitions with in offsetof.
Clang supports defining a type as the first argument as a conforming
extension due to how many projects use the construct in C99 and earlier
to calculate the alignment of a type. GCC also supports defining a type
as the first argument.

This adds extension warnings and documentation for the functionality
Clang explicitly supports.

Fixes #57065
Reverts the revert of 39da55e8f548a11f7dadefa73ea73d809a5f1729

Co-authored-by: Yingchi Long <i@lyc.dev>
Co-authored-by: Aaron Ballman <aaron@aaronballman.com>

Differential Revision: https://reviews.llvm.org/D133574
2023-01-18 08:51:21 -05:00
Arthur Eubanks
39da55e8f5 Revert "Diagnose extensions in 'offsetof'"
This reverts commit f1f0a0d8e8fdd2e534d9423b2e64c6b8aaa53aee.

Causes crashes on

$ echo 'typedef int a; void c() { __builtin_offsetof(struct {a b}, b); }' | bin/clang -cc1 -emit-llvm -o /dev/null - -x c
2023-01-17 22:35:21 -08:00
Aaron Ballman
f1f0a0d8e8 Diagnose extensions in 'offsetof'
https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2350.htm made very
clear that it is an UB having type definitions with in offsetof.
Clang supports defining a type as the first argument as a conforming
extension due to how many projects use the construct in C99 and earlier
to calculate the alignment of a type. GCC also supports defining a type
as the first argument.

This adds extension warnings and documentation for the functionality
Clang explicitly supports.

Fixes #57065

Co-authored-by: Yingchi Long <i@lyc.dev>
Co-authored-by: Aaron Ballman <aaron@aaronballman.com>
2023-01-17 14:30:57 -05:00
Matt Arsenault
437346abe1 clang: Add __builtin_elementwise canonicalize and copysign
Just copy paste from the other functions. I also need fma, but
the current code seems to assume 1 or 2 arguments.
2022-12-21 18:01:42 -05:00
Aaron Ballman
e321c53f7b [C2x] Relaxing requirements for va_start
This implements WG14 N2975 relaxing requirements for va_start
(https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2975.pdf), which
does two things:

1) Allows the declaration of a variadic function without any named
arguments. e.g., void f(...) is now valid, as in C++.
2) Modified the signature of the va_start macro to be a variadic macro
that accepts one or more arguments; the second (and later) arguments
are not expanded or evaluated.

I followed the GCC implementation in terms of not modifying the
behavior of `__builtin_va_start` (it still requires exactly two
arguments), but this approach has led to several QoI issues that I've
documented with FIXME comments in the test. Specifically, the
requirement that we do not evaluate *or expand* the second and later
arguments means it's no longer possible to issue diagnostics for
compatibility with older C versions and C++. I am reaching out to
folks in WG14 to see if we can get an NB comment to address these
concerns (the US comment period has already closed, so I cannot file
the comment myself), so the diagnostic behavior may change in the
future.

I took this opportunity to add some documentation for all the related
builtins in this area, since there was no documentation for them yet.

Differential Revision: https://reviews.llvm.org/D139436
2022-12-08 07:36:07 -05:00
Joshua Batista
a5d14f757b Add builtin_elementwise_sin and builtin_elementwise_cos
Add codegen for llvm cos and sin elementwise builtins
The sin and cos elementwise builtins are 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.
The new builtins are restricted to floating point types only.

Reviewed By: craig.topper, fhahn

Differential Revision: https://reviews.llvm.org/D135011
2022-11-10 23:30:27 -08:00
Evgeny Shulgin
5b567637e2 [Clang] Add __has_constexpr_builtin support
The `__has_constexpr_builtin` macro can be used to check
whether the builtin in constant-evaluated by Clang frontend.

Reviewed By: aaron.ballman, shafik

Differential Revision: https://reviews.llvm.org/D136036
2022-10-21 11:23:10 +00:00
Aaron Ballman
2a1bd10a99 Fix the clang Sphinx build
This should address the issue found in:
https://lab.llvm.org/buildbot/#/builders/92/builds/34157
2022-10-13 16:04:25 -04:00
Bill Wendling
8c7b3461a5 [clang] Update ASM goto documentation to reflect how Clang differs from GCC
That said, we are planning to add this support in the near future.

Link: https://github.com/llvm/llvm-project/issues/53562

Differential Revision: https://reviews.llvm.org/D135818
2022-10-13 12:05:40 -07:00
Christopher Di Bella
14e64cb8d5 [clang] makes __is_destructible KEYALL instead of KEYMS
This makes it possible to be used in all modes, instead of just when
`-fms-extensions` is enabled. Also moves the `-fms-extensions`-exclusive
traits into their own file so we can check the others aren't dependent
on this flag.

This is information that the compiler already has, and should be exposed
so that the library doesn't need to reimplement the exact same
functionality.

This was originally a part of D116280.

Depends on D135177.

Differential Revision: https://reviews.llvm.org/D135339
2022-10-11 00:13:58 +00:00
Christopher Di Bella
a089defa24 [clang] adds __is_scoped_enum, __is_nullptr, and __is_referenceable
... as builtins.

This is information that the compiler already has, and should be exposed
so that the library doesn't need to reimplement the exact same
functionality.

This was originally a part of D116280.

Depends on D135175.

Differential Revision: https://reviews.llvm.org/D135177
2022-10-11 00:13:58 +00:00
Christopher Di Bella
bd3f48eefc [clang] adds __is_bounded_array and __is_unbounded_array as builtins
This is information that the compiler already has, and should be exposed
so that the library doesn't need to reimplement the exact same
functionality.

This was originally a part of D116280.

Differential Revision: https://reviews.llvm.org/D135175
2022-10-11 00:13:58 +00:00
Evgeny Shulgin
ec32386404 [Clang] Support constexpr builtin fmin
Support constexpr version of __builtin_fmin and its variations.

Reviewed By: jcranmer-intel

Differential Revision: https://reviews.llvm.org/D135493
2022-10-10 16:06:23 +00:00
Evgeny Shulgin
0edff6faa2 [Clang] Support constexpr builtin fmax
Support constexpr version of __builtin_fmax and its variations.

Reviewed By: jcranmer-intel

Differential Revision: https://reviews.llvm.org/D134369
2022-10-07 20:27:17 +00:00
Anastasia Stulova
db664a666c [Doc][OpenCL] Fixed typos in code examples 2022-09-22 17:46:47 +01:00
Joe Loser
cf77333da9 [clang][docs] Fix supported element types for __builtin_reduce_(add|mul)
The docs mention that `__builtin_reduce_add` and `__builtin_reduce_mul` support
both integer and floating point element types, but only integer element types
are actually supported. See https://github.com/llvm/llvm-project/issues/57847,
and specifically,
00874c48ea/clang/lib/Sema/SemaChecking.cpp (L2631) for the fact that floating point element types are not supported yet.

Fix the docs to only mention support for integer element types.
2022-09-22 07:52:22 -06:00