Commit Graph

96591 Commits

Author SHA1 Message Date
Xiang Li bad2e6c830 [HLSL] clang codeGen for HLSLNumThreadsAttr
Translate HLSLNumThreadsAttr into function attribute with name "dx.numthreads" and value format as "x,y,z".

Reviewed By: beanz

Differential Revision: https://reviews.llvm.org/D131799
2022-09-22 15:30:52 -07:00
Yaxun (Sam) Liu 5e25284dbc [AMDGPU] Emit module flag for all code object versions
Reviewed by: Changpeng Fang, Matt Arsenault, Brian Sumner

Differential Revision: https://reviews.llvm.org/D134355
2022-09-22 16:51:33 -04:00
Craig Topper 52708be182 [RISCV] Remove support for the unratified Zbe, Zbf, and Zbm extensions.
These extensions do not appear to be on their way to ratification.
2022-09-22 13:04:41 -07:00
Jan Svoboda 20fa87c7e8 [clang][modules][deps] Preserve module map load order
In `ASTWriter`, input files are sorted based on whether they are system or user. The current implementation used single `std::queue` with `push_back` and `push_front`. This resulted in the user files being reversed.

This patch fixes that by keeping the system/user distinction, but otherwise serializing files in the order they were loaded by the `SourceManager`. This is then used in the dependency scanner to report module map dependencies in the correct order.

Depends on D134224.

Reviewed By: Bigcheese

Differential Revision: https://reviews.llvm.org/D134248
2022-09-22 12:54:51 -07:00
Teresa Johnson a212d8da94 [MemProf] Memprof profile matching and annotation
Profile matching and IR annotation for memprof profiles.

See also related RFCs:
RFC: Sanitizer-based Heap Profiler [1]
RFC: A binary serialization format for MemProf [2]
RFC: IR metadata format for MemProf [3]*

* Note that the IR metadata format has changed from the RFC during
implementation, as described in the preceeding patch adding the basic
metadata and verification support.

The matching is performed during the normal PGO annotation phase, to
ensure that the inlines applied in the IR at that point are a subset
of the inlines in the profiled binary and thus reflected in the
profile's call stacks. This is important because the call frames are
associated with functions in the profile based on the inlining in the
symbolized call stacks, and this simplifies locating the subset of
profile data relevant for matching onto each function's IR.

The PGOInstrumentationUse pass is enhanced to perform matching for
whatever combination of memprof and regular PGO profile data exists in
the profile.

Using the utilities introduced in D128854:
The memprof profile data for each context is converted to "cold" or
"notcold" based on parameterized thresholds for size, access count, and
lifetime. The memprof allocation contexts are trimmed to the minimal
amount of context required to uniquely identify whether the context is
cold or not cold. For allocations where all profiled contexts have the
same allocation type, no memprof metadata is attached and instead the
allocation call is directly annotated with an attribute specifying the
alloction type. This is the same attributed that will be applied to
allocation calls once cloned for different contexts, and later used
during LibCall simplification to emit allocation hints [4].

Depends on D128141 and D128854.

[1] https://lists.llvm.org/pipermail/llvm-dev/2020-June/142744.html
[2] https://lists.llvm.org/pipermail/llvm-dev/2021-September/153007.html
[3] https://discourse.llvm.org/t/rfc-ir-metadata-format-for-memprof/59165
[4] ab87cf382d

Differential Revision: https://reviews.llvm.org/D128142
2022-09-22 12:48:31 -07:00
Jan Svoboda f35230ae0a [clang][modules][deps] Report modulemaps describing excluded headers
Module map files describing excluded headers do affect compilation. Track them in the compiler, serialize them into the PCM file and report them in the scanner.

Depends on D134222.

Reviewed By: Bigcheese

Differential Revision: https://reviews.llvm.org/D134224
2022-09-22 12:36:05 -07:00
Yitzhak Mandelbaum 0b12efc7a4 [clang][dataflow] Add support for nested method calls.
Extend the context-sensitive analysis to handle a call to a method (of the same
class) from within a method. That, is a member-call expression through `this`.

Differential Revision: https://reviews.llvm.org/D134432
2022-09-22 19:16:31 +00:00
Jan Svoboda 9dc0b16748 [clang][deps] Report module map describing compiled module
This patch fixes compilation failure with explicit modules caused by scanner not reporting the module map describing the module whose implementation is being compiled.

Below is a breakdown of the attached test case. Note the VFS that makes frameworks "A" and "B" share the same header "shared/H.h".

In non-modular build, Clang skips the last import, since the "shared/H.h" header has already been included.

During scan (or implicit build), the compiler handles "tu.m" as follows:
  * `@import B` imports module "B", as expected,
  * `#import <A/H.h>` is resolved textually (due to `-fmodule-name=A`) to "shared/H.h" (due to the VFS remapping),
  * `#import <B/H.h>` is resolved to import module "A_Private", since the header "shared/H.h" is already known to be part of that module, and the import is skipped.
In the end, the only modular dependency of the TU is "B".

In explicit modular build without `-fmodule-name=A`, TU does depend on module "A_Private" properly, not just textually. Clang therefore builds & loads its PCM, and knows to ignore the last import, since "shared/H.h" is known to be part of "A_Private".

But with current scanner behavior and `-fmodule-name=A` present, the last import fails during explicit build. Clang doesn't know about "A_Private" (it's included textually) and tries to import "B_Private" instead, which it doesn't know about either (the scanner correctly didn't report it as dependency). This is fixed by reporting the module map describing "A" and matching the semantics of implicit build.

Reviewed By: Bigcheese

Differential Revision: https://reviews.llvm.org/D134222
2022-09-22 12:06:02 -07:00
Xiang Li e3fd0b2073 [HLSL] Add resource binding attribute for HLSL.
The resource binding attribute is to set the virtual registers and logical register spaces resources in HLSL are bound to.
Format is ''register(ID,  space)'' like register(t3,  space1).
ID must be start with
t – for shader resource views (SRV),
s – for samplers,
u – for unordered access views (UAV),
b – for constant buffer views (CBV).

Register space is default to space0.

The full documentation is available here: https://docs.microsoft.com/en-us/windows/win32/direct3d12/resource-binding-in-hlsl

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D130033
2022-09-22 11:51:21 -07:00
Jonathan Camilleri 4cd7529e4c [clang][DebugInfo] Emit access specifiers for typedefs
The accessibility level of a typedef or using declaration in a
struct or class was being lost when producing debug information.

Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D134339
2022-09-22 17:08:41 +00:00
Aaron Ballman 9018fa1745 Update the C status page for WG14 N2359
We don't yet implement this paper, so this adds a basic test
demonstrating that.
2022-09-22 13:05:49 -04: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
Erich Keane babdef27c5 Re-apply "Deferred Concept Instantiation Implementation"
This reverts commit 95d94a6775.

This implements the deferred concepts instantiation, which should allow
the libstdc++ ranges to properly compile, and for the CRTP to work for
constrained functions.

Since the last attempt, this has fixed the issues from @wlei and
@mordante.

Differential Revision: https://reviews.llvm.org/D126907
2022-09-22 05:53:59 -07:00
Haojian Wu e0cdafe8d4 [AST] Better recovery on an expression refers to an invalid decl.
Prior to the patch, we didn't build a DeclRefExpr if the Decl being
referred to is invalid, because many clang downstream AST consumers
assume it, violating it will cause many diagnostic regressions.

With this patch, we build a DeclRefExpr enven for an invalid decl (when the
AcceptInvalidDecl is true), and wrap it with a dependent-type
RecoveryExpr (to prevent follow-up semantic analysis, and diagnostic
regressions).

This is a revised version of https://reviews.llvm.org/D76831

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D121599
2022-09-22 14:23:47 +02:00
serge-sans-paille dad36245a5 [clang] Rework IsTailPaddedMemberArray into isFlexibleArrayMemberExpr
This fixes a bunch of FIXME within IsTailPaddedMemberArray related code.

As a side effect, this now also triggers a warning when trying to access a
"struct hack" member with an index above address space index range.

Differential Revision: https://reviews.llvm.org/D133108
2022-09-22 14:04:35 +02:00
Tim Northover 677da09d02 AArch64: add support for newer Apple CPUs
They're roughly ARMv8.6. This works in the .td file, but in
AArch64TargetParser.def, marking them v8.6 brings in support for the SM4
cryptographic hash and we don't actually have that. So TargetParser side
they're marked as v8.5, with the extra features (BF16 and I8MM added manually).

Finally, A16 supports the HCX extension in addition to v8.6. This has no
TargetParser implications.
2022-09-22 11:58:51 +01:00
serge-sans-paille d442040292 [clang] Fix interaction between asm labels and inline builtins
One must pick the same name as the one referenced in CodeGenFunction when
generating .inline version of an inline builtin, otherwise they are not
correctly replaced.

Differential Revision: https://reviews.llvm.org/D134362
2022-09-22 09:24:47 +02:00
Craig Topper 182aa0cbe0 [RISCV] Remove support for the unratified Zbp extension.
This extension does not appear to be on its way to ratification.

Still need some follow up to simplify the RISCVISD nodes.
2022-09-21 21:22:42 -07:00
Chuanqi Xu 327141fb1d [C++] [Coroutines] Prefer aligned (de)allocation for coroutines -
implement the option2 of P2014R0

This implements the option2 of
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p2014r0.pdf.

This also fixes https://github.com/llvm/llvm-project/issues/56671.

Although wg21 didn't get consensus for the direction of the problem,
we're happy to have some implementation and user experience first. And
from issue56671, the option2 should be the pursued one.

Reviewed By: ychen

Differential Revision: https://reviews.llvm.org/D133341
2022-09-22 11:28:29 +08:00
Corentin Jabot c932cef32a Update Unicode to 15.0
Unicode 15.0 adds 4,489 characters, for a total of 149,186 characters.
These additions include 2 new scripts along with 20 new emoji characters,
and 4,193 CJK ideographs.

This changes modify most existing tables including
 - XID_Start/XID_Continue in Clang
 - The character name database (used by \N{} in Clang)
 - The list of formattable/printable codepoints
 - The case folding algorithm (which we had not updated since Unicode 9)
 - The list of nonspacing/enclosing marks used by the column width
   computation algorithm. The rest of the column width algorithm
   is not updated.

Reviewed By: tahonermann

Differential Revision: https://reviews.llvm.org/D133807
2022-09-22 05:03:01 +02:00
Jan Korous 85d97aac80 [analyzer] Support implicit parameter 'self' in path note
showBRParamDiagnostics assumed stores happen only via function parameters while that
can also happen via implicit parameters like 'self' or 'this'.
The regression test caused a failed assert in the original cast to ParmVarDecl.

Differential Revision: https://reviews.llvm.org/D133815
2022-09-21 17:26:09 -07:00
Fangrui Song 8edeedfb21 [test] Fix CodeGen/arm-crc32.c to not write an output to CWD
CWD may be read-only in some testing environments.
2022-09-21 16:13:25 -07:00
Michael Wyman aa4bcaab96 Remove the unused/undefined `_cmd` parameter in `objc_direct` methods.
When `objc_direct` methods were implemented, the implicit `_cmd` parameter was left as an argument to the method implementation function, but was unset by callers; if the method body referenced the `_cmd` variable, a selector load would be emitted inside the body. However, this leaves an unused argument in the ABI, and is unnecessary.

This change removes the empty/unset argument, and if `_cmd` is referenced inside an `objc_direct` method it will emit local storage for the implicit variable. From the ABI perspective, `objc_direct` methods will have the implicit `self` parameter, immediately followed by whatever explicit arguments are defined on the method, rather than having one unset/undefined register in the middle.

Differential Revision: https://reviews.llvm.org/D131424
2022-09-21 15:37:48 -07:00
Fangrui Song 23e4299261 [Driver] Add --gcc-install-dir=
This option specifies a GCC installation directory such as
/usr/lib/gcc/x86_64-linux-gnu/12, /usr/lib/gcc/x86_64-gentoo-linux-musl/11.2.0 .

It is intended to replace --gcc-toolchain=, which specifies a directory where
`lib/gcc{,-cross}` can be found. When --gcc-toolchain= is specified, the
selected `lib/gcc/$triple/$version` installation uses complex logic and the
largest GCC version is picked. There is no way to specify another version in the
presence of multiple GCC versions.

D25661 added gcc-config detection for Gentoo: `ScanGentooConfigs`.
The implementation may be simplified by using --gcc-install-dir=.

Reviewed By: mgorny

Differential Revision: https://reviews.llvm.org/D133329
2022-09-21 14:11:15 -07:00
owenca e347c0fc9b [clang-format][NFC] Reformat the clang/unittests/Format directory
Also add a .clang-format file to clang/include/clang/Format and
clang/unittests/Format to keep the directories formatted.
2022-09-21 13:26:59 -07:00
Evgeny Shulgin 3285f9a239 [Clang] Support case and default labels at end of compound statement
Direct continuation of https://reviews.llvm.org/D133887

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

Differential Revision: https://reviews.llvm.org/D134207
2022-09-21 19:37:22 +00:00
Aaron Ballman b63b4d8966 Add tests & update the C99 DR statuses for dr315 and dr316 2022-09-21 15:33:03 -04:00
Xiang Li 52d7ce0cc1 [HLSL] Allow SV_GroupIndex for lib profile.
Lib profile could include all kind of entry functions.

Reviewed By: beanz

Differential Revision: https://reviews.llvm.org/D134326
2022-09-21 12:29:58 -07:00
owenca 3d62139862 [clang-format][NFC] Reformat clang/lib/Format using 6257832bf9
Fix braces and add .clang-format to keep the directory formatted.

Differential Revision: https://reviews.llvm.org/D134329
2022-09-21 12:02:49 -07:00
Aaron Ballman 1ae5310ebb Changing some strange code into an assert; NFC
This code was added in b65b1f322b, but it
was not noticed that the [[fallthrough]] behavior was very wrong. In C
mode, we would set the ParenExprType to CompoundLiteral and then
promptly overwrite that information by falling through.

After some investigation, I convinced myself that it is not possible to
hit this code path in C, only in C++. I've switched it to be an
assertion; I don't expect to hit it, but if we do hit it, that will at
least give us a code example we can use to reason about the intent of
the original code.
2022-09-21 14:59:51 -04:00
Fangrui Song efd97c716b [libclang] Fix -Wswitch after D129883 2022-09-21 11:55:14 -07:00
Fangrui Song 069ecd0c6e [ARM] Check target feature support for __builtin_arm_crc*
`__builtin_arm_crc*` requires the target feature crc which is available on armv8
and above. Calling the fuctions for armv7 leads to a SelectionDAG crash.

```
% clang -c --target=armv7-unknown-linux-gnueabi -c a.c
fatal error: error in backend: Cannot select: intrinsic %llvm.arm.crc32b
PLEASE submit a bug report to ...
```

Add `TARGET_BUILTIN` and define required features for these builtins to
report an error in `CodeGenFunction::checkTargetFeatures`. The problem is quite widespread.
I will add `TARGET_BUILTIN` for more builtins later.

Fix https://github.com/llvm/llvm-project/issues/57802

Differential Revision: https://reviews.llvm.org/D134127
2022-09-21 11:50:15 -07:00
Xiang Li a7e3de2450 [NFC] Fix build error ignored by MSVC. 2022-09-21 10:57:43 -07:00
Xiang Li 782ac2182c [HLSL] Support cbuffer/tbuffer for hlsl.
This is first part for support cbuffer/tbuffer.

The format for cbuffer/tbuffer is
BufferType [Name] [: register(b#)] { VariableDeclaration [: packoffset(c#.xyzw)]; ... };

More details at https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-constants

New keyword 'cbuffer' and 'tbuffer' are added.
New AST node HLSLBufferDecl is added.
Build AST for simple cbuffer/tbuffer without attribute support.

The special thing is variables declared inside cbuffer is exposed into global scope.
So isTransparentContext should return true for HLSLBuffer.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D129883
2022-09-21 10:07:43 -07:00
Akira Hatanaka adaf62ced2 [Sema] Reject array element types whose sizes aren't a multiple of their
alignments

In the following code, the first element is aligned on a 16-byte
boundary, but the remaining elements aren't:

```
typedef char int8_a16 __attribute__((aligned(16)));
int8_a16 array[4];
```

Currently clang doesn't reject the code, but it should since it can
cause crashes at runtime. This patch also fixes assertion failures in
CodeGen caused by the changes in https://reviews.llvm.org/D123649.

Differential Revision: https://reviews.llvm.org/D133711
2022-09-21 09:15:03 -07:00
Joel E. Denny 28412d1800 [lit] Implement DEFINE and REDEFINE directives
These directives define per-test lit substitutions.  The concept was
discussed at
<https://discourse.llvm.org/t/iterating-lit-run-lines/62596/10>.

For example, the following directives can be inserted into a test file
to define `%{cflags}` and `%{fcflags}` substitutions with empty
initial values, which serve as the parameters of another newly defined
`%{check}` substitution:

```
// DEFINE: %{cflags} =
// DEFINE: %{fcflags} =

// DEFINE: %{check} = %clang_cc1 %{cflags} -emit-llvm -o - %s | \
// DEFINE:            FileCheck %{fcflags} %s
```

The following directives then redefine the parameters before each use
of `%{check}`:

```
// REDEFINE: %{cflags} = -foo
// REDEFINE: %{fcflags} = -check-prefix=FOO
// RUN: %{check}

// REDEFINE: %{cflags} = -bar
// REDEFINE: %{fcflags} = -check-prefix=BAR
// RUN: %{check}
```

Of course, `%{check}` would typically be more elaborate, increasing
the benefit of the reuse.

One issue is that the strings `DEFINE:` and `REDEFINE:` already appear
in 5 tests.  This patch adjusts those tests not to use those strings.
Our prediction is that, in the vast majority of cases, if a test
author mistakenly uses one of those strings for another purpose, the
text appearing after the string will not happen to have the syntax
required for these directives.  Thus, the test author will discover
the mistake immediately when lit reports the syntax error.

This patch also expands the documentation on existing lit substitution
behavior.

Reviewed By: jhenderson, MaskRay, awarzynski

Differential Revision: https://reviews.llvm.org/D132513
2022-09-21 11:32:05 -04:00
Chris Bieneman bc97751a23 [NFC] Add GitHub issues to HLSL FIXME comments
In order to make this easier to track I've filed issues for each of the
HLSL FIXME comments that I can find. I may have missed some, but I want
this to be the new default mode.
2022-09-21 10:31:25 -05:00
Anders Langlands bc14ed7de0 Add clang_CXXMethod_isDeleted function
Adds a function to check if a method has been deleted by copy-pasting
the existing implementation of clang_CXXMethod_isDefaulted and changing
it to call CXXMethod::isDeleted() instead.

Differential Revision: https://reviews.llvm.org/D133924
2022-09-21 11:12:48 -04:00
zhijian d47f0be0e8 [AIX] change "llvm-nm" to "env OBJECT_MODE=any llvm-nm" in clang/test for AIX OS
Summary:
   since default object mode of llvm-nm is change to -X32 (from default -Xany) in patch https://reviews.llvm.org/D132494.In order not effect the test cases in clang/test we need to change "llvm-nm" to "env OBJECT_MODE=any llvm-nm" in clang/test for AIX OS

Reviewers: James Henderson,David Tenty, Hubert Tong
Differential Revision: https://reviews.llvm.org/D134284
2022-09-21 09:38:13 -04:00
Matheus Izvekov ef4bbfe338
[clang] AST: SubstTemplateTypeParmType support for non-canonical underlying type
This change allows us to represent in the AST some specific
circumstances where we substitute a template parameter type
which is part of the underlying type of a previous substitution.

This presently happens in some circumstances dealing with
substitution of defaulted parameters of template template
parameters, and in some other cases during concepts substitution.

The main motivation for this change is for the future use in the
implementation of template specialization resugaring, as this will
allow us to represent a substitution with sugared types.

Signed-off-by: Matheus Izvekov <mizvekov@gmail.com>

Differential Revision: https://reviews.llvm.org/D132816
2022-09-21 14:22:19 +02:00
Michał Górny 8a774c35e9 [clang] [Driver] Support multiple configuration files
Support specifying multiple configuration files via multiple `--config`
options.  When multiple files are specified, the options from subsequent
files are appended to the options from the initial file.

While at it, remove the incorrect assertion about CfgFileName being
non-empty.  It can be empty if `--config ""` is passed, and it makes
sense to report it as non-existing file rather than crash.

Differential Revision: https://reviews.llvm.org/D134270
2022-09-21 13:14:36 +02:00
Wei Yi Tee 94747094c7 [clang][dataflow] Remove deprecated `transfer(const Stmt *, ...)` API.
Reviewed By: gribozavr2

Differential Revision: https://reviews.llvm.org/D134318
2022-09-21 11:06:21 +00:00
Wei Yi Tee 003566cb1f [clang][dataflow] Remove deprecated overloads of `checkDataflow` in `TestingSupport.h`.
Reviewed By: gribozavr2

Differential Revision: https://reviews.llvm.org/D134081
2022-09-21 10:36:44 +00:00
Michał Górny 3db2917e27 [clang] [docs] Improve formatting & fix typo in config docs
Fix teletype formatting in configuration file documentation to use
double backticks rather than single backticks.  Cover some more names
with this formatting.  Correct the name of config file for `clang-cl`
invocation.

Differential Revision: https://reviews.llvm.org/D134271
2022-09-21 07:26:56 +02:00
Jennifer Yu 48ffd40ba2 [Clang][OpenMP] Codegen generation for has_device_addr claues.
This patch add codegen support for the has_device_addr clause. It use
the same logic of is_device_ptr. But passing &var instead pointer to var
to kernal.

Differential Revision: https://reviews.llvm.org/D134268
2022-09-20 21:12:30 -07:00
Craig Topper 70a64fe7b1 [RISCV] Remove support for the unratified Zbt extension.
This extension does not appear to be on its way to ratification.

Out of the unratified bitmanip extensions, this one had the
largest impact on the compiler.

Posting this patch to start a discussion about whether we should
remove these extensions. We'll talk more at the RISC-V sync meeting this
Thursday.

Reviewed By: asb, reames

Differential Revision: https://reviews.llvm.org/D133834
2022-09-20 20:26:48 -07:00
Fangrui Song 669e508772 [Driver] Fix -f[no-]unwind-tables -Wunused-command-line-argument after 4388b56d52 2022-09-20 20:13:30 -07:00
Volodymyr Sapsai e12f6c26c3 [modules] Fix error "malformed or corrupted AST file: 'SourceLocation remap refers to unknown module...'".
When a framework can be found at a new location, all references to it in
the module cache become outdated. When we try to load such outdated .pcm
file, we shouldn't change any already loaded and processed modules.

If `Module` has `ASTFile`, it means we've read its AST block already and
it is too late to undo that. If `ASTFile` is `None`, there is no value
in setting it to `None` again. So we don't reset `ASTFile` in
`ModuleManager::removeModules` at all.

rdar://97216258

Differential Revision: https://reviews.llvm.org/D134249
2022-09-20 17:55:37 -07:00
Kazu Hirata 7a239200e6 [clang] Fix an unused variable warning
This patch fixes:

  clang/lib/Driver/ToolChains/PS4CPU.cpp:159:14: error: unused
  variable 'IsPS5' [-Werror,-Wunused-variable]
2022-09-20 17:41:58 -07:00
Matheus Izvekov c493d49cef
[clang] Fix missing template arguments in AST of access to member variable template
Signed-off-by: Matheus Izvekov <mizvekov@gmail.com>

Differential Revision: https://reviews.llvm.org/D134295
2022-09-21 00:46:18 +02:00
Xiang Li 079a5ffb0a [HLSL] Support PCH for cc1 mode
Add HLSLExternalSemaSource as ExternalSemaSource instead of ASTContext::ExternalSource when PCH is included.

This allows a different external source to be set for the AST context.

Reviewed By: beanz

Differential Revision: https://reviews.llvm.org/D132421
2022-09-20 15:13:43 -07:00
Matthew Voss 45c7da241f [PS4] Always enable the .debug_aranges section when using LTO
This flag enables the .debug_aranges section by passing a flag to LLD
and our internal linker. This also adds a new routine that will generate
the correct flag for our internal linker or set of flags for LLD when
given a list of LLVM options. That ensures multiple LLVM codegen options
can be passed to either linker consistently.

Differential Revision: https://reviews.llvm.org/D134296
2022-09-20 14:44:56 -07:00
Joshua Batista d76c654d02 [HLSL] remove unnecessary abs attributes
remove abs non-elementwise attribute statements, stick to elementwise.

Reviewed By: beanz

Differential Revision: https://reviews.llvm.org/D134312
2022-09-20 16:04:21 -05:00
Joshua Batista b95c57444a [HLSL] add sqrt library function
This change exposes the sqrt library function for HLSL scalar types,
excluding long and long long doubles. Sqrt is supported for all scalar, vector,
and matrix types. This patch only adds a subset of scalar type support.

Long and long long double support is missing in this patch because that type
doesn't exist in HLSL.

The full documentation of the HLSL asin function is available here:
https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-sqrt

Reviewed By: beanz

Differential Revision: https://reviews.llvm.org/D132711
2022-09-20 15:42:08 -05:00
Craig Topper 549231d38e [RISCV] Support -mno-implicit-float.
This can be used to disable vectorization and memcpy/memset
expansion for things like OS kernels. It also disables implicit
uses of scalar FP, but I don't know if we have any of those for
RISC-V.

NOTE: Without this patch you can still do -Xclang -no-implicit-float

Reviewed By: rui.zhang

Differential Revision: https://reviews.llvm.org/D134077
2022-09-20 13:32:40 -07:00
owenca 6257832bf9 [clang-format] Wrap inserted braces only if preceded by comments
Fixes #57805.

Differential Revision: https://reviews.llvm.org/D134233
2022-09-20 12:09:39 -07:00
Douglas Yung f2949febf3 Add explicit tests for the PS4/PS5 C/C++ standards version defaults. 2022-09-20 11:31:38 -07:00
Alex Brachet 16f735d2fb [Driver] Make --execute-only the default for aarch64-fuchsia
Clang already generates code that doesn't use writeable data in executable
sections so the linker flag is all that is necessary.

-Wl,--no-execute-only can be used to turn this default off.

Differential Revision: https://reviews.llvm.org/D134289
2022-09-20 18:25:16 +00:00
Philip Reames eda2af575f [RISCV][MC] Add support for experimental Zawrs extension
This implements experimental support for the Zawrs extension as specified here: https://github.com/riscv/riscv-zawrs/releases/download/V1.0-rc3/Zawrs.pdf. Despite the 1.0 version name, this has not been ratified and there was a major change to proposed specification between rc2 and rc3.  Once this is ratified, it'll move out of experimental status.

This change adds assembly support, but does not include C language or IR intrinsics. We can decide if we want them, and handle that in a separate patch.

Differential Revision: https://reviews.llvm.org/D133443
2022-09-20 10:15:11 -07:00
Mingming Liu ce7b4747e8 [AArch64] Define __ARM_FEATURE_RCPC
This patch implements the definition of __ARM_FEATURE_RCPC when clang
command specifies +rcpc.

Differential Revision: https://reviews.llvm.org/D127798
2022-09-20 10:03:13 -07:00
yronglin 8392f1cc78 Fix __builtin_assume_aligned incorrect type descriptor and C++ object polymorphic address
Fix __builtin_assume_aligned incorrect type descriptor

example from @rsmith

struct A { int n; };
struct B { int n; };
struct C : A, B {};

void *f(C *c) {
  // Incorrectly returns `c` rather than the address of the B base class.
  return __builtin_assume_aligned((B*)c, 8);
}

Differential Revision: https://reviews.llvm.org/D133583
2022-09-20 12:35:18 -04:00
Chris Bieneman 0c89b34337 [HLSL] Pass flags to cc1 based on language
Having the flags only pass through if you're using the dxc-driver means
that the clang driver doesn't work for HLSL, which is undesirable. This
change switches to instead passing flags based on the language mode
similar to how OpenCL does it. This allows the clang driver to be used
for HLSL source files as well.

Reviewed By: python3kgae

Differential Revision: https://reviews.llvm.org/D133958
2022-09-20 10:56:17 -05:00
Chris Bieneman 8aed4bb278 [CMake] [NFC] Add clang headers to IDE projects
This just adds the clang headers into a source group so that they get
collected and added into generated IDE projects.
2022-09-20 10:41:27 -05:00
Tim Northover 58f9abaed4 AAArch64: disable asynchronous unwind by default for MachO.
AArch64 MachO has a compact unwind format where most functions' unwind info can
be represented in just 4 bytes. But this cannot represent any asynchronous CFI
function, so it's essentially disabled when that's used. This is a large
code-size hit that we'd rather not take unless explicitly requested.
2022-09-20 10:47:18 +01:00
Tim Northover 4388b56d52 Refactor unwind table driver interface to expose default level. NFC. 2022-09-20 10:47:18 +01:00
Dmitry Polukhin 41dbee1e66 [clang] Update ReleaseNotes about a crash fix (Issue 53628)
Update ReleaseNotes about a crash fix (Issue 53628)

Test Plan: none

Differential Revision: https://reviews.llvm.org/D134112
2022-09-20 02:05:36 -07:00
Michał Górny a7d2409bac [clang] [Driver] Do not transform explicit --config filename
Disable transformations (e.g. attempting to replace target architecture)
in the config filename that is passed explicitly via `--config`.  This
behavior is surprising and confusing -- if user passes an explicit
config filename, Clang should use it as is.  The transformations are
still applied when the name is deduced from filename.

Update the tests accordingly.  This primarily ensures that full filename
with .cfg suffix is passed to --config (appending `.cfg` implicitly is
not documented, and would collide with use of filenames with other
suffixes).  The config-file2.c suite is removed entirely as it tested
the transformations on the argument to --config.  However, the aspects
of that that were not tested as part of config-file3.c are now added
there (based on config filename deduced from executable).

This change streamlines the code in Driver::loadConfigFile(), opening
the possibility of further changes, including support for handling
multiple --config options and refactoring of filename deduction.

Differential Revision: https://reviews.llvm.org/D134208
2022-09-20 07:58:27 +02:00
Ron Lieberman d5b5289561 revert 684f76643 [Clang][OpenMP] Codegen generation for has_device_addr claues.
breaks amdgpu buildbot
2022-09-20 01:37:27 +00:00
Phoebe Wang 46bb4b99ae [X86][fastcall][vectorcall] Move capability check before free register update
When passing arguments with `__fastcall` or `__vectorcall` in 32-bit MSVC, the following arguments have chance to be passed by register if the current one failed. `__regcall` from ICC is on the contrary: https://godbolt.org/z/4MPbzhaMG
All the three calling conversions are not supported in GCC.

Fixes: #57737

Reviewed By: rnk

Differential Revision: https://reviews.llvm.org/D133920
2022-09-20 09:18:23 +08:00
Jennifer Yu 684f766431 [Clang][OpenMP] Codegen generation for has_device_addr claues.
Summary: This patch add codegen support for the has_device_addr clause.  It
use the same logic of is_device_ptr.

Differential Revision: https://reviews.llvm.org/D134186
2022-09-19 16:14:57 -07:00
owenca 7349084e7a [clang-format] Update removed brace's next token's WhitespaceRange
Fixes #57803.

Differential Revision: https://reviews.llvm.org/D134146
2022-09-19 15:02:08 -07:00
Roy Jacobson 368b6832de [Clang] Implement fix for DR2628
Implement suggested fix for [[ https://cplusplus.github.io/CWG/issues/2628.html | DR2628. ]] Couldn't update the DR docs because there hasn't been a DR index since it was filed, but the tests still run in CI.

Note: I only transfer the constructor constraints, not the struct constraints. I think that's OK because the struct constraints are the same
for all constructors so they don't affect the overload resolution, and if they deduce to something that doesn't pass the constraints
we catch it anyway. So (hopefully) that should be more efficient without sacrificing correctness.

Closes:
https://github.com/llvm/llvm-project/issues/57646
https://github.com/llvm/llvm-project/issues/43829

Reviewed By: erichkeane

Differential Revision: https://reviews.llvm.org/D134145
2022-09-20 00:07:41 +03:00
David Majnemer 955d7c39ff [clang] Add support for #pragma strict_gs_check 2022-09-19 20:07:14 +00:00
Joseph Huber b647f13226 [CUDA][HIP] Fix new driver crashing when using -save-temps in RDC-mode
Previously when using the `clang-offload-packager` we did not pass the
active offloading kinds. Then in Clang when we attempted to detect when
there was host-offloading action that needed to be embedded in the host
we did not find it. This patch adds the active offloading kinds so we
know when there is input to be embedded.

Reviewed By: tra

Differential Revision: https://reviews.llvm.org/D134189
2022-09-19 14:38:44 -05:00
Wei Yi Tee 88210b81ee [clang][dataflow] Refactor `clang/Analysis/FlowSensitive/MatchSwitchTest.cpp`.
- Remove use of `runDataflowAnalysis` to keep test isolated.
- Add test for `ASTMatchSwitch<CXXCtorInitializer, ...>`.

Reviewed By: gribozavr2, sgatev

Differential Revision: https://reviews.llvm.org/D133935
2022-09-19 19:10:41 +00:00
Wei Yi Tee 41d52c5a7f [clang][dataflow] Modify `transfer` in `DataflowModel` to take `CFGElement` as input instead of `Stmt`.
To keep API of transfer functions consistent.

The single use of this transfer function in `ChromiumCheckModel` is also updated.

Reviewed By: gribozavr2, sgatev

Differential Revision: https://reviews.llvm.org/D133933
2022-09-19 18:40:29 +00:00
Wei Yi Tee cf94c52e35 [clang][dataflow] Replace `transfer(const Stmt *, ...)` with `transfer(const CFGElement *, ...)` in `clang/Analysis/FlowSensitive`.
Reviewed By: gribozavr2, sgatev

Differential Revision: https://reviews.llvm.org/D133931
2022-09-19 18:06:57 +00:00
Wei Yi Tee 7538b36045 [clang][dataflow] Replace usage of deprecated functions with the optional check
- Update `transfer` and `diagnose` to take `const CFGElement *` as input in `Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel`.
- Update `clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.cpp` accordingly.
- Rename `runDataflowAnalysisOnCFG` to `runDataflowAnalysis` and remove the deprecated `runDataflowAnalysis` (this was only used by the now updated optional check).

Reviewed By: gribozavr2, sgatev

Differential Revision: https://reviews.llvm.org/D133930
2022-09-19 17:33:25 +00:00
Haojian Wu e782d9a4a4 [clang] Fix a nullptr-access crash in CheckTemplateArgument.
It is possible that we can pass a null ParamType to
CheckNonTypeTemplateParameter -- the ParamType var can be reset to a null
type on Line 6940, and the followed bailout if is not entered.

Differential Revision: https://reviews.llvm.org/D134180
2022-09-19 19:18:50 +02:00
Michał Górny daebf2c13c [clang] Make config-related options CoreOptions
Make `--config`, `--no-default-config` and `--config-*-dir` CoreOptions
to enable their availability to all clang driver modes.  This improves
consistency given that the default set of configuration files is
processed independently of mode anyway.

Differential Revision: https://reviews.llvm.org/D134191
2022-09-19 18:58:09 +02:00
mydeveloperday 95b3947111 [clang-format] JSON formatting add new option for controlling newlines in json arrays
Working in a mixed environment of both vscode/vim with a team configured prettier configuration, this can leave clang-format and prettier fighting each other over the formatting of arrays, both simple arrays of elements.

This review aims to add some "control knobs" to the Json formatting in clang-format to help align the two tools so they can be used interchangeably.

This will allow simply arrays `[1, 2, 3]` to remain on a single line but will break those arrays based on context within that array.

Happy to change the name of the option (this is the third name I tried)

Reviewed By: HazardyKnusperkeks, owenpan

Differential Revision: https://reviews.llvm.org/D133589
2022-09-19 17:54:39 +01:00
Xiang Li 649a59712f [clang] Allow vector of BitInt
Remove check which disable BitInt as element type for ext_vector.

Enabling it for HLSL to use _BitInt(16) as 16bit int at https://reviews.llvm.org/D133668

Reviewed By: erichkeane

Differential Revision: https://reviews.llvm.org/D133634
2022-09-19 09:26:56 -07:00
Aaron Ballman a244194f73 Add additional test coverage for C2x N2508
This spotted a mistake with the original patch, so it puts the status
back to "partial" in the C status tracking page.

This amends 510383626f.
2022-09-19 07:52:07 -04:00
Aaron Ballman f51789ce5e Fix a typo in the release notes; NFC 2022-09-19 07:37:41 -04:00
Kazu Hirata 981cbfb592 [clang] Don't include StringSwitch.h (NFC)
These files don't seem to use StringSwitch.
2022-09-18 22:21:32 -07:00
Weining Lu 7d88a05cc0 [Clang][LoongArch] Implement ABI lowering
Reuse most of RISCV's implementation with several exceptions:

1. Assign signext/zeroext attribute to args passed in stack.
On RISCV, integer scalars passed in registers have signext/zeroext
when promoted, but are anyext if passed on the stack. This is defined
in early RISCV ABI specification. But after this change [1], integers
should also be signext/zeroext if passed on the stack. So I think
RISCV's ABI lowering should be updated [2].

While in LoongArch ABI spec, we can see that integer scalars narrower
than GRLEN bits are zero/sign-extended no matter passed in registers
or on the stack.

2. Zero-width bit fields are ignored.
This matches GCC's behavior but it hasn't been documented in ABI sepc.
See https://gcc.gnu.org/r12-8294.

3. `char` is signed by default.
There is another difference worth mentioning is that `char` is signed
by default on LoongArch while it is unsigned on RISCV.

This patch also adds `_BitInt` type support to LoongArch and handle it
in LoongArchABIInfo::classifyArgumentType.

[1] cec39a064e
[2] https://github.com/llvm/llvm-project/issues/57261

Differential Revision: https://reviews.llvm.org/D132285
2022-09-19 12:05:00 +08:00
Chuanqi Xu b76da14b3b [C++] [Modules] Generate the initializer for modules if we compile a
module unit directly

Previously we lack a test which ensures that the module unit will
generate initializer if it is compiled directly (instead of from a pcm
file). Now we add the test back.
2022-09-19 11:30:34 +08:00
wanglian 5ed25e4df6 [CUDA][NFC] Rename 'addDeviceDepences' to 'addDeviceDependences' in DeviceActionBuilder.
Reviewed By: tra

Differential Revision: https://reviews.llvm.org/D134007
2022-09-19 10:43:09 +08:00
Chuanqi Xu 298d08dfa5 [NFC] Move the position of CodeGen/module-initializer*.cpp
Previsouly the module-initializer*.cpp lives in the CodeGen dir instead
of CodeGenCXX dir, which is not consistency with other tests since
modules are features for C++.
2022-09-19 10:36:28 +08:00
Emilia Dreamer 8dab452740
[clang-format] Disallow requires clauses to become function declarations
There already exists logic to disallow requires *expressions* to be
treated as function declarations, but this expands it to include
requires *clauses*, when they happen to also be parenthesized.

Previously, in the following case:

```
template <typename T>
  requires(Foo<T>)
T foo();
```

The line with the requires clause was actually being considered as the
line with the function declaration due to the parentheses, and the
*real* function declaration on the next line became a trailing
annotation

(Together with https://reviews.llvm.org/D134049) Fixes https://github.com/llvm/llvm-project/issues/56213

Reviewed By: HazardyKnusperkeks, owenpan

Differential Revision: https://reviews.llvm.org/D134052
2022-09-19 04:04:31 +03:00
Emilia Dreamer 0bf63f0d1b
[clang-format] Disallow trailing return arrows to be operators
In the following construction:
`template <typename T> requires Foo<T> || Bar<T> auto func() -> int;`

The `->` of the trailing return type was actually considered as an
operator as part of the binary operation in the requires clause, with
the precedence level of `PrecedenceArrowAndPeriod`, leading to fake
parens being inserted in strange locations, that would never be closed.

Fixes one part of https://github.com/llvm/llvm-project/issues/56213
(the rest will probably be in a separate patch)

Reviewed By: HazardyKnusperkeks, owenpan

Differential Revision: https://reviews.llvm.org/D134049
2022-09-19 04:04:31 +03:00
Xiang Li edbf36c5e9 [HLSL] [clang] Add vector version of abs for HLSL
Add vector version of abs as
```
__attribute__((clang_builtin_alias(__builtin_elementwise_abs)))
int2 abs (int2 );
__attribute__((clang_builtin_alias(__builtin_elementwise_abs)))
int3 abs (int3 );
```
To make this work.
Allowed custom type checking builtins to be recelareable.

Reviewed By: RKSimon

Differential Revision: https://reviews.llvm.org/D133737
2022-09-18 14:59:30 -07:00
Shafik Yaghmour f8a37a6ce6 [Clang] Fix compat diagnostic to detect a nontype template parameter has a placeholder type using getContainedAutoType()
Based on the changes introduced by 15361a21e0 it
looks like C++17 compatibility diagnostic should have been checking
getContainedAutoType().

This fixes: https://github.com/llvm/llvm-project/issues/57369
  https://github.com/llvm/llvm-project/issues/57643
  https://github.com/llvm/llvm-project/issues/57793

Differential Revision: https://reviews.llvm.org/D132990
2022-09-18 11:54:32 -07:00
owenca 93fcc80d1c [clang-format] Skip token annotation in passes that don't need it
Differential Revision: https://reviews.llvm.org/D134103
2022-09-18 11:19:40 -07:00
Kazu Hirata abbe9c561d [clang] Use x.empty() instead of llvm::empty(x) (NFC)
I'm planning to deprecate and eventually remove llvm::empty.

Note that no use of llvm::empty requires the ability of llvm::empty to
determine the emptiness from begin/end only.
2022-09-18 11:07:50 -07:00
Kazu Hirata 5e5a6c5b07 Use std::conditional_t (NFC) 2022-09-18 10:25:06 -07:00
Phoebe Wang 2f8a4acf1a [Clang][NFC] update predicate and reduce redundant check 2022-09-18 21:56:31 +08:00
Jun Zhang 303526ef3a
[Docs] Add a link that refers to C++ standard modules in Clang modules doc
Currently there're two pages that both talk about "Modules" in clang, but
they're different. The one that describes C++ standard modules explicitly
spells out the difference but the other one which targeting Clang modules
doesn't.

This patch adds a link that refers to the C++ standard modules
one in Clang modules doc, as you usually got the later page when
googling. I believe this will make newcomers less confused.

Signed-off-by: Jun Zhang <jun@junz.org>

Differential Revision: https://reviews.llvm.org/D134105
2022-09-18 18:31:49 +08:00
Phoebe Wang 490de4ab47 [Clang][NFC] update obsolete check predicate 2022-09-18 18:00:36 +08:00