Commit Graph

96532 Commits

Author SHA1 Message Date
Aaron Ballman 1b2efe8d87 Fix this test to be more robust
The test is failing because it lacks a target triple, so the number of
diagnostics differs between Windows and Linux targets.

This should correct the issue found by:
https://lab.llvm.org/buildbot/#/builders/109/builds/46804
2022-09-17 08:06:16 -04:00
Aaron Ballman 5d92d0b0f8 Correctly diagnose use of long long literals w/o a suffix
We would diagnose use of `long long` as an extension in C89 and C++98
modes when the user spelled the type `long long` or used the `LL`
literal suffix, but failed to diagnose when the literal had no suffix
but required a `long long` to represent the value.
2022-09-17 07:55:10 -04:00
Xiang Li 8b2f8b3098 [NFC} update CodeGenHLSL tests to use cc1 instead of driver-mode 2022-09-17 00:11:44 -07:00
Matheus Izvekov 52dce8900c
[clang] Fix AST representation of expanded template arguments.
Extend clang's SubstTemplateTypeParm to represent the pack substitution index.

Fixes PR56099.

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

Differential Revision: https://reviews.llvm.org/D128113
2022-09-17 01:24:46 +02:00
Chris Bieneman 10378c4505 [HLSL] Enable availability attribute
Some HLSL functionality is gated on the target shader model version.
Enabling the use of availability markup allows us to diagnose
availability issues easily in the frontend.

Reviewed By: erichkeane

Differential Revision: https://reviews.llvm.org/D134067
2022-09-16 16:04:27 -05:00
Aiden Grossman c0bc461999 [Clang] Give error message for invalid profile path when compiling IR
Before this patch, when compiling an IR file (eg the .llvmbc section
from an object file compiled with -Xclang -fembed-bitcode=all) and
profile data was passed in using the -fprofile-instrument-use-path
flag, there would be no error printed (as the previous implementation
relied on the error getting caught again in the constructor of
CodeGenModule which isn't called when -x ir is set). This patch
moves the error checking directly to where the error is caught
originally rather than failing silently in setPGOUseInstrumentor and
waiting to catch it in CodeGenModule to print diagnostic information to
the user.

Regression test added.

Reviewed By: xur, mtrofin

Differential Revision: https://reviews.llvm.org/D132991
2022-09-16 19:45:57 +00:00
David Majnemer 8a868d8859 Revert "Revert "[clang, llvm] Add __declspec(safebuffers), support it in CodeView""
This reverts commit cd20a18286 and adds a
"let Heading" to NoStackProtectorDocs.
2022-09-16 19:39:48 +00:00
Abhina Sreeskantharajan ce19343114 [test] Use host platform specific error message substitution
This patch modifies the testcase to use error substitution so it will pass on all platforms.

Reviewed By: fanbo-meng, zibi

Differential Revision: https://reviews.llvm.org/D134034
2022-09-16 15:13:45 -04:00
Wei Yi Tee a4f8e3d240 Revert "[clang][dataflow] Replace `transfer(const Stmt *, ...)` with `transfer(const CFGElement *, ...)` in `Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel`."
This reverts commit 41f235d268.

Details at https://lab.llvm.org/buildbot#builders/139/builds/28171.
Breakage due to API change.
2022-09-16 18:07:35 +00:00
Wei Yi Tee 41f235d268 [clang][dataflow] Replace `transfer(const Stmt *, ...)` with `transfer(const CFGElement *, ...)` in `Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel`.
Reviewed By: gribozavr2, sgatev

Differential Revision: https://reviews.llvm.org/D133930
2022-09-16 17:54:12 +00:00
Michał Górny 587729c3ad [clang] [Driver] Add an option to disable default config filenames
Add a `--no-default-config` option that disables the search for default
set of config filenames (based on the compiler executable name).

Suggested in https://discourse.llvm.org/t/rfc-adding-a-default-file-location-to-config-file-support/63606.

Differential Revision: https://reviews.llvm.org/D134018
2022-09-16 19:38:11 +02:00
Jan Svoboda 4e637fcb25 [clang][deps] Make sure ScanInstance outlives collector
The `ScanInstance` is a local variable in `DependencyScanningAction::runInvocation()` that is referenced by `ModuleDepCollector`. Since D132405, `ModuleDepCollector` can escape the function and can outlive its `ScanInstance`. This patch fixes that.

Reviewed By: benlangmuir

Differential Revision: https://reviews.llvm.org/D133988
2022-09-16 09:44:12 -07:00
Michael Buch e456d2ba8b [clang][ASTImporter] DeclContext::localUncachedLookup: Continue lookup into decl chain when regular lookup fails
The uncached lookup is mainly used in the ASTImporter/LLDB code-path
where we're not allowed to load from external storage. When importing
a FieldDecl with a DeclContext that had no external visible storage
(but came from a Clang module or PCH) the above call to `lookup(Name)`
the regular `DeclContext::lookup` fails because:
1. `DeclContext::buildLookup` doesn't set `LookupPtr` for decls
   that came from a module
2. LLDB doesn't use the `SharedImporterState`

In such a case we would never continue with the "slow" path of iterating
through the decl chain on the DeclContext. In some cases this means that
ASTNodeImporter::VisitFieldDecl ends up importing a decl into the
DeclContext a second time.

The patch removes the short-circuit in the case where we don't find
any decls via the regular lookup.

**Tests**

* Un-skip the failing LLDB API tests

Differential Revision: https://reviews.llvm.org/D133945
2022-09-16 12:38:50 -04:00
Wei Yi Tee 9cbdef6103 [clang][dataflow] Replace usage of the deprecated overload of `checkDataflow`.
Updated files:
- `ChromiumCheckModelTest.cpp`.
- `MatchSwitchTest.cpp`.
- `MultiVarConstantPropagationTest.cpp`.
- `SingleVarConstantPropagationTest.cpp`.
- `TestingSupportTest.cpp`.
- `TransferTest.cpp`.

Reviewed By: gribozavr2, sgatev

Differential Revision: https://reviews.llvm.org/D133865
2022-09-16 16:19:07 +00:00
Matheus Izvekov f4ea3bd4b2
[clang] Fixes how we represent / emulate builtin templates
We change the template specialization of builtin templates to
behave like aliases.

Though unlike real alias templates, these might still produce a canonical
TemplateSpecializationType when some important argument is dependent.

For example, we can't do anything about make_integer_seq when the
count is dependent, or a type_pack_element when the index is dependent.

We change type deduction to not try to deduce canonical TSTs of
builtin templates.

We also change those buitin templates to produce substitution sugar,
just like a real instantiation would, making the resulting type correctly
represent the template arguments used to specialize the underlying template.

And make_integer_seq will now produce a TST for the specialization
of it's first argument, which we use as the underlying type of
the builtin alias.

When performing member access on the resulting type, it's now
possible to map from a Subst* node to the template argument
as-written used in a regular fashion, without special casing.

And this fixes a bunch of bugs with relation to these builtin
templates factoring into deduction.

Fixes GH42102 and GH51928.

Depends on D133261

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

Differential Revision: https://reviews.llvm.org/D133262
2022-09-16 17:44:12 +02:00
Matheus Izvekov 591452eb23
NFC: [clang] add template AST test for make_integer_seq and type_pack_element
Signed-off-by: Matheus Izvekov <mizvekov@gmail.com>

Differential Revision: https://reviews.llvm.org/D133261
2022-09-16 17:12:49 +02:00
Zahira Ammarguellat 1b69ce1208 Currently the options ‘ffast-math’ and ‘ffp-contract’ are connected.
When ‘ffast-math’ is set, ffp-contract is altered this way:
-ffast-math/ Ofast -> ffp-contract=fast
-fno-fast-math -> if ffp-contract= fast then ffp-contract=on else
ffp-contract unchanged

This differs from gcc which doesn’t connect the two options.

Connecting these two options in clang, resulted in spurious warnings
when the user combines these two options -ffast-math -fno-fast-math; see
issue https://github.com/llvm/llvm-project/issues/54625.

The issue is that the ‘ffast-math’ option is an on/off flag, but the
‘ffp-contract’ is an on/off/fast flag. So when ‘fno-fast-math’ is used
there is no obvious value for ‘ffp-contract’. What should the value of
ffp-contract be for -ffp-contract=fast -fno-fast-math and -ffast-math
-ffp-contract=fast -fno-fast-math? The current logic sets ffp-contract
back to on in these cases. This doesn’t take into account that the value
of ffp-contract is modified by an explicit ffp-contract` option.
This patch is proposing a set of rules to apply when ffp-contract',
ffast-math and fno-fast-math are combined. These rules would give the
user the expected behavior and no diagnostic would be needed.

See RFC
https://discourse.llvm.org/t/rfc-making-ffast-math-option-unrelated-to-ffp-contract-option/61912
2022-09-16 11:08:41 -04:00
Matheus Izvekov 00ce271712
[clang] extend getCommonSugaredType to merge sugar nodes
This continues D111283 by extending the getCommonSugaredType
implementation to also merge non-canonical type nodes.

We merge these nodes by going up starting from the canonical
node, calculating their merged properties on the way.

If we reach a pair that is too different, or which we could not
otherwise unify, we bail out and don't try to keep going on to
the next pair, in effect striping out all the remaining top-level
sugar nodes. This avoids mismatching 'companion' nodes, such as
ElaboratedType, so that they don't end up elaborating some other
unrelated thing.

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

Differential Revision: https://reviews.llvm.org/D130308
2022-09-16 17:04:10 +02:00
Matheus Izvekov 67e2298311
[clang] use getCommonSugar in an assortment of places
For this patch, a simple search was performed for patterns where there are
two types (usually an LHS and an RHS) which are structurally the same, and there
is some result type which is resolved as either one of them (typically LHS for
consistency).

We change those cases to resolve as the common sugared type between those two,
utilizing the new infrastructure created for this purpose.

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

Differential Revision: https://reviews.llvm.org/D111509
2022-09-16 16:36:00 +02:00
sstwcw e5964223d9 [clang-format] Fix template arguments in macros
Fixes https://github.com/llvm/llvm-project/issues/57738

old
```
#define FOO(typeName, realClass)                               \
  {                                                            \
#typeName, foo < FooType>(new foo <realClass>(#typeName))  \
  }
```
new
```
#define FOO(typeName, realClass)                                \
  { #typeName, foo<FooType>(new foo<realClass>(#typeName)) }
```

Previously, when an UnwrappedLine began with a hash in a macro
definition, the program incorrectly assumed the line was a preprocessor
directive.  It should be stringification.

The rule in spaceRequiredBefore was added in 8b5297117b.  Its purpose is
to add a space in an include directive.  It also added a space to a
template opener when the line began with a stringification hash.  So we
changed it.

Reviewed By: HazardyKnusperkeks, owenpan

Differential Revision: https://reviews.llvm.org/D133954
2022-09-16 13:30:46 +00:00
sstwcw 2183fe2160 [clang-format] Parse the else part of `#if 0`
Fixes https://github.com/llvm/llvm-project/issues/57539

Previously things outside of `#if` blocks were parsed as if only the
first branch of the conditional compilation branch existed, unless the
first condition is 0.  In that case the outer parts would be parsed as
if nothing inside the conditional parts existed.  Now we use the second
conditional branch if the first condition is 0.

Reviewed By: owenpan

Differential Revision: https://reviews.llvm.org/D133647
2022-09-16 13:30:46 +00:00
Aaron Ballman c7c0ce7d9e Fix the clang Sphinx bot
This addresses failures introduced by:
https://lab.llvm.org/buildbot/#/builders/92/builds/32809

It also fixes a secondary issue that crept in after the above build
started failing.
2022-09-16 07:19:30 -04:00
Kadir Cetinkaya 23ace26e0d
[clang(d)] Include/Exclude CLDXC options properly
This handles the new CLDXC options that was introduced in
https://reviews.llvm.org/D128462 inside clang-tooling to make sure cl driver
mode is not broken.

Fixes https://github.com/clangd/clangd/issues/1292.

Differential Revision: https://reviews.llvm.org/D133962
2022-09-16 12:20:22 +02:00
Matheus Izvekov 1d1a98e9a0
Revert "[clang] use getCommonSugar in an assortment of places"
This reverts commit aff1f6310e.
2022-09-16 12:03:34 +02:00
Matheus Izvekov aff1f6310e
[clang] use getCommonSugar in an assortment of places
For this patch, a simple search was performed for patterns where there are
two types (usually an LHS and an RHS) which are structurally the same, and there
is some result type which is resolved as either one of them (typically LHS for
consistency).

We change those cases to resolve as the common sugared type between those two,
utilizing the new infrastructure created for this purpose.

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

Differential Revision: https://reviews.llvm.org/D111509
2022-09-16 11:55:40 +02:00
Stanislav Mekhanoshin e540965915 [AMDGPU] Added __builtin_amdgcn_ds_bvh_stack_rtn
Differential Revision: https://reviews.llvm.org/D133966
2022-09-16 02:42:09 -07:00
Matheus Izvekov 989f76ce90
[clang] template / auto deduction deduces common sugar
After upgrading the type deduction machinery to retain type sugar in
D110216, we were left with a situation where there is no general
well behaved mechanism in Clang to unify the type sugar of multiple
deductions of the same type parameter.

So we ended up making an arbitrary choice: keep the sugar of the first
deduction, ignore subsequent ones.

In general, we already had this problem, but in a smaller scale.
The result of the conditional operator and many other binary ops
could benefit from such a mechanism.

This patch implements such a type sugar unification mechanism.

The basics:

This patch introduces a `getCommonSugaredType(QualType X, QualType Y)`
method to ASTContext which implements this functionality, and uses it
for unifying the results of type deduction and return type deduction.
This will return the most derived type sugar which occurs in both X and
Y.

Example:

Suppose we have these types:
```
using Animal = int;
using Cat = Animal;
using Dog = Animal;

using Tom = Cat;
using Spike = Dog;
using Tyke = Dog;
```
For `X = Tom, Y = Spike`, this will result in `Animal`.
For `X = Spike, Y = Tyke`, this will result in `Dog`.

How it works:

We take two types, X and Y, which we wish to unify as input.
These types must have the same (qualified or unqualified) canonical
type.

We dive down fast through top-level type sugar nodes, to the
underlying canonical node. If these canonical nodes differ, we
build a common one out of the two, unifying any sugar they had.
Note that this might involve a recursive call to unify any children
of those. We then return that canonical node, handling any qualifiers.

If they don't differ, we walk up the list of sugar type nodes we dived
through, finding the last identical pair, and returning that as the
result, again handling qualifiers.

Note that this patch will not unify sugar nodes if they are not
identical already. We will simply strip off top-level sugar nodes that
differ between X and Y. This sugar node unification will instead be
implemented in a subsequent patch.

This patch also implements a few users of this mechanism:
* Template argument deduction.
* Auto deduction, for functions returning auto / decltype(auto), with
  special handling for initializer_list as well.

Further users will be implemented in a subsequent patch.

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

Differential Revision: https://reviews.llvm.org/D111283
2022-09-16 11:20:10 +02:00
Fangrui Song 45b85aebdb [Driver][test] Disable hip-link-bc-to-bc.hip
As it was disabled due to unsupported feature "clang-driver" before.
2022-09-15 21:41:18 -07:00
Fangrui Song 9e1c1ecb14 [HIP][test] Avoid %T
%T is a deprecated lit feature. It refers to the parent directory.
When two tests in test/Driver refer to the same `%T/foo`, they are racy with each other.
%t includes the test name and is safe for use.

Reviewed By: tra

Differential Revision: https://reviews.llvm.org/D133998
2022-09-15 19:58:42 -07:00
Gulfem Savrun Yeniceri d6aed77f0d [InstrProfiling] No runtime hook for unused funcs
This is a reland of https://reviews.llvm.org/D122336.
Original patch caused a problem in collecting coverage in
Fuchsia because it was returning early without putting unused
function names into __llvm_prf_names section. This patch
fixes that issue.

The original commit message is as the following:
CoverageMappingModuleGen generates a coverage mapping record
even for unused functions with internal linkage, e.g.
static int foo() { return 100; }
Clang frontend eliminates such functions, but InstrProfiling pass
still emits runtime hook since there is a coverage record.
Fuchsia uses runtime counter relocation, and pulling in profile
runtime for unused functions causes a linker error:
undefined hidden symbol: __llvm_profile_counter_bias.
Since https://reviews.llvm.org/D98061, we do not hook profile
runtime for the binaries that none of its translation units
have been instrumented in Fuchsia. This patch extends that for
the instrumented binaries that consist of only unused functions.

Reviewed By: phosek

Differential Revision: https://reviews.llvm.org/D122336
2022-09-16 02:05:09 +00:00
Brad Smith 3eca0b395f [lit] Set shlibpath_var on OpenBSD 2022-09-15 21:43:54 -04:00
Colin Cross 7fe475756b Set HOME for tests that use module cache path
Getting the default module cache path calls llvm::sys::path::cache_directory,
which calls home_directory, which checks the HOME environment variable
before falling back to getpwuid.  When compiling against musl libc,
which does not support NSS, and running on a machine that doesn't have
the current user in /etc/passwd due to NSS, no home directory can
be found.  Set the HOME environment variable in the tests to avoid
depending on getpwuid.

Reviewed By: pirama, srhines

Differential Revision: https://reviews.llvm.org/D132984
2022-09-15 23:58:57 +00:00
Navid Emamdoost 3e52c0926c Add -fsanitizer-coverage=control-flow
Reviewed By: kcc, vitalybuka, MaskRay

Differential Revision: https://reviews.llvm.org/D133157
2022-09-15 15:56:04 -07:00
Amy Huang 9ada3d5a13 Fix error in clang /MT equivalent flag patch.
This is a followup to reviews.llvm.org/D133457.
2022-09-15 20:24:51 +00:00
Erich Keane 49832b7a92 Stop trying to fixup 'overloadable' prototypeless functions.
While investigating something else, I discovered that a prototypeless
function with 'overloadable' was having the attribute left on the
declaration, which caused 'ambiguous' call errors later on. This lead to
some confusion.  This patch removes the 'overloadable' attribute from
the declaration and leaves it as prototypeless, instead of trying to
make it variadic.
2022-09-15 12:10:54 -07:00
Amy Huang fda44bedd6 Add Clang driver flags equivalent to cl's /MD, /MT, /MDd, /MTd.
This will allow selecting the MS C runtime library without having to use
cc1 flags.

Differential Revision: https://reviews.llvm.org/D133457
2022-09-15 17:45:41 +00:00
Aleksandr Platonov 3ce7d256f2 [clang][RecoveryExpr] Don't perform alignment check if parameter type is dependent
This patch fixes a crash which appears because of getTypeAlignInChars() call with depentent type.

Reviewed By: hokein

Differential Revision: https://reviews.llvm.org/D133886
2022-09-15 15:51:43 +03:00
Aaron Ballman e076680bd5 Add a "Potentially Breaking Changes" section to the Clang release notes
Sometimes we make changes to the compiler that we expect may cause
disruption for users. For example, we may strengthen a warning to
default to be an error, or fix an accepts-invalid bug that's been
around for a long time, etc which may cause previously accepted code to
now be rejected. Rather than hope users discover that information by
reading all of the release notes, it's better that we call these out in
one location at the top of the release notes.

Based on feedback collected in the discussion at:
https://discourse.llvm.org/t/configure-script-breakage-with-the-new-werror-implicit-function-declaration/65213/

Differential Revision: https://reviews.llvm.org/D133771
2022-09-15 07:29:49 -04:00
Dhruva Chakrabarti 839ac62c50 Revert "[OpenMP] Codegen aggregate for outlined function captures"
This reverts commit 7539e9cf81.
2022-09-15 03:08:46 +00:00
Giorgis Georgakoudis 7539e9cf81 [OpenMP] Codegen aggregate for outlined function captures
Parallel regions are outlined as functions with capture variables explicitly generated as distinct parameters in the function's argument list. That complicates the fork_call interface in the OpenMP runtime: (1) the fork_call is variadic since there is a variable number of arguments to forward to the outlined function, (2) wrapping/unwrapping arguments happens in the OpenMP runtime, which is sub-optimal, has been a source of ABI bugs, and has a hardcoded limit (16) in the number of arguments, (3)  forwarded arguments must cast to pointer types, which complicates debugging. This patch avoids those issues by aggregating captured arguments in a struct to pass to the fork_call.

Reviewed By: jdoerfert, jhuber6, ABataev

Differential Revision: https://reviews.llvm.org/D102107
2022-09-15 00:54:05 +00:00
Craig Topper 6106a6d7fe [RISCV] Update error message to not call 'RV32' and 'RV64' an extension.
I used RV32 so I didn't have to write RV32I and RV32E. Ideally
these builtins will be wrapped in a header someday so long term I don't
expect users to see these errors.

Reviewed By: asb

Differential Revision: https://reviews.llvm.org/D133444
2022-09-14 14:51:37 -07:00
Vitaly Buka c69b269111 [pipelines] Require GlobalsAA after sanitizers
Restore GlobalsAA if sanitizers inserted at early optimize callback.
The analysis can be useful for the following FunctionPassManager.

Reviewed By: aeubanks

Differential Revision: https://reviews.llvm.org/D133537
2022-09-14 13:33:53 -07:00
Vitaly Buka 270c843005 [NFC][CodeGen] Remove empty line 2022-09-14 13:29:15 -07:00
John Ericson 3a1c81e327 [CMake] Avoid `LLVM_BINARY_DIR` when other more specific variable are better-suited, part 2
A simple sed doing these substitutions:

- `${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}\>` -> `${LLVM_LIBRARY_DIR}`
- `${LLVM_BINARY_DIR}/bin\>` -> `${LLVM_TOOLS_BINARY_DIR}`

where `\>` means "word boundary".

The only manual modifications were reverting changes in

- `runtimes/CMakeLists.txt`

because these were "entry points" where we wanted to tread carefully not not introduce a "loop" which would end with an undefined variable being expanded to nothing.

There are some `${LLVM_BINARY_DIR}/lib` without the `${LLVM_LIBDIR_SUFFIX}`, but these refer to the lib subdirectory of the source (`llvm/lib`). That `lib` is automatically appended to make the local `CMAKE_CURRENT_BINARY_DIR` value by `add_subdirectory`; since the directory name in the source tree is fixed without any suffix, the corresponding `CMAKE_CURRENT_BINARY_DIR` will also be. We therefore do not replace it but leave it as-is.

This picks up where D133828 left off, getting the occurrences with*out* `CMAKE_CFG_INTDIR`. But this is difficult to do correctly and so not done in the (retroactively) previous diff.

This hopefully increases readability overall, and also decreases the usages of `LLVM_LIBDIR_SUFFIX`, preparing us for D130586.

Reviewed By: sebastian-ne

Differential Revision: https://reviews.llvm.org/D132316
2022-09-14 15:48:58 -04:00
Julius 49e7ef2c09 [Clang]: Diagnose deprecated copy operations also in MSVC compatibility mode
When running in MSVC compatibility mode, previously no deprecated copy
operation warnings (enabled by -Wdeprecated-copy) were raised. This
restriction was already in place when the deprecated copy warning was
first introduced.

This patch removes said restriction so that deprecated copy warnings, if
enabled, are also raised in MSVC compatibility mode. The reasoning here
being that these warnings are still useful when running in MSVC
compatibility mode and also have to be semi-explicitly enabled in the
first place (using -Wdeprecated-copy, -Wdeprecated or -Wextra).

Differential Revision: https://reviews.llvm.org/D133354
2022-09-14 19:48:08 +02:00
Nico Weber 5631d20bfc Revert "[clang] fix generation of .debug_aranges with LTO"
This reverts commit 6bf6730ac5.
Breaks tests if LLD isn't being built, see comments on
https://reviews.llvm.org/D133092
2022-09-14 12:43:24 -04:00
Ashay Rane f1848b0a0e
[clang] fix linker executable path in test
A previous patch (https://reviews.llvm.org/D132810) introduced a test
that fails on systems where the linker executable (`ld`) has a `.exe`
extension.  This patch updates the regex in the test so that lit can
look for both `ld` as well as `ld.exe`.

Reviewed By: stella.stamenova

Differential Revision: https://reviews.llvm.org/D133773
2022-09-14 11:35:37 -05:00
Nico Weber db6a53450f Revert "[test][clang] run test for lld emitting dwarf-aranages only if lld is presented"
This reverts commit 44075cc34a.
Broke check-clang, see comments on https://reviews.llvm.org/D133841
2022-09-14 12:17:41 -04:00
Haojian Wu f6e759bd26 Remove some unused static functions in CGOpenMPRuntimeGPU.cpp, NFC 2022-09-14 17:20:02 +02:00
Joseph Huber bae1a2cf3c [OpenMP] Remove unused function after removing simplified interface
Summary:
A previous patch removed the user of this function but did not remove
the function causing unused function warnings. Remove it.
2022-09-14 10:14:43 -05:00
Balazs Benics b8e1da0506 [analyzer] Initialize ShouldEmitErrorsOnInvalidConfigValue analyzer option
Downstream users who doesn't make use of the clang cc1 frontend for
commandline argument parsing, won't benefit from the Marshalling
provided default initialization of the AnalyzerOptions entries. More
about this later.
Those analyzer option fields, as they are bitfields, cannot be default
initialized at the declaration (prior c++20), hence they are initialized
at the constructor.
The only problem is that `ShouldEmitErrorsOnInvalidConfigValue` was
forgotten.

In this patch I'm proposing to initialize that field with the rest.

Note that this value is read by
`CheckerRegistry.cpp:insertAndValidate()`.
The analyzer options are initialized by the marshalling at
`CompilerInvocation.cpp:GenerateAnalyzerArgs()` by the expansion of the
`ANALYZER_OPTION_WITH_MARSHALLING` xmacro to the appropriate default
value regardless of the constructor initialized list which I'm touching.
Due to that this only affects users using CSA as a library, without
serious effort, I believe we cannot test this.

Reviewed By: martong

Differential Revision: https://reviews.llvm.org/D133851
2022-09-14 16:45:44 +02:00
Joseph Huber 194ec844f5 [OpenMP][AMDGPU] Link bitcode ROCm device libraries per-TU
Previously, we linked in the ROCm device libraries which provide math
and other utility functions late. This is not stricly correct as this
library contains several flags that are only set per-TU, such as fast
math or denormalization. This patch changes this to pass the bitcode
libraries per-TU using the same method we use for the CUDA libraries.
This has the advantage that we correctly propagate attributes making
this implementation more correct. Additionally, many annoying unused
functions were not being fully removed during LTO. This lead to
erroneous warning messages and remarks on unused functions.

I am not sure if not finding these libraries should be a hard error. let
me know if it should be demoted to a warning saying that some device
utilities will not work without them.

Reviewed By: JonChesterfield

Differential Revision: https://reviews.llvm.org/D133726
2022-09-14 09:42:06 -05:00
Joseph Huber 2d26ecb1fb [OpenMP] Remove simplified device runtime handling
The old device runtime had a "simplified" version that prevented many of
the runtime features from being initialized. The old device runtime was
deleted in LLVM 14 and is no longer in use. Selectively deactivating
features is now done using specific flags rather than the old technique.
This patch simply removes the extra logic required for handling the old
simple runtime scheme.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D133802
2022-09-14 09:41:50 -05:00
Azat Khuzhin 44075cc34a [test][clang] run test for lld emitting dwarf-aranages only if lld is presented
Fixes: https://reviews.llvm.org/D133092
CI: https://lab.llvm.org/buildbot/#/builders/109/builds/46592

Reviewed By: hokein

Differential Revision: https://reviews.llvm.org/D133841
2022-09-14 10:17:03 +02:00
Timm Bäder a8843643cd [clang][Interp] Remove struct from a testcase
This should fix the leak sanitizer breakage introduced by
https://reviews.llvm.org/D132997, e.g.
https://lab.llvm.org/buildbot/#/builders/5/builds/27410
2022-09-14 09:44:01 +02:00
Chuanqi Xu 1c0a90fd47 [C++20] [Coroutines] Prefer sized deallocation in promise_type
Now when the compiler can't find the sized deallocation function
correctly in promise_type if there are multiple deallocation function
overloads there.

According to [dcl.fct.def.coroutine]p12:
> If both a usual deallocation function with only a pointer parameter
> and a usual deallocation function with both a pointer parameter and a
> size parameter are found, then the selected deallocation function
> shall be the one with two parameters.

So when there are multiple deallocation functions, the compiler should
choose the sized one instead of the unsized one. The patch fixes this.
2022-09-14 15:07:31 +08:00
Xiang Li f712c0131f [HLSL]Add -O and -Od option for dxc mode.
Two new dxc mode options -O and -Od are added for dxc mode.
-O is just alias of existing cc1 -O option.
-Od will be lowered into -O0 and -dxc-opt-disable.

-dxc-opt-disable is cc1 option added to for build ShaderFlags.

Reviewed By: beanz

Differential Revision: https://reviews.llvm.org/D128845
2022-09-13 21:26:18 -07:00
Alexander Shaposhnikov b6965f7246 [IR] Add alignment for llvm.threadlocal.address
This diff sets the alignment attribute for the return value
and the argument of llvm.threadlocal.address.

(https://github.com/llvm/llvm-project/issues/57438)

Test plan: ninja check-all

Differential revision: https://reviews.llvm.org/D133741
2022-09-13 23:10:55 +00:00
Argyrios Kyrtzidis b340c5ae42 [Lex/DependencyDirectivesScanner] Handle the case where the source line starts with a `tok::hashhash`
Differential Revision: https://reviews.llvm.org/D133674
2022-09-13 15:48:50 -07:00
Azat Khuzhin 6bf6730ac5 [clang] fix generation of .debug_aranges with LTO
Right now in case of LTO the section is not emited:

    $ cat test.c
    void __attribute__((optnone)) bar()
    {
    }
    void __attribute__((optnone)) foo()
    {
            bar();
    }
    int main()
    {
            foo();
    }

    $ clang -flto=thin -gdwarf-aranges -g -O3 test.c
    $ eu-readelf -waranges a.out  | fgrep -c -e foo -e bar
    0

    $ clang -gdwarf-aranges -g -O3 test.c
    $ eu-readelf -waranges a.out  | fgrep -c -e foo -e bar
    2

Fix this by passing explicitly -mllvm -generate-arange-section.

P.S. although this looks like a hack, since none of -mllvm was passed to
the lld before.

Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
Suggested-by: OCHyams <orlando.hyams@sony.com>

Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D133092
2022-09-13 22:33:56 +00:00
Chris Bieneman 0c9b242cf0 [HLSL] Adding a test change I forgot to add
This test just verifies that even at -O0 the buffer subscript operators
are inlined. The original change was
fb5baffc28.
2022-09-13 20:53:39 -05:00
Chris Bieneman fb5baffc28 [HLSL] Mark buffer subscript operators as AlwaysInline
HLSL requires aggressive inlineing for resource accesses. This just
enforces that we get resource handle accesses inlined early.
2022-09-13 20:31:29 -05:00
Evgeny Shulgin 67f08bf1bf [Clang] [Sema] Ignore invalid multiversion function redeclarations
If a redeclaration of a multiversion function is invalid,
it may be in a broken condition (for example, missing an important
attribute). We shouldn't analyze invalid redeclarations.

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

Reviewed By: tahonermann

Differential Revision: https://reviews.llvm.org/D133641
2022-09-13 20:12:09 +00:00
Chris Bieneman a8a49923dd [HLSL] Call global destructors from entries
HLSL doesn't have a C++ runtime that supports `atexit` registration. To
enable global destructors we instead rely on the `llvm.global_dtor`
mechanism.

This change disables `atexit` generation for HLSL and updates the HLSL
code generation to call global destructors on the exit from entry
functions.

Depends on D132977.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D133518
2022-09-13 15:05:47 -05:00
Aaron Ballman b8266f512a Correct the __has_c_attribute value for fallthrough
The original proposal was seen in Apr 2019 and we accidentally used
that date (201904L) as the feature testing value. However, WG14 N2408
was adopted at the Oct 2019 meeting and so that's the correct date for
the feature testing macro. The committee draft for C2x shows 201910L
for this value, so this changes brings us in line with the standard.
2022-09-13 11:08:58 -04:00
Aaron Ballman 843d074400 Update the C Status page for the Clang 15 release
Now that Clang 15 is out, we can swap all the unreleased entries over.
2022-09-13 09:36:54 -04:00
Aaron Ballman 0f28cf416d Correct the __has_c_attribute value for maybe_unused
The original proposal was adopted in Apr 2019, but was subsequently
updated by WG14 N2662 in June 2021. We already supported the attribute
on a label and it behaved as expected, but we had not bumped the
feature test value.
2022-09-13 09:33:20 -04:00
Aaron Ballman 1b19df12b8 Correct the __has_c_attribute value for nodiscard
The original proposal was adopted in Apr 2019 and so the previous value
was 201904L. However, a subsequent proposal (N2448) was adopted to add
an optional message argument to the attribute. We already support that
functionality, but had not bumped the feature test value.
2022-09-13 08:13:01 -04:00
Animesh Kumar 7f57b646d1 [OpenMP] Extend lit test for parallel for simd construct
This construct is being tested for atomic operation based upon
the test 5.0/parallel_for_simd/test_parallel_for_simd_atomic.c
from the SOLLVE repo: https://github.com/SOLLVE/sollve_vv

Differential Revision: https://reviews.llvm.org/D132643
2022-09-13 17:07:11 +05:30
Alexander Kornienko 637da9de4c Revert "[clang] template / auto deduction deduces common sugar"
This reverts commit d200db3863, which causes a
clang crash. See https://reviews.llvm.org/D111283#3785755

Test case for convenience:
```
template <typename T>
using P = int T::*;

template <typename T, typename... A>
void j(P<T>, T, A...);

template <typename T>
void j(P<T>, T);

struct S {
  int b;
};
void g(P<S> k, S s) { j(k, s); }
```
2022-09-13 12:18:07 +02:00
Sven van Haastregt 5a7764c9ff [OpenCL] Guard depth image builtins
Ensure any uses of `image2d_depth_t` and `image2d_array_depth_t` are
guarded behind the `cl_khr_depth_images` extension in
`OpenCLBuiltins.td`.

Fix a few missing guards in `opencl-c.h`.
2022-09-13 10:10:48 +01:00
Sylvestre Ledru cd20a18286 Revert "[clang, llvm] Add __declspec(safebuffers), support it in CodeView"
Causing:
https://github.com/llvm/llvm-project/issues/57709

This reverts commit ab56719acd.
2022-09-13 10:53:59 +02:00
Timm Bäder 53d8687a13 [clang][Interp][NFC] Use constexpr if in OffsetHelper
Add is a template parameter, so we can use constexpr if here.
2022-09-13 10:41:34 +02:00
Timm Bäder b02f6890f5 [clang][Interp][NFC] InterpFrame::getParam can be const
Make stackRef() const as well and use that.
2022-09-13 10:41:28 +02:00
Timm Bäder 5d2451468c [clang][Interp][NFC] InterpFrame::getLocal() can be const
Make localRef() const and use that.
2022-09-13 10:41:24 +02:00
Timm Bäder f756ddba17 [clang][Interp][NFC] InterpFrame: localBlock() can be const 2022-09-13 10:41:18 +02:00
Timm Bäder 9b087a70e6 [clang][Interp][NFC] Forward-declare Pointer in PrimType header
No need to include the full Pointer.h here.
2022-09-13 10:40:52 +02:00
Timm Bäder bf3efa8b16 [clang][Interp] Handle DeclRefExpr of reference types
References are implemented through pointers, so we need a second deref
when encountering a DeclRefExpr of a reference type.

Differential Revision: https://reviews.llvm.org/D132997
2022-09-13 10:40:51 +02:00
Martin Storsjö fbfe1db4a9 [clang] Explicitly set the EmulatedTLS codegen option. NFC.
Set the EmulatedTLS option based on `Triple::hasDefaultEmulatedTLS()`
if the user didn't specify it; set `ExplicitEmulatedTLS` to true
in `llvm::TargetOptions` and set `EmulatedTLS` to Clang's
opinion of what the default or preference is.

This avoids any risk of deviance between the two.

This affects one check of `getCodeGenOpts().EmulatedTLS` in
`shouldAssumeDSOLocal` in CodeGenModule, but as that check only
is done for `TT.isWindowsGNUEnvironment()`, and
`hasDefaultEmulatedTLS()` returns false for such environments
it doesn't make any current testable difference - thus NFC.

Some mingw distributions carry a downstream patch, that enables
emulated TLS by default for mingw targets in `hasDefaultEmulatedTLS()`
- and for such cases, this patch does make a difference and fixes the
detection of emulated TLS, if it is implicitly enabled.

Differential Revision: https://reviews.llvm.org/D132916
2022-09-13 10:40:54 +03:00
Balazs Benics 7cddf9cad1 [analyzer] Dump the environment entry kind as well
By this change the `exploded-graph-rewriter` will display the class kind
of the expression of the environment entry. It makes easier to decide if
the given entry corresponds to the lvalue or to the rvalue of some
expression.

It turns out the rewriter already had support for visualizing it, but
probably was never actually used?

Reviewed By: martong

Differential Revision: https://reviews.llvm.org/D132109
2022-09-13 09:04:27 +02:00
Balazs Benics afcd862b2e [analyzer] LazyCompoundVals should be always bound as default bindings
`LazyCompoundVals` should only appear as `default` bindings in the
store. This fixes the second case in this patch-stack.

Depends on: D132142

Reviewed By: xazax.hun

Differential Revision: https://reviews.llvm.org/D132143
2022-09-13 08:58:46 +02:00
Balazs Benics f8643a9b31 [analyzer] Prefer wrapping SymbolicRegions by ElementRegions
It turns out that in certain cases `SymbolRegions` are wrapped by
`ElementRegions`; in others, it's not. This discrepancy can cause the
analyzer not to recognize if the two regions are actually referring to
the same entity, which then can lead to unreachable paths discovered.

Consider this example:

```lang=C++
struct Node { int* ptr; };
void with_structs(Node* n1) {
  Node c = *n1; // copy
  Node* n2 = &c;
  clang_analyzer_dump(*n1); // lazy...
  clang_analyzer_dump(*n2); // lazy...
  clang_analyzer_dump(n1->ptr); // rval(n1->ptr): reg_$2<int * SymRegion{reg_$0<struct Node * n1>}.ptr>
  clang_analyzer_dump(n2->ptr); // rval(n2->ptr): reg_$1<int * Element{SymRegion{reg_$0<struct Node * n1>},0 S64b,struct Node}.ptr>
  clang_analyzer_eval(n1->ptr != n2->ptr); // UNKNOWN, bad!
  (void)(*n1);
  (void)(*n2);
}
```

The copy of `n1` will insert a new binding to the store; but for doing
that it actually must create a `TypedValueRegion` which it could pass to
the `LazyCompoundVal`. Since the memregion in question is a
`SymbolicRegion` - which is untyped, it needs to first wrap it into an
`ElementRegion` basically implementing this untyped -> typed conversion
for the sake of passing it to the `LazyCompoundVal`.
So, this is why we have `Element{SymRegion{.}, 0,struct Node}` for `n1`.

The problem appears if the analyzer evaluates a read from the expression
`n1->ptr`. The same logic won't apply for `SymbolRegionValues`, since
they accept raw `SubRegions`, hence the `SymbolicRegion` won't be
wrapped into an `ElementRegion` in that case.

Later when we arrive at the equality comparison, we cannot prove that
they are equal.

For more details check the corresponding thread on discourse:
https://discourse.llvm.org/t/are-symbolicregions-really-untyped/64406

---

In this patch, I'm eagerly wrapping each `SymbolicRegion` by an
`ElementRegion`; basically canonicalizing to this form.
It seems reasonable to do so since any object can be thought of as a single
array of that object; so this should not make much of a difference.

The tests also underpin this assumption, as only a few were broken by
this change; and actually fixed a FIXME along the way.

About the second example, which does the same copy operation - but on
the heap - it will be fixed by the next patch.

Reviewed By: martong

Differential Revision: https://reviews.llvm.org/D132142
2022-09-13 08:58:46 +02:00
Chuanqi Xu 79fa0ec8c4 [C++20] [Modules] Make member functions with a in-class definition in HU implicitly inline
According to [dcl.inline]p7/note4,

> In the global module, a function defined within a class definition is
> implicitly inline.

And the declarations in the header unit are attached to the global
module fragment. So the function defined within a class definition in
header units should be implicitly inline too.

This fixes https://github.com/llvm/llvm-project/issues/57571.
2022-09-13 13:11:56 +08:00
Fangrui Song 6f9c4851ab [MinGW] Reject explicit hidden visibility applied to dllexport and hidden/protected applied to dllimport
Hidden visibility is incompatible with dllexport.
Hidden and protected visibilities are incompatible with dllimport.
(PlayStation uses dllexport protected.)

When an explicit visibility attribute applies on a dllexport/dllimport
declaration, report a Frontend error (Sema does not compute visibility).

Reviewed By: mstorsjo

Differential Revision: https://reviews.llvm.org/D133266
2022-09-12 15:56:36 -07:00
David Majnemer ab56719acd [clang, llvm] Add __declspec(safebuffers), support it in CodeView
__declspec(safebuffers) is equivalent to
__attribute__((no_stack_protector)).  This information is recorded in
CodeView.

While we are here, add support for strict_gs_check.
2022-09-12 21:15:34 +00:00
Ben Langmuir 4a72459ed6 Revert "[clang][test] Disallow using the default module cache path in lit tests"
This reverts commit d96f526196.

Some systems do not support `env -u`.
2022-09-12 13:10:22 -07:00
Richard Howell 3c1b42347b [clang] sort additional module maps when serializing
Sort additional module maps when serializing pcm files. This ensures
the `MODULE_MAP_FILE` record is deterministic across repeated builds.

Reviewed By: benlangmuir

Differential Revision: https://reviews.llvm.org/D133611
2022-09-12 12:00:43 -07:00
Corentin Jabot 7eead180b9 [Clang] NFC: Make UnqualifiedId::Kind private for consistency.
Differential Revision: https://reviews.llvm.org/D133703
2022-09-12 19:14:06 +02:00
Ben Langmuir d96f526196 [clang][test] Disallow using the default module cache path in lit tests
Make the default module cache path invalid when running lit tests so
that tests are forced to provide a cache path. This avoids accidentally
escaping to the system default location, and would have caught the
failure recently found in ClangScanDeps/multiple-commands.c.

Differential Revision: https://reviews.llvm.org/D133622
2022-09-12 09:54:56 -07:00
Jun Zhang 1d51bb824f
[Clang] Reword diagnostic for scope identifier with linkage
If the declaration of an identifier has block scope, and the identifier has
external or internal linkage, the declaration shall have no initializer for
the identifier.

Clang now gives a more suitable diagnosis for this case.
Fixes https://github.com/llvm/llvm-project/issues/57478

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

 Differential Revision: https://reviews.llvm.org/D133088
2022-09-12 22:40:54 +08:00
Jonas Hahnfeld f0403c853b Fix build of Lex unit test with CLANG_DYLIB
If CLANG_LINK_CLANG_DYLIB, clang_target_link_libraries ignores all
indivial libraries and only links clang-cpp. As LLVMTestingSupport
is separate, pass it via target_link_libraries directly.
2022-09-12 13:49:57 +02:00
Muhammad Usman Shahid ea26ed1f9c Rewording note note_constexpr_invalid_cast
The diagnostics here are correct, but the note is really silly. It
talks about reinterpret_cast in C code. So rewording it for c mode by
using another %select{}.
```
int array[(long)(char *)0];
```
previous note:
```
cast that performs the conversions of a reinterpret_cast is not allowed in a constant expression
```
reworded note:
```
this conversion is not allowed in a constant expression
```

Differential Revision: https://reviews.llvm.org/D133194
2022-09-12 07:47:39 -04:00
owenca 5889ed83a0 [clang-format] Don't insert braces for loops with a null statement
This is a workaround for #57539.

Fixes #57509.

Differential Revision: https://reviews.llvm.org/D133635
2022-09-12 00:37:47 -07:00
Corentin Jabot 0e8afddaa1 [Clang] NFC: Remove duplicated variable def in CheckLValueConstantExpression 2022-09-10 19:10:23 +02:00
Rainer Orth 1e56821bac [Linux] Hack around Linux/sparc <bits/stdio-ldbl.h>
I've been using this hack to work around the Linux/sparc64 compile failure
described in Issue #47994
<https://github.com/llvm/llvm-project/issues/47994>, especially since the
underlying glibc PR build/27558
<https://sourceware.org/bugzilla/show_bug.cgi?id=27558> doesn't seem to be
making progress and some fix is required to have LLVM build on
`sparc64-unknown-linux-gnu` at all, as evidenced on the buildbot.

Tested on `sparc64-unknown-linux-gnu`.

Differential Revision: https://reviews.llvm.org/D133405
2022-09-10 09:37:35 +02:00
Mohammed Keyvanzadeh 467bb47c84
[clang][cmake] Remove extra brace
Remove the extra trailing brace from the local variable accessor.

Differential Revision: https://reviews.llvm.org/D133613
2022-09-10 05:00:23 +04:30
Bruno Cardoso Lopes f4a13c9c0a [Clang][ScanDeps] Change multiple-commands.c test to use -fmodules-cache-path on implicit builds
The module cache escapes the test output dirs in this test. Since its default location maybe
composed of system and user related path this can cause problems in some builders (e.g. not
accessible paths inherited in a chroot environment).

Clean the test a bit by passing `-fmodules-cache-path` inside the test output dirs.

Differential Revision: https://reviews.llvm.org/D133617
2022-09-09 16:20:04 -07:00
Xiang Li 71fae33f5e [NFC] Cleanup test for D132913 Preserve vec3 for HLSL
Support number for parameter test added in
https://reviews.llvm.org/D132913
2022-09-09 15:04:59 -07:00
Xiang Li c9d2b6b92d [HLSL] Preserve vec3 for HLSL.
Preserve vec3 for HLSL by set -fpreserve-vec3-type.

Reviewed By: beanz

Differential Revision: https://reviews.llvm.org/D132913
2022-09-09 10:55:45 -07:00
Jamie Schmeiser 5e3ac79690 Loop names used in reporting can grow very large
Summary:
The code for generating a name for loops for various reporting scenarios
created a name by serializing the loop into a string.  This may result in
a very large name for a loop containing many blocks.  Use the getName()
function on the loop instead.

Author: Jamie Schmeiser <schmeise@ca.ibm.com>
Reviewed By: Whitney (Whitney Tsang), aeubanks (Arthur Eubanks)
Differential Revision: https://reviews.llvm.org/D133587
2022-09-09 13:45:14 -04:00
Yitzhak Mandelbaum abc16c7a5b [NFC] Remove a FIXME fixed by an earlier patch.
Commit 28bd7945ea incidentally fixed the
associated FIXME, but didn't delete it.

Differential Revision: https://reviews.llvm.org/D133588
2022-09-09 17:13:52 +00:00
Steven Wu 493766e068 Frontend: Respect -working-directory when checking if output files can be written
Call `FixupRelativePath` when opening output files to ensure that
`-working-directory` is used when checking up front for write failures,
not just when finalizing the files at the end. This also moves the
temporary file into the same directory as the output file.

Reviewed By: benlangmuir

Differential Revision: https://reviews.llvm.org/D95497
2022-09-09 08:57:12 -07:00
mydeveloperday 28bd7945ea [clang-format] NFC remove incorrect whitespace causing documentation issue 2022-09-09 16:03:48 +01:00
Chris Bieneman d3c54a172d [HLSL] Call global constructors inside entry
HLSL doesn't have a runtime loader model that supports global
construction by a loader or runtime initializer. To allow us to leverage
global constructors with minimal code generation impact we put calls to
the global constructors inside the generated entry function.

Differential Revision: https://reviews.llvm.org/D132977
2022-09-09 09:01:28 -05:00
Serge Pavlov 7b9fae05b4 [Clang] Use virtual FS in processing config files
Clang has support of virtual file system for the purpose of testing, but
treatment of config files did not use it. This change enables VFS in it
as well.

Differential Revision: https://reviews.llvm.org/D132867
2022-09-09 18:24:45 +07:00
Serge Pavlov 55e1441f7b Revert "[Clang] Use virtual FS in processing config files"
This reverts commit 9424497e43.
Some buildbots failed, reverted for investigation.
2022-09-09 16:43:15 +07:00
Serge Pavlov 9424497e43 [Clang] Use virtual FS in processing config files
Clang has support of virtual file system for the purpose of testing, but
treatment of config files did not use it. This change enables VFS in it
as well.

Differential Revision: https://reviews.llvm.org/D132867
2022-09-09 16:28:51 +07:00
Vitaly Buka 7dc0734567 [msan] Insert simplification passes after instrumentation
This resolves TODO from D96406.
InstCombine issue is fixed with D133394.

Save 4.5% of .text on CTMark.
2022-09-09 00:33:04 -07:00
Alvin Wong a3a8bd00c8 [clang][MinGW] Add `-mguard=cf` and `-mguard=cf-nochecks`
This option can be used to enable Control Flow Guard checks and
generation of address-taken function table. They are equivalent to
`/guard:cf` and `/guard:cf,nochecks` in clang-cl. Passing this flag to
the Clang driver will also pass `--guard-cf` to the MinGW linker.

This feature is disabled by default. The option `-mguard=none` is also
available to explicitly disable this feature.

Reviewed By: rnk

Differential Revision: https://reviews.llvm.org/D132810
2022-09-09 09:55:40 +03:00
Vitaly Buka e261b03396 [sanitizers] Add experimental flag to insert sanitizers earlier 2022-09-08 19:05:17 -07:00
Fangrui Song d8c09b7bbc Revert D111509 "[clang] use getCommonSugar in an assortment of places"
This reverts commit d42122cd5d.

`clang++ gcc/libstdc++-v3/src/c++98/complex_io.cc` (all language modes) crashes.
Also see https://reviews.llvm.org/D111509#3777980
2022-09-08 17:09:18 -07:00
Fangrui Song 1f6a86b309 [cc1as] Support --compress-debug-sections=zstd
`clang -gz=zstd -c a.s` generates ELFCOMPRESS_ZSTD compressed debug info
sections if compression decreases size.
2022-09-08 16:31:45 -07:00
Joe Loser 1b3a78d1d5 [clang] Use std::size instead of llvm::array_lengthof
LLVM contains a helpful function for getting the size of a C-style
array: `llvm::array_lengthof`. This is useful prior to C++17, but not as
helpful for C++17 or later: `std::size` already has support for C-style
arrays.

Change call sites to use `std::size` instead. Leave the few call sites that
use a locally defined `array_lengthof` that are meant to test previous bugs
with NTTPs in clang analyzer and SemaTemplate.

Differential Revision: https://reviews.llvm.org/D133520
2022-09-08 17:20:25 -06:00
Fangrui Song 4d4ca6c9d0 [Driver] Rename Z to Zlib 2022-09-08 16:14:31 -07:00
Fangrui Song 781dea021a [Support] Rename DebugCompressionType::Z to Zlib
"Z" was so named when we had both gABI ELFCOMPRESS_ZLIB and the legacy .zdebug support.
Now we have just one zlib format, we should use the more descriptive name.
2022-09-08 16:11:29 -07:00
Fangrui Song 48203b327d Revert D130308 "[clang] extend getCommonSugaredType to merge sugar nodes"
This reverts commit 16e5d6d7f9.
There are multiple complaints on the review.

In addition, it may cause spurious
```
error: invalid operands to binary expression ('SinkPrinter' and 'char[cluster_name_length]')
note: candidate template ignored: substitution failure: variably modified type 'char *' cannot be used as a template argument SinkPrinter operator<<(const SinkPrinter &s, T) {
```
for some C++ code
2022-09-08 15:09:39 -07:00
Fangrui Song 2f23dc9127 [AST/Interp] Fix left shift overflow bug in D64146
Noticed by Dmitri Gribenko
2022-09-08 13:49:07 -07:00
Fangrui Song 49c289879c [AST/Interp] Fix latent unitialized use of memory bug in D64146
Exposed by D132727: clang/test/AST/Interp/arrays.cpp fails with --config=msan
2022-09-08 13:39:30 -07:00
Tom Honermann 8d03328e7b [clang] NFC: Add a missing const qualifier to Decl::isLocalExternDecl(). 2022-09-08 13:21:10 -07:00
Dominic Chen ac77b3fde1 [clang][ARM][NFC] Clean up signed conversion and undefined macros in builtin header
These warnings were identified while debugging modules with Wsystem-headers.

Differential Revision: https://reviews.llvm.org/D132003
2022-09-08 12:46:08 -07:00
Matheus Izvekov 16e5d6d7f9
[clang] extend getCommonSugaredType to merge sugar nodes
This continues D111283 by extending the getCommonSugaredType
implementation to also merge non-canonical type nodes.

We merge these nodes by going up starting from the canonical
node, calculating their merged properties on the way.

If we reach a pair that is too different, or which we could not
otherwise unify, we bail out and don't try to keep going on to
the next pair, in effect striping out all the remaining top-level
sugar nodes. This avoids mismatching 'companion' nodes, such as
ElaboratedType, so that they don't end up elaborating some other
unrelated thing.

Depends on D111509

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

Differential Revision: https://reviews.llvm.org/D130308
2022-09-08 19:17:53 +02:00
Matheus Izvekov d42122cd5d
[clang] use getCommonSugar in an assortment of places
For this patch, a simple search was performed for patterns where there are
two types (usually an LHS and an RHS) which are structurally the same, and there
is some result type which is resolved as either one of them (typically LHS for
consistency).

We change those cases to resolve as the common sugared type between those two,
utilizing the new infrastructure created for this purpose.

Depends on D111283

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

Differential Revision: https://reviews.llvm.org/D111509
2022-09-08 19:17:53 +02:00
Matheus Izvekov d200db3863
[clang] template / auto deduction deduces common sugar
After upgrading the type deduction machinery to retain type sugar in
D110216, we were left with a situation where there is no general
well behaved mechanism in Clang to unify the type sugar of multiple
deductions of the same type parameter.

So we ended up making an arbitrary choice: keep the sugar of the first
deduction, ignore subsequent ones.

In general, we already had this problem, but in a smaller scale.
The result of the conditional operator and many other binary ops
could benefit from such a mechanism.

This patch implements such a type sugar unification mechanism.

The basics:

This patch introduces a `getCommonSugaredType(QualType X, QualType Y)`
method to ASTContext which implements this functionality, and uses it
for unifying the results of type deduction and return type deduction.
This will return the most derived type sugar which occurs in both X and
Y.

Example:

Suppose we have these types:
```
using Animal = int;
using Cat = Animal;
using Dog = Animal;

using Tom = Cat;
using Spike = Dog;
using Tyke = Dog;
```
For `X = Tom, Y = Spike`, this will result in `Animal`.
For `X = Spike, Y = Tyke`, this will result in `Dog`.

How it works:

We take two types, X and Y, which we wish to unify as input.
These types must have the same (qualified or unqualified) canonical
type.

We dive down fast through top-level type sugar nodes, to the
underlying canonical node. If these canonical nodes differ, we
build a common one out of the two, unifying any sugar they had.
Note that this might involve a recursive call to unify any children
of those. We then return that canonical node, handling any qualifiers.

If they don't differ, we walk up the list of sugar type nodes we dived
through, finding the last identical pair, and returning that as the
result, again handling qualifiers.

Note that this patch will not unify sugar nodes if they are not
identical already. We will simply strip off top-level sugar nodes that
differ between X and Y. This sugar node unification will instead be
implemented in a subsequent patch.

This patch also implements a few users of this mechanism:
* Template argument deduction.
* Auto deduction, for functions returning auto / decltype(auto), with
  special handling for initializer_list as well.

Further users will be implemented in a subsequent patch.

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

Differential Revision: https://reviews.llvm.org/D111283
2022-09-08 19:17:48 +02:00
Kadir Cetinkaya abd2b1a9d0
[clang] Fix a crash in constant evaluation 2022-09-08 18:21:44 +02:00
Jonas Paulsson 906ea59d00 [SystemZ] Fix new test case
Add 'REQUIRES: systemz-registered-target'.
2022-09-08 18:05:17 +02:00
Jonas Paulsson de0e3117d4 [SystemZ] Improve handling of vector alignments.
Make the DataLayout string always hold a vector alignment of 8 bytes,
regardless of the vector ABI. This makes the datalayout depend only on the
target triple which is the general expectation (in assertions).

On older architectures where vectors use the natural alignment (16 bytes),
the front end will maintain the same behavior and produce an overalignment
compared to the datalayout.

Reviewed By: uweigand

Differential Revision: https://reviews.llvm.org/D131158
2022-09-08 17:33:05 +02:00
Thomas Lively ac3b8df8f2 [WebAssembly] Prototype `f32x4.relaxed_dot_bf16x8_add_f32`
As proposed in https://github.com/WebAssembly/relaxed-simd/issues/77. Only an
LLVM intrinsic and a clang builtin are implemented. Since there is no bfloat16
type, use u16 to represent the bfloats in the builtin function arguments.

Differential Revision: https://reviews.llvm.org/D133428
2022-09-08 08:07:49 -07:00
David Spickett e428baf001 [LLVM][ARM] Remove options for armv2, 2A, 3 and 3M
Fixes #57486

These pre v4 architectures are not specifically supported
by codegen. As demonstrated in the linked issue.

GCC has not supported 3M since GCC 9 and presumably
2 and 2A earlier than that. So we are aligned in that sense.

(see https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=2abd6e34fcf3bd9f9ffafcaa47cdc3ed443f9add)

This removes the options and associated testing.

The Pre_v4 build attribute remains mainly because its absence
would be more confusing. It will not be used other than to
complete the list of build attributes as shown in the ABI.

https://github.com/ARM-software/abi-aa/blob/main/addenda32/addenda32.rst#3352the-target-related-attributes

Reviewed By: nickdesaulniers, peter.smith, rengolin

Differential Revision: https://reviews.llvm.org/D133109
2022-09-08 09:49:48 +00:00
Fangrui Song a0365abad8 [Driver] Support -gz=zstd
The driver option translates to --compress-debug-sections=zstd cc1/cc1as/GNU
assembler/linker options.

`clang -g -gz=zstd -c a.c` generates ELFCOMPRESS_ZSTD compressed debug info
sections if compression decreases size.
2022-09-08 01:39:06 -07:00
Fangrui Song 3e99b8d947 C++/ObjC++: switch to gnu++17 as the default standard
Clang's default C++ standard is now `gnu++17` instead of `gnu++14`:
https://discourse.llvm.org/t/c-objc-switch-to-gnu-17-as-the-default-standard/64360

* CUDA/HIP are unchanged: C++14 from D103221.
* Sony PS4/PS5 are unchanged: https://discourse.llvm.org/t/c-objc-switch-to-gnu-17-as-the-default-standard/64360/6
* lit feature `default-std-cxx` is added to keep CLANG_DEFAULT_STD_CXX=xxx tests working.
  Whether the cmake variable should be retained is disccused in D133375.

Depends on D131464

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

Differential Revision: https://reviews.llvm.org/D131465
2022-09-08 08:22:04 +00:00
Timm Bäder 86271798e5 [clang][Interp] Only initialize initmaps for primitive arrays
As the comment states, this code should only run for primitive arrays.

This should fix the memory sanitize builds.
2022-09-08 10:03:06 +02:00
Nikita Popov fd2475049e Revert "C++/ObjC++: switch to gnu++17 as the default standard"
This reverts commit e321c8dd2c.

This causes many failures in llvm-test-suite, for example:

    /home/npopov/repos/llvm-test-suite/build-O3/tools/timeit --summary MultiSource/Applications/lambda-0.1.3/CMakeFiles/lambda.dir/token_stream.cc.o.time /home/npopov/repos/llvm-project/build/bin/clang++ -DNDEBUG -I/home/npopov/repos/llvm-test-suite/MultiSource/Applications/lambda-0.1.3 -O3   -w -Werror=date-time -MD -MT MultiSource/Applications/lambda-0.1.3/CMakeFiles/lambda.dir/token_stream.cc.o -MF MultiSource/Applications/lambda-0.1.3/CMakeFiles/lambda.dir/token_stream.cc.o.d -o MultiSource/Applications/lambda-0.1.3/CMakeFiles/lambda.dir/token_stream.cc.o -c /home/npopov/repos/llvm-test-suite/MultiSource/Applications/lambda-0.1.3/token_stream.cc
    /home/npopov/repos/llvm-test-suite/MultiSource/Applications/lambda-0.1.3/token_stream.cc:192:2: error: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
            register char chr;
            ^~~~~~~~~
2022-09-08 09:45:50 +02:00
Timm Bäder 651f4ce7b1 [clang][Interp][NFC] Use constexpr if when possible in Integral.h 2022-09-08 07:31:08 +02:00
Timm Bäder 0da7e409e0 [clang][Interp][NFC] Context::classify() can be const 2022-09-08 07:31:08 +02:00
Timm Bäder 3a7d476087 [clang][Interp] Implement array initializers and subscript expressions
Differential Revision: https://reviews.llvm.org/D132727
2022-09-08 07:31:07 +02:00
Timm Bäder aa7c5c9c4e [clang][Interp] Handle missing local initializers better
This is illegal in a constexpr context. We can already figure that out,
but we'd still run into an assertion later on when trying to visit the
missing initializer or run the invalid function.

Differential Revision: https://reviews.llvm.org/D132832
2022-09-08 07:31:07 +02:00
Timm Bäder 5c4dbff0b6 [clang][Interp] Handle SubstNonTypeTemplateParmExprs
Differential Revision: https://reviews.llvm.org/D132831
2022-09-08 07:31:07 +02:00
Timm Bäder 4d700ffe67 [clang][Interp] Implement ImplicitValueInitExprs
Take the existing Zero opcode and emit it.

Differential Revision: https://reviews.llvm.org/D132829
2022-09-08 07:31:07 +02:00
Timm Bäder 95e6a407d9 [clang][Interp] Implement IntegralToBoolean casts
Redo how we do IntegralCasts and implement IntegralToBoolean casts using
the already existing cast op.

Differential Revision: https://reviews.llvm.org/D132739
2022-09-08 07:31:07 +02:00
Timm Bäder 8e41e6a4ea [clang][Interp] Implement function calls
Add Call() and CallVoid() ops and use them to call functions. Only
FunctionDecls are supported for now.

Differential Revision: https://reviews.llvm.org/D132286
2022-09-08 07:31:07 +02:00
Timm Bäder 5777c05d16 [clang] Perform implicit lvalue-to-rvalue cast with new interpreter
The EvaluateAsRValue() documentation mentions that an implicit
lvalue-to-rvalue cast is being performed if the result is an lvalue.
However, that was not being done if the new constant interpreter was in
use.

Just always do it.

Differential Revision: https://reviews.llvm.org/D132136
2022-09-08 07:31:07 +02:00
Fangrui Song bc502d9c24 Revert D133266 "[MinGW] Reject explicit non-default visibility applied to dllexport/dllimport declaration"
This reverts commit 91d8324366.

The combo dllexport protected makes sense and is used by PlayStation.
Will change the patch to allow dllexport protected.
2022-09-07 16:06:19 -07:00
Volodymyr Sapsai 3e7350f317 [ODRHash diagnostics] Move `ODRDiagsEmitter` to libAST in separate files. NFC.
Intend to use `ODRDiagsEmitter` during parsing to diagnose a parsed
definition differing from a definition with the same name from a hidden
[sub]module.

Differential Revision: https://reviews.llvm.org/D128695
2022-09-07 14:40:37 -07:00
Fangrui Song e321c8dd2c C++/ObjC++: switch to gnu++17 as the default standard
Clang's default C++ standard is now `gnu++17` instead of `gnu++14`:
https://discourse.llvm.org/t/c-objc-switch-to-gnu-17-as-the-default-dialect/64360

* CUDA/HIP are unchanged: C++14 from D103221.
* Sony PS4/PS5 are unchanged: https://discourse.llvm.org/t/c-objc-switch-to-gnu-17-as-the-default-dialect/64360/6
* lit feature `default-std-cxx` is added to keep CLANG_DEFAULT_STD_CXX=xxx tests working.
  Whether the cmake variable should be retained is disccused in D133375.

Depends on D131464

Close https://github.com/llvm/llvm-project/issues/56946

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

Differential Revision: https://reviews.llvm.org/D131465
2022-09-07 14:17:52 -07:00
Marco Elver c4842bb2e9 [Clang] Introduce -fexperimental-sanitize-metadata=
Introduces the frontend flag -fexperimental-sanitize-metadata=, which
enables SanitizerBinaryMetadata instrumentation.

The first intended user of the binary metadata emitted will be a variant
of GWP-TSan [1]. The plan is to open source a stable and production
quality version of GWP-TSan. The development of which, however, requires
upstream compiler support.

[1] https://llvm.org/devmtg/2020-09/slides/Morehouse-GWP-Tsan.pdf

Until the tool has been open sourced, we mark this kind of
instrumentation as "experimental", and reserve the option to change
binary format, remove features, and similar.

Reviewed By: vitalybuka, MaskRay

Differential Revision: https://reviews.llvm.org/D130888
2022-09-07 21:25:40 +02:00
Craig Topper cc14e195e7 [RISCV] Remove space before colon in error message. 2022-09-07 11:34:33 -07:00
Craig Topper 9ea7e4f7c1 [RISCV] Remove unnecessary word from error message. 2022-09-07 10:31:48 -07:00
Argyrios Kyrtzidis aa484c90cf [Lex/DependencyDirectivesScanner] Keep track of the presence of tokens between the last scanned directive and EOF
Directive `dependency_directives_scan::tokens_present_before_eof` is introduced to indicate there were tokens present before
the last scanned dependency directive and EOF.
This is useful to ensure we correctly identify the macro guards when lexing using the dependency directives.

Differential Revision: https://reviews.llvm.org/D133357
2022-09-07 10:31:29 -07:00
yronglin 6ed21fc515 Avoid __builtin_assume_aligned crash when the 1st arg is array type
Avoid __builtin_assume_aligned crash when the 1st arg is array type (or
string literal).

Fixes Issue #57169

Differential Revision: https://reviews.llvm.org/D133202
2022-09-07 12:46:20 -04:00
Philip Reames a4a29438f4 [RISCV][MC] Add minimal support for Ztso extension
This is a minimalist implementation which simply adds the extension (in the experimental namespace since its not ratified), and wires up the setting of the required ELF header flag. Future changes will include codegen changes to exploit the stronger memory model.

This is intended to implement v0.1 of the proposed specification which can be found in Chapter 25 of https://github.com/riscv/riscv-isa-manual/releases/download/draft-20220723-10eea63/riscv-spec.pdf.

Differential Revision: https://reviews.llvm.org/D133239
2022-09-07 09:30:57 -07:00