Commit Graph

95129 Commits

Author SHA1 Message Date
Balazs Benics f1b18a79b7 [analyzer][NFC] Remove dead code and modernize surroundings
Thanks @kazu for helping me clean these parts in D127799.

I'm leaving the dump methods, along with the unused visitor handlers and
the forwarding methods.

The dead parts actually helped to uncover two bugs, to which I'm going
to post separate patches.

Reviewed By: martong

Differential Revision: https://reviews.llvm.org/D127836
2022-06-15 16:50:12 +02:00
Shao-Ce SUN e180cc5ff1 [Driver][test] Make RISCV tests robust with PATH=
When `riscv64-unknown-linux-gnu-ld` is in the PATH, `clang -### -fuse-ld=ld --target=riscv64-unknown-linux-gnu` will use unknown-linux-gnu-ld first, which causes the error in the lit test.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D127589
2022-06-15 22:25:22 +08:00
Krasimir Georgiev 8f2ba36336 Revert "[ARM][Thumb] Command-line option to ensure AAPCS compliant Frame Records AND [NFC][Thumb] Update frame-chain codegen test to use thumbv6m"
This reverts commit 7625e01d66 and
dependent cbcce82ef6.

Commit 7625e01d66 causes some new codegen test
failures under asan, e.g., CodeGen/ARM/execute-only.ll:
https://lab.llvm.org/buildbot/#/builders/5/builds/24659/steps/15/logs/stdio.
2022-06-15 16:10:02 +02:00
Gabor Marton f7a38eeccb [analyzer][NFC][test] Add new RUN line with support-symbolic-integer-casts=true to expr-inspection.cpp
Added a new run line to bolster gradual transition of handling cast operations,
see https://discourse.llvm.org/t/roadmap-of-modeling-symbolic-cast-operations/63107

Differential Revision: https://reviews.llvm.org/D127649
2022-06-15 16:06:53 +02:00
Timm Bäder c149fa1f5f [clang][sema] Provide better diagnostic for missing template arguments
Instead of just complaining that "x is not a class, namespace or
enumeration", mention that using x requires template arguments.

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

Fixes https://github.com/llvm/llvm-project/issues/55962
2022-06-15 16:06:06 +02:00
Timm Bäder bce55d0690 [clang][NFC] Remove unused parameter from ActOnCXXNestedNameSpecifier 2022-06-15 16:06:06 +02:00
Furkan Usta 462def25ec
[clang] Use correct visibility parameters when following a Using declaration
Fixes https://github.com/clangd/clangd/issues/1137

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D127629
2022-06-15 15:52:59 +02:00
Gabor Marton 3605ebca32 [analyzer][NFC][test] Add new RUN lint with support-symbolic-integer-casts=true to svalbuilder-rearrange-comparisons.c
Added a new run line to bolster gradual transition of handling cast operations,
see https://discourse.llvm.org/t/roadmap-of-modeling-symbolic-cast-operations/63107

Differential Revision: https://reviews.llvm.org/D127646
2022-06-15 13:52:18 +02:00
Simon Pilgrim 43e7ba6495 Fix signed/unsigned comparison warning 2022-06-15 11:53:08 +01:00
Benjamin Kramer 170ca11aef [Sema] Remove unused function after 8c7b64b5ae 2022-06-15 12:20:44 +02:00
Stanislav Gatev 8fcdd62585 [clang][dataflow] Add support for correlated branches to optional model
Add support for correlated branches to the std::optional dataflow model.

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

Reviewed-by: ymandel, xazax.hun
2022-06-15 10:00:44 +00:00
Martin Boehme 8c7b64b5ae [clang] Reject non-declaration C++11 attributes on declarations
For backwards compatiblity, we emit only a warning instead of an error if the
attribute is one of the existing type attributes that we have historically
allowed to "slide" to the `DeclSpec` just as if it had been specified in GNU
syntax. (We will call these "legacy type attributes" below.)

The high-level changes that achieve this are:

- We introduce a new field `Declarator::DeclarationAttrs` (with appropriate
  accessors) to store C++11 attributes occurring in the attribute-specifier-seq
  at the beginning of a simple-declaration (and other similar declarations).
  Previously, these attributes were placed on the `DeclSpec`, which made it
  impossible to reconstruct later on whether the attributes had in fact been
  placed on the decl-specifier-seq or ahead of the declaration.

- In the parser, we propgate declaration attributes and decl-specifier-seq
  attributes separately until we can place them in
  `Declarator::DeclarationAttrs` or `DeclSpec::Attrs`, respectively.

- In `ProcessDeclAttributes()`, in addition to processing declarator attributes,
  we now also process the attributes from `Declarator::DeclarationAttrs` (except
  if they are legacy type attributes).

- In `ConvertDeclSpecToType()`, in addition to processing `DeclSpec` attributes,
  we also process any legacy type attributes that occur in
  `Declarator::DeclarationAttrs` (and emit a warning).

- We make `ProcessDeclAttribute` emit an error if it sees any non-declaration
  attributes in C++11 syntax, except in the following cases:
  - If it is being called for attributes on a `DeclSpec` or `DeclaratorChunk`
  - If the attribute is a legacy type attribute (in which case we only emit
    a warning)

The standard justifies treating attributes at the beginning of a
simple-declaration and attributes after a declarator-id the same. Here are some
relevant parts of the standard:

- The attribute-specifier-seq at the beginning of a simple-declaration
  "appertains to each of the entities declared by the declarators of the
  init-declarator-list" (https://eel.is/c++draft/dcl.dcl#dcl.pre-3)

- "In the declaration for an entity, attributes appertaining to that entity can
  appear at the start of the declaration and after the declarator-id for that
  declaration." (https://eel.is/c++draft/dcl.dcl#dcl.pre-note-2)

- "The optional attribute-specifier-seq following a declarator-id appertains to
  the entity that is declared."
  (https://eel.is/c++draft/dcl.dcl#dcl.meaning.general-1)

The standard contains similar wording to that for a simple-declaration in other
similar types of declarations, for example:

- "The optional attribute-specifier-seq in a parameter-declaration appertains to
  the parameter." (https://eel.is/c++draft/dcl.fct#3)

- "The optional attribute-specifier-seq in an exception-declaration appertains
  to the parameter of the catch clause" (https://eel.is/c++draft/except.pre#1)

The new behavior is tested both on the newly added type attribute
`annotate_type`, for which we emit errors, and for the legacy type attribute
`address_space` (chosen somewhat randomly from the various legacy type
attributes), for which we emit warnings.

Depends On D111548

Reviewed By: aaron.ballman, rsmith

Differential Revision: https://reviews.llvm.org/D126061
2022-06-15 11:58:26 +02:00
Sven van Haastregt 7acc88be03 [OpenCL] Reword unknown extension pragma diagnostic
For newer OpenCL extensions that do not require a pragma, such as
`cl_khr_subgroup_shuffle`, a user could still accidentally attempt to
use a pragma.  This would result in a warning
  "unknown OpenCL extension 'cl_khr_subgroup_shuffle' - ignoring"
which could be mistakenly interpreted as "clang does not support this
extension at all" instead of "clang does not require any pragma for
this extension".

Differential Revision: https://reviews.llvm.org/D126660
2022-06-15 10:54:46 +01:00
Martin Boehme 4c2bccfda3 [Clang] Documentation-only: Add missing closing `>` in AttrDocs.td 2022-06-15 10:59:07 +02:00
Martin Boehme 1784fe7be7 [Clang] Fix signed-unsigned comparison warning that breaks the ppc64 build. 2022-06-15 10:53:14 +02:00
Martin Boehme 665da187cc [Clang] Add the `annotate_type` attribute
This is an analog to the `annotate` attribute but for types. The intent is to allow adding arbitrary annotations to types for use in static analysis tools.

For details, see this RFC:

https://discourse.llvm.org/t/rfc-new-attribute-annotate-type-iteration-2/61378

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D111548
2022-06-15 09:47:28 +02:00
owenca 07b3446d72 [clang-format] Never analyze insert/remove braces in the same pass
Turn off RemoveBracesLLVM while analyzing InsertBraces and vice
versa to avoid potential interference of each other and better the
performance.

Differential Revision: https://reviews.llvm.org/D127685
2022-06-14 22:42:54 -07:00
Ben Shi 753b915167 [Driver] Improve linking options for target AVR
1. Support user specified linker (-fuse-ld)
2. Support user specified linker script (-T)

Reviewed By: MaskRay, haowei

Differential Revision: https://reviews.llvm.org/D126192
2022-06-15 02:57:31 +00:00
Yaxun (Sam) Liu af9ee3357c [HIP] fix long double size
For amdgpu target long double type is the same as double type.
The width and align of long double type was incorrectly
overridden when copying aux target properties, which
caused assertion in codegen when emitting global
variables with long double type.

This patch fix that by saving and restoring width
and align of long double type.

Reviewed by: Artem Belevich

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

Fixes: SWDEV-335515
2022-06-14 21:57:56 -04:00
Haowei Wu 7fae15f925 Revert "[Driver] Improve linking options for target AVR"
This reverts commit 3b6e166999 which
causes Clang Driver test failures on Fuchsia builders.
2022-06-14 17:53:46 -07:00
Wei Yi Tee 97d69cdaf3 [clang][dataflow] Rename `getPointeeLoc` to `getReferentLoc` for ReferenceValue.
We distinguish between the referent location for `ReferenceValue` and pointee location for `PointerValue`. The former must be non-empty but the latter may be empty in the case of a `nullptr`

Reviewed By: gribozavr2, sgatev

Differential Revision: https://reviews.llvm.org/D127745
2022-06-15 00:53:30 +02:00
Anders Waldenborg 657e954939 [clang] Add tests for statement expression in initializers
The commit 683e83c5
  [Clang][C++2b] P2242R3: Non-literal variables [...] in constexpr
fixed a code generation bug when using (C-extension) statement
expressions inside initializer expressions.

Before that commit a nested static initializer inside the statement
expression would not be emitted, causing it to be zero initialized.

It is a bit surprising (at least to me) that a commit implementing a new
C++ feature would fix this code generation bug. Zooming in it is the
change done in ExprConstant.cpp that helps. That changes so that
"ESR_Failed" is returned in more cases, causing the expression to not be
deemed constant. This fixes the code generation as instead the compiler
has to resort to generating a dynamic initializer.

That commit also meant that some statement expressions (in particular
the ones using static variables) that previously were accepted now are
errors due to not being constant (matching GCC behavior).

Given how a seemingly unrelated change caused this behavior to change,
it is probably a good thing to add at least some rudimentary tests for
these kind expressions.

Differential Revision: https://reviews.llvm.org/D127201
2022-06-14 23:16:41 +02:00
Joseph Huber c4a2674e21 [Clang] Simplify unifying target features
This patch simplifies how we unify target features. Now we simply
iterate the input in reverse and only insert the feature if it hasn't
been seen yet. The only reason we need to reverse this at the end is to
keep the features in order for the existing tests.

Reviewed By: tra

Differential Revision: https://reviews.llvm.org/D127707
2022-06-14 15:58:16 -04:00
Shivam 6ccc2733e7
Update ASTImportError.h 2022-06-15 00:45:07 +05:30
isuckatcs caf2767c47 [Clang][AST] Fixed BindingDecl AST-dump for tuple like structures
The AST of a BindingDecl in case of tuple like structures wasn't
properly printed. For these bidnings there is information stored
in BindingDecl::getHoldingVar(), and this information was't
printed in the AST-dump.

Differential Revision: https://reviews.llvm.org/D126131
2022-06-14 21:13:04 +02:00
phyBrackets 9d637956b7 [clang][NFC][AST] rename the ImportError to ASTImportError
this patch is the continuation of my previous patch regarding the ImportError in ASTImportError.h

Reviewed By: martong

Differential Revision: https://reviews.llvm.org/D125340
2022-06-15 00:40:32 +05:30
Balazs Benics 21ff652de9 [analyzer][NFC] Replace getLastArg with hasArg when applicable
Depends on D126215.
2022-06-14 19:28:44 +02:00
Petr Hosek 18a1fc8459 [CMake][compiler-rt] Provide a dedicated option for LLVM unwinder
This allows configuring LLVM unwinder separately from the C++ library
matching how we configure it in libcxx.

This also applies changes made to libunwind+libcxxabi+libcxx in D113253
to compiler-rt.

Differential Revision: https://reviews.llvm.org/D115674
2022-06-14 17:26:25 +00:00
Balazs Benics cf078adc90 [analyzer][NFC] Remove unused ExprEngine::evalBinOp functions
Reviewed By: martong

Differential Revision: https://reviews.llvm.org/D127732
2022-06-14 19:15:20 +02:00
Balazs Benics 40940fb2a6 [analyzer][NFC] Substitute the SVal::evalMinus and evalComplement functions
Depends on D126127

Reviewed By: martong

Differential Revision: https://reviews.llvm.org/D127734
2022-06-14 18:56:43 +02:00
Balazs Benics cfc915149c [analyzer][NFC] Relocate unary transfer functions
This is an initial step of removing the SimpleSValBuilder abstraction. The SValBuilder alone should be enough.

Reviewed By: martong

Differential Revision: https://reviews.llvm.org/D126127
2022-06-14 18:56:43 +02:00
Matheus Izvekov 671eb7dc1e
[clang] AST/Print: honor AlwaysIncludeTypeForTemplateArgument policy
This redoes D103040 in a way that `AlwaysIncludeTypeForTemplateArgument = false`
policy is honored for printing template specialization types.
This can be seen for example when printing a canonicalized
dependent TemplateSpecializationType which has integral arguments.

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

Reviewed By: v.g.vassilev

Differential Revision: https://reviews.llvm.org/D126620
2022-06-14 18:18:24 +02:00
Serge Pavlov 6117784c5f [NFC] Remove unused function parameter 2022-06-14 22:00:59 +07:00
Shivam Gupta 48e1829874 [Diagnostics] Fix inconsistent shift-overflow warnings in C++20
This fixes https://github.com/llvm/llvm-project/issues/52873.
Don't warn in C++2A mode (and newer), as signed left shifts
always wrap and never overflow. Ref. -
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1236r1.html.
2022-06-14 20:19:46 +05:30
Joseph Huber 6a6484c666 [OpenMP] Fix offload packager not writing to temps correctly
The offloading packager doesn't have a normal offloading kind. This
would result in its output being sent to the executable name when in
save-temps mode. This would then get overwritten by the actual output.
This patch adds specific checks to make sure that it gets the correct
name.

Reviewed By: tra

Differential Revision: https://reviews.llvm.org/D127673
2022-06-14 09:16:28 -04:00
Lucas Prates 7625e01d66 [ARM][Thumb] Command-line option to ensure AAPCS compliant Frame Records
Currently the a AAPCS compliant frame record is not always created for
functions when it should. Although a consistent frame record might not
be required in some cases, there are still scenarios where applications
may want to make use of the call hierarchy made available trough it.

In order to enable the use of AAPCS compliant frame records whilst keep
backwards compatibility, this patch introduces a new command-line option
(`-mframe-chain=[none|aapcs|aapcs+leaf]`) for Aarch32 and Thumb backends.
The option allows users to explicitly select when to use it, and is also
useful to ensure the extra overhead introduced by the frame records is
only introduced when necessary, in particular for Thumb targets.

Reviewed By: efriedma

Differential Revision: https://reviews.llvm.org/D125094
2022-06-14 13:37:51 +01:00
Jun Zhang 44f0a2658d
Revert "Reland "[CodeGen] Keep track info of lazy-emitted symbols in ModuleBuilder""
This reverts commit 781ee538da.

Asan build is still broken :(
2022-06-14 19:53:17 +08:00
Balazs Benics de6ba9704d [analyzer][Casting] Support isa, cast, dyn_cast of SVals
This change specializes the LLVM RTTI mechanism for SVals.
After this change, we can use the well-known `isa`, `cast`, `dyn_cast`.

Examples:

  // SVal V = ...;
  // Loc MyLoc = ...;

  bool IsInteresting = isa<loc::MemRegionVal, loc::GotoLabel>(MyLoc);
  auto MRV = cast<loc::MemRegionVal>(MyLoc);
  Optional<loc::MemRegionVal> MaybeMRV = dyn_cast<loc::MemRegionVal>(V)

The current `SVal::getAs` and `castAs` member functions are redundant at
this point, but I believe that they are still handy.

The member function version is terse and reads left-to-right, which IMO
is a great plus. However, we should probably add a variadic `isa` member
function version to have the same casting API in both cases.

Thanks for the extensive TMP help @bzcheeseman!

Reviewed By: bzcheeseman

Differential Revision: https://reviews.llvm.org/D125709
2022-06-14 13:43:04 +02:00
Guillaume Chatelet d9b8d13f8b [NFC][Alignment] Use MaybeAlign in CGCleanup/CGExpr 2022-06-14 10:56:36 +00:00
Jun Zhang 781ee538da
Reland "[CodeGen] Keep track info of lazy-emitted symbols in ModuleBuilder"
This reverts commits:
d3ddc251ac
d90eecff5c

This relands below commit with asan fix:

The intent of this patch is to selectively carry some states over to
the Builder so we won't lose the information of the previous symbols.

This used to be several downstream patches of Cling, it aims to fix
errors in Clang Interpreter when trying to use inline functions.
Before this patch:

clang-repl> inline int foo() { return 42;}
clang-repl> int x = foo();

JIT session error: Symbols not found: [ _Z3foov ]
error: Failed to materialize symbols:
{ (main, { x, $.incr_module_1.__inits.0, __orc_init_func.incr_module_1 }) }

Co-authored-by: Axel Naumann <Axel.Naumann@cern.ch>
Signed-off-by: Jun Zhang <jun@junz.org>

Differential Revision: https://reviews.llvm.org/D127730
2022-06-14 18:36:03 +08:00
Balazs Benics 9da697e1bc Reland "[analyzer] Deprecate the unused 'analyzer-opt-analyze-nested-blocks' cc1 flag"
It was previously reverted by 8406839d19.

---

This flag was introduced by
6818991d71
    commit 6818991d71
    Author: Ted Kremenek <kremenek@apple.com>
    Date:   Mon Dec 7 22:06:12 2009 +0000

  Add clang-cc option '-analyzer-opt-analyze-nested-blocks' to treat
  block literals as an entry point for analyzer checks.

The last reference was removed by this commit:
5c32dfc5fb

    commit 5c32dfc5fb
    Author: Anna Zaks <ganna@apple.com>
    Date:   Fri Dec 21 01:19:15 2012 +0000

  [analyzer] Add blocks and ObjC messages to the call graph.
  This paves the road for constructing a better function dependency graph.
  If we analyze a function before the functions it calls and inlines,
  there is more opportunity for optimization.
  Note, we add call edges to the called methods that correspond to
  function definitions (declarations with bodies).

Consequently, we should remove this dead flag.
However, this arises a couple of burning questions.
 - Should the `cc1` frontend still accept this flag - to keep
   tools/users passing this flag directly to `cc1` (which is unsupported,
   unadvertised) working.
 - If we should remain backward compatible, how long?
 - How can we get rid of deprecated and obsolete flags at some point?

Reviewed By: martong

Differential Revision: https://reviews.llvm.org/D126067
2022-06-14 10:22:37 +02:00
Balazs Benics 24bd47dc17 [analyzer][NFC] Inline AnalyzerOptions::getUserMode()
When I read the code I found it easier to reason about if `getUserMode`
is inlined. It might be a personal preference though.

Reviewed By: martong

Differential Revision: https://reviews.llvm.org/D127486
2022-06-14 09:42:58 +02:00
Balazs Benics ffe7950ebc Reland "[analyzer] Deprecate `-analyzer-store region` flag"
I'm trying to remove unused options from the `Analyses.def` file, then
merge the rest of the useful options into the `AnalyzerOptions.def`.
Then make sure one can set these by an `-analyzer-config XXX=YYY` style
flag.
Then surface the `-analyzer-config` to the `clang` frontend;

After all of this, we can pursue the tablegen approach described
https://discourse.llvm.org/t/rfc-tablegen-clang-static-analyzer-engine-options-for-better-documentation/61488

In this patch, I'm proposing flag deprecations.
We should support deprecated analyzer flags for exactly one release. In
this case I'm planning to drop this flag in `clang-16`.

In the clang frontend, now we won't pass this option to the cc1
frontend, rather emit a warning diagnostic reminding the users about
this deprecated flag, which will be turned into error in clang-16.

Unfortunately, I had to remove all the tests referring to this flag,
causing a mass change. I've also added a test for checking this warning.

I've seen that `scan-build` also uses this flag, but I think we should
remove that part only after we turn this into a hard error.

Reviewed By: martong

Differential Revision: https://reviews.llvm.org/D126215
2022-06-14 09:20:41 +02:00
Chuanqi Xu 735e6c40b5 [Coroutines] Convert coroutine.presplit to enum attr
This is required by @nikic in https://reviews.llvm.org/D127383 to
decrease the cost to check whether a function is a coroutine and this
fixes a FIXME too.

Reviewed By: rjmccall, ezhulenev

Differential Revision: https://reviews.llvm.org/D127471
2022-06-14 14:23:46 +08:00
Argyrios Kyrtzidis f7e19a5928 [Lex] Keep track of skipped preprocessor blocks and advance the lexer directly if they are revisited
This speeds up preprocessing, specifically for preprocessing the clang sources time is reduced by about -36%,
using measurements on M1Pro with a release+thinLTO build.

Differential Revision: https://reviews.llvm.org/D127379
2022-06-13 21:46:46 -07:00
Fangrui Song 11cf75f602 [Driver][test] Make ananas.c and solaris-ld.c robust
`{{.*}}crt{{[^.]+}}.o` may match `"-r" "/tmp/lit-tmp-9ur5crtx/solaris-ld-4fa504.o"`
in a lit invocation.
2022-06-13 19:44:24 -07:00
Fangrui Song 0ba43f4c2b [sanitizer] Add -lresolv only for non-Android non-musl Linux
Refine the D127145 logic with my original suggestion.
It turns out that many OSes don't have libresolv.
2022-06-13 19:12:13 -07:00
Ben Shi 3b6e166999 [Driver] Improve linking options for target AVR
1. Support user specified linker (-fuse-ld)
2. Support user specified linker script (-T)

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D126192
2022-06-14 01:30:49 +00:00
Ben Shi 520d17bfa0 Revert "[Driver] Improve linking options for target AVR"
This reverts commit d7599be9e8.
2022-06-14 09:12:21 +08:00
Ben Shi d7599be9e8 [Driver] Improve linking options for target AVR
1. Support linking with lld
2. Support user specifed linker script

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D126192
2022-06-13 23:38:59 +00:00
Mitch Phillips 2a5d567041 Fix-forward broken ASan test on Windows.
Hopefully the final whack-a-mole.

Relevant differential revision: https://reviews.llvm.org/D126929
2022-06-13 14:23:23 -07:00
Mitch Phillips 77475ffd22 Reland "Add sanitizer metadata attributes to clang IR gen."
RE-LAND (reverts a revert):
This reverts commit 8e1f47b596.

This patch adds generation of sanitizer metadata attributes (which were
added in D126100) to the clang frontend.

We still currently generate the llvm.asan.globals that's consumed by
the IR pass, but the plan is to eventually migrate off of that onto
purely debuginfo and these IR attributes.

Reviewed By: vitalybuka, kstoimenov

Differential Revision: https://reviews.llvm.org/D126929
2022-06-13 12:23:27 -07:00
Balazs Benics 0539b456b7 [analyzer][NFC] Remove unused Analyses enum
Reviewed By: martong

Differential Revision: https://reviews.llvm.org/D127485
2022-06-13 21:19:55 +02:00
Mitch Phillips 8e1f47b596 Revert "Add sanitizer metadata attributes to clang IR gen."
This reverts commit e7766972a6.

Broke the Windows buildbots.
2022-06-13 12:11:13 -07:00
owenca 7cb0bc8abf [clang-format] Handle more cases for RemoveBracesLLVM
Call mightFitOneOneline() on the line before the closing brace only
if it is at the level of the block.

Differential Revision: https://reviews.llvm.org/D127614
2022-06-13 12:10:35 -07:00
Stephen Long d4245ed67c [clang-cl] Accept /FA[c][s][u], but ignore the arguments
Previously, /FAsc would emit a warning. Now, it will just do what /FA does.

https://docs.microsoft.com/en-us/cpp/build/reference/fa-fa-listing-file?view=msvc-170

Reviewed By: hans

Differential Revision: https://reviews.llvm.org/D127519
2022-06-13 12:01:54 -07:00
Stephen Long ee6ad7af45 [clang-cl][MSVC] Map /external:Wn n=1-4 to -Wsystem-headers
https://docs.microsoft.com/en-us/cpp/build/reference/external-external-headers-diagnostics?view=msvc-170

Reviewed By: hans

Differential Revision: https://reviews.llvm.org/D127452
2022-06-13 11:26:07 -07:00
Mitch Phillips e7766972a6 Add sanitizer metadata attributes to clang IR gen.
This patch adds generation of sanitizer metadata attributes (which were
added in D126100) to the clang frontend.

We still currently generate the `llvm.asan.globals` that's consumed by
the IR pass, but the plan is to eventually migrate off of that onto
purely debuginfo and these IR attributes.

Reviewed By: vitalybuka, kstoimenov

Differential Revision: https://reviews.llvm.org/D126929
2022-06-13 11:19:15 -07:00
Nico Weber 8c974bfe1c Reland: unbreak Modules/cxx20-export-import.cpp with LLVM_APPEND_VC_REV after 8c8a2679a2
See revision b8b7a9dcdc for prior art.

Reland of: 4463bd0f89 since the dependent
patch D126340 is also relanding.
2022-06-13 13:45:13 -04:00
David Tenty 6a8673038b Reland [clang][AIX] add option mdefault-visibility-export-mapping
The option mdefault-visibility-export-mapping is created to allow
mapping default visibility to an explicit shared library export
(e.g. dllexport). Exactly how and if this is manifested is target
dependent (since it depends on how they map dllexport in the IR).

Three values are provided for the option:

* none: the default and behavior without the option, no additional export linkage information is created.
* explicit: add the export for entities with explict default visibility from the source, including RTTI
* all: add the export for all entities with default visibility

This option is useful for targets which do not export symbols as part of
their usual default linkage behaviour (e.g. AIX), such targets
traditionally specified such information in external files (e.g. export
lists), but this mapping allows them to use the visibility information
typically used for this purpose on other (e.g. ELF) platforms.

This relands commit: 8c8a2679a2

with fixes for the compile time and assert problems that were reported
by:

* making shouldMapVisibilityToDLLExport inline and provide an early return
in the case where no mapping is in effect (aka non-AIX platforms)
* don't try to export RTTI types which we will give internal linkage to

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D126340
2022-06-13 13:43:46 -04:00
Mitch Phillips d3ddc251ac Revert "[CodeGen] Keep track info of lazy-emitted symbols in ModuleBuilder"
This reverts commit b8f9459715.

Broke the ASan buildbot. See https://reviews.llvm.org/D126781 for more
information.
2022-06-13 10:12:38 -07:00
Mitch Phillips d90eecff5c Revert "Also move WeakRefReferences in CodeGenModule::moveLazyEmssionStates"
This reverts commit 0ecbedc098.

Parent change broke the ASan buildbot. See
https://reviews.llvm.org/D126781 for more information.
2022-06-13 10:12:38 -07:00
Joseph Huber 1054a73187 [Clang] Change host/device only compilation to a driver mode
We use the flags `--offload-host-only` and `--offload-device-only` to
change the driver's code generation for offloading programs. These are
currently parsed out independently in many places. This patch simply
refactors this to work as a mode for the Driver. This stopped us from
emitting warnings if unused because it's always used now, but I don't
think this is a great loss.

Reviewed By: tra

Differential Revision: https://reviews.llvm.org/D127515
2022-06-13 11:33:54 -04:00
Jan Svoboda d9390b6ac3 Reapply "[clang][lex] NFCI: Use DirectoryEntryRef in HeaderSearch::load*()"
This reverts commit 340654e0f2, essentially reapplying 1d3ba05e4a.

The test VFS/real-path-found-first.m that was failing on Windows is now passing with a workaround.
2022-06-13 17:03:32 +02:00
Quinn Pham 35aaf54823 [clang][driver] fix to correctly set devtoolset on RHEL
This patch correctly sets the devtoolset on RHEL.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D127310
2022-06-13 09:12:49 -05:00
wangpc 93b4a41b55 [RISCV] Add vread_csr and vwrite_csr to riscv_vector.h
These two functions are described in RVV intrinsics doc
to read/write RVV CSRs. This matches what GCC does.

This reapply aebe24a which was reverted in 0f6f429 due
to missing REQUIRES in tests.

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D125875
2022-06-13 20:38:52 +08:00
Jan Svoboda 2de36d0369 [clang][driver] Only run multi-arch tests on Darwin
This fixes the test introduced in a85670001b that causes failures on non-Darwin systems.
2022-06-13 14:03:23 +02:00
Jez Ng e4a21e1644 [MC] Fix likely uninitialized memory bug
See https://reviews.llvm.org/D122258#inline-1223493. I can't repro the
issue locally but this seems like the likely culprit.

Reviewed By: uabelho

Differential Revision: https://reviews.llvm.org/D127630
2022-06-13 07:41:17 -04:00
wangpc 0f6f4295d1 Revert "[RISCV] Add vread_csr and vwrite_csr to riscv_vector.h"
This reverts commit aebe24a856.

`REQUIRES` for RISCV target is needed in tests.
2022-06-13 19:31:25 +08:00
Jan Svoboda a85670001b [clang][driver] Fix compilation database dump with multiple architectures
Command lines with multiple `-arch` arguments expand into multiple entries in the compilation database. However, the file writes are not appending, meaning subsequent writes end up overwriting the previous ones, resulting in garbled output.

This patch fixes that by always appending to the file.

rdar://90165004

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D121997
2022-06-13 13:30:57 +02:00
Jan Svoboda c12577c61d [clang][driver] Introduce new -fdriver-only flag
This patch introduces the new -fdriver-only flag which instructs Clang to only execute the driver logic without running individual jobs. In a way, this is very similar to -###, with the following differences:
 * it doesn't automatically print all jobs,
 * it doesn't avoid side effects (e.g. it will generate compilation database when -MJ is specified).

This flag will be useful in testing D121997.

Reviewed By: dexonsmith, egorzhdan

Differential Revision: https://reviews.llvm.org/D127408
2022-06-13 13:30:56 +02:00
wangpc aebe24a856 [RISCV] Add vread_csr and vwrite_csr to riscv_vector.h
These two functions are described in RVV intrinsics doc
to read/write RVV CSRs. This matches what GCC does.

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D125875
2022-06-13 19:12:15 +08:00
David Truby b4f2f7bebd [clang][AArch64][SVE] Implicit conversions for vector-scalar operations
This patch allows the same implicit conversions for vector-scalar
operations in SVE that are allowed for NEON.

Depends on D126377

Reviewed By: c-rhodes

Differential Revision: https://reviews.llvm.org/D126380
2022-06-13 10:22:10 +00:00
Lucas Prates 33b9ad647e Revert "[ARM][Thumb] Command-line option to ensure AAPCS compliant Frame Records"
Reverting change due to test failure.

This reverts commit 6119053dab.
2022-06-13 11:00:49 +01:00
Lucas Prates 6119053dab [ARM][Thumb] Command-line option to ensure AAPCS compliant Frame Records
Currently the a AAPCS compliant frame record is not always created for
functions when it should. Although a consistent frame record might not
be required in some cases, there are still scenarios where applications
may want to make use of the call hierarchy made available trough it.

In order to enable the use of AAPCS compliant frame records whilst keep
backwards compatibility, this patch introduces a new command-line option
(`-mframe-chain=[none|aapcs|aapcs+leaf]`) for Aarch32 and Thumb backends.
The option allows users to explicitly select when to use it, and is also
useful to ensure the extra overhead introduced by the frame records is
only introduced when necessary, in particular for Thumb targets.

Reviewed By: efriedma

Differential Revision: https://reviews.llvm.org/D125094
2022-06-13 10:21:06 +01:00
owenca b1c300fe68 [clang-format] Handle deprecated options in dump_format_style.py
Also add two deprecated options as comments back to Format.h.
2022-06-12 23:35:48 -07:00
Jez Ng d4bcb45db7 [MC][re-land] Omit DWARF unwind info if compact unwind is present where eligible
This reverts commit d941d59783.

Differential Revision: https://reviews.llvm.org/D122258
2022-06-12 17:24:19 -04:00
Nuno Lopes 571ae1abeb fix test expected output (fixes arm buildbot failure) [NFC] 2022-06-12 19:29:00 +01:00
Nuno Lopes 4dd1bffc9d [clang][CodeGen] Switch a few placeholders from UndefValue to PoisonValue
This change is cosmetic, as these are dummy values that are not observable, but it
gets us closer to removing undef.
NFC
2022-06-12 19:07:59 +01:00
Kazu Hirata f13019f836 [clang] Use any_of and none_of (NFC) 2022-06-12 10:17:12 -07:00
Jez Ng d941d59783 Revert "[MC] Omit DWARF unwind info if compact unwind is present where eligible"
This reverts commit ef501bf85d.
2022-06-12 10:47:08 -04:00
Jez Ng ef501bf85d [MC] Omit DWARF unwind info if compact unwind is present where eligible
Previously, omitting unnecessary DWARF unwinds was only done in two
cases:
* For Darwin + aarch64, if no DWARF unwind info is needed for all the
  functions in a TU, then the `__eh_frame` section would be omitted
  entirely. If any one function needed DWARF unwind, then MC would emit
  DWARF unwind entries for all the functions in the TU.
* For watchOS, MC would omit DWARF unwind on a per-function basis, as
  long as compact unwind was available for that function.

This diff makes it so that we omit DWARF unwind on a per-function basis
for Darwin + aarch64 as well. In addition, we introduce the flag
`--emit-dwarf-unwind=` which can toggle between `always`,
`no-compact-unwind` (only emit DWARF when CU cannot be emitted for a
given function), and the target platform `default`.  `no-compact-unwind`
is particularly useful for newer x86_64 platforms: we don't want to omit
DWARF unwind for x86_64 in general due to possible backwards compat
issues, but we should make it possible for people to opt into this
behavior if they are only targeting newer platforms.

**Motivation:** I'm working on adding support for `__eh_frame` to LLD,
but I'm concerned that we would suffer a perf hit. Processing compact
unwind is already expensive, and that's a simpler format than EH frames.
Given that MC currently produces one EH frame entry for every compact
unwind entry, I don't think processing them will be cheap. I tried to do
something clever on LLD's end to drop the unnecessary EH frames at parse
time, but this made the code significantly more complex. So I'm looking
at fixing this at the MC level instead.

**Addendum:** It turns out that there was a latent bug in the X86
backend when `OmitDwarfIfHaveCompactUnwind` is naively enabled, which is
not too surprising given that this combination has not been heretofore
used.

For functions that have unwind info that cannot be encoded with CU, MC
would end up dropping both the compact unwind entry (OK; existing
behavior) as well as the DWARF entries (not OK).  This diff fixes things
so that we emit the DWARF entry, as well as a CU entry with encoding
`UNWIND_X86_MODE_DWARF` -- this basically tells the unwinder to look for
the DWARF entry. I'm not 100% sure the `UNWIND_X86_MODE_DWARF` CU entry
is necessary, this was the simplest fix. ld64 seems to be able to handle
both the absence and presence of this CU entry. Ultimately ld64 (and
LLD) will synthesize `UNWIND_X86_MODE_DWARF` if it is absent, so there
is no impact to the final binary size.

Reviewed By: davide, lhames

Differential Revision: https://reviews.llvm.org/D122258
2022-06-12 10:03:56 -04:00
Yuki Okushi e43a85a363
[docs][clang] Fix a broken link on the APINotes doc
This patch replaces a link with a GitHub one.

Fixes llvm#55748

Differential Revision: https://reviews.llvm.org/D126599
2022-06-12 22:53:32 +09:00
Kazushi (Jam) Marukawa 140ad7d378 [Clang][VE][NFC] Fix a comment 2022-06-12 10:27:30 +09:00
Nico Weber 5f57ca208b fix comment typo to cycle bots 2022-06-11 18:55:40 -04:00
Kazu Hirata 439a675a5a Use getValueOr (NFC) 2022-06-11 11:24:57 -07:00
Kazu Hirata 5ee3876905 Use isa instead of dyn_cast (NFC) 2022-06-11 11:15:52 -07:00
Craig Topper ff80dc8544 [X86] Add __extension__ to f16c macro intrinsics to suppress warnings about compound literals
This had previously been fixed, but was lost 4 years ago when __extension__
was removed from many intrinsic macros.

Refixes PR32491.
2022-06-11 08:34:37 -07:00
ksyx 45b278f195 [Clang][Doc][SafeStack] Fix deadlink (NFC) 2022-06-11 10:59:51 -04:00
Simon Pilgrim 781dc344f5 [clang][docs] Fix typo in code-block declaration 2022-06-11 09:28:38 +01:00
owenca 05d771021a [clang-format] Fix a bug in RemoveBracesLLVM
Remove the braces of an else block only if the r_brace of the block
is followed by an if.

Differential Revision: https://reviews.llvm.org/D127532
2022-06-11 01:12:11 -07:00
Sheng 6cf83480ea [NFC][clang] Fix typo
Change 'otuer' to 'outer'.
2022-06-11 15:59:05 +08:00
Fangrui Song adf4142f76 [MC] De-capitalize SwitchSection. NFC
Add SwitchSection to return switchSection. The API will be removed soon.
2022-06-10 22:50:55 -07:00
Kazu Hirata 2e603c67c2 [clang] Construct SmallVector with iterator ranges (NFC) 2022-06-10 22:45:26 -07:00
Kazu Hirata f5ef2c5838 [clang] Convert for_each to range-based for loops (NFC) 2022-06-10 22:39:45 -07:00
Anders Waldenborg ff4abe7552 [scan-build-py] Fix exception on shutdown with sarif-html output format
When running scan-build-py's analyze-build script with output format set
to sarif & html it wants to print a message on how to look at the
defects mentioning the directory name twice.

But the path argument was only given once to the logging function,
causing "TypeError: not enough arguments for format string" exception.

Differential Revision: https://reviews.llvm.org/D126974
2022-06-10 23:21:09 +02:00
Argyrios Kyrtzidis fbaa8b9ae5 [Lex] Fix `fixits` for typo-corrections of preprocessing directives within skipped blocks
The `EndLoc` parameter was always unset so no fixit was emitted. But it is also unnecessary for determining the range so we can remove it.

Differential Revision: https://reviews.llvm.org/D127251
2022-06-10 13:32:19 -07:00
Paul Robinson 0fe88f9679 [PS4/PS5] Don't inherit base class alignment 2022-06-10 13:15:17 -07:00
John Ericson 0bb317b7bf Revert "[cmake] Don't export `LLVM_TOOLS_INSTALL_DIR` anymore"
This reverts commit d5daa5c5b0.
2022-06-10 19:26:12 +00:00
Dávid Bolvanský b3b08ad623 [Clang] Added missing doc for minsize attribute
Fixes https://github.com/llvm/llvm-project/issues/53226
2022-06-10 21:18:45 +02:00
Sam Estep a9ad689e35 [clang][dataflow] Don't `assert` full LHS coverage in `optional` model
Followup to D127434.

Reviewed By: ymandel, sgatev

Differential Revision: https://reviews.llvm.org/D127502
2022-06-10 19:10:20 +00:00
Kai Nacke b5019ffc8e [SystemZ/z/OS] Set DWARF version to 4 for z/OS.
The DWARF version was raised to 5 for all platforms which do not opt
out. Default to DWARF version to 4 for z/OS again.

Reviewed By: abhina.sreeskantharajan, uweigand

Differential Revision: https://reviews.llvm.org/D127498
2022-06-10 13:38:58 -04:00
Shivam Gupta a01579ad0a [NFC] Suggest Release mode in clang GettingStarted.html
This fix https://github.com/llvm/llvm-project/issues/23841.
Lots of beginners are not of aware of this option do suggesting it here
would be helpful.
2022-06-10 11:00:05 +05:30
Christopher Di Bella f21187eb2d [clang][tablegen] adds human documentation to `WarningOption`
Building on D126796, this commit adds the infrastructure for being able
to print out descriptions of what each warning does.

Differential Revision: https://reviews.llvm.org/D126832
2022-06-10 17:23:00 +00:00
Sam Estep cd0d52610d [clang][dataflow] In `optional` model, match call return via hasType
Currently the unchecked-optional-access model fails on this example:

    #include <memory>
    #include <optional>

    void foo() {
      std::unique_ptr<std::optional<float>> x;
      *x = std::nullopt;
    }

You can verify the failure by saving the file as `foo.cpp` and running this command:

    clang-tidy -checks='-*,bugprone-unchecked-optional-access' foo.cpp -- -std=c++17

The failing `assert` is in the `transferAssignment` function of the `UncheckedOptionalAccessModel.cpp` file:

    assert(OptionalLoc != nullptr);

The symptom can be treated by replacing that `assert` with an early `return`:

    if (OptionalLoc == nullptr)
      return;

That would be better anyway since we cannot expect to always cover all possible LHS expressions, but it is out of scope for this patch and left as a followup.

Note that the failure did not occur on this very similar example:

    #include <optional>

    template <typename T>
    struct smart_ptr {
      T& operator*() &;
      T* operator->();
    };

    void foo() {
      smart_ptr<std::optional<float>> x;
      *x = std::nullopt;
    }

The difference is caused by the `isCallReturningOptional` matcher, which was previously checking the `functionDecl` of the `callee`. This patch changes it to instead use `hasType` directly on the call expression, fixing the failure for the `std::unique_ptr` example above.

Reviewed By: sgatev

Differential Revision: https://reviews.llvm.org/D127434
2022-06-10 14:52:05 +00:00
John Ericson d5daa5c5b0 [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-06-10 14:35:18 +00:00
Simon Tatham 9073b53e5d [Clang,ARM] Add release note for D127197.
I should have put that in the original commit, but @lenary only just
reminded me that it needed to be there.
2022-06-10 15:19:33 +01:00
Guillaume Chatelet 38637ee477 [clang] Add support for __builtin_memset_inline
In the same spirit as D73543 and in reply to https://reviews.llvm.org/D126768#3549920 this patch is adding support for `__builtin_memset_inline`.

The idea is to get support from the compiler to easily write efficient memory function implementations.

This patch could be split in two:
 - one for the LLVM part adding the `llvm.memset.inline.*` intrinsics.
 - and another one for the Clang part providing the instrinsic as a builtin.

Differential Revision: https://reviews.llvm.org/D126903
2022-06-10 13:13:59 +00:00
Nico Weber 8406839d19 Revert "[analyzer] Deprecate `-analyzer-store region` flag"
This reverts commit d50d9946d1.
Broke check-clang, see comments on https://reviews.llvm.org/D126067

Also revert dependent change "[analyzer] Deprecate the unused 'analyzer-opt-analyze-nested-blocks' cc1 flag"
This reverts commit 07b4a6d046.

Also revert "[analyzer] Fix buildbots after introducing a new frontend warning"
This reverts commit 90374df15d.
(See https://reviews.llvm.org/rG90374df15ddc58d823ca42326a76f58e748f20eb)
2022-06-10 08:50:13 -04:00
Balazs Benics 90374df15d [analyzer] Fix buildbots after introducing a new frontend warning
It seems like I should have ran the `check-clang` target after introducing a new warning diagnostic entry.
My bad. I'll run it next time; `check-clang-analysis` was not enough.
Here is a link to the broken bot: http://45.33.8.238/linux/78236/step_7.txt

This commit should fix this.

Differential Revision: https://reviews.llvm.org/D126067
2022-06-10 14:47:23 +02:00
Balazs Benics 07b4a6d046 [analyzer] Deprecate the unused 'analyzer-opt-analyze-nested-blocks' cc1 flag
This flag was introduced by
6818991d71
    commit 6818991d71
    Author: Ted Kremenek <kremenek@apple.com>
    Date:   Mon Dec 7 22:06:12 2009 +0000

  Add clang-cc option '-analyzer-opt-analyze-nested-blocks' to treat
  block literals as an entry point for analyzer checks.

The last reference was removed by this commit:
5c32dfc5fb

    commit 5c32dfc5fb
    Author: Anna Zaks <ganna@apple.com>
    Date:   Fri Dec 21 01:19:15 2012 +0000

  [analyzer] Add blocks and ObjC messages to the call graph.
  This paves the road for constructing a better function dependency graph.
  If we analyze a function before the functions it calls and inlines,
  there is more opportunity for optimization.
  Note, we add call edges to the called methods that correspond to
  function definitions (declarations with bodies).

Consequently, we should remove this dead flag.
However, this arises a couple of burning questions.
 - Should the `cc1` frontend still accept this flag - to keep
   tools/users passing this flag directly to `cc1` (which is unsupported,
   unadvertised) working.
 - If we should remain backward compatible, how long?
 - How can we get rid of deprecated and obsolete flags at some point?

Reviewed By: martong

Differential Revision: https://reviews.llvm.org/D126067
2022-06-10 13:09:37 +02:00
Balazs Benics b73c2280f5 [analyzer][NFC] Remove unused RegionStoreFeatures
Reviewed By: martong

Differential Revision: https://reviews.llvm.org/D126216
2022-06-10 13:02:26 +02:00
Balazs Benics d50d9946d1 [analyzer] Deprecate `-analyzer-store region` flag
I'm trying to remove unused options from the `Analyses.def` file, then
merge the rest of the useful options into the `AnalyzerOptions.def`.
Then make sure one can set these by an `-analyzer-config XXX=YYY` style
flag.
Then surface the `-analyzer-config` to the `clang` frontend;

After all of this, we can pursue the tablegen approach described
https://discourse.llvm.org/t/rfc-tablegen-clang-static-analyzer-engine-options-for-better-documentation/61488

In this patch, I'm proposing flag deprecations.
We should support deprecated analyzer flags for exactly one release. In
this case I'm planning to drop this flag in `clang-16`.

In the clang frontend, now we won't pass this option to the cc1
frontend, rather emit a warning diagnostic reminding the users about
this deprecated flag, which will be turned into error in clang-16.

Unfortunately, I had to remove all the tests referring to this flag,
causing a mass change. I've also added a test for checking this warning.

I've seen that `scan-build` also uses this flag, but I think we should
remove that part only after we turn this into a hard error.

Reviewed By: martong

Differential Revision: https://reviews.llvm.org/D126215
2022-06-10 12:57:15 +02:00
Andrzej Warzynski 3e782ba21b [flang][driver] Fix support for `-x`
Until now, `-x` wasn't really taken into account in Flang's compiler and
frontend drivers. `flang-new` and `flang-new -fc1` only recently gained
powers to consume inputs other than Fortran files and that's probably
why this hasn't been noticed yet.

This patch makes sure that `-x` is supported correctly and consistently
with Clang. To this end, verification is added when reading LLVM IR
files (i.e. IR modules are verified with `llvm::verifyModule`). This
way, LLVM IR parsing errors are correctly reported to Flang users. This
also aids testing.

With the new functionality, we can verify that `-x ir` breaks
compilation for e.g. Fortran files and vice-versa. Tests are updated
accordingly.

Differential Revision: https://reviews.llvm.org/D127207
2022-06-10 10:36:25 +00:00
Simon Tatham ceb21fa4e4 [ARM] Fix how size-0 bitfields affect homogeneous aggregates.
By both AAPCS32 and AAPCS64, the test for whether an aggregate
qualifies as homogeneous (either HFA or HVA) is based on the data
layout alone. So any logical member of the structure that does not
affect the data layout also should not affect homogeneity. In
particular, an empty bitfield ('int : 0') should make no difference.

In fact, clang considered it to make a difference in C but not in C++,
and justified that policy as compatible with gcc. But that's
considered a bug in gcc as well (at least for Arm targets), and it's
fixed in gcc 12.1.

This fix mimics gcc's: zero-sized bitfields are now ignored in all
languages for the Arm (32- and 64-bit) ABIs. But I've left the
previous behaviour unchanged in other ABIs, by means of adding an
ABIInfo::isZeroLengthBitfieldPermittedInHomogeneousAggregate query
method which the Arm subclasses override.

Reviewed By: lenary

Differential Revision: https://reviews.llvm.org/D127197
2022-06-10 11:27:24 +01:00
Balazs Benics 07a7fd314a [analyzer] Print the offending function at EndAnalysis crash
I've faced crashes in the past multiple times when some
`check::EndAnalysis` callback caused some crash.
It's really anoying that it doesn't tell which function triggered this
callback.

This patch adds the well-known trace for that situation as well.
Example:
  1.      <eof> parser at end of file
  2.      While analyzing stack:
          #0 Calling test11

Note that this does not have tests.
I've considered `unittests` for this purpose, by using the
`ASSERT_DEATH()` similarly how we check double eval called functions in
`ConflictingEvalCallsTest.cpp`, however, that the testsuite won't invoke
the custom handlers. Only the message of the `llvm_unreachable()` will
be printed. Consequently, it's not applicable for us testing this
feature.

I've also considered using an end-to-end LIT test for this.
For that, we would need to somehow overload the `clang_analyzer_crash()`
`ExprInspection` handler, to get triggered by other events than the
`EvalCall`. I'm not saying that we could not come up with a generic way
of causing crash in a specific checker callback, but I'm not sure if
that would worth the effort.

Reviewed By: martong

Differential Revision: https://reviews.llvm.org/D127389
2022-06-10 12:21:17 +02:00
isuckatcs 1d3d5ecea5 [Documentation] Fixed typos in LibASTMatchers tutorial
There was one missing parenthesis and a typo in the mentioned
part of the documentation.

Differential Revision: https://reviews.llvm.org/D124738
2022-06-10 10:22:36 +02:00
Balázs Kéri f93dee1033 [clang][ASTImporter] Fix import of function with auto return type.
Fix a case of importing a function with auto return type
that is resolved with a type template argument that is declared
inside the function.
Fixes #55500

Reviewed By: martong

Differential Revision: https://reviews.llvm.org/D127396
2022-06-10 10:18:53 +02:00
owenca e9f2d47bfe [clang-format][NFC] Remove unused FormatStyle members
Differential Revision: https://reviews.llvm.org/D127390
2022-06-09 22:34:31 -07:00
Jun Zhang 0ecbedc098
Also move WeakRefReferences in CodeGenModule::moveLazyEmssionStates
I forgot this field in b8f9459715
Signed-off-by: Jun Zhang <jun@junz.org>
2022-06-10 13:11:09 +08:00
Alex Brachet fac39d14b1 [clang] Allow CLANG_MODULE_CACHE_PATH env var to override module caching behavior
CLANG_MODULE_CACHE_PATH can be used to change where clang should
put the module cache, or can be set to "" to disable caching entirely.

Differential revision: https://reviews.llvm.org/D126678
2022-06-09 16:55:37 +00:00
Jun Zhang b8f9459715
[CodeGen] Keep track info of lazy-emitted symbols in ModuleBuilder
The intent of this patch is to selectively carry some states over to
the Builder so we won't lose the information of the previous symbols.

This used to be several downstream patches of Cling, it aims to fix
errors in Clang Interpreter when trying to use inline functions.
Before this patch:

clang-repl> inline int foo() { return 42;}
clang-repl> int x = foo();

JIT session error: Symbols not found: [ _Z3foov ]
error: Failed to materialize symbols:
{ (main, { x, $.incr_module_1.__inits.0, __orc_init_func.incr_module_1 }) }

Co-authored-by: Axel Naumann <Axel.Naumann@cern.ch>
Signed-off-by: Jun Zhang <jun@junz.org>

Differential Revision: https://reviews.llvm.org/D126781
2022-06-09 23:12:21 +08:00
Yitzhak Mandelbaum dd38caf3b5 [clang][dataflow] Track `optional` contents in `optional` model.
This patch adds partial support for tracking (i.e. modeling) the contents of an
optional value. Specifically, it supports tracking the value after it is
accessed. We leave tracking constructed/assigned contents to a future patch.

Differential Revision: https://reviews.llvm.org/D124932
2022-06-09 14:17:39 +00:00
Gabor Marton bc2c759aee [analyzer] Fix assertion failure after getKnownValue call
Depends on D126560. `getKnownValue` has been changed by the parent patch
in a way that simplification was removed. This is not correct when the
function is called by the Checkers. Thus, a new internal function is
introduced, `getConstValue`, which simply queries the constraint manager.
This `getConstValue` is used internally in the `SimpleSValBuilder` when a
binop is evaluated, this way we avoid the recursion into the `Simplifier`.

Differential Revision: https://reviews.llvm.org/D127285
2022-06-09 16:13:57 +02:00
Yuki Okushi cedfb5462c
[docs] Update supported language standards list for C++
Differential Revision: https://reviews.llvm.org/D127065
2022-06-09 22:14:08 +09:00
Timm Bäder 8feb92add8 [clang][tests] Add missing compiler name
The driver stripts the first argument. Without the compiler name, the
test depends on whether GCC_INSTALL_PREFIX is set or not.

See https://reviews.llvm.org/D125862
2022-06-09 15:11:40 +02:00
Aaron Ballman 8e1a29ecab Use HTTPS links instead of HTTP ones in the C DR status page 2022-06-09 08:52:30 -04:00
Nathan Sidwell 65b34b78f8 [clang][pr55896]:co_yield/co_await thread-safety
co_await and co_yield are represented by (classes derived from)
CoroutineSuspendExpr.  That has a number of child nodes, not all of
which are used for code-generation.  In particular the operand is
represented multiple times, and, like the problem with co_return
(55406) it must only be emitted in the CFG exactly once.  The operand
also appears inside OpaqueValueExprs, but that's ok.

This adds a visitor for SuspendExprs to emit the required children in
the correct order.  Note that this CFG is pre-coro xform.  We don't
have initial or final suspend points.

Reviewed By: bruno

Differential Revision: https://reviews.llvm.org/D127236
2022-06-09 04:42:10 -07:00
Matheus Izvekov 51608515fa
cmake: use llvm dir variables for clang/utils/hmaptool
Copy hmaptool using the paths for CURRENT_TOOLS_DIR, so
everything goes in the right place in case llvm is included
from a top level CMakeLists.txt.

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

Reviewed By: stephenneuendorffer

Differential Revision: https://reviews.llvm.org/D126308
2022-06-09 12:25:38 +02:00
owenca 40a5d79a5c [clang-format][NFC] Format lib/Format and unittests/Format in clang
Reformat these directories with InsertBraces and RemoveBracesLLVM.

Differential Revision: https://reviews.llvm.org/D127366
2022-06-09 02:25:06 -07:00
Matthias Gehre 7e17e15c9f clang: Introduce -fexperimental-max-bitint-width
This splits of the introduction of -fexperimental-max-bitint-width
from https://reviews.llvm.org/D122234
because that PR is still blocked on discussions on the backend side.

I was asked [0] to upstream at least the flag.

[0] 09854f2af3 (commitcomment-75116619)

Differential Revision: https://reviews.llvm.org/D127287
2022-06-09 07:15:03 +01:00
Bruno Cardoso Lopes e6a76a4935 [Clang][CoverageMapping] Fix compile time explosions by adjusting only appropriated skipped ranges
D83592 added comments to be part of skipped regions, and as part of that, it
also shrinks a skipped range if it spans a line that contains a non-comment
token. This is done by `adjustSkippedRange`.

The `adjustSkippedRange` currently runs on skipped regions that are not
comments, causing a 5min regression while building a big C++ files without any
comments.

Fix the compile time introduced in D83592 by tagging SkippedRange with kind
information and use that to decide what needs additional processing.

Differential Revision: https://reviews.llvm.org/D127338
2022-06-08 23:13:39 -07:00
Jose Manuel Monsalve Diaz d6f6cd5cd5 [docs][clang] Fixing minor typo
Changing "tot the" to "to the"
2022-06-08 23:35:11 +00:00
Wei Yi Tee a1b2b7d979 [clang][dataflow] Remove IndirectionValue class, moving PointeeLoc field into PointerValue and ReferenceValue
This patch precedes a future patch to make PointeeLoc for PointerValue possibly empty (for nullptr), by using a pointer instead of a reference type.
ReferenceValue should maintain a non-empty PointeeLoc reference.

Reviewed By: gribozavr2

Differential Revision: https://reviews.llvm.org/D127312
2022-06-09 01:29:16 +02:00
Matheus Izvekov cfda534b99
[NFC] clang: add test for PR55886
Signed-off-by: Matheus Izvekov <mizvekov@gmail.com>

Differential Revision: https://reviews.llvm.org/D127361
2022-06-09 01:20:58 +02:00
owenca 5ead1f13a2 [clang-format] Remove braces of else blocks that embody an if block
Fixes #55663.

Differential Revision: https://reviews.llvm.org/D127260
2022-06-08 16:05:20 -07:00
Aaron Ballman f0a6a57330 Switch links to use https consistently
The WG14 website was recently updated to support SSL, and we might as
well make use of that.
2022-06-08 15:53:55 -04:00
Aaron Ballman b685426970 Add missing entries for Annex F and Annex H to the C status page 2022-06-08 15:53:54 -04:00
Wei Yi Tee 49ed5bf519 [clang][dataflow] Enable use of synthetic properties on all Value instances.
This patch moves the implementation of synthetic properties from the StructValue class into the Value base class so that it can be used across all Value instances.

Reviewed By: gribozavr2, ymandel, sgatev, xazax.hun

Differential Revision: https://reviews.llvm.org/D127196
2022-06-08 20:20:26 +02:00
Ben Langmuir 835fcf2aa5 [clang][deps] Make order of module dependencies deterministic
This fixes the underlying module dependencies, which had a
non-deterministic order, which was also visible in the order of calls to
DependencyConsumer methods. This was not directly observable in
the clang-scan-deps utility, because it was previously seeing a sorted
order from std::map in DependencyScanningTool. However, the underlying
API previously created a likely issue for any other clients. Note: if
you only apply the change from DependencyScanningTool, you can see the
issue in clang-scan-deps, and existing tests will fail
non-deterministicaly.

Differential Revision: https://reviews.llvm.org/D127243
2022-06-08 11:09:17 -07:00
Ben Langmuir 7a72dca74a [clang][deps] Set -disable-free for module compilations
The command-line arguments for module builds are cc1 commands, so they
do not implicitly set -disable-free like a driver invocation, and
Tooling will disable it for the scanning instance itself. Set
-disable-free explicitly so that separate invocations for building
modules will not pay for freeing memory unnecessarily.

Differential Revision: https://reviews.llvm.org/D127229
2022-06-08 11:09:17 -07:00
Christopher Di Bella 288c1bff96 [clang][driver] adds `-print-diagnostics`
Prints a list of all the warnings that Clang offers.

Differential Revision: https://reviews.llvm.org/D126796
2022-06-08 17:55:31 +00:00
Jose Manuel Monsalve Diaz 28aa7d1884 [docs][clang] Minor typo fix
Changing "iamge" to "image"
2022-06-08 17:41:04 +00:00
Thomas Lively aff679a48c [WebAssembly] Implement remaining relaxed SIMD instructions
Add codegen, intrinsics, and builtins for the i16x8.relaxed_q15mulr_s,
i16x8.dot_i8x16_i7x16_s, and i32x4.dot_i8x16_i7x16_add_s instructions. These are
the last instructions from the relaxed SIMD proposal[1] that had not been
implemented.

[1]:
https://github.com/WebAssembly/relaxed-simd/blob/main/proposals/relaxed-simd/Overview.md.

Differential Revision: https://reviews.llvm.org/D127170
2022-06-08 10:32:10 -07:00
Andrew Browne c7689fd552 [Clang] Fix memory leak due to TemplateArgumentListInfo used in AST node.
It looks like the leak is rooted at the allocation here:
1a155ee7de/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp (L3857)

The VarTemplateSpecializationDecl is allocated using placement new which uses the AST structure for ownership: 1a155ee7de/clang/lib/AST/DeclBase.cpp (L99)

The problem is the TemplateArgumentListInfo inside 1a155ee7de/clang/include/clang/AST/DeclTemplate.h (L2721)
This object contains a vector which does not use placement new: 1a155ee7de/clang/include/clang/AST/TemplateBase.h (L564)

Apparently ASTTemplateArgumentListInfo should be used instead 1a155ee7de/clang/include/clang/AST/TemplateBase.h (L575)

https://reviews.llvm.org/D125802#3551305

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D126944
2022-06-08 09:58:25 -07:00
Andy Soffer 9d6d069f4e Add a parameter to LoadFromASTFile that accepts a file system and defaults to the real file-system.
Reviewed By: ymandel

Differential Revision: https://reviews.llvm.org/D126888
2022-06-08 15:37:52 +00:00
Nathan Sidwell 4f8668d9f7 [clang] co_return cleanup
There's no need for the CoreturnStmt getChildren member to deal with
the presence or absence of the operand member. All users already deal
with null children.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D125542
2022-06-08 08:08:42 -07:00
David Truby d261d3e4a7 [clang][NFC][SVE] Add tests for operators on VLS vectors
This patch adds codegen tests for operators on SVE VLS vector types
2022-06-08 16:06:46 +01:00
Aaron Ballman 98d4f0651a Correcting some links in the C status page
The paper titles were correct, but the document number and links were
incorrect (typo'ed numbers).
2022-06-08 08:52:31 -04:00
Aaron Ballman bf21cda7f2 Add the 2022 papers to the C status tracking page
This adds the papers from Feb 2022 (parts 1 and 2) and May 2022.
2022-06-08 07:42:39 -04:00
Benjamin Kramer b3c0918fb4 [AST] Make header self-contained
There's a dependency in AbstractTypeReader.inc that becomes an error
after D127231.
2022-06-08 12:36:36 +02:00
Martin Storsjö 20ca739701 [doc] Add release notes about SEH unwind information on ARM
Differential Revision: https://reviews.llvm.org/D127150
2022-06-08 11:32:17 +03:00
Kevin Athey 69cd7417f0 Add checks for -lresolv to sanitizer-ld test.
These were missed in https://reviews.llvm.org/D127145.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D127177
2022-06-07 16:07:02 -07:00
owenca b5b33fbffb [clang-format] Skip parsing a block if it's nested too deep
Fixes #55912.

Differential Revision: https://reviews.llvm.org/D127183
2022-06-07 15:28:03 -07:00
Douglas Yung 7805ae257f Revert "[clang-diff] Fix assertion error when dealing with wide strings"
This reverts commit e80748ff88.

This was causing a test failure on a buildbot: https://lab.llvm.org/buildbot/#/builders/139/builds/22964
2022-06-07 14:58:10 -07:00
Vitaly Buka d7df3f0a4b [NFC] Exctract getNoSanitizeMask lambda 2022-06-07 14:08:43 -07:00
Vitaly Buka f32ad5703e [NFC] Move part of SanitizerMetadata into private method 2022-06-07 14:08:43 -07:00
Mitch Phillips 5d9de5f446 [NFC] Clang-format parts of D126929 and D126100 2022-06-07 14:08:43 -07:00
Mitch Phillips f49a5844b6 [NFC][CodeGen] Rename method
Extracted from D84652.
2022-06-07 14:08:42 -07:00
Joseph Huber f06731e3c3 [Binary] Make the OffloadingImage type own the memory
Summary:
The OffloadingBinary uses a convenience struct to help manage the memory
that will be serialized using the binary format. This currently uses a
reference to an existing buffer, but this should own the memory instead
so it is easier to work with seeing as its only current use requires
saving the buffer anyway.
2022-06-07 15:56:09 -04:00
Aaron Ballman d46e7aecb4 Update the C2x status page from latest working draft
This adds the papers for the Jun, Sep, and Dec 2021 meetings. 2022
papers will be handled in a follow-up.
2022-06-07 15:53:47 -04:00
Sam Estep dcb4950d5b [clang][dataflow][NFC] Fix filename typos in tests
Reviewed By: ymandel

Differential Revision: https://reviews.llvm.org/D127008
2022-06-07 19:20:20 +00:00
Erich Keane 5c3bde9625 [CodeGen] Fix an issue when the 'extern C' replacement names broke
Originally broken by me in D122608, this is a regression where we
attempt to replace an extern-C thing with 'itself'.  The problem is that
we end up deleting it, causing the value to fail when it gets put into
llvm.used.
2022-06-07 11:30:59 -07:00
Kaining Zhong e80748ff88 [clang-diff] Fix assertion error when dealing with wide strings
Directly using StringLiteral::getString for wide string is not
currently supported; therefore in ASTDiff, getStmtValue will fail when
asserting that the StringLiteral has a width of 1. This patch also
covers cases for UTF16 and UTF32 encoding, along with corresponding
test cases.

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

Reviewed By: johannes

Differential Revision: https://reviews.llvm.org/D126651
2022-06-07 20:24:34 +02:00
Vince Bridgers c7fa4e8a8b [analyzer] Fix null pointer deref in CastValueChecker
A crash was seen in CastValueChecker due to a null pointer dereference.

The fix uses QualType::getAsString to avoid the null dereference
when a CXXRecordDecl cannot be obtained. A small reproducer is added,
and cast value notes LITs are updated for the new debug messages.

Reviewed By: steakhal

Differential Revision: https://reviews.llvm.org/D127105
2022-06-07 13:34:06 -04:00
Benjamin Kramer 1fd6f06b9e [format] Fix an uninitialized variable
parseBlock may decide to leave it unchanged. Found by msan.
2022-06-07 18:18:29 +02:00
David Truby 133a5f22d3 [clang][AArch64][SVE] Improve diagnostics for SVE operators
This patch corrects some diagnostics for the SVE sizeless vector
operators, including correctly diagnosing when the vectors are
different sizes.

Differential Revision: https://reviews.llvm.org/D126377
2022-06-07 15:35:36 +01:00
Pengxuan Zheng e3a6784ac9 [clang-cl] Add support for /kernel
MSVC defines _KERNEL_MODE when /kernel is passed.
Also, /kernel disables RTTI and C++ exception handling.

https://docs.microsoft.com/en-us/cpp/build/reference/kernel-create-kernel-mode-binary?view=msvc-170

Reviewed By: thakis

Differential Revision: https://reviews.llvm.org/D126719
2022-06-07 06:42:35 -07:00
Guillaume Chatelet 19647e5b3b Fix change of variable name in test 2022-06-07 11:20:57 +00:00
Gabor Marton 8131ee4c43 [analyzer] Remove NotifyAssumeClients
Depends on D126560.

Differential Revision: https://reviews.llvm.org/D126878
2022-06-07 13:02:03 +02:00
Gabor Marton 17e9ea6138 [analyzer][NFC] Add LLVM_UNLIKELY to assumeDualImpl
Aligned with the measures we had in D124674, this condition seems to be
unlikely.

Nevertheless, I've made some new measurments with stats just for this,
and data confirms this is indeed unlikely.

Differential Revision: https://reviews.llvm.org/D127190
2022-06-07 12:48:48 +02:00
Yuki Okushi aa9b3389ff
[clang] Remove some `U+C2AD`s in `__cpp_multidimensional_subscript`
The `Builder.defineMacro("__cpp_multidimensional_subscript", "202110L");` line has
some `U+C2AD`s that shouldn't necessary here. So removed them.

Differential Revision: https://reviews.llvm.org/D127066
2022-06-07 19:29:01 +09:00
owenca ec90bc0ea4 [clang-format][NFC] Clean up the unwrapped line parser
Change the signatures of parseBlock(), parseLevel(), and
parseStructuralElement() to support combining else and if when
removing braces. See #55663.

Differential Revision: https://reviews.llvm.org/D127005
2022-06-07 02:58:57 -07:00
Guillaume Chatelet d8b540cd31 Cleanup sema checking for buitlin_memcpy_inline 2022-06-07 09:49:36 +00:00
Gabor Marton f66f4d3b07 [analyzer] Track assume call stack to detect fixpoint
Assume functions might recurse (see `reAssume` or `tryRearrange`).
During the recursion, the State might not change anymore, that means we
reached a fixpoint. In this patch, we avoid infinite recursion of assume
calls by checking already visited States on the stack of assume function
calls. This patch renders the previous "workaround" solution (D47155)
unnecessary. Note that this is not an NFC patch. If we were to limit the
maximum stack depth of the assume calls to 1 then would it be equivalent
with the previous solution in D47155.

Additionally, in D113753, we simplify the symbols right at the beginning
of evalBinOpNN. So, a call to `simplifySVal` in `getKnownValue` (added
in D51252) is no longer needed.

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

Differential Revision: https://reviews.llvm.org/D126560
2022-06-07 08:36:11 +02:00
Evgeny Shulgin a4f8590247 [clang] Allow consteval functions in default arguments
We should not mark a function as "referenced" if we call it within a
ConstantExpr, because the expression will be folded to a value in LLVM
IR. To prevent emitting consteval function declarations, we should not "jump
over" a ConstantExpr when it is a top-level ParmVarDecl's subexpression.

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

Reviewed By: erichkeane, aaron.ballman, ChuanqiXu

Differenitial Revision: https://reviews.llvm.org/D119646
2022-06-07 10:54:37 +08:00
Akira Hatanaka 3ba6ace3cc [gmodules] Skip CXXDeductionGuideDecls when visiting FunctionDecls in
DebugTypeVisitor

This recommits d1346e2. I've added a line to the test case to enable it
only on assert builds.

Differential Revision: https://reviews.llvm.org/D125839
2022-06-06 19:12:26 -07:00
Akira Hatanaka 834e5d12c7 Revert "[gmodules] Skip CXXDeductionGuideDecls when visiting FunctionDecls in"
This reverts commit d1346e2ee2.

The commit broke a few bots.
2022-06-06 18:48:24 -07:00
Kevin Athey 6dce56b2a3 [Driver] add -lresolv for all but Android.
As there 3 intercepts that depend on libresolv, link tests in ./configure scripts may be confuse by the presence of resolv symbols (i.e. dn_expand) even with -lresolv and get a runtime error.

Android provides the functionality in libc.

https://reviews.llvm.org/D122849
https://reviews.llvm.org/D126851

Reviewed By: eugenis, MaskRay

Differential Revision: https://reviews.llvm.org/D127145
2022-06-06 15:49:42 -07:00
Matheus Izvekov 43ef17cac1
[clang] P2266: apply move elision rules on throw expr nested in function prototypes
Our rules to determine if the throw expression are within the variable
scope were giving a false negative result in case the throw expression
would appear within a decltype in a nested function declaration.

Per P2266R3, the relevant rule is: [expr.prim.id.unqual]/2
```
    if the id-expression (possibly parenthesized) is the operand of a throw-expression, and names an implicitly movable entity that belongs to a scope that does not contain the compound-statement of the innermost lambda-expression, try-block , or function-try-block (if any) whose compound-statement or ctor-initializer encloses the throw-expression.
```

This fixes PR54341.

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

Reviewed By: rsmith

Differential Revision: https://reviews.llvm.org/D127075
2022-06-07 00:08:24 +02:00
Sam Clegg 47039a1a4b [WebAssembly] Remove restriction on main name mangling
Summary: Emscripten now handles/supports this new mode.

Subscribers: dschuff, jgravelle-google, aheejin, sunfish, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D75277
2022-06-06 14:04:27 -07:00
Martin Storsjö fcb784db49 [clang] [MinGW] Default to WinEH (SEH) exception handling instead of Dwarf
The relevant runtime libraries have been updated to support this
now.

Differential Revision: https://reviews.llvm.org/D126871
2022-06-06 23:27:31 +03:00
Martin Storsjö 2293d46a01 [clang] [Headers] Check __SEH__, when checking if ARM EHABI is implied
ARM EHABI isn't signalled by any specific compiler builtin define,
but is implied by the lack of defines specifying any other
exception handling mechanism, `__USING_SJLJ_EXCEPTIONS__` or
`__ARM_DWARF_EH__`.

As Windows SEH also can be used for unwinding, check for the
`__SEH__` define too, in the same way.

This is the same change as 4a3722a2c3 /
D126866, applied on the clang headers.

Differential Revision: https://reviews.llvm.org/D126865
2022-06-06 23:21:05 +03:00
Akira Hatanaka d1346e2ee2 [gmodules] Skip CXXDeductionGuideDecls when visiting FunctionDecls in
DebugTypeVisitor

Differential Revision: https://reviews.llvm.org/D125839
2022-06-06 12:51:36 -07:00
Aaron Ballman cc30d43ce4 Fix a -Wlogical-op-parentheses warning; NFC
This should address bot failures like:
https://lab.llvm.org/buildbot/#/builders/77/builds/18317
2022-06-06 07:52:12 -04:00
Aaron Ballman 881125ad91 Allow use of an elaborated type specifier in a _Generic association in C++
Currently, Clang accepts this code in C mode (where the tag is required
to be used) but rejects it in C++ mode thinking that the association is
defining a new type.

void foo(void) {
  struct S { int a; };
  _Generic(something, struct S : 1);
}
Clang thinks this in C++ because it sees struct S : when parsing the
class specifier and decides that must be a type definition (because the
colon signifies the presence of a base class type). This patch adds a
new declarator context to represent a _Generic association so that we
can distinguish these situations properly.

Fixes #55562

Differential Revision: https://reviews.llvm.org/D126969
2022-06-06 07:17:35 -04:00
Qingyuan Zheng c119a17e7f [AST] Fix clang RecursiveASTVisitor for definition of XXXTemplateSpecializationDecl
Fixes https://github.com/clangd/clangd/issues/1132
where clangd's semantic highlighting is missing for symbols of a template
specialization definition. It turns out the visitor didn't traverse the
base classes of Class/Var##TemplateSpecializationDecl, i.e.
CXXRecordDecl/VarDecl. This patch adds them back as what is done in
DEF_TRAVERSE_TMPL_PART_SPEC_DECL.

Reviewed By: rsmith

Differential Revision: https://reviews.llvm.org/D126757
2022-06-06 02:35:34 -04:00
Chuanqi Xu 448995c521 [NFC] [Coroutines] Add test for ambiguous allocation functions in
promise_type

Address the post-commit comment in
https://reviews.llvm.org/D125517#inline-1217244
2022-06-06 14:23:35 +08:00
Chris Bieneman f06abbb393 LLVM Driver Multicall tool
This patch adds an llvm-driver multicall tool that can combine multiple
LLVM-based tools. The build infrastructure is enabled for a tool by
adding the GENERATE_DRIVER option to the add_llvm_executable CMake
call, and changing the tool's main function to a canonicalized
tool_name_main format (i.e. llvm_ar_main, clang_main, etc...).

As currently implemented llvm-driver contains dsymutil, llvm-ar,
llvm-cxxfilt, llvm-objcopy, and clang (if clang is included in the
build).

llvm-driver can be enabled from builds by setting
LLVM_TOOL_LLVM_DRIVER_BUILD=On.

There are several limitations in the current implementation, which can
be addressed in subsequent patches:

(1) the multicall binary cannot currently properly handle
multi-dispatch tools. This means symlinking llvm-ranlib to llvm-driver
will not properly result in llvm-ar's main being called.
(2) the multicall binary cannot be comprised of tools containing
conflicting cl::opt options as the global cl::opt option list cannot
contain duplicates.

These limitations can be addressed in subsequent patches.

Differential revision: https://reviews.llvm.org/D109977
2022-06-06 04:27:32 +00:00
Phoebe Wang 52818fd97f [Clang][FP16] Add 4 builtins for _Float16
We are lacking builtins support for `_Float16`. In most cases, we can use other floating-type builtins and truncate them to `_Float16`.
But it's a problem to SNaN, e.g., https://gcc.godbolt.org/z/cqr5nG1jh
This patch adds `__builtin_nansf16` support as well as other 3 ones since they are usually used together.

Reviewed By: LuoYuanke

Differential Revision: https://reviews.llvm.org/D127050
2022-06-06 09:00:26 +08:00
Kazu Hirata d93728978b [clang] Use llvm::is_contained (NFC) 2022-06-05 17:56:40 -07:00
Fangrui Song 332d5204c5 [Driver][test] Remove unneeded -no-canonical-prefixes and -o %t.o
Similar to 980679981f
2022-06-05 16:06:09 -07:00
owenca fc1c160f73 [clang-format] Handle attributes for for/while loops
Fixes #55853.

Differential Revision: https://reviews.llvm.org/D127054
2022-06-05 15:45:25 -07:00
Aditya Kumar 8f7b14898f [NFC] Make comment consistent with allow|ignore list renamings
Reviewed By: thakis
Differential Revision: https://reviews.llvm.org/D123640
2022-06-05 14:49:01 -07:00
Matheus Izvekov f62433f17c
[NFC] Add test cases reported in PR54341
Signed-off-by: Matheus Izvekov <mizvekov@gmail.com>

Differential Revision: https://reviews.llvm.org/D127074
2022-06-05 20:34:28 +02:00
Fangrui Song 95a134254a Remove unneeded cl::ZeroOrMore for cl::opt/cl::list options 2022-06-05 01:07:51 -07:00
Fangrui Song d86a206f06 Remove unneeded cl::ZeroOrMore for cl::opt/cl::list options 2022-06-05 00:31:44 -07:00
Fangrui Song d0d1c416cb Remove unneeded cl::ZeroOrMore for cl::list options 2022-06-04 23:51:13 -07:00
Kazu Hirata e0039b8d6a Use llvm::less_second (NFC) 2022-06-04 22:48:32 -07:00
Kazu Hirata 8cc9fa6f78 Use static_cast from SmallString to std::string (NFC) 2022-06-04 22:09:27 -07:00
Kazu Hirata 4969a6924d Use llvm::less_first (NFC) 2022-06-04 21:23:18 -07:00
Fangrui Song 734c223445 [clang-link-wrapper] Remove unneeded cl::ZeroOrMore for cl::opt options. NFC
Similar to 557efc9a8b
2022-06-03 22:02:11 -07:00
Jake Egan c3c75d805c [clang][test] Mark test arm-float-abi-lto.c unsupported on AIX
This test is failing after the introduction of opaque pointers (https://reviews.llvm.org/D125847). The test is flaky and fails from segmentation fault, but it's unclear why. So, mark this test unsupported while it's investigated.
2022-06-03 21:04:56 -04:00
Paul Pluzhnikov 490990bb1f [test] Modify test to verify D126396 (Clean "./" from __FILE__ expansion)
Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D127009
2022-06-03 17:54:03 -07:00
Anders Waldenborg dd2362a8ba [clang] Allow const variables with weak attribute to be overridden
A variable with `weak` attribute signifies that it can be replaced with
a "strong" symbol link time. Therefore it must not emitted with
"weak_odr" linkage, as that allows the backend to use its value in
optimizations.

The frontend already considers weak const variables as
non-constant (note_constexpr_var_init_weak diagnostic) so this change
makes frontend and backend consistent.

This commit reverses the
  f49573d1 weak globals that are const should get weak_odr linkage.
commit from 2009-08-05 which introduced this behavior. Unfortunately
that commit doesn't provide any details on why the change was made.

This was discussed in
https://discourse.llvm.org/t/weak-attribute-semantics-on-const-variables/62311

Differential Revision: https://reviews.llvm.org/D126324
2022-06-03 23:44:15 +02:00
Joseph Huber 1257fe193a [Clang] Change the offload packager build to be a clang tool
Summary:
This patch changes the CMake build configruation for the
`clang-offload-packager` to be a clang tool rather than an executable.
2022-06-03 17:35:26 -04:00
Yitzhak Mandelbaum 6adfc64e70 [clang][dataflow] Modify `optional` model to handle type aliases.
Previously, type aliases were not handled (and resulted in an assertion
firing). This patch generalizes the model to consider aliases everywhere (a
previous patch already considered aliases for optional-returning functions).

Differential Revision: https://reviews.llvm.org/D126972
2022-06-03 18:57:43 +00:00
python3kgae 436fef21ef [NFC] Fix issue on CMake Xcode build configuration.
add missing dependency for hlsl-resource-headers and clang-resource-headers.

Reviewed By: rastogishubham

Differential Revision: https://reviews.llvm.org/D126892
2022-06-03 11:03:02 -07:00
Leonard Grey dd6bcdbf21 [Attributes] Remove AttrSyntax and migrate uses to AttributeCommonInfo::Syntax (NFC)
This is setup for allowing hasAttribute to work for plugin-provided attributes

Differential Revision: https://reviews.llvm.org/D126902
2022-06-03 12:11:48 -04:00
Jamie Schmeiser efbf0136b4 Only issue warning for subtraction involving null pointers on live code paths
Summary:
Change the warning produced for subtraction from (or with) a null pointer
to only be produced when the code path is live.
https://github.com/llvm/llvm-project/issues/54570

Author: Jamie Schmeiser <schmeise@ca.ibm.com>
Reviewed By: anarazel (Andres Freund)
Differential Revision: https://reviews.llvm.org/D126816
2022-06-03 10:10:37 -04:00
Stanislav Gatev 65e710c3fc [clang][dataflow] Model calls returning optionals
Model calls returning optionals

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

Reviewed-by: ymandel, xazax.hun
2022-06-03 13:38:22 +00:00
Aaron Ballman 1896df18cc Correct the behavior of this test for non-Windows targets
This should address build failures like:
https://lab.llvm.org/buildbot/#/builders/188/builds/14980
https://lab.llvm.org/buildbot/#/builders/171/builds/15515
https://lab.llvm.org/buildbot/#/builders/91/builds/9877
2022-06-03 09:00:05 -04:00
Aaron Ballman 3472b6eb0a Updating more entries in the C DR Status page
Adds test coverage or information for ~25 more C DRs.
2022-06-03 08:29:06 -04:00
Hans Wennborg 166f9be330 Update old mailing list link in the nullability doc 2022-06-03 14:23:41 +02:00
Guillaume Chatelet c698189696 [NFC] Format CGBuilder.h 2022-06-03 07:54:01 +00:00
Timm Bäder a459d1eb2c [clang][sema] Remove unused paramter from VerifyBitField
The ZeroWidth paramter is unused in every call site of VerifyBitField.
2022-06-03 09:52:37 +02:00
Jonas Hahnfeld 0d2186373f [Driver] Add multiarch path for RISC-V
This is required to find headers on the Debian port for RISC-V.

Differential Revision: https://reviews.llvm.org/D126672
2022-06-03 09:10:34 +02:00
Martin Storsjö e8402d5de8 [clang] [MSVC] Enable unwind tables for ARM
The backend now can generate working unwind information for this
target.

Improve the existing windows-exceptions.cpp testcase to check for
the state of unwind tables on all MSVC architectures.

Differential Revision: https://reviews.llvm.org/D126862
2022-06-03 09:32:00 +03:00
Timm Bäder 9f97720268 [clang][driver] Dynamically select gcc-toolset/devtoolset
Instead of adding all devtoolset and gcc-toolset prefixes to the list of
prefixes, just scan the /opt/rh/ directory for the one with the highest
version number and only add that one.

Differential Revision: https://reviews.llvm.org/D125862
2022-06-03 08:12:27 +02:00
Shilei Tian b917433835 [NFC][Doc] Finish atomic compare 2022-06-02 21:50:07 -04:00
Shilei Tian c4a90db720 [Clang][OpenMP] Add the codegen support for `atomic compare capture`
This patch adds the codegen support for `atomic compare capture` in clang.

Reviewed By: ABataev

Differential Revision: https://reviews.llvm.org/D120290
2022-06-02 21:38:21 -04:00
Mike Rice 48d6a6c9ad [OpenMP][NFC] update status for 'omp_all_memory' directive to 'done' 2022-06-02 17:31:33 -07:00
Akira Hatanaka 66e08995b0 [Sema] Reject list-initialization of enumeration types from a
brace-init-list containing a single element of a different scoped
enumeration type

It is rejected because it doesn't satisfy the condition that the element
has to be implicitly convertible to the underlying type of the
enumeration.

http://eel.is/c++draft/dcl.init.list#3.8

Differential Revision: https://reviews.llvm.org/D126084
2022-06-02 17:25:11 -07:00
Akira Hatanaka b64f6e5722 Add a release note for the scope enum initialization bug fix in
https://reviews.llvm.org/D126084
2022-06-02 17:13:05 -07:00
Paul Pluzhnikov 4ad17d2e96 Clean "./" from __FILE__ expansion.
This is alternative to https://reviews.llvm.org/D121733
and helps with Clang header modules in which FILE
may expand to "./foo.h" or "foo.h" depending on whether the file was
included directly or not.

Only do this when UseTargetPathSeparator is true, as we are already
changing the path in that case.

Reviewed By: ayzhao

Differential Revision: https://reviews.llvm.org/D126396
2022-06-02 18:00:19 -04:00
Shilei Tian 3a96256b7e [Clang][OpenMP] Avoid using `IgnoreImpCasts` if possible
This patch removes all `IgnoreImpCasts` in Sema, and only uses it if necessary. If the expression is not of the same type as the pointer value, a cast is inserted.

Reviewed By: ABataev

Differential Revision: https://reviews.llvm.org/D126602
2022-06-02 17:45:02 -04:00
Paul Robinson aa1cdf87b5 [PS5] Ignore 'packed' on one-byte bitfields, matching PS4 2022-06-02 14:41:18 -07:00
David Blaikie cb08f4aa44 Support warn_unused_result on typedefs
While it's not as robust as using the attribute on enums/classes (the
type information may be lost through a function pointer, a declaration
or use of the underlying type without using the typedef, etc) but I
think there's still value in being able to attribute a typedef and have
all return types written with that typedef pick up the
warn_unused_result behavior.

Specifically I'd like to be able to annotate LLVMErrorRef (a wrapper for
llvm::Error used in the C API - the underlying type is a raw pointer, so
it can't be attributed itself) to reduce the chance of unhandled errors.

Differential Revision: https://reviews.llvm.org/D102122
2022-06-02 20:57:31 +00:00
Xiang Li 6bea9ff913 [HLSL] Add WaveActiveCountBits as Langugage builtin function for HLSL
One clang builtins are introduced
 uint WaveActiveCountBits( bool bBit ) as Langugage builtin function for HLSL.

The detail for WaveActiveCountBits is at
https://github.com/microsoft/DirectXShaderCompiler/wiki/Wave-Intrinsics#uint-waveactivecountbits-bool-bbit-

This is only clang part change to make WaveActiveCountBits into AST.
llvm intrinsic for WaveActiveCountBits will be add in separate PR.

Reviewed By: Anastasia

Differential Revision: https://reviews.llvm.org/D126857
2022-06-02 13:06:01 -07:00
Paul Robinson 30b7ffe74e [PS5] Pack non-POD members in packed structs, matching PS4 ABI 2022-06-02 12:26:26 -07:00
Paul Robinson bb7835e2a7 [PS5] Apply 'packed' attribute to base classes, matching PS4 ABI 2022-06-02 12:26:26 -07:00
Anders Waldenborg 4c1e487c41 scan-build-py: Change scripts to explicitly require python3
The "#!" line in all scan-build-py scripts were using just bare
"/usr/bin/python" which according to PEP-0394 can be either python3,
python2 or not exist at all.

E.g in latest debian and ubuntu releases "/usr/bin/python" does not
exist at all by default and user must install python-is-python2 or
python-is-python3 packages to get the bare version less "python"
command.

Until recently (70b06fe8a1 "scan-build-py: Force the opening in utf-8"
changed "libscanbuild") these scripts worked in both python2 and
python3, but now they (rightfully) are python3 only, and broke on
systems where the "python" command means python2.

By changing the "#!" to be "python3" it is not only explicit that the
scripts require python3 it also works on systems where "python" command
is python2 or nonexistent.

Differential Revision: https://reviews.llvm.org/D126804
2022-06-02 20:08:21 +02:00
Paul Pluzhnikov 35ab2a11bb Fix a buglet in remove_dots().
The function promises to canonicalize the path, but neglected to do so
for the root component.

For example, calling remove_dots("/tmp/foo.c", Style::windows_backslash)
resulted in "/tmp\foo.c". Now it produces "\tmp\foo.c".

Also fix FIXME in the corresponding test.

Reviewed By: rnk

Differential Revision: https://reviews.llvm.org/D126412
2022-06-02 11:07:44 -07:00
Paul Robinson dc5175adef [PS5] Make passing unions in registers match PS4 ABI 2022-06-02 11:00:54 -07:00
Paul Robinson cc756f91c3 [PS5] Classify __m64 as integer, matching PS4 ABI 2022-06-02 11:00:53 -07:00
Balazs Benics 7d24641f89 [llvm][analyzer][NFC] Introduce SFINAE for specializing FoldingSetTraits
Reviewed By: martong

Differential Revision: https://reviews.llvm.org/D126803
2022-06-02 19:46:38 +02:00
Balazs Benics cf1f1b7240 [analyzer][NFC] Uplift checkers after D126801
Reviewed By: martong

Differential Revision: https://reviews.llvm.org/D126802
2022-06-02 19:46:38 +02:00
Balazs Benics 33ca5a447e [analyzer][NFC] Add partial specializations for ProgramStateTraits
I'm also hoisting common code from the existing specializations into a
common trait impl to reduce code duplication.

Reviewed By: martong

Differential Revision: https://reviews.llvm.org/D126801
2022-06-02 19:46:38 +02:00
Paul Robinson 5a6352bc70 Tidy up `pragma comment lib` handling and testing
A bit of historical research shows that over the years:
Commit 99efc036 added `pragma comment lib` support for PS4.
Commit fd4db533 added `pragma comment lib` support for all ELF targets.
Commit 1d16515f reworked dependent-library support for all ELF targets.

The upshot is that some PS4-specific code became dead, and the
testing became somewhat fragmented.  I've removed the dead code and
combined the previous PS4-specific and linux-specific tests for the
diagnostics into one generic ELF test.
Also added a couple of PS5 runs while I was in there.
2022-06-02 07:52:26 -07:00
Aaron Ballman 0b46121c41 Update more DR status information for C.
This adds new files to track DRs 100-199 and 400-499, but the file
contents are still a work in progress. It also updates the associated
status in the DR tracking page.
2022-06-02 09:32:44 -04:00
Nico Weber e37421669e Revert "unbreak Modules/cxx20-export-import.cpp with LLVM_APPEND_VC_REV after 8c8a2679a20f"
This reverts commit 4463bd0f89.
8c8a2679a2 was reverted in d42fe9aa84.
2022-06-02 09:31:57 -04:00
Paul Robinson b2c6251c06 [PS5] Support r and y specifiers of freebsd_kernel_printf format strings 2022-06-02 06:27:11 -07:00
Hans Wennborg d42fe9aa84 Revert "[clang][AIX] add option mdefault-visibility-export-mapping"
This caused assertions, see comment on the code review:

llvm/clang/lib/AST/Decl.cpp:1510:
clang::LinkageInfo clang::LinkageComputer::getLVForDecl(const clang::NamedDecl *, clang::LVComputationKind):
Assertion `D->getCachedLinkage() == LV.getLinkage()' failed.

> The option mdefault-visibility-export-mapping is created to allow
> mapping default visibility to an explicit shared library export
> (e.g. dllexport). Exactly how and if this is manifested is target
> dependent (since it depends on how they map dllexport in the IR).
>
> Three values are provided for the option:
>
> * none: the default and behavior without the option, no additional export linkage information is created.
> * explicit: add the export for entities with explict default visibility from the source, including RTTI
> * all: add the export for all entities with default visibility
>
> This option is useful for targets which do not export symbols as part of
> their usual default linkage behaviour (e.g. AIX), such targets
> traditionally specified such information in external files (e.g. export
> lists), but this mapping allows them to use the visibility information
> typically used for this purpose on other (e.g. ELF) platforms.
>
> Reviewed By: MaskRay
>
> Differential Revision: https://reviews.llvm.org/D126340

This reverts commit 8c8a2679a2.
2022-06-02 15:09:39 +02:00
Nikita Popov 30ad481e87 Revert "cmake: use llvm dir variables for clang/utils/hmaptool"
As discussed on the review, this change breaks the standalone
clang build. When building against an installed LLVM, the
LLVM_TOOLS_BINARY_DIR cmake variable points to the location of
the installed LLVM tools, not to the cmake build directory. This
means that we would end up trying to move hmaptool into something
like /usr/bin as part of the normal build, while this should only
be happening when running an install target.

This reverts commit bf1ab1f0eb.
2022-06-02 14:55:58 +02:00
Aaron Ballman c745f2ce6c Revert "Drop qualifiers from return types in C (DR423)"
This reverts commit d374b65f2d.

The changes lose AST fidelity (reported in #55778), but also may be
improperly dropping _Atomic qualifiers. I am rolling the changes back
until I've finished discussions in WG14 about the proper resolution to
DR423.
2022-06-02 08:28:43 -04:00
Gabor Marton 81e44414aa [analyzer][NFC] Move overconstrained check from reAssume to assumeDualImpl
Depends on D126406. Checking of the overconstrained property is much
better suited here.

Differential Revision: https://reviews.llvm.org/D126707
2022-06-02 11:41:19 +02:00
Martin Storsjö f730749e85 [clang] [ARM] Add __builtin_sponentry like on aarch64
This is used for calling the SEH aware setjmp on MinGW.

Differential Revision: https://reviews.llvm.org/D126764
2022-06-02 12:29:59 +03:00
owenca db15e31212 [clang-format] Handle do-while loops for RemoveBracesLLVM
Also updates the unit tests to match the updated LLVM Coding
Standards.

Differential Revision: https://reviews.llvm.org/D126758
2022-06-02 01:08:40 -07:00
Stanislav Gatev 0e286b77cf [clang][dataflow] Add transfer functions for structured bindings
This is part of the implementation of the dataflow analysis framework.
See "[RFC] A dataflow analysis framework for Clang AST" on cfe-dev.

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

Reviewed-by: ymandel, xazax.hun
2022-06-02 08:02:26 +00:00
Nikita Popov 41d5033eb1 [IR] Enable opaque pointers by default
This enabled opaque pointers by default in LLVM. The effect of this
is twofold:

* If IR that contains *neither* explicit ptr nor %T* types is passed
  to tools, we will now use opaque pointer mode, unless
  -opaque-pointers=0 has been explicitly passed.
* Users of LLVM as a library will now default to opaque pointers.
  It is possible to opt-out by calling setOpaquePointers(false) on
  LLVMContext.

A cmake option to toggle this default will not be provided. Frontends
or other tools that want to (temporarily) keep using typed pointers
should disable opaque pointers via LLVMContext.

Differential Revision: https://reviews.llvm.org/D126689
2022-06-02 09:40:56 +02:00