Commit Graph

95665 Commits

Author SHA1 Message Date
Erich Keane 0b36a62d5f [NFC] Add some additional features to MultiLevelTemplateArgumentList
These are useful when dealing with multi-depth instantiation in deferred
concepts, so this is split off of that patch.
2022-07-22 13:05:42 -07:00
Erich Keane 70c62f4cad [NFC] give getParentFunctionOrMethod a 'Lexical' parameter
Split up from the deferred concepts implementation, this function is
useful for determining the containing function of a different function.
However, in some cases it is valuable to instead get the lexical parent.
This adds a parameter to the existing function to allow a 'Lexical'
parameter to instead select the lexical parent.
2022-07-22 12:52:26 -07:00
Erich Keane 3ff86f9610 [NFC] Start saving InstantiatedFromDecl in non-template functions
In cases where a non-template function is defined inside a function
template, we don't have information about the original uninstantiated
version.  In the case of concepts instantiation, we will need the
ability to get back to the original template.  This patch splits a piece
of the deferred concepts instantaition patch off to accomplish the
storage of this, with minor runtime overhead, and zero additional
storage.
2022-07-22 12:37:14 -07:00
Aaron Ballman 7068aa9841 Strengthen -Wint-conversion to default to an error
Clang has traditionally allowed C programs to implicitly convert
integers to pointers and pointers to integers, despite it not being
valid to do so except under special circumstances (like converting the
integer 0, which is the null pointer constant, to a pointer). In C89,
this would result in undefined behavior per 3.3.4, and in C99 this rule
was strengthened to be a constraint violation instead. Constraint
violations are most often handled as an error.

This patch changes the warning to default to an error in all C modes
(it is already an error in C++). This gives us better security posture
by calling out potential programmer mistakes in code but still allows
users who need this behavior to use -Wno-error=int-conversion to retain
the warning behavior, or -Wno-int-conversion to silence the diagnostic
entirely.

Differential Revision: https://reviews.llvm.org/D129881
2022-07-22 15:24:54 -04:00
Sergei Barannikov 37502e042f [clang][CodeGen] Only include ABIInfo.h where required (NFC)
Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D130322
2022-07-22 10:45:02 -07:00
Dylan Fleming 846439dd97 [Flang] Generate documentation for compiler flags
This patch aims to create a webpage to document
Flang's command line options on https://flang.llvm.org/docs/
in a similar way to Clang's
https://clang.llvm.org/docs/ClangCommandLineReference.html

This is done by using clang_tablegen to generate an .rst
file from Options.td (which is current shared with Clang)
For this to work, ClangOptionDocEmitter.cpp was updated
to allow specific Flang flags to be included,
rather than bulk excluding clang flags.

Note:
Some headings in the generated documentation will incorrectly
contain references to Clang, e.g.
"Flags controlling the behaviour of Clang during compilation"
This is because Options.td (Which is shared between both Clang and Flang)
contains hard-coded DocBrief sections. I couldn't find a non-intrusive way
to make this target-dependant, as such I've left this as is, and it will need revisiting later.

Reviewed By: awarzynski

Differential Revision: https://reviews.llvm.org/D129864
2022-07-22 17:05:04 +00:00
VitalyR effe79993f [CUDA] remove duplicate condition
Reviewed by: Yaxun Liu

Differential Revision: https://reviews.llvm.org/D130168

Change-Id: Ia00c3dfa9ea20e61235817fd4bb61d33c7c98a60
2022-07-22 11:27:19 -04:00
Sam Estep aed1ab8cab [clang][dataflow] Refactor ApplyBuiltinTransfer field out into DataflowAnalysisOptions struct
Depends On D130304

This patch pulls the `ApplyBuiltinTransfer` from the `TypeErasedDataflowAnalysis` class into a new `DataflowAnalysisOptions` struct, to allow us to add additional options later without breaking existing code.

Reviewed By: gribozavr2, sgatev

Differential Revision: https://reviews.llvm.org/D130305
2022-07-22 15:16:29 +00:00
Sam Estep 32dcb759c3 [clang][dataflow] Move NoopAnalysis from unittests to include
This patch moves `Analysis/FlowSensitive/NoopAnalysis.h` from `clang/unittests/` to `clang/include/clang/`, so that we can use it for doing context-sensitive analysis.

Reviewed By: ymandel, gribozavr2, sgatev

Differential Revision: https://reviews.llvm.org/D130304
2022-07-22 14:11:32 +00:00
Egor Zhdan 1d0cc51051 [Clang][Driver] Fix include paths for `--sysroot /` on OpenBSD/FreeBSD
This is the same change as https://reviews.llvm.org/D126289, but applied for OpenBSD & FreeBSD.

Differential Revision: https://reviews.llvm.org/D129654
2022-07-22 14:30:32 +01:00
Nathan James 251b5b8641
[ASTMatchers] Fix standalone build
Disable the tests and remove private include introduced in d89f9e963e.
2022-07-22 10:32:49 +01:00
Benjamin Kramer 35b80c448b Don't write to source directory in test 2022-07-22 11:14:26 +02:00
Chuanqi Xu 6d9b84797c [C++20] [Modules] Handle reachability for partial specialization
Previously we don't catch the reachability for partial specialization.
Handle them in this patch.
2022-07-22 17:03:38 +08:00
Sebastian Neubauer f359eac5df [CMake][Clang] Copy folder without permissions
Copying the folder keeps the original permissions by default. This
creates problems when the source folder is read-only, e.g. in a
packaging environment.
Then, the copied folder in the build directory is read-only as well.
Later on, with configure_file, ClangConfig.cmake is copied into that
directory (in the build tree), failing when the directory is read-only.

Fix that problem by copying the folder without keeping the original
permissions.

Differential Revision: https://reviews.llvm.org/D130254
2022-07-22 10:38:54 +02:00
Kazu Hirata 70257fab68 Use any_of (NFC) 2022-07-22 01:05:17 -07:00
Iain Sandoe afda39a566 re-land [C++20][Modules] Build module static initializers per P1874R1.
The re-land fixes module map module dependencies seen on Greendragon, but
not in the clang test suite.

---

Currently we only implement this for the Itanium ABI since the correct
mangling for the initializers in other ABIs is not yet known.

Intended result:

For a module interface [which includes partition interface and implementation
units] (instead of the generic CXX initializer) we emit a module init that:

 - wraps the contained initializations in a control variable to ensure that
   the inits only happen once, even if a module is imported many times by
   imports of the main unit.

 - calls module initializers for imported modules first.  Note that the
   order of module import is not significant, and therefore neither is the
   order of imported module initializers.

 - We then call initializers for the Global Module Fragment (if present)
 - We then call initializers for the current module.
 - We then call initializers for the Private Module Fragment (if present)

For a module implementation unit, or a non-module TU that imports at least one
module we emit a regular CXX init that:

 - Calls the initializers for any imported modules first.
 - Then proceeds as normal with remaining inits.

For all module unit kinds we include a global constructor entry, this allows
for the (in most cases unusual) possibility that a module object could be
included in a final binary without a specific call to its initializer.

Implementation:

 - We provide the module pointer in the AST Context so that CodeGen can act
   on it and its sub-modules.

 - We need to account for module build lines like this:
  ` clang -cc1 -std=c++20 Foo.pcm -emit-obj -o Foo.o` or
  ` clang -cc1 -std=c++20 -xc++-module Foo.cpp -emit-obj -o Foo.o`

 - in order to do this, we add to ParseAST to set the module pointer in
   the ASTContext, once we establish that this is a module build and we
   know the module pointer. To be able to do this, we make the query for
   current module public in Sema.

 - In CodeGen, we determine if the current build requires a CXX20-style module
   init and, if so, we defer any module initializers during the "Eagerly
   Emitted" phase.

 - We then walk the module initializers at the end of the TU but before
   emitting deferred inits (which adds any hidden and static ones, fixing
   https://github.com/llvm/llvm-project/issues/51873 ).

 - We then proceed to emit the deferred inits and continue to emit the CXX
   init function.

Differential Revision: https://reviews.llvm.org/D126189
2022-07-22 08:38:07 +01:00
Fangrui Song 2191528373 [Driver][test] Remove unused "-o %t.s" from frame-pointer*.c 2022-07-21 19:41:25 -07:00
Volodymyr Sapsai 381fcaa136 [modules] Replace `-Wauto-import` with `-Rmodule-include-translation`.
Diagnostic for `-Wauto-import` shouldn't be a warning because it doesn't
represent a potential problem in code that should be fixed. And the
emitted fix-it is likely to trigger `-Watimport-in-framework-header`
which makes it challenging to have a warning-free codebase. But it is
still useful to see how include directives are translated into modular
imports and which module a header belongs to, that's why keep it as a remark.

Keep `-Wauto-import` for now to allow a gradual migration for codebases
using `-Wno-auto-import`, e.g., `-Weverything -Wno-auto-import`.

rdar://79594287

Differential Revision: https://reviews.llvm.org/D130138
2022-07-21 17:42:04 -07:00
Ryan Prichard 02a25279ae [Frontend] Correct values of ATOMIC_*_LOCK_FREE to match builtin
Correct the logic used to set `ATOMIC_*_LOCK_FREE` preprocessor macros not
to rely on the ABI alignment of types. Instead, just assume all those
types are aligned correctly by default since clang uses safe alignment
for `_Atomic` types even if the underlying types are aligned to a lower
boundary by default.

For example, the `long long` and `double` types on x86 are aligned to
32-bit boundary by default. However, `_Atomic long long` and `_Atomic
double` are aligned to 64-bit boundary, therefore satisfying
the requirements of lock-free atomic operations.

This fixes PR #19355 by correcting the value of
`__GCC_ATOMIC_LLONG_LOCK_FREE` on x86, and therefore also fixing
the assumption made in libc++ tests. This also fixes PR #30581 by
applying a consistent logic between the functions used to implement
both interfaces.

Reviewed By: hfinkel, efriedma

Differential Revision: https://reviews.llvm.org/D28213
2022-07-21 17:23:29 -07:00
Ryan Prichard 408a2638fd [CUDA] Ignore __CLANG_ATOMIC_LLONG_LOCK_FREE on i386
The default host CPU for an i386 triple is typically at least an i586,
which has cmpxchg8b (Clang feature, "cx8"). Therefore,
`__CLANG_ATOMIC_LLONG_LOCK_FREE` is 2 on the host, but the value should
be 1 for the device.

Also, grep for `__CLANG_ATOMIC_*` instead of `__GCC_ATOMIC_*`. The CLANG
macros are always emitted, but the GCC macros are omitted for the
*-windows-msvc targets. The `__GCC_HAVE_SYNC_COMPARE_AND_SWAP` macro
always has GCC in its name, not CLANG, however.

Reviewed By: tra

Differential Revision: https://reviews.llvm.org/D127465
2022-07-21 17:23:29 -07:00
Chi Chun Chen ccc12a2376 [OpenMP][NFC] Claim iterators in 'map' clause and motion clauses 2022-07-21 15:50:22 -05:00
Ziqing Luo b17baa1db6 [ASTMatchers] Adding a new matcher for callee declarations of Obj-C
message expressions

For an Obj-C message expression `[o m]`, the adding matcher will match
the declaration of the method `m`.  This commit overloads the existing
`callee` ASTMatcher, which originally was only for C/C++ nodes but
also applies to Obj-C messages now.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D129398
2022-07-21 13:35:31 -07:00
John Ericson 07b749800c [cmake] Don't export `LLVM_TOOLS_INSTALL_DIR` anymore
First of all, `LLVM_TOOLS_INSTALL_DIR` put there breaks our NixOS
builds, because `LLVM_TOOLS_INSTALL_DIR` defined the same as
`CMAKE_INSTALL_BINDIR` becomes an *absolute* path, and then when
downstream projects try to install there too this breaks because our
builds always install to fresh directories for isolation's sake.

Second of all, note that `LLVM_TOOLS_INSTALL_DIR` stands out against the
other specially crafted `LLVM_CONFIG_*` variables substituted in
`llvm/cmake/modules/LLVMConfig.cmake.in`.

@beanz added it in d0e1c2a550 to fix a
dangling reference in `AddLLVM`, but I am suspicious of how this
variable doesn't follow the pattern.

Those other ones are carefully made to be build-time vs install-time
variables depending on which `LLVMConfig.cmake` is being generated, are
carefully made relative as appropriate, etc. etc. For my NixOS use-case
they are also fine because they are never used as downstream install
variables, only for reading not writing.

To avoid the problems I face, and restore symmetry, I deleted the
exported and arranged to have many `${project}_TOOLS_INSTALL_DIR`s.
`AddLLVM` now instead expects each project to define its own, and they
do so based on `CMAKE_INSTALL_BINDIR`. `LLVMConfig` still exports
`LLVM_TOOLS_BINARY_DIR` which is the location for the tools defined in
the usual way, matching the other remaining exported variables.

For the `AddLLVM` changes, I tried to copy the existing pattern of
internal vs non-internal or for LLVM vs for downstream function/macro
names, but it would good to confirm I did that correctly.

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D117977
2022-07-21 19:04:00 +00:00
Zequan Wu d870a57563 [SemaCXX] Set promotion type for enum if its type is promotable to integer type even if it has no definition.
EnumDecl's promotion type is set either to the parsed type or calculated type
after completing its definition. When it's bool type and has no definition,
its promotion type is bool which is not allowed by clang.

Fixes #56560.

Differential Revision: https://reviews.llvm.org/D130210
2022-07-21 11:23:21 -07:00
Johannes Doerfert 48d6f52401 [CUDA][FIX] Make shfl[_sync] for unsigned long long non-recursive
A copy-paste error caused UB in the definition of the unsigned long long
versions of the shfl intrinsics. Reported and diagnosed by @trws.

Differential Revision: https://reviews.llvm.org/D129536
2022-07-21 12:36:54 -05:00
Joseph Huber 080022d8ed [LinkerWrapper] Embed OffloadBinaries for OpenMP offloading images
The OpenMP offloading runtine currently uses an array of linked
offloading images. One downside to this is that we cannot know the
architecture or triple associated with the given image. In this patch,
instead of embedding the image itself, we embed an offloading binary
instead. This binary is simply a binary format that wraps around the
original linked image to provide some additional metadata. This will
allow us to support offloading to multiple architecture, or performing
future JIT compilation inside of the runtime, more clearly.
Additionally, these can be placed at a special section such that the
supported architectures can be identified using objdump with the support
from D126904. This needs to be stored in a new section name
`.llvm.offloading.images` because the `.llvm.offloading` section
implicitly uses the `SHF_EXCLUDE` flag and will always be stripped.

This patch does not contain the necessary code to parse these in
libomptarget.

Depends on D127246

Reviewed By: saiislam

Differential Revision: https://reviews.llvm.org/D127304
2022-07-21 13:20:01 -04:00
Abraham Corea Diaz 119d22310b [clang] Add -fdiagnostics-format=sarif option for future SARIF output
Adds `sarif` option to the existing `-fdiagnostics-format` flag
for intended future work with SARIF diagnostics. Currently issues a warning
against the use of diagnostics in SARIF mode, then defaults to clang style for
diagnostics.

Reviewed By: cjdb, denik, aaron.ballman

Differential Revision: https://reviews.llvm.org/D129886
2022-07-21 16:51:15 +00:00
David Sherwood ceb6c23b70 [NFC][LoopVectorize] Explicitly disable tail-folding on some SVE tests
This patch is in preparation for enabling vectorisation with tail-folding
by default for SVE targets. Once we do that many existing tests will
break that depend upon having normal unpredicated vector loops. For
all such tests I have added the flag:

  -prefer-predicate-over-epilogue=scalar-epilogue

Differential Revision: https://reviews.llvm.org/D129137
2022-07-21 15:23:00 +01:00
Erich Keane 1da3119025 Revert "Rewording the "static_assert" to static assertion"
Looks like we again are going to have problems with libcxx tests that
are overly specific in their dependency on clang's diagnostics.

This reverts commit 6542cb55a3.
2022-07-21 06:40:14 -07:00
Muhammad Usman Shahid 6542cb55a3 Rewording the "static_assert" to static assertion
This patch is basically the rewording of the static assert statement's
output(error) on screen after failing. Failing a _Static_assert in C
should not report that static_assert failed. It’d probably be better to
reword the diagnostic to be more like GCC and say “static assertion”
failed in both C and C++.

consider a c file having code

_Static_assert(0, "oh no!");

In clang the output is like:

<source>:1:1: error: static_assert failed: oh no!
_Static_assert(0, "oh no!");
^              ~
1 error generated.
Compiler returned: 1

Thus here the "static_assert" is not much good, it will be better to
reword it to the "static assertion failed" to more generic. as the gcc
prints as:

<source>:1:1: error: static assertion failed: "oh no!"
    1 | _Static_assert(0, "oh no!");
          | ^~~~~~~~~~~~~~
          Compiler returned: 1

The above can also be seen here. This patch is about rewording
the static_assert to static assertion.

Differential Revision: https://reviews.llvm.org/D129048
2022-07-21 06:34:14 -07:00
Andrzej Warzynski ce824078de Revert "[Flang] Generate documentation for compiler flags"
This reverts commit 396e944d82.

Failing bot: https://lab.llvm.org/buildbot/#/builders/89/builds/30096
2022-07-21 11:54:49 +00:00
Dylan Fleming 396e944d82 [Flang] Generate documentation for compiler flags
This patch aims to create a webpage to document
Flang's command line options on https://flang.llvm.org/docs/
in a similar way to Clang's
https://clang.llvm.org/docs/ClangCommandLineReference.html

This is done by using clang_tablegen to generate an .rst
file from Options.td (which is current shared with Clang)
For this to work, ClangOptionDocEmitter.cpp was updated
to allow specific Flang flags to be included,
rather than bulk excluding clang flags.

Reviewed By: awarzynski

Differential Revision: https://reviews.llvm.org/D129864
2022-07-21 11:33:19 +00:00
Chuanqi Xu ea623af7c9 [C++20] [Modules] Avoid inifinite loop when iterating default args
Currently, clang may meet an infinite loop in a very tricky case when it
iterates the default args. This patch tries to fix this by adding a
`fixed` check.
2022-07-21 17:25:05 +08:00
Qiu Chaofan 708084ec37 [PowerPC] Support x86 compatible intrinsics on AIX
These headers used to be guarded only on PowerPC64 Linux or FreeBSD, but
they can also be enabled for AIX OS target since it's big-endian ready.

Reviewed By: shchenz

Differential Revision: https://reviews.llvm.org/D129461
2022-07-21 16:33:41 +08:00
Iain Sandoe 97af17c5ca re-land [C++20][Modules] Update handling of implicit inlines [P1779R3]
re-land fixes an unwanted interaction with module-map modules, seen in
Greendragon testing.

This provides updates to
[class.mfct]:
Pre C++20 [class.mfct]p2:
  A member function may be defined (8.4) in its class definition, in
  which case it is an inline member function (7.1.2)
Post C++20 [class.mfct]p1:
  If a member function is attached to the global module and is defined
  in its class definition, it is inline.

and
[class.friend]:
Pre-C++20 [class.friend]p5
  A function can be defined in a friend declaration of a
  class . . . . Such a function is implicitly inline.
Post C++20 [class.friend]p7
  Such a function is implicitly an inline function if it is attached
  to the global module.

We add the output of implicit-inline to the TextNodeDumper, and amend
a couple of existing tests to account for this, plus add tests for the
cases covered above.

Differential Revision: https://reviews.llvm.org/D129045
2022-07-21 09:17:01 +01:00
Chen Zheng ecdeabef38 enable P10 vector builtins test on AIX 64 bit; NFC
Verify that P10 vector builtins with type `vector signed __int128`
and `vector unsigned __int128` work well on AIX 64 bit.
2022-07-21 03:51:30 -04:00
Shraiysh Vaishay 61fa7a88c7 [clang][OpenMP] Add IRBuilder support for taskgroup
This patch makes use of OMPIRBuilder support for codegen of taskgroup
construct in clang.

Depends on D128203

Reviewed By: Meinersbur

Differential Revision: https://reviews.llvm.org/D129992
2022-07-21 11:13:57 +05:30
owenca a4c62f6654 [clang-format][NFC] Refactor RequiresDoesNotChangeParsingOfTheRest
Differential Revision: https://reviews.llvm.org/D129982
2022-07-20 21:56:48 -07:00
owenca 892a9968ec [clang-format] Indent tokens after hash only if it starts a line
Fixes #56602.

Differential Revision: https://reviews.llvm.org/D130136
2022-07-20 21:52:17 -07:00
Steven Wu d072826057 [Darwin toolchain] Tune the logic for finding arclite.
The heuristic used to determine where the arclite libraries are to be
found was based on the path of the `clang` executable. However, in some
scenarios the `clang` executable is within a toolchain that does not
have arclite. When this happens, derive the arclite paths from the
sysroot option.

This allows Clang to correctly derive the arclite directory in, e.g.,
Swift CI, using similar logic to what the Swift driver has been doing
for several years.

Patched by Doug Gregor.

Reviewed By: keith

Differential Revision: https://reviews.llvm.org/D130205
2022-07-20 16:45:52 -07:00
Joseph Huber 0c1b32717b [HIP] Allow the new driver to compile HIP in non-RDC mode
The new driver primarily allows us to support RDC-mode compilations with
proper linking. This is not needed for non-RDC mode compilation, but we
still would like the new driver to be able to handle this mode so we can
transition away from the old driver in the future. This patch adds the
necessary code to support creating a fatbinary for HIP code generation.

Reviewed By: yaxunl

Differential Revision: https://reviews.llvm.org/D129784
2022-07-20 16:52:23 -04:00
Xiang Li a73a84c447 [HLSL] add -I option for dxc mode.
A new option -I is added for dxc mode.
It is just alias of existing cc1 -I option.

Reviewed By: beanz

Differential Revision: https://reviews.llvm.org/D128462
2022-07-20 11:03:22 -07:00
Arthur Eubanks 7e77d31af7 [test] Remove unnecessary -verify-machineinstrs=0
Issue #38784 seems to be fixed and removing these doesn't cause any issues.
2022-07-20 10:55:54 -07:00
Jake Egan bd519b9335 redo UNSUPPORT test on 64-bit AIX too
The test failure affects both bitmodes.
2022-07-20 10:18:28 -04:00
Jake Egan 7373497a4b UNSUPPORT test on 64-bit AIX too
The test failure affects both bitmodes.
2022-07-20 10:05:03 -04:00
Louis Dionne 7169659752 [clang] Small adjustments for -fexperimental-library
Move -lc++experimental before -lc++abi (that was forgotten in the
original patch), and mark a test as UNSUPPORTED on AIX. I contacted
the owners of the AIX bot that failed because I was unable to reproduce
the issue locally.
2022-07-20 09:14:55 -04:00
Nicolai Hähnle 1ddc51d89d Inliner: don't mark call sites as 'nounwind' if that would be redundant
When F calls G calls H, G is nounwind, and G is inlined into F, then the
inlined call-site to H should be effectively nounwind so as not to lose
information during inlining.

If H itself is nounwind (which often happens when H is an intrinsic), we
no longer mark the callsite explicitly as nounwind. Previously, there
were cases where the inlined call-site of H differs from a pre-existing
call-site of H in F *only* in the explicitly added nounwind attribute,
thus preventing common subexpression elimination.

v2:
- just check CI->doesNotThrow

v3 (resubmit after revert at 3443788087):
- update Clang tests

Differential Revision: https://reviews.llvm.org/D129860
2022-07-20 14:17:23 +02:00
Nicolai Hähnle 7af2818a99 Update some more tests with update_cc_test_checks.py 2022-07-20 13:27:18 +02:00
Nicolai Hähnle 5a4033c367 update-test-checks: safely handle tests with #if's
There is at least one Clang test (clang/test/CodeGen/arm_acle.c) which
has functions guarded by #if's that cause those functions to be compiled
only for a subset of RUN lines.

This results in a case where one RUN line has a body for the function
and another doesn't. Treat this case as a conflict for any prefixes that
the two RUN lines have in common.

This change exposed a bug where functions with '$' in the name weren't
properly recognized in ARM assembly (despite there being a test case
that was supposed to catch the problem!). This bug is fixed as well.

Differential Revision: https://reviews.llvm.org/D130089
2022-07-20 11:23:49 +02:00
Fangrui Song 23ba688f02 [X86] Use Min behavior for cf-protection-{return,branch}/ibt-seal module flags
These features require that all object files are compiled with the support. When
the feature is disabled for an object file, the merge behavior should treat the
file having a value of 0 (see D129911).

Reviewed By: xiangzhangllvm

Differential Revision: https://reviews.llvm.org/D130065
2022-07-19 21:20:02 -07:00
Douglas Yung e882ac54c4 Mark test experimental-library-flag.cpp as XFAIL on PS4 and PS5 to get the bot green until the author can investigate.
Should fix https://lab.llvm.org/buildbot/#/builders/139/builds/25208

Test was originally introduced in D121141.
2022-07-19 21:18:46 -07:00
Kazu Hirata 0387da6f4f Use value instead of getValue (NFC) 2022-07-19 21:18:26 -07:00
Kazu Hirata 41ae78ea3a Use has_value instead of hasValue (NFC) 2022-07-19 20:15:44 -07:00
Alex Brachet 09d4dbc382 [llvm-driver] Generate symlinks instead of executables for tools
When LLVM_TOOL_LLVM_DRIVER_BUILD is On, create symlinks
to llvm instead of creating the executables. Currently
this only works for install and not
install-distribution, the work for the later will be
split up into a second patch.

Differential Revision: https://reviews.llvm.org/D127800
2022-07-20 01:42:56 +00:00
Qwinci 3f73c57935 Argument name support for function pointer signature hints
Fixes https://github.com/clangd/clangd/issues/1068

Reviewed By: nridge

Differential Revision: https://reviews.llvm.org/D125120
2022-07-19 20:02:26 -04:00
Volodymyr Sapsai f693874c53 [ODRHash diagnostics] Preparation to minimize subsequent diffs. NFC.
Specifically, making the following changes:
* Turn lambdas calculating ODR hashes into static functions.
* Move `ODRCXXRecordDifference` where it is used.
* Rename some variables and move some lines of code.
* Replace `auto` with explicit type when the deduced type is not mentioned.
* Add `const` for unmodified objects, so we can pass them to more functions.

Differential Revision: https://reviews.llvm.org/D128690
2022-07-19 16:29:33 -07:00
Denys Petrov a364987368 [analyzer][NFC] Use `SValVisitor` instead of explicit helper functions
Summary: Get rid of explicit function splitting in favor of specifically designed Visitor. Move logic from a family of `evalCastKind` and `evalCastSubKind` helper functions to `SValVisitor`.

Differential Revision: https://reviews.llvm.org/D130029
2022-07-19 23:10:00 +03:00
Louis Dionne ca495e36c1 [clang] Add a new flag -fexperimental-library to enable experimental library features
Based on the discussion at [1], this patch adds a Clang flag called
-fexperimental-library that controls whether experimental library
features are provided in libc++. In essence, it links against the
experimental static archive provided by libc++ and defines a feature
that can be picked up by libc++ to enable experimental features.

This ensures that users don't start depending on experimental
(and hence unstable) features unknowingly.

[1]: https://discourse.llvm.org/t/rfc-a-compiler-flag-to-enable-experimental-unstable-language-and-library-features

Differential Revision: https://reviews.llvm.org/D121141
2022-07-19 15:04:58 -04:00
Akira Hatanaka a62868aaea [libclang][ObjC] Inherit availability attribute from containing decls or
interface decls

This patch teaches getCursorPlatformAvailabilityForDecl to look for
availability attributes on the containing decls or interface decls if
the current decl doesn't have any availability attributes.

Differential Revision: https://reviews.llvm.org/D129504
2022-07-19 09:17:39 -07:00
Louis Dionne 7300a651f5 [libc++] Re-apply "Always build c++experimental.a""
This re-applies bb939931a1, which had been reverted by 09cebfb978
because it broke Chromium. The issues seen by Chromium should be
addressed by 1d0f79558c.

Differential Revision: https://reviews.llvm.org/D128927
2022-07-19 10:44:19 -04:00
Nicolai Hähnle 3d2256cc75 Revert "Update some more tests with update_cc_test_checks.py"
This reverts commit 9fb33d52b0.

Buildbots are showing a number of regressions that don't reproduce
locally. Needs more investigating.
2022-07-19 16:39:57 +02:00
Nicolai Hähnle 9fb33d52b0 Update some more tests with update_cc_test_checks.py 2022-07-19 16:18:35 +02:00
Xiang1 Zhang 4bb19de4b6 [X86] Add 64 bit implement for __SSC_MARK
Reviewed By: craig.topper, pengfei.wang, jinsong
Differential Revision: https://reviews.llvm.org/D129826
2022-07-19 16:13:41 +08:00
Nicolai Hähnle 5fc6213551 Revert change to clang/test/CodeGen/arm_acle.c
For some reason, update_cc_test_checks.py produced a failing test.

Partial revert of 301011fa60
2022-07-19 09:11:23 +02:00
Nicolai Hähnle 301011fa60 Rerun ./utils/update_cc_test.py on a bunch of tests
Due to update script changes; this reduces the size of a later
"real" diff.
2022-07-19 08:53:05 +02:00
ksyx 3198364e6e [RISCV][Clang] Add support for Zmmul extension
This patch implements recently ratified extension Zmmul, a subextension
of M (Integer Multiplication and Division) consisting only
multiplication part of it.

Differential Revision: https://reviews.llvm.org/D103313
Reviewed By: craig.topper, jrtc27, asb
2022-07-18 20:26:08 -04:00
Argyrios Kyrtzidis d1b58cada6 [unittests/Tooling/DependencyScannerTest] Add a target triple for `ScanDepsWithFS` test
This should fix the `clang-ppc64-aix` builder.
2022-07-18 16:55:07 -07:00
Björn Schäpers d2eda49202 [clang-format] Mark constexpr lambdas as lambda
Otherwise the brace was detected as a function brace, not wrong per se,
but when directly calling the lambda the calling parens were put on the
next line.

Differential Revision: https://reviews.llvm.org/D129946
2022-07-18 21:42:34 +02:00
Björn Schäpers 3c18a8b3a3 [clang-format] Indent TT_CtorInitializerColon after requires clauses
Fixes https://github.com/llvm/llvm-project/issues/56215

Differential Revision: https://reviews.llvm.org/D129942
2022-07-18 21:41:09 +02:00
Björn Schäpers 2b04c41b28 [clang-format] Fix misannotation of colon in presence of requires clause
For clauses without parentheses it was annotated as TT_InheritanceColon.
Relates to https://github.com/llvm/llvm-project/issues/56215

Differential Revision: https://reviews.llvm.org/D129940
2022-07-18 21:41:09 +02:00
Stanislav Mekhanoshin 523a99c0eb [AMDGPU] Support for gfx940 fp8 smfmac
Differential Revision: https://reviews.llvm.org/D129908
2022-07-18 12:12:41 -07:00
Stanislav Mekhanoshin 2695f0a688 [AMDGPU] Support for gfx940 fp8 mfma
Differential Revision: https://reviews.llvm.org/D129906
2022-07-18 11:49:56 -07:00
Stanislav Mekhanoshin 9fa5a6b7e8 [AMDGPU] Support for gfx940 fp8 conversions
Differential Revision: https://reviews.llvm.org/D129902
2022-07-18 11:48:43 -07:00
Nicolai Hähnle 1586075a00 Rerun ./utils/update_cc_test.py on a bunch of tests
Due to update script changes; this reduces the size of a later "real"
diff.
2022-07-18 18:48:34 +02:00
Joseph Huber 47b0aa5e4b [LinkerWrapper] Rework passing args to the LLVM backend 2022-07-18 12:44:15 -04:00
Argyrios Kyrtzidis fbbabd4ca0 [Tooling/DependencyScanning] Enable passing a `vfs::FileSystem` object to `DependencyScanningTool`
Also include a unit test to validate that the `vfs::FileSystem` object is properly used.

Differential Revision: https://reviews.llvm.org/D129912
2022-07-18 09:37:17 -07:00
Hans Wennborg 09cebfb978 Revert "[libc++] Always build c++experimental.a"
This caused build failures when building Clang and libc++ together on Mac:

  fatal error: 'experimental/memory_resource' file not found

See the code review for details. Reverting until the problem and how to
solve it is better understood.

(Updates to some test files were not reverted, since they seemed
unrelated and were later updated by 340b48b267b96.)

> This is the first part of a plan to ship experimental features
> by default while guarding them behind a compiler flag to avoid
> users accidentally depending on them. Subsequent patches will
> also encompass incomplete features (such as <format> and <ranges>)
> in that categorization. Basically, the idea is that we always
> build and ship the c++experimental library, however users can't
> use what's in it unless they pass the `-funstable` flag to Clang.
>
> Note that this patch intentionally does not start guarding
> existing <experimental/FOO> content behind the flag, because
> that would merely break users that might be relying on such
> content being in the headers unconditionally. Instead, we
> should start guarding new TSes behind the flag, and get rid
> of the existing TSes we have by shipping their Standard
> counterpart.
>
> Also, this patch must jump through a few hoops like defining
> _LIBCPP_ENABLE_EXPERIMENTAL because we still support compilers
> that do not implement -funstable yet.
>
> Differential Revision: https://reviews.llvm.org/D128927

This reverts commit bb939931a1.
2022-07-18 16:57:15 +02:00
Benjamin Kramer 313f8a20fd Don't include private gtest/gmock headers
Only gmock.h and gtest.h are supposed to be user-visible.
2022-07-18 16:34:36 +02:00
Vaibhav Yenamandra 4b03ad6506 [clang] Emit SARIF Diagnostics: Create `clang::SarifDocumentWriter` interface
[clang] Emit SARIF Diagnostics: Create clang::SarifDocumentWriter interface

Create an interface for writing SARIF documents from within clang:

The primary intent of this change is to introduce the interface
clang::SarifDocumentWriter, which allows incrementally adding
diagnostic data to a JSON backed document. The proposed interface is
not yet connected to the compiler internals, which will be covered in
future work. As such this change will not change the input/output
interface of clang.

This change also introduces the clang::FullSourceRange type that is
modeled after clang::SourceRange + clang::FullSourceLoc, this is useful
for packaging a pair of clang::SourceLocation objects with their
corresponding SourceManagers.

Previous discussions:

RFC for this change: https://lists.llvm.org/pipermail/cfe-dev/2021-March/067907.html
https://lists.llvm.org/pipermail/cfe-dev/2021-July/068480.html
SARIF Standard (2.1.0):

https://docs.oasis-open.org/sarif/sarif/v2.1.0/os/sarif-v2.1.0-os.html

Differential Revision: https://reviews.llvm.org/D109701
2022-07-18 08:37:59 -04:00
serge-sans-paille f764dc99b3 [clang] Introduce -fstrict-flex-arrays=<n> for stricter handling of flexible arrays
Some code [0] consider that trailing arrays are flexible, whatever their size.
Support for these legacy code has been introduced in
f8f6324983 but it prevents evaluation of
__builtin_object_size and __builtin_dynamic_object_size in some legit cases.

Introduce -fstrict-flex-arrays=<n> to have stricter conformance when it is
desirable.

n = 0: current behavior, any trailing array member is a flexible array. The default.
n = 1: any trailing array member of undefined, 0 or 1 size is a flexible array member
n = 2: any trailing array member of undefined or 0 size is a flexible array member

This takes into account two specificities of clang: array bounds as macro id
disqualify FAM, as well as non standard layout.

Similar patch for gcc discuss here: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101836

[0] https://docs.freebsd.org/en/books/developers-handbook/sockets/#sockets-essential-functions
2022-07-18 12:45:52 +02:00
Chuanqi Xu 4983fdfec0 [C++20] [Modules] Handle reachability for deduction guide
Previously, we forget to handle reachability for deduction guide.
The deduction guide is a hint to the compiler. And the deduction guide
should be able to use if the corresponding template decl is reachable.
2022-07-18 15:46:26 +08:00
Kazu Hirata 8b3ed1fa98 Remove redundant return statements (NFC)
Identified with readability-redundant-control-flow.
2022-07-17 15:37:46 -07:00
Kazu Hirata 8dfdb80f72 Ensure newlines at the end of files (NFC) 2022-07-17 15:37:45 -07:00
Brad Smith abc8f2b724 [Driver] Don't passs --dynamic-linker in -r mode
No behavior change as GNU ld/gold/ld.lld ignore --dynamic-linker in -r mode.
This change makes the intention clearer as we already suppress --dynamic-linker
for -shared, -static, and -static-pie.

Reviewed by: MaskRay, phosek

Differential Revision: https://reviews.llvm.org/D129714
2022-07-16 20:13:24 -04:00
Vitaly Buka 0fbafb5a1c [test] Fix memory leak in validateTargetProfile
Unfortunatly fixing leak expose use-after-free if delete more then one
Compilation for the same Driver, so I am changing validateTargetProfile
to create own Driver each time.

The test was added by D122865.
2022-07-16 16:47:50 -07:00
Vitaly Buka 45067f8fbf [test] Don't leak DerivedArgList in test 2022-07-16 14:03:38 -07:00
owenca a0458d92e9 [clang-format] Never remove braces in macro definitions
Fixes #56559.

Differential Revision: https://reviews.llvm.org/D129921
2022-07-16 13:11:10 -07:00
Vitaly Buka bbc4a71e41 [test] Fix leak in test 2022-07-16 12:41:12 -07:00
Krystian Kuzniarek b2465748f2 [clang-format][docs] Fix incorrect 'clang-format 7' option markers
Introduced by 23a5090c6, some style option markers indicated
'clang-format 7', though their respective options were available in
different releases.
2022-07-16 18:19:11 +02:00
Kazu Hirata 3b0dce5b8b Use value_or (NFC) 2022-07-15 19:46:29 -07:00
owenca a7789d6315 [clang-format][NFC] Replace SmallVector parameter with ArrayRef
Addresses https://reviews.llvm.org/D129466#3654410.
2022-07-15 17:26:22 -07:00
Argyrios Kyrtzidis 46a6989736 [unittests/Tooling/DependencyScannerTest.cpp] Use `using namespace` instead of wrapping the `.cpp` file contents in namespaces, NFC
This makes the file consistent with the coding style of the rest of LLVM.
2022-07-15 16:10:36 -07:00
Joseph Huber bb957a8d52 [CUDA] Make the new driver properly ignore non-CUDA inputs
The new driver generated offloadinga actions for each active toolchain.
However, for CUDA and HIP it is possible for the toolchain to be active
but one of the files is not a valid input. This can occur if the user
compiles both a CUDA and C source file in the same compiler invocation.
This patch adds some simple logic to quit if the input is not valid as
well.

Reviewed By: tra, MaskRay

Differential Revision: https://reviews.llvm.org/D129885
2022-07-15 17:38:34 -04:00
Haojian Wu 5b8337cf40 [syntax] Some #includes cleanup, NFC. 2022-07-15 21:05:59 +02:00
Vang Thao 67357739c6 [AMDGPU] Add remarks to output some resource usage
Add analyis remarks to output kernel name, register usage, occupancy,
scratch usage, spills, and LDS information.

Reviewed By: arsenm

Differential Revision: https://reviews.llvm.org/D123878
2022-07-15 11:01:53 -07:00
Fangrui Song 0d5a62faca [sanitizer] Add "mainfile" prefix to sanitizer special case list
When an issue exists in the main file (caller) instead of an included file
(callee), using a `src` pattern applying to the included file may be
inappropriate if it's the caller's responsibility. Add `mainfile` prefix to check
the main filename.

For the example below, the issue may reside in a.c (foo should not be called
with a misaligned pointer or foo should switch to an unaligned load), but with
`src` we can only apply to the innocent callee a.h. With this patch we can use
the more appropriate `mainfile:a.c`.
```
//--- a.h
// internal linkage
static inline int load(int *x) { return *x; }

//--- a.c, -fsanitize=alignment
#include "a.h"
int foo(void *x) { return load(x); }
```

See the updated clang/docs/SanitizerSpecialCaseList.rst for a caveat due
to C++ vague linkage functions.

Reviewed By: #sanitizers, kstoimenov, vitalybuka

Differential Revision: https://reviews.llvm.org/D129832
2022-07-15 10:39:26 -07:00
Denys Petrov bc08c3cb7f [analyzer] Add new function `clang_analyzer_value` to ExprInspectionChecker
Summary: Introduce a new function 'clang_analyzer_value'. It emits a report that in turn prints a RangeSet or APSInt associated with SVal. If there is no associated value, prints "n/a".
2022-07-15 20:07:04 +03:00
Denys Petrov 82f76c0477 [analyzer][NFC] Tidy up handler-functions in SymbolicRangeInferrer
Summary: Sorted some handler-functions into more appropriate visitor functions of the SymbolicRangeInferrer.
- Spread `getRangeForNegatedSub` body over several visitor functions: `VisitSymExpr`, `VisitSymIntExpr`, `VisitSymSymExpr`.
- Moved `getRangeForComparisonSymbol` from `infer` to `VisitSymSymExpr`.

Differential Revision: https://reviews.llvm.org/D129678
2022-07-15 19:24:57 +03:00
dongjunduo f5d9de8cc3 [Clang] Add a new clang option "-ftime-trace=<value>"
The time profiler traces the stages during the clang compile
process. Each compiling stage of a single source file
corresponds to a separately .json file which holds its
time tracing data. However, the .json files are stored in the
same path/directory as its corresponding stage's '-o' option.
For example, if we compile the "demo.cc" to "demo.o" with option
"-o /tmp/demo.o", the time trace data file path is "/tmp/demo.json".

A typical c++ project can contain multiple source files in different
path, but all the json files' paths can be a mess.

The option "-ftime-trace=<value>" allows you to specify where the json
files should be stored. This allows the users to place the time trace
data files of interest in the desired location for further data analysis.

Usage:
    - clang/clang++ -ftime-trace ...
    - clang/clang++ -ftime-trace=the-directory-you-want ...
    - clang/clang++ -ftime-trace=the-directory-you-want/ ...
    - clang/clang++ -ftime-trace=the-full-file-path-you-want ...

Differential Revision: https://reviews.llvm.org/D128048
2022-07-15 08:55:17 -07:00
Haojian Wu 5775c5d05c Remove an unsued-variable warning, NFC. 2022-07-15 14:40:52 +02:00
Haojian Wu 30c2406e27 [syntax] Add virtual destructor in TokenManager.
Fix `-Wnon-virtual-dtor` warning.
2022-07-15 11:51:13 +02:00
Krasimir Georgiev 8dd2ef2130 [clang-format] distinguish multiplication after brace-init from pointer
After b646f09555,
the added regression test started being formatted as-if the
multiplication `*` was a pointer. This adapts the heuristic to
distinguish between these two cases.

Reviewed By: jackhong12, curdeius, HazardyKnusperkeks, owenpan

Differential Revision: https://reviews.llvm.org/D129771
2022-07-15 11:45:12 +02:00
Haojian Wu 263dcf452f [syntax] Introduce a TokenManager interface.
TokenManager defines Token interfaces for the clang syntax-tree. This is the level
of abstraction that the syntax-tree should use to operate on Tokens.

It decouples the syntax-tree from a particular token implementation (TokenBuffer
previously).  This enables us to use a different underlying token implementation
for the syntax Leaf node -- in clang pseudoparser, we want to produce a
syntax-tree with its own pseudo::Token rather than syntax::Token.

Differential Revision: https://reviews.llvm.org/D128411
2022-07-15 10:30:37 +02:00
Fangrui Song 3c849d0aef Modernize Optional::{getValueOr,hasValue} 2022-07-15 01:20:39 -07:00
Nikita Popov 2a721374ae [IR] Don't use blockaddresses as callbr arguments
Following some recent discussions, this changes the representation
of callbrs in IR. The current blockaddress arguments are replaced
with `!` label constraints that refer directly to callbr indirect
destinations:

    ; Before:
    %res = callbr i8* asm "", "=r,r,i"(i8* %x, i8* blockaddress(@test8, %foo))
    to label %asm.fallthrough [label %foo]
    ; After:
    %res = callbr i8* asm "", "=r,r,!i"(i8* %x)
    to label %asm.fallthrough [label %foo]

The benefit of this is that we can easily update the successors of
a callbr, without having to worry about also updating blockaddress
references. This should allow us to remove some limitations:

* Allow unrolling/peeling/rotation of callbr, or any other
  clone-based optimizations
  (https://github.com/llvm/llvm-project/issues/41834)
* Allow duplicate successors
  (https://github.com/llvm/llvm-project/issues/45248)

This is just the IR representation change though, I will follow up
with patches to remove limtations in various transformation passes
that are no longer needed.

Differential Revision: https://reviews.llvm.org/D129288
2022-07-15 10:18:17 +02:00
Chuanqi Xu 2f1555fb11 [C++20] [Modules] Handle reachability for enum class
In previous reachability patch, we missed the case for enum class.
Trying to handle it in this patch and add the corresponding tests.
2022-07-15 15:57:04 +08:00
Jonas Devlieghere 888673b6e3
Revert "[clang] Implement ElaboratedType sugaring for types written bare"
This reverts commit 7c51f02eff because it
stills breaks the LLDB tests. This was  re-landed without addressing the
issue or even agreement on how to address the issue. More details and
discussion in https://reviews.llvm.org/D112374.
2022-07-14 21:17:48 -07:00
Matheus Izvekov 7c51f02eff
[clang] Implement ElaboratedType sugaring for types written bare
Without this patch, clang will not wrap in an ElaboratedType node types written
without a keyword and nested name qualifier, which goes against the intent that
we should produce an AST which retains enough details to recover how things are
written.

The lack of this sugar is incompatible with the intent of the type printer
default policy, which is to print types as written, but to fall back and print
them fully qualified when they are desugared.

An ElaboratedTypeLoc without keyword / NNS uses no storage by itself, but still
requires pointer alignment due to pre-existing bug in the TypeLoc buffer
handling.

---

Troubleshooting list to deal with any breakage seen with this patch:

1) The most likely effect one would see by this patch is a change in how
   a type is printed. The type printer will, by design and default,
   print types as written. There are customization options there, but
   not that many, and they mainly apply to how to print a type that we
   somehow failed to track how it was written. This patch fixes a
   problem where we failed to distinguish between a type
   that was written without any elaborated-type qualifiers,
   such as a 'struct'/'class' tags and name spacifiers such as 'std::',
   and one that has been stripped of any 'metadata' that identifies such,
   the so called canonical types.
   Example:
   ```
   namespace foo {
     struct A {};
     A a;
   };
   ```
   If one were to print the type of `foo::a`, prior to this patch, this
   would result in `foo::A`. This is how the type printer would have,
   by default, printed the canonical type of A as well.
   As soon as you add any name qualifiers to A, the type printer would
   suddenly start accurately printing the type as written. This patch
   will make it print it accurately even when written without
   qualifiers, so we will just print `A` for the initial example, as
   the user did not really write that `foo::` namespace qualifier.

2) This patch could expose a bug in some AST matcher. Matching types
   is harder to get right when there is sugar involved. For example,
   if you want to match a type against being a pointer to some type A,
   then you have to account for getting a type that is sugar for a
   pointer to A, or being a pointer to sugar to A, or both! Usually
   you would get the second part wrong, and this would work for a
   very simple test where you don't use any name qualifiers, but
   you would discover is broken when you do. The usual fix is to
   either use the matcher which strips sugar, which is annoying
   to use as for example if you match an N level pointer, you have
   to put N+1 such matchers in there, beginning to end and between
   all those levels. But in a lot of cases, if the property you want
   to match is present in the canonical type, it's easier and faster
   to just match on that... This goes with what is said in 1), if
   you want to match against the name of a type, and you want
   the name string to be something stable, perhaps matching on
   the name of the canonical type is the better choice.

3) This patch could exposed a bug in how you get the source range of some
   TypeLoc. For some reason, a lot of code is using getLocalSourceRange(),
   which only looks at the given TypeLoc node. This patch introduces a new,
   and more common TypeLoc node which contains no source locations on itself.
   This is not an inovation here, and some other, more rare TypeLoc nodes could
   also have this property, but if you use getLocalSourceRange on them, it's not
   going to return any valid locations, because it doesn't have any. The right fix
   here is to always use getSourceRange() or getBeginLoc/getEndLoc which will dive
   into the inner TypeLoc to get the source range if it doesn't find it on the
   top level one. You can use getLocalSourceRange if you are really into
   micro-optimizations and you have some outside knowledge that the TypeLocs you are
   dealing with will always include some source location.

4) Exposed a bug somewhere in the use of the normal clang type class API, where you
   have some type, you want to see if that type is some particular kind, you try a
   `dyn_cast` such as `dyn_cast<TypedefType>` and that fails because now you have an
   ElaboratedType which has a TypeDefType inside of it, which is what you wanted to match.
   Again, like 2), this would usually have been tested poorly with some simple tests with
   no qualifications, and would have been broken had there been any other kind of type sugar,
   be it an ElaboratedType or a TemplateSpecializationType or a SubstTemplateParmType.
   The usual fix here is to use `getAs` instead of `dyn_cast`, which will look deeper
   into the type. Or use `getAsAdjusted` when dealing with TypeLocs.
   For some reason the API is inconsistent there and on TypeLocs getAs behaves like a dyn_cast.

5) It could be a bug in this patch perhaps.

Let me know if you need any help!

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

Differential Revision: https://reviews.llvm.org/D112374
2022-07-15 04:16:55 +02:00
Shafik Yaghmour 80dec2ecff [Clang] Modify CXXMethodDecl::isMoveAssignmentOperator() to look through type sugar
AcceptedPublic

Currently CXXMethodDecl::isMoveAssignmentOperator() does not look though type
sugar and so if the parameter is a type alias it will not be able to detect
that the method is a move assignment operator. This PR fixes that and adds a set
of tests that covers that we correctly detect special member functions when
defaulting or deleting them.

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

Differential Revision: https://reviews.llvm.org/D129591
2022-07-14 16:09:52 -07:00
owenca 6ab7307177 [clang-format] Fix invalid-code-generation by RemoveBracesLLVM
When removing an r_brace that is the first token of an annotated line, if the
line above ends with a line comment, clang-format generates invalid code by
merging the tokens after the r_brace into the line comment.

Fixes #56488.

Differential Revision: https://reviews.llvm.org/D129742
2022-07-14 15:19:57 -07:00
isuckatcs b032e3ff61 [analyzer] Evaluate construction of non-POD type arrays
Introducing the support for evaluating the constructor
of every element in an array. The idea is to record the
index of the current array member being constructed and
create a loop during the analysis. We looping over the
same CXXConstructExpr as many times as many elements
the array has.

Differential Revision: https://reviews.llvm.org/D127973
2022-07-14 23:30:21 +02:00
Jez Ng 7dbfc4fc06 [clang] Document -femit-compact-unwind option in the User’s Manual
Reviewed By: #lld-macho, thakis

Differential Revision: https://reviews.llvm.org/D129772
2022-07-14 16:50:36 -04:00
Vitaly Buka a629ec2f47 [test] Fix D129789 for 32bit platforms 2022-07-14 12:44:15 -07:00
Ellis Hoag af58684f27 [InstrProf] Add options to profile function groups
Add two options, `-fprofile-function-groups=N` and `-fprofile-selected-function-group=i` used to partition functions into `N` groups and only instrument the functions in group `i`. Similar options were added to xray in https://reviews.llvm.org/D87953 and the goal is the same; to reduce instrumented size overhead by spreading the overhead across multiple builds. Raw profiles from different groups can be added like normal using the `llvm-profdata merge` command.

Reviewed By: ianlevesque

Differential Revision: https://reviews.llvm.org/D129594
2022-07-14 11:41:30 -07:00
Nick Desaulniers 140bfdca60 [clang][CodeGen] add fn_ret_thunk_extern to synthetic fns
Follow up fix to
commit 2240d72f15 ("[X86] initial -mfunction-return=thunk-extern
support")
https://reviews.llvm.org/D129572

@nathanchance reported that -mfunction-return=thunk-extern was failing
to annotate the asan and tsan contructors.
https://lore.kernel.org/llvm/Ys7pLq+tQk5xEa%2FB@dev-arch.thelio-3990X/

I then noticed the same occurring for gcov synthetic functions.

Similar to
commit 2786e67 ("[IR][sanitizer] Add module flag "frame-pointer" and set
it for cc1 -mframe-pointer={non-leaf,all}")
define a new module level MetaData, "fn_ret_thunk_extern", then when set
adds the fn_ret_thunk_extern IR Fn Attr to synthetically created
Functions.

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

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D129709
2022-07-14 11:25:24 -07:00
Vitaly Buka a2e01bdcc2 [test][CodeGen] Don't miss lifetime markers in lifetime tests
Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D129789
2022-07-14 11:14:07 -07:00
Mitch Phillips 041d4012e4 Revert "Rewording "static_assert" diagnostics"
This reverts commit b7e77ff25f.

Reason: Broke sanitizer builds bots + libcxx. 'static assertion
expression is not an integral constant expression'. More details
available in the Phabricator review: https://reviews.llvm.org/D129048
2022-07-14 10:59:20 -07:00
Nick Desaulniers d2792e7d37 [clang][test] fix typo in fn attr
While testing backports of
https://reviews.llvm.org/D129572#inline-1245936
commit 2240d72f15 ("[X86] initial -mfunction-return=thunk-extern support")
I noticed that one of my unit tests mistyped a function attribute. The
unit test was intended to test fn attr merging behavior, but with the
typo it was not.  Small fixup.

Reviewed By: aaron.ballman, erichkeane

Differential Revision: https://reviews.llvm.org/D129691
2022-07-14 09:49:11 -07:00
Erich Keane e71fd54719 [NFC] Move check for isEqualityOp to CheckFloatComparisons
So callers don't have to.  Also, fix a clang-format/use of auto fix in
CheckFloatComparisons.
2022-07-14 09:30:29 -07:00
Ella Ma 32fe1a4be9 [analyzer] Fixing SVal::getType returns Null Type for NonLoc::ConcreteInt in boolean type
In method `TypeRetrievingVisitor::VisitConcreteInt`, `ASTContext::getIntTypeForBitwidth` is used to get the type for `ConcreteInt`s.
However, the getter in ASTContext cannot handle the boolean type with the bit width of 1, which will make method `SVal::getType` return a Null `Type`.
In this patch, a check for this case is added to fix this problem by returning the bool type directly when the bit width is 1.

Differential Revision: https://reviews.llvm.org/D129737
2022-07-14 22:00:38 +08:00
Adam Czachorowski cab3cfd013 [clang] Do not crash on "requires" after a fatal error occurred.
The code would assume that SubstExpr() cannot fail on concept
specialization. This is incorret - we give up on some things after fatal
error occurred, since there's no value in doing futher work that the
user will not see anyway. In this case, this lead to crash.

The fatal error is simulated in tests with -ferror-limit=1, but this
could happen in other cases too.

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

Differential Revision: https://reviews.llvm.org/D129499
2022-07-14 15:45:32 +02:00
Muhammad Usman Shahid b7e77ff25f Rewording "static_assert" diagnostics
This patch rewords the static assert diagnostic output. Failing a
_Static_assert in C should not report that static_assert failed. This
changes the wording to be more like GCC and uses "static assertion"
when possible instead of hard coding the name. This also changes some
instances of 'static_assert' to instead be based on the token in the
source code.

Differential Revision: https://reviews.llvm.org/D129048
2022-07-14 07:47:37 -04:00
Aaron Puchert e0c66c699e Thread safety analysis: Don't erase TIL_Opcode type (NFC)
This is mainly for debugging, but it also eliminates some casts.
2022-07-14 13:36:35 +02:00
Aaron Puchert bfe63ab63e Thread safety analysis: Support builtin pointer-to-member operators
We consider an access to x.*pm as access of the same kind into x, and
an access to px->*pm as access of the same kind into *px. Previously we
missed reads and writes in the .* case, and operations to the pointed-to
data for ->* (we didn't miss accesses to the pointer itself, because
that requires an LValueToRValue cast that we treat independently).

We added support for overloaded operator->* in D124966.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D129514
2022-07-14 13:36:14 +02:00
Fangrui Song 52cb972537 [CommandLine] --help: print "-o <xxx>" instead of "-o=<xxx>"
Accepting -o= is a quirk of CommandLine. For --help, we should print the
conventional "-o <xxx>".
2022-07-14 01:28:28 -07:00
Shoaib Meenai 42b3a5fb46 [clang] Add missing header include
With my version of the MSVC tools (14.11.25503), this was failing to
build because of missing declarations of `std::isalnum` and
`std::isdigit`. Include `<cctype>` to get these.
2022-07-14 00:21:09 -07:00
Kazu Hirata cb2c8f694d [clang] Use value instead of getValue (NFC) 2022-07-13 23:39:33 -07:00
Corentin Jabot 6882ca9aff [Clang] Adjust extension warnings for delimited sequences
WG21 approved delimited escape sequences and named escape
sequences.
Adjust the extension warnings accordingly, and update
the release notes.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D129664
2022-07-14 07:50:58 +02:00
Joseph Huber b370be37cc [CUDA] Allow the new driver to compile CUDA in non-RDC mode
The new driver primarily allows us to support RDC-mode compilations with
proper linking. This is not needed for non-RDC mode compilation, but we
still would like the new driver to be able to handle this mode so we can
transition away from the old driver in the future. This patch adds the
necessary code to support creating a fatbinary for CUDA code generation
as well as removing old assumptions and errors about RDC-mode with the
new driver.

Reviewed By: tra

Differential Revision: https://reviews.llvm.org/D129655
2022-07-13 21:49:15 -04:00
Nico Weber 422e6e7629 [docs] Document git-clang-format
clang-format's documentation documented the more general clang-format-diff.py
script. Add documentation for the less general but arguably easier-to-use
git integration as well.

Differential Revision: https://reviews.llvm.org/D129563
2022-07-13 21:06:00 -04:00
einvbri 1d7e58cfad [analyzer] Fix use of length in CStringChecker
CStringChecker is using getByteLength to get the length of a string
literal. For targets where a "char" is 8-bits, getByteLength() and
getLength() will be equal for a C string, but for targets where a "char"
is 16-bits getByteLength() returns the size in octets.

This is verified in our downstream target, but we have no way to add a
test case for this case since there is no target supporting 16-bit
"char" upstream. Since this cannot have a test case, I'm asserted this
change is "correct by construction", and visually inspected to be
correct by way of the following example where this was found.

The case that shows this fails using a target with 16-bit chars is here.
getByteLength() for the string literal returns 4, which fails when
checked against "char x[4]". With the change, the string literal is
evaluated to a size of 2 which is a correct number of "char"'s for a
16-bit target.

```
void strcpy_no_overflow_2(char *y) {
  char x[4];
  strcpy(x, "12"); // with getByteLength(), returns 4 using 16-bit chars
}
```

This change exposed that embedded nulls within the string are not
handled. This is documented as a FIXME for a future fix.

```
    void strcpy_no_overflow_3(char *y) {
      char x[3];
      strcpy(x, "12\0");
    }

```

Reviewed By: martong

Differential Revision: https://reviews.llvm.org/D129269
2022-07-13 19:19:23 -05:00
Dave Lee b5ccfeb6bf [lldb] Add image dump pcm-info command
Add `pcm-info` to the `target module dump` subcommands.

This dump command shows information about clang .pcm files. This command
effectively runs `clang -module-file-info` and produces identical output.

The .pcm file format is tightly coupled to the clang version. The clang
embedded in lldb is not guaranteed to match the version of the clang executable
available on the local system.

There have been times when I've needed to view the details about a .pcm file
produced by lldb's embedded clang, but because the clang executable was a
slightly different version, the `-module-file-info` invocation failed. With
this command, users can inspect .pcm files generated by lldb too.

Differential Revision: https://reviews.llvm.org/D129456
2022-07-13 16:56:53 -07:00
owenca 36229fa388 [clang-format][NFC] Replace most of std::vector with SmallVector
Differential Revision: https://reviews.llvm.org/D129466
2022-07-13 16:45:22 -07:00
Fangrui Song e690137dde [Support] Change compression::zlib::{compress,uncompress} to use uint8_t *
It's more natural to use uint8_t * (std::byte needs C++17 and llvm has
too much uint8_t *) and most callers use uint8_t * instead of char *.
The functions are recently moved into `llvm::compression::zlib::`, so
downstream projects need to make adaption anyway.
2022-07-13 16:26:54 -07:00
Roy Jacobson 202b327f5d [DOC] Add DR1734 and DR1496 Clang's cxx_dr_status as not implemented
Those two DRs about the (copy) triviality of types with deleted special member functions are not implemented in Clang.
Document them as such.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D129583
2022-07-14 00:48:35 +03:00
Martin Storsjö 779ba43234 [clang][deps] Silence a GCC warning about missing returns after a fully covered switch. NFC. 2022-07-13 23:57:01 +03:00
Ben Langmuir 3ce78cbd23 [clang][deps] Fix handling of -MT in module command-line
Follow-up to 6626f6fec3, this fixes the handling of -MT
* If no targets are provided, we need to invent one since cc1 expects
  the driver to have handled it. The default is to use -o, quoting as
  necessary for a make target.
* Fix the splitting for empty string, which was incorrectly treated as
  {""} instead of {}.
* Add a way to test this behaviour in clang-scan-deps.

Differential Revision: https://reviews.llvm.org/D129607
2022-07-13 13:36:15 -07:00
Joseph Huber 6abaa8e210 [CUDA][HIP][NFC] Do not add `-fgpu-rdc` flag twice
Summary:
We currently add the `-fgpu-rdc` flag twice. Once unconditionally for
both the host and device phases of compilation, and a second time only
for the host. When we moved to an unconditional addition of this flag it
the old one was most likely not removed. This patch simply removes the
redundant flag and changes no functionality.
2022-07-13 15:57:53 -04:00
Joseph Huber 1a5c1ee5b8 [LinkerWrapper] Fix deleted constructor error on older compilers
Summary:
The previous patch moved some functoinality into a new function and
returned it. The vector contained move-only members. Newer compilers
should figure this out and I didn't notice any problems, but other ones
have problems. Explicitly move this vector to hopefully solve the issue.
2022-07-13 15:45:35 -04:00
Jolanta Jensen 07df9e918e [NFC] Minor cleanup of usage of FloatModeKind with bitmask enums
Differential Revision: https://reviews.llvm.org/D129373
2022-07-13 20:44:06 +01:00
Joseph Huber c70db40ceb [LinkerWrapper] Support time tracing in the linker wrapper
Summary:
This patch adds the new `--wrapper-time-trace=` option to write a time
tracing JSON file indicating where time was spent in the linker wrapper.
We also reformat and group some of the existing code to make
constraining the scope easier for time tracing.  We use the `--wrapper`
prefix to set this apart from the time tracing that lld may use.
2022-07-13 15:38:39 -04:00
Joseph Huber 96f16a6867 [LinkerWrapper] Add support for timescope tracing 2022-07-13 15:38:39 -04:00
Zarko Todorovski a61b202d4e [Clang][Sema][AIX][PowerPC] Emit byval alignment warning only when struct is passed to a function
Previous warning went on whenever a struct with a struct member with alignment => 16
was declared. This led to too many false positives and led to diagnostic lit failures
due to it being emitted too frequently. Only emit the warning when such a struct and
that struct contains a member that has an alignment of 16 bytes is passed to a caller
function since this is where the potential binary compatibility issue with XL 16.1.0
and older exists.

Reviewed By: sfertile, aaron.ballman

Differential Revision: https://reviews.llvm.org/D118350
2022-07-13 15:32:29 -04:00
Joseph Huber 20d253e3bf [LinkerWrapper] Fix linker-wrapper not working with host-LTO 2022-07-13 12:32:02 -04:00
Jonas Devlieghere 3968936b92
Revert "[clang] Implement ElaboratedType sugaring for types written bare"
This reverts commit bdc6974f92 because it
breaks all the LLDB tests that import the std module.

  import-std-module/array.TestArrayFromStdModule.py
  import-std-module/deque-basic.TestDequeFromStdModule.py
  import-std-module/deque-dbg-info-content.TestDbgInfoContentDequeFromStdModule.py
  import-std-module/forward_list.TestForwardListFromStdModule.py
  import-std-module/forward_list-dbg-info-content.TestDbgInfoContentForwardListFromStdModule.py
  import-std-module/list.TestListFromStdModule.py
  import-std-module/list-dbg-info-content.TestDbgInfoContentListFromStdModule.py
  import-std-module/queue.TestQueueFromStdModule.py
  import-std-module/stack.TestStackFromStdModule.py
  import-std-module/vector.TestVectorFromStdModule.py
  import-std-module/vector-bool.TestVectorBoolFromStdModule.py
  import-std-module/vector-dbg-info-content.TestDbgInfoContentVectorFromStdModule.py
  import-std-module/vector-of-vectors.TestVectorOfVectorsFromStdModule.py

https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/45301/
2022-07-13 09:20:30 -07:00
Mitch Phillips 7045519359 Add missing sanitizer metadata plumbing from CFE.
clang misses attaching sanitizer metadata for external globals.

Reviewed By: eugenis

Differential Revision: https://reviews.llvm.org/D129492
2022-07-13 08:54:41 -07:00
Mitch Phillips 90e5a8ac47 Remove 'no_sanitize_memtag'. Add 'sanitize_memtag'.
For MTE globals, we should have clang emit the attribute for all GV's
that it creates, and then use that in the upcoming AArch64 global
tagging IR pass. We need a positive attribute for this sanitizer (rather
than implicit sanitization of all globals) because it needs to interact
with other parts of LLVM, including:

  1. Suppressing certain global optimisations (like merging),
  2. Emitting extra directives by the ASM writer, and
  3. Putting extra information in the symbol table entries.

While this does technically make the LLVM IR / bitcode format
non-backwards-compatible, nobody should have used this attribute yet,
because it's a no-op.

Reviewed By: eugenis

Differential Revision: https://reviews.llvm.org/D128950
2022-07-13 08:54:41 -07:00
Kai Nacke 880eb839e6 [SystemZ] Enable `-mtune=` option in clang.
https://reviews.llvm.org/D128910 enabled handling of
attribute "tune-cpu" in LLVM. This PR now enables
option `-mtune` in clang, which then generates the
new attribute.

Reviewed By: uweigand

Differential Revision: https://reviews.llvm.org/D129562
2022-07-13 11:39:24 -04:00
serge-sans-paille 66fa2847a7 [clang] Ignore DependentSizeArray in -Warray-parameter
Acknowledge we don't know how to handle those yet.
2022-07-13 14:58:23 +02:00
Jun Zhang 8082a00286
[CodeGen] Keep track of decls that were deferred and have been emitted.
This patch adds a new field called EmittedDeferredDecls in CodeGenModule
that keeps track of decls that were deferred and have been emitted.

The intention of this patch is to solve issues in the incremental c++,
we'll lose info of decls that are lazily emitted when we undo their
usage.

See example below:

clang-repl> inline int foo() { return 42;}
clang-repl> int bar = foo();
clang-repl> %undo
clang-repl> int baz = foo();
JIT session error: Symbols not found: [ _Z3foov ]
error: Failed to materialize symbols: { (main, { baz, $.incr_module_2.inits.0,
orc_init_func.incr_module_2 }) }

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

Differential Revision: https://reviews.llvm.org/D128782
2022-07-13 20:00:59 +08:00
Wei Yi Tee b8d83e8004 [clang][dataflow] Generate readable form of input and output of satisfiability checking.
Differential Revision: https://reviews.llvm.org/D129548
2022-07-13 11:58:51 +00:00
Wei Yi Tee 3ec2b2f4ec [clang][dataflow] Rename `Status` field in a `Solver::Result` struct to `SATCheckStatus`.
Previously, `Status` was named after the enum type `Status` which caused the enum to be hidden by the non-type declaration of the `Status` field. This patch fixes this issue by using different names for the field and type.

Differential Revision: https://reviews.llvm.org/D129568
2022-07-13 11:40:37 +00:00
Wei Yi Tee c9666d2339 [clang][dataflow] Generate readable form of boolean values.
Differential Revision: https://reviews.llvm.org/D129547
2022-07-13 10:35:17 +00:00
Wei Yi Tee 1e9cd04d7b [clang][dataflow] Refactor boolean creation as a test utility.
Differential Revision: https://reviews.llvm.org/D129546
2022-07-13 10:35:17 +00:00
Wei Yi Tee 632de855a0 [clang][dataflow] Refactor boolean creation as a test utility.
Differential Revision: https://reviews.llvm.org/D129546
2022-07-13 10:15:06 +00:00
Cullen Rhodes 7c3cda551a [AArch64][SVE] Prefer SIMD&FP variant of clast[ab]
The scalar variant with GPR source/dest has considerably higher latency
than the SIMD&FP scalar variant across a variety of micro-architectures:

  Core           Scalar    SIMD&FP
  --------------------------------
  Neoverse V1     9 cyc      3 cyc
  Neoverse N2     8 cyc      3 cyc
  Cortex A510     8 cyc      4 cyc
  A64FX          29 cyc      6 cyc
2022-07-13 08:53:36 +00:00
Corentin Jabot d4892a168f [Clang] Add a warning on invalid UTF-8 in comments.
Introduce an off-by default `-Winvalid-utf8` warning
that detects invalid UTF-8 code units sequences in comments.

Invalid UTF-8 in other places is already diagnosed,
as that cannot appear in identifiers and other grammar constructs.

The warning is off by default as its likely to be somewhat disruptive
otherwise.

This warning allows clang to conform to the yet-to be approved WG21
"P2295R5 Support for UTF-8 as a portable source file encoding"
paper.

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

Differential Revision: https://reviews.llvm.org/D128059
2022-07-13 10:19:26 +02:00
Kazu Hirata 53daa177f8 [clang, clang-tools-extra] Use has_value instead of hasValue (NFC) 2022-07-12 22:47:41 -07:00
Jorge Gorbe Moya fcbb4e1fa4 [NFCI] Fix unused variable warning with asserts off in clang/lib/Sema/TypeLocBuilder.cpp 2022-07-12 17:40:41 -07:00
Matheus Izvekov bdc6974f92
[clang] Implement ElaboratedType sugaring for types written bare
Without this patch, clang will not wrap in an ElaboratedType node types written
without a keyword and nested name qualifier, which goes against the intent that
we should produce an AST which retains enough details to recover how things are
written.

The lack of this sugar is incompatible with the intent of the type printer
default policy, which is to print types as written, but to fall back and print
them fully qualified when they are desugared.

An ElaboratedTypeLoc without keyword / NNS uses no storage by itself, but still
requires pointer alignment due to pre-existing bug in the TypeLoc buffer
handling.

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

Differential Revision: https://reviews.llvm.org/D112374
2022-07-13 02:10:09 +02:00
Jorge Gorbe Moya ee88c0cf09 [NFCI] Fix unused variable/function warnings in MacroCallReconstructorTest.cpp when asserts are disabled. 2022-07-12 16:46:58 -07:00
Joseph Huber a3cbb158a2 [LinkerWrapper] Tweak save-temps output name
Summary:
A previous patch added the Task to the output filename when doing
`save-temps` the majority of cases there is only a single task so we
only add the task explicitly to differentiate it from the first one.
2022-07-12 19:42:04 -04:00
Jonas Devlieghere a262f4dbd7 Revert "[Clang] Add a warning on invalid UTF-8 in comments."
This reverts commit cc309721d2 because it
breaks the following tests on GreenDragon:

  TestDataFormatterObjCCF.py
  TestDataFormatterObjCExpr.py
  TestDataFormatterObjCKVO.py
  TestDataFormatterObjCNSBundle.py
  TestDataFormatterObjCNSData.py
  TestDataFormatterObjCNSError.py
  TestDataFormatterObjCNSNumber.py
  TestDataFormatterObjCNSURL.py
  TestDataFormatterObjCPlain.py
  TestDataFormatterObjNSException.py

https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/45288/
2022-07-12 15:22:29 -07:00
Aaron Ballman 2346d19a26 Speculatively fix this C DR test
There is a failing bot:
http://45.33.8.238/macm1/40002/step_7.txt

It looks to be failing because of a regex and how it handles whitespace,
so modifying the CHECK line slightly to account for that.
2022-07-12 15:18:03 -04:00
Nico Weber 953ba18fda [clang/ios] Make -mios-version-min the canonical spelling over -miphoneos-version-min
Like https://reviews.llvm.org/D129226, but for iOS.

No behavior change.

Differential Revision: https://reviews.llvm.org/D129569
2022-07-12 15:09:04 -04:00
Sunil Srivastava a844378b2b Change default C dialect for PS5 to gnu17/gnu18.
Differential Revision: https://reviews.llvm.org/D129404
2022-07-12 11:14:56 -07:00
Aaron Ballman 514dd3c3c3 Update the status for more C DRs
This mostly finishes the DRs in the 200s. There are a few DRs left
which will require more thought and work to test.
2022-07-12 14:06:39 -04:00
Yuanfang Chen fcb7d76d65 [coroutine] add nomerge function attribute to `llvm.coro.save`
It is illegal to merge two `llvm.coro.save` calls unless their
`llvm.coro.suspend` users are also merged. Marks it "nomerge" for
the moment.

This reverts D129025.

Alternative to D129025, which affects other token type users like WinEH.

Reviewed By: ChuanqiXu

Differential Revision: https://reviews.llvm.org/D129530
2022-07-12 10:39:38 -07:00
Aaron Ballman 23d8ecaa9f Silence a sphinx diagnostic; NFC
This addresses the failure with:
https://lab.llvm.org/buildbot/#/builders/92/builds/29618
2022-07-12 13:02:20 -04:00
Roy Jacobson 0b89d1d59f [Sema] Add deprecation warnings for some compiler provided __has_* type traits
Some compiler provided type traits like __has_trivial_constructor have been documented
as deprecated for quite some time.
Still, some people apparently still use them, even though mixing them with concepts
and with deleted functions leads to weird results. There's also disagreement about some
edge cases between GCC (which Clang claims to follow) and MSVC.

This patch adds deprecation warnings for the usage of those builtins, except for __has_trivial_destructor
which doesn't have a GCC alternative.

I made the warning on by default, so I had to silence it for some tests but it's not too many.

Some (decade old) history of issues with those builtins:
https://github.com/llvm/llvm-project/issues/18187
https://github.com/llvm/llvm-project/issues/18559
https://github.com/llvm/llvm-project/issues/22161
https://github.com/llvm/llvm-project/issues/33063

The abseil usage of them that triggered me to add this warning:
https://github.com/abseil/abseil-cpp/issues/1201

Weird interaction of those builtins with C++20's conditionally trivial special member functions:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106085

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

Differential Revision: https://reviews.llvm.org/D129170
2022-07-12 19:24:17 +03:00
Nick Desaulniers 2240d72f15 [X86] initial -mfunction-return=thunk-extern support
Adds support for:
* `-mfunction-return=<value>` command line flag, and
* `__attribute__((function_return("<value>")))` function attribute

Where the supported <value>s are:
* keep (disable)
* thunk-extern (enable)

thunk-extern enables clang to change ret instructions into jmps to an
external symbol named __x86_return_thunk, implemented as a new
MachineFunctionPass named "x86-return-thunks", keyed off the new IR
attribute fn_ret_thunk_extern.

The symbol __x86_return_thunk is expected to be provided by the runtime
the compiled code is linked against and is not defined by the compiler.
Enabling this option alone doesn't provide mitigations without
corresponding definitions of __x86_return_thunk!

This new MachineFunctionPass is very similar to "x86-lvi-ret".

The <value>s "thunk" and "thunk-inline" are currently unsupported. It's
not clear yet that they are necessary: whether the thunk pattern they
would emit is beneficial or used anywhere.

Should the <value>s "thunk" and "thunk-inline" become necessary,
x86-return-thunks could probably be merged into x86-retpoline-thunks
which has pre-existing machinery for emitting thunks (which could be
used to implement the <value> "thunk").

Has been found to build+boot with corresponding Linux
kernel patches. This helps the Linux kernel mitigate RETBLEED.
* CVE-2022-23816
* CVE-2022-28693
* CVE-2022-29901

See also:
* "RETBLEED: Arbitrary Speculative Code Execution with Return
Instructions."
* AMD SECURITY NOTICE AMD-SN-1037: AMD CPU Branch Type Confusion
* TECHNICAL GUIDANCE FOR MITIGATING BRANCH TYPE CONFUSION REVISION 1.0
  2022-07-12
* Return Stack Buffer Underflow / Return Stack Buffer Underflow /
  CVE-2022-29901, CVE-2022-28693 / INTEL-SA-00702

SystemZ may eventually want to support "thunk-extern" and "thunk"; both
options are used by the Linux kernel's CONFIG_EXPOLINE.

This functionality has been available in GCC since the 8.1 release, and
was backported to the 7.3 release.

Many thanks for folks that provided discrete review off list due to the
embargoed nature of this hardware vulnerability. Many Bothans died to
bring us this information.

Link: https://www.youtube.com/watch?v=IF6HbCKQHK8
Link: https://github.com/llvm/llvm-project/issues/54404
Link: https://gcc.gnu.org/legacy-ml/gcc-patches/2018-01/msg01197.html
Link: https://www.intel.com/content/www/us/en/developer/articles/technical/software-security-guidance/advisory-guidance/return-stack-buffer-underflow.html
Link: https://arstechnica.com/information-technology/2022/07/intel-and-amd-cpus-vulnerable-to-a-new-speculative-execution-attack/?comments=1
Link: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=ce114c866860aa9eae3f50974efc68241186ba60
Link: https://www.intel.com/content/www/us/en/security-center/advisory/intel-sa-00702.html
Link: https://www.intel.com/content/www/us/en/security-center/advisory/intel-sa-00707.html

Reviewed By: aaron.ballman, craig.topper

Differential Revision: https://reviews.llvm.org/D129572
2022-07-12 09:17:54 -07:00
Chuanqi Xu 5791bcf9db [AST] [Modules] Handle full cases of DefaultArgStorage::setInherited
There were two assertions in DefaultArgStorage::setInherited previously.
It requires the DefaultArgument is either empty or an argument value. It
would crash if it has a pointer refers to the previous declaration or
contains a chain to the previous declaration.

But there are edge cases could hit them actually. One is
InheritDefaultArguments.cppm that I found recently. Another one is pr31469.cpp,
which was created fives years ago.

This patch tries to fix the two failures by handling full cases in
DefaultArgStorage::setInherited.

This is guaranteed to not introduce any breaking change since it lives
in the path we wouldn't touch before. And the added assertions for
sameness should keep the correctness.

Reviewed By: v.g.vassilev

Differential Revision: https://reviews.llvm.org/D128974
2022-07-13 00:13:56 +08:00
Chuanqi Xu f6b0ae144e [AST] Accept identical TypeConstraint referring to other template
parameters.

The current implementation to judge the similarity of TypeConstraint in
ASTContext::isSameTemplateParameter is problematic, it couldn't handle
the following case:

```C++
template <__integer_like _Tp, C<_Tp> Sentinel>
constexpr _Tp operator()(_Tp &&__t, Sentinel &&last) const {
    return __t;
}
```

When we see 2 such declarations from different modules, we would judge
their similarity by `ASTContext::isSame*` methods. But problems come for
the TypeConstraint. Originally, we would profile each argument one by
one. But it is not right. Since the profiling result of `_Tp` would
refer to two different template type declarations. So it would get
different results. It is right since the `_Tp` in different modules
refers to different declarations indeed. So the same declaration in
different modules would meet incorrect our-checking results.

It is not the thing we want. We want to know if the TypeConstraint have
the same expression.

Reviewer: vsapsai, ilya-biryukov

Differential Revision: https://reviews.llvm.org/D129068
2022-07-12 23:57:44 +08:00
Joseph Huber 1586b59528 [LinkerWrapper] Clean-up unused definitions
Summary:

There are a few definitions that are unused or unnecessary after
previous changes, clean them up.
2022-07-12 11:46:46 -04:00
Joseph Huber 86a49a4f4f [LinkerWrapper] Make ThinLTO work inside the linker wrapper
Summary:
Previous assumptions held that the LTO stage would only have a single
output. This is incorrect when using thinLTO which outputs multiple
files. Additionally there were some bugs with how we hanlded input that
cause problems when performing thinLTO. This patch addresses these
issues.

The performance of Thin-LTO is currently pretty bad. But I am content to
leave it that way as long as it compiles.
2022-07-12 11:46:46 -04:00
Chuanqi Xu 4b95a5a772 [Modules] Add ODR Check for concepts
Closing https://github.com/llvm/llvm-project/issues/56310

Previously we don't check the contents of concept so it might merge
inconsistent results.

Important Note: this patch might break existing code but the behavior
might be right.

Reviewed By: erichkeane

Differential Revision: https://reviews.llvm.org/D129104
2022-07-12 23:45:53 +08:00
Krzysztof Drewniak d6ef3d20b4 [mlir] Remove VectorToROCDL
Between issues such as
https://github.com/llvm/llvm-project/issues/56323, the fact that this
lowering (unlike the code in amdgpu-to-rocdl) does not correctly set
up bounds checks (and thus will cause page faults on reads that might
need to be padded instead), and that fixing these problems would,
essentially, involve replicating amdgpu-to-rocdl, remove
--vector-to-rocdl for being broken. In addition, the lowering does not
support many aspects of transfer_{read,write}, like supervectors, and
may not work correctly in their presence.

We (the MLIR-based convolution generator at AMD) do not use this
conversion pass, nor are we aware of any other clients.

Migration strategies:
- Use VectorToLLVM
- If buffer ops are particularly needed in your application, use
amdgpu.raw_buffer_{load,store}

A VectorToAMDGPU pass may be introduced in the future.

Reviewed By: ThomasRaoux

Differential Revision: https://reviews.llvm.org/D129308
2022-07-12 15:21:22 +00:00
Ben Langmuir 6626f6fec3 [clang][deps] Override dependency and serialized diag files for modules
When building modules, override secondary outputs (dependency file,
dependency targets, serialized diagnostic file) in addition to the pcm
file path. This avoids inheriting per-TU command-line options that
cause non-determinism in the results (non-deterministic command-line for
the module build, non-determinism in which TU's .diag and .d files will
contain the module outputs). In clang-scan-deps we infer whether to
generate dependency or serialized diagnostic files based on an original
command-line. In a real build system this should be modeled explicitly.

Differential Revision: https://reviews.llvm.org/D129389
2022-07-12 08:19:52 -07:00
Paul Robinson 2b9055cee6 [PS4/PS5] NFC: Use preferred predicate in a triple check
Also add a test to verify this difference in the PS4/PS5 ABIs,
now that we have identified it.
2022-07-12 08:10:25 -07:00
Nico Weber d489268392 [clang/mac] Make -mmacos-version-min the canonical spelling over -mmacosx-version-min
This was promised 5 years ago in https://reviews.llvm.org/D32796,
let's do it.

Both flags are still accepted. No behavior change except for which
form shows up in --help output and in dumps of internal state
(such as with RC_DEBUG_OPTIONS).

Differential Revision: https://reviews.llvm.org/D129226
2022-07-12 11:03:51 -04:00
Corentin Jabot cc309721d2 [Clang] Add a warning on invalid UTF-8 in comments.
Introduce an off-by default `-Winvalid-utf8` warning
that detects invalid UTF-8 code units sequences in comments.

Invalid UTF-8 in other places is already diagnosed,
as that cannot appear in identifiers and other grammar constructs.

The warning is off by default as its likely to be somewhat disruptive
otherwise.

This warning allows clang to conform to the yet-to be approved WG21
"P2295R5 Support for UTF-8 as a portable source file encoding"
paper.

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

Differential Revision: https://reviews.llvm.org/D128059
2022-07-12 14:34:30 +02:00
Joseph Huber d214bfe78d [OpenMP] Do not link static library with `-nogpulib`
Normally we do not link the device libraries if the user passed
`nogpulib` we do this for the standard bitcode library. This behaviour
was not added when using the static library for LTO, causing it to
always be linked in. This patch fixes that.

Reviewed By: JonChesterfield

Differential Revision: https://reviews.llvm.org/D129534
2022-07-12 08:15:15 -04:00
Aaron Ballman 3cfa32a71e Undeprecate ATOMIC_FLAG_INIT in C++
C++20 deprecated ATOMIC_FLAG_INIT thinking it was deprecated in C when it
wasn't. It is expected to be undeprecated in C++23 as part of LWG3659
(https://wg21.link/LWG3659), which is currently Tentatively Ready.

This handles the case where the user includes <stdatomic.h> in C++ code in a
freestanding compile mode. The corollary libc++ changes are in
1544d1f9fd.
2022-07-12 06:48:31 -04:00
Manuel Klimek f44d28f840 Fix build errors. 2022-07-12 07:43:26 +00:00
Manuel Klimek d6d0dc1f45 [clang-format] Add MacroUnexpander.
MacroUnexpander applies the structural formatting of expanded lines into
UnwrappedLines to the corresponding unexpanded macro calls, resulting in
UnwrappedLines for the macro calls the user typed.

Differential Revision: https://reviews.llvm.org/D88299
2022-07-12 07:11:46 +00:00
Xiang1 Zhang a45dd3d814 [X86] Support -mstack-protector-guard-symbol
Reviewed By: nickdesaulniers

Differential Revision: https://reviews.llvm.org/D129346
2022-07-12 10:17:00 +08:00
Xiang1 Zhang 643786213b Revert "[X86] Support -mstack-protector-guard-symbol"
This reverts commit efbaad1c4a.
due to miss adding review info.
2022-07-12 10:14:32 +08:00
Xiang1 Zhang efbaad1c4a [X86] Support -mstack-protector-guard-symbol 2022-07-12 10:13:48 +08:00
Joseph Huber fe6a391357 [Clang] Fix tests failing due to invalid syntax for host triple
Summary:
We use the `--host-triple=` argument to manually set the target triple.
This was changed to include the `=` previously but was not included in
these additional test cases, causing it for fail on some unsupported
systems.
2022-07-11 21:31:56 -04:00
Argyrios Kyrtzidis fe3780f32a [DependencyScanningTool.cpp] Use `using namespace` instead of wrapping the `.cpp` file contents in namespaces, NFC
This makes the file consistent with the coding style of the rest of LLVM.
2022-07-11 17:44:17 -07:00
Petr Hosek 0ed8d82095 [Driver] Don't use frame pointer on Fuchsia when optimizations are enabled
This matches the standard behavior on other platforms.

Differential Revision: https://reviews.llvm.org/D129512
2022-07-11 21:45:42 +00:00
Jonas Devlieghere c7fd7512a5
Revert "[C++20][Modules] Update handling of implicit inlines [P1779R3]"
This reverts commit ef0fa9f0ef as a follow up to b19d3ee712 which
reverted commit ac507102d2. See https://reviews.llvm.org/D126189 for
more details.
2022-07-11 13:59:41 -07:00
Joseph Huber ce091eb3b9 [HIP] Add support for handling HIP in the linker wrapper
This patch adds the necessary changes required to bundle and wrap HIP
files. The bundling is done using `clang-offload-bundler` currently to
mimic `fatbinary` and the wrapping is done using very similar runtime
calls to CUDA. This still does not support managed / surface / texture
variables, that would require some additional information in the entry.

One difference in the codegeneration with AMD is that I don't check if
the handle is null before destructing it, I'm not sure if that's
required.

With this we should be able to support HIP with the new driver.

Depends on D128850

Reviewed By: JonChesterfield

Differential Revision: https://reviews.llvm.org/D128914
2022-07-11 15:49:23 -04:00
Joseph Huber e88d53d25f [HIP] Generate offloading entries for HIP with the new driver.
This patch adds the small change required to output offloading entried
for HIP instead of CUDA. These should be placed in different sections so
because they need to be distinct to the offloading toolchain, otherwise
we'd have HIP trying to register CUDA kernels or vice-versa. This patch will
precede support for HIP in the linker wrapper.

Reviewed By: yaxunl, tra

Differential Revision: https://reviews.llvm.org/D128850
2022-07-11 15:49:21 -04:00
Joseph Huber 359e4a8247 [Clang] Parse toolchain-specific offloading arguments directly
OpenMP supports multiple offloading toolchains and architectures. In
order to support this we originally used `getArgsForToolchain` to get
the arguments only intended for each toolchain. This allowed users to
manually specify if an `--offload-arch=` argument was intended for which
toolchain using `-Xopenmp-target=` or other methods. For example,

```
clang input.c -fopenmp -fopenmp-targets=nvptx64,amdgcn -Xopenmp-target=nvptx64 --offload-arch=sm_70 -Xopenmp-target=amdgcn --offload-arch=gfx908
```

However, this was causing problems with the AMDGPU toolchain. This is
because the AMDGPU toolchain for OpenMP uses an `amdgpu` arch to determine the
architecture. If this tool is not availible the compiler will exit with an error
even when manually specifying the architecture. This patch pulls out the logic in
`getArgsForToolchain` and specializes it for extracting `--offload-arch`
arguments to avoid this.

Reviewed By: JonChesterfield, yaxunl

Differential Revision: https://reviews.llvm.org/D129435
2022-07-11 15:37:50 -04:00
Mitch Phillips f18de7619e Update DynInit generation for ASan globals.
Address a follow-up TODO for Sanitizer Metadata.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D128672
2022-07-11 12:23:37 -07:00
Iain Sandoe b19d3ee712 Revert "[C++20][Modules] Build module static initializers per P1874R1."
This reverts commit ac507102d2.

reverting while we figuere out why one of the green dragon lldb test fails.
2022-07-11 19:50:31 +01:00
Iain Sandoe e7c8ded6df Revert "[C++20][Modules] Fix two tests for CTORs that return pointers [NFC]."
This reverts commit 4328b96017.

reverting while we figure out why one of the Greendragon lldb tests fails.
2022-07-11 19:49:48 +01:00
Prabhdeep Singh Soni ac892c70a4 [OMPIRBuilder] Add support for simdlen clause
This patch adds OMPIRBuilder support for the simdlen clause for the
simd directive. It uses the simdlen support in OpenMPIRBuilder when
it is enabled in Clang. Simdlen is lowered by OpenMPIRBuilder by
generating the loop.vectorize.width metadata.

Reviewed By: jdoerfert, Meinersbur

Differential Revision: https://reviews.llvm.org/D129149
2022-07-11 13:29:06 -04:00
spupyrev b444358126 Revert "Rebase: [Facebook] Add clang driver options to test debug info and BOLT"
This reverts commit f921985a29.
2022-07-11 09:50:46 -07:00