Commit Graph

25023 Commits

Author SHA1 Message Date
Endre Fulop 3078b51166 [NFC] Test commit access
llvm-svn: 365189
2019-07-05 12:00:52 +00:00
Kristof Umann d5c9d9b682 [CFG] Add a new function to get the proper condition of a CFGBlock
getTerminatorCondition() returned a condition that may be outside of the
block, while the new function returns the proper one:

if (A && B && C) {}

Return C instead of A && B && C.

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

llvm-svn: 365177
2019-07-05 09:52:00 +00:00
Vassil Vassilev 16de81c158 [modules] Add PP callbacks for entering and leaving a submodule.
llvm-svn: 365153
2019-07-04 19:06:52 +00:00
Simon Pilgrim d74c36cf6e Fix -Wdocumentation warning.
llvm-svn: 365126
2019-07-04 10:28:31 +00:00
Csaba Dabis 57835bcfbd [analyzer] ReturnValueChecker: Model the guaranteed boolean return value of function calls
Summary: It models the known LLVM methods paired with their class.

Reviewers: NoQ, xazax.hun, ravikandhadai, baloghadamsoftware, Szelethus

Reviewed By: NoQ

Subscribers: dschuff, aheejin, mgorny, szepet, rnkovacs, a.sidorin,
             mikhail.ramalho, donat.nagy, dkrupp, cfe-commits

Tags: #clang

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

llvm-svn: 365103
2019-07-04 00:50:50 +00:00
Francis Visoiu Mistrih e0308279cb [Bitcode] Move Bitstream to a separate library
This moves Bitcode/Bitstream*, Bitcode/BitCodes.h to Bitstream/.

This is needed to avoid a circular dependency when using the bitstream
code for parsing optimization remarks.

Since Bitcode uses Core for the IR part:

libLLVMRemarks -> Bitcode -> Core

and Core uses libLLVMRemarks to generate remarks (see
IR/RemarkStreamer.cpp):

Core -> libLLVMRemarks

we need to separate the Bitstream and Bitcode part.

For clang-doc, it seems that it doesn't need the whole bitcode layer, so
I updated the CMake to only use the bitstream part.

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

llvm-svn: 365091
2019-07-03 22:40:07 +00:00
Kristof Umann 9854d771bd Revert "[analyzer][CFG] Return the correct terminator condition"
This reverts commit 7a57118a6fcfa3770f984453543bbdfd0b233e84.

Causes a bunch of crashes, I need to time to evaluate this.

llvm-svn: 365037
2019-07-03 13:03:33 +00:00
Kristof Umann 00aab1d45e [analyzer][CFG] Return the correct terminator condition
For the following terminator statement:

if (A && B && C && D)
The built CFG is the following:

[B5 (ENTRY)]
  Succs (1): B4

[B1]
  1: 10
  2: j
  3: [B1.2] (ImplicitCastExpr, LValueToRValue, int)
  4: [B1.1] / [B1.3]
  5: int x = 10 / j;
  Preds (1): B2
  Succs (1): B0

[B2]
  1: C
  2: [B2.1] (ImplicitCastExpr, LValueToRValue, _Bool)
  T: if [B4.4] && [B3.2] && [B2.2]
  Preds (1): B3
  Succs (2): B1 B0

[B3]
  1: B
  2: [B3.1] (ImplicitCastExpr, LValueToRValue, _Bool)
  T: [B4.4] && [B3.2] && ...
  Preds (1): B4
  Succs (2): B2 B0

[B4]
  1: 0
  2: int j = 0;
  3: A
  4: [B4.3] (ImplicitCastExpr, LValueToRValue, _Bool)
  T: [B4.4] && ...
  Preds (1): B5
  Succs (2): B3 B0

[B0 (EXIT)]
  Preds (4): B1 B2 B3 B4

However, even though the path of execution in B2 only depends on C's value,
CFGBlock::getCondition() would return the entire condition (A && B && C). For
B3, it would return A && B. I changed this the actual condition.

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

llvm-svn: 365036
2019-07-03 12:53:19 +00:00
Kristof Umann 71a9dc39e4 [analyzer][Dominator] Add post dominators to CFG + a new debug checker
Transform clang::DominatorTree to be able to also calculate post dominators.

* Tidy up the documentation
* Make it clang::DominatorTree template class (similarly to how
  llvm::DominatorTreeBase works), rename it to clang::CFGDominatorTreeImpl
* Clang's dominator tree is now called clang::CFGDomTree
* Clang's brand new post dominator tree is called clang::CFGPostDomTree
* Add a lot of asserts to the dump() function
* Create a new checker to test the functionality

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

llvm-svn: 365028
2019-07-03 11:39:12 +00:00
Kristof Umann 85211c0835 [Dominators] PR42041: Skip nullpointer successors
https://bugs.llvm.org/show_bug.cgi?id=42041

In Clang's CFG, we use nullpointers to represent unreachable nodes, for
example, in the included testfile, block B0 is unreachable from block
B1, resulting in a nullpointer dereference somewhere in
llvm::DominatorTreeBase<clang::CFGBlock, false>::recalculate.

This patch fixes this issue by specializing
llvm::DomTreeBuilder::SemiNCAInfo::ChildrenGetter::Get for
clang::CFG to not contain nullpointer successors.

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

llvm-svn: 365026
2019-07-03 11:14:42 +00:00
Ivan Donchevskii 080014ee6d [clang-tidy] Fix the YAML created for checks like modernize-pass-by-value
Currently this check generates the replacement with the newline in the end.
The proper way to export it to YAML is to have two \n\n instead of one.
Without this fix clients should reinterpret the replacement as
"#include <utility> " instead of "#include <utility>\n"

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

llvm-svn: 365017
2019-07-03 10:21:50 +00:00
Fangrui Song 7264a474b7 Change std::{lower,upper}_bound to llvm::{lower,upper}_bound or llvm::partition_point. NFC
llvm-svn: 365006
2019-07-03 08:13:17 +00:00
Kadir Cetinkaya 1f6d9845d8 [clang][HeaderSearch] Shorten paths for includes in mainfile's directory
Summary:
Currently HeaderSearch only looks at SearchDir's passed into it, but in
addition to those paths headers can be relative to including file's directory.

This patch makes sure that is taken into account.

Reviewers: gribozavr

Subscribers: jkorous, arphaman, cfe-commits

Tags: #clang

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

llvm-svn: 365005
2019-07-03 07:47:19 +00:00
Erik Pilkington eee944e7f9 [C++2a] Add __builtin_bit_cast, used to implement std::bit_cast
This commit adds a new builtin, __builtin_bit_cast(T, v), which performs a
bit_cast from a value v to a type T. This expression can be evaluated at
compile time under specific circumstances.

The compile time evaluation currently doesn't support bit-fields, but I'm
planning on fixing this in a follow up (some of the logic for figuring this out
is in CodeGen). I'm also planning follow-ups for supporting some more esoteric
types that the constexpr evaluator supports, as well as extending
__builtin_memcpy constexpr evaluation to use the same infrastructure.

rdar://44987528

Differential revision: https://reviews.llvm.org/D62825

llvm-svn: 364954
2019-07-02 18:28:13 +00:00
Sam McCall 04ee232ff2 clang-format: Add new style option AlignConsecutiveMacros
This option behaves similarly to AlignConsecutiveDeclarations and
AlignConsecutiveAssignments, aligning the assignment of C/C++
preprocessor macros on consecutive lines.

I've worked in many projects (embedded, mostly) where header files full
of large, well-aligned "#define" blocks are a common pattern. We
normally avoid using clang-format on these files, since it ruins any
existing alignment in said blocks. This style option will align "simple"
PP macros (no parameters) and PP macros with parameter lists on
consecutive lines.

Related Bugzilla entry (thanks mcuddie):
https://llvm.org/bugs/show_bug.cgi?id=20637

Patch by Nick Renieris (VelocityRa)!

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

llvm-svn: 364938
2019-07-02 15:53:14 +00:00
Yitzhak Mandelbaum 727bdcb237 [LibTooling] Extend `RewriteRule` with support for adding includes.
Summary:
This revision allows users to specify the insertion of an included directive (at
the top of the file being rewritten) as part of a rewrite rule.  These
directives are bundled with `RewriteRule` cases, so that different cases can
potentially result in different include actions.

Reviewers: ilya-biryukov, gribozavr

Subscribers: cfe-commits

Tags: #clang

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

llvm-svn: 364917
2019-07-02 13:11:04 +00:00
Nico Weber 8cce399b9d clang-cl: Make /d1reportAllClassLayout actually work and improve test
See review thread for r301567.

llvm-svn: 364901
2019-07-02 10:22:11 +00:00
Benjamin Kramer 8758dce45f [ASTImporter] Make headers self-contained
llvm-svn: 364891
2019-07-02 08:01:41 +00:00
Artem Dergachev f301096f51 [analyzer] NFC: CallDescription: Implement describing C library functions.
When matching C standard library functions in the checker, it's easy to forget
that they are often implemented as macros that are expanded to builtins.

Such builtins would have a different name, so matching the callee identifier
would fail, or may sometimes have more arguments than expected, so matching
the exact number of arguments would fail, but this is fine as long as we have
all the arguments that we need in their respective places.

This patch adds a set of flags to the CallDescription class so that to handle
various special matching rules, and adds the first flag into this set,
which enables a more fuzzy matching for functions that
may be implemented as compiler builtins.

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

llvm-svn: 364867
2019-07-01 23:02:07 +00:00
Artem Dergachev ec8e95640f [analyzer] NFC: Add a convenient CallDescriptionMap class.
It encapsulates the procedure of figuring out whether a call event
corresponds to a function that's modeled by a checker.

Checker developers no longer need to worry about performance of
lookups into their own custom maps.

Add unittests - which finally test CallDescription itself as well.

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

llvm-svn: 364866
2019-07-01 23:02:03 +00:00
Alexey Bataev b600ae37a5 [OPENMP]Fix handling of lambda captures in target regions.
Previously, lambda captures were processed in the function called during
capturing the variables. It leads to the recursive functions calls and
may result in the compiler crash.

llvm-svn: 364820
2019-07-01 17:46:52 +00:00
Gabor Marton 2afbfb6b22 [ASTImporter] Mark erroneous nodes in shared st
Summary:
Now we store the errors for the Decls in the "to" context too. For
that, however, we have to put these errors in a shared state (among all
the ASTImporter objects which handle the same "to" context but different
"from" contexts).

After a series of imports from different "from" TUs we have a "to" context
which may have erroneous nodes in it. (Remember, the AST is immutable so
there is no way to delete a node once we had created it and we realized
the error later.) All these erroneous nodes are marked in
ASTImporterSharedState::ImportErrors.  Clients of the ASTImporter may
use this as an input. E.g. the static analyzer engine may not try to
analyze a function if that is marked as erroneous (it can be queried via
ASTImporterSharedState::getImportDeclErrorIfAny()).

Reviewers: a_sidorin, a.sidorin, shafik

Subscribers: rnkovacs, dkrupp, Szelethus, gamesh411, cfe-commits

Tags: #clang

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

llvm-svn: 364785
2019-07-01 15:37:07 +00:00
Gabor Marton 1ad4b99d94 [ASTImporter] Mark erroneous nodes in from ctx
Summary:
During import of a specific Decl D, it may happen that some AST nodes
had already been created before we recognize an error. In this case we
signal back the error to the caller, but the "to" context remains
polluted with those nodes which had been created. Ideally, those nodes
should not had been created, but that time we did not know about the
error, the error happened later.  Since the AST is immutable (most of
the cases we can't remove existing nodes) we choose to mark these nodes
as erroneous.
Here are the steps of the algorithm:
1) We keep track of the nodes which we visit during the import of D: See
ImportPathTy.
2) If a Decl is already imported and it is already on the import path
(we have a cycle) then we copy/store the relevant part of the import
path. We store these cycles for each Decl.
3) When we recognize an error during the import of D then we set up this
error to all Decls in the stored cycles for D and we clear the stored
cycles.

Reviewers: a_sidorin, a.sidorin, shafik

Subscribers: rnkovacs, dkrupp, Szelethus, gamesh411, cfe-commits

Tags: #clang

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

llvm-svn: 364771
2019-07-01 14:19:53 +00:00
Fangrui Song 765eba38c8 [Driver] Fix style issues of --print-supported-cpus after D63105
Reviewed By: ziangwan

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

llvm-svn: 364704
2019-06-29 01:24:36 +00:00
Djordje Todorovic 0f65168566 [clang] Add DISuprogram and DIE for a func decl
Attach a unique DISubprogram to a function declaration that will be
used for call site debug info.

([7/13] Introduce the debug entry values.)

Co-authored-by: Ananth Sowda <asowda@cisco.com>
Co-authored-by: Nikola Prica <nikola.prica@rt-rk.com>
Co-authored-by: Ivan Baev <ibaev@cisco.com>

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

llvm-svn: 364502
2019-06-27 06:44:44 +00:00
Aaron Puchert b207baeb28 [Clang] Remove unused -split-dwarf and obsolete -enable-split-dwarf
Summary:
The changes in D59673 made the choice redundant, since we can achieve
single-file split DWARF just by not setting an output file name.
Like llc we can also derive whether to enable Split DWARF from whether
-split-dwarf-file is set, so we don't need the flag at all anymore.

The test CodeGen/split-debug-filename.c distinguished between having set
or not set -enable-split-dwarf with -split-dwarf-file, but we can
probably just always emit the metadata into the IR.

The flag -split-dwarf wasn't used at all anymore.

Reviewers: dblaikie, echristo

Reviewed By: dblaikie

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

llvm-svn: 364479
2019-06-26 21:36:35 +00:00
Alex Lorenz d5f7196feb [clang-scan-deps] Introduce the DependencyScanning library with the
thread worker code and better error handling

This commit extracts out the code that will powers the fast scanning
worker into a new file in a new DependencyScanning library. The error
and output handling is improved so that the clients can gather
errors/results from the worker directly.

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

llvm-svn: 364474
2019-06-26 21:11:51 +00:00
JF Bastien 0e82895826 BitStream reader: propagate errors
The bitstream reader handles errors poorly. This has two effects:

 * Bugs in file handling (especially modules) manifest as an "unexpected end of
   file" crash
 * Users of clang as a library end up aborting because the code unconditionally
   calls `report_fatal_error`

The bitstream reader should be more resilient and return Expected / Error as
soon as an error is encountered, not way late like it does now. This patch
starts doing so and adopting the error handling where I think it makes sense.
There's plenty more to do: this patch propagates errors to be minimally useful,
and follow-ups will propagate them further and improve diagnostics.

https://bugs.llvm.org/show_bug.cgi?id=42311
<rdar://problem/33159405>

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

llvm-svn: 364464
2019-06-26 19:50:12 +00:00
Sven van Haastregt 1006a068c6 [OpenCL] Improve diagnostic for placement new
Without an explicit declaration for placement new, clang would reject
uses of placement new with "'default new' is not supported in OpenCL
C++".  This may mislead users into thinking that placement new is not
supported, see e.g. PR42060.

Clarify that placement new requires an explicit declaration.

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

llvm-svn: 364423
2019-06-26 13:31:24 +00:00
Djordje Todorovic 639d36b34e [CC1Option] Add the option to enable the debug entry values
The option enables debug info about parameter's entry values.

The example of using the option:

clang -g -O2 -Xclang -femit-debug-entry-values test.c

In addition, when the option is set add the flag all_call_sites
in a subprogram in order to support GNU extension as well.

([3/13] Introduce the debug entry values.)

Co-authored-by: Ananth Sowda <asowda@cisco.com>
Co-authored-by: Nikola Prica <nikola.prica@rt-rk.com>
Co-authored-by: Ivan Baev <ibaev@cisco.com>

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

llvm-svn: 364399
2019-06-26 09:38:09 +00:00
Kadir Cetinkaya c3a7302397 [clang][Tooling] Infer target and mode from argv[0] when using JSONCompilationDatabase
Summary:
Wraps JSON compilation database with a target and mode adding database
wrapper. So that driver can correctly figure out which toolchain to use.

Note that clients that wants to make use of this target discovery mechanism
needs to link in TargetsInfos and initialize them at startup.

Reviewers: ilya-biryukov

Subscribers: mgorny, cfe-commits

Tags: #clang

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

llvm-svn: 364386
2019-06-26 07:39:03 +00:00
Yaxun Liu c3dfe9082b [HIP] Support attribute hip_pinned_shadow
This patch introduces support of hip_pinned_shadow variable for HIP.

A hip_pinned_shadow variable is a global variable with attribute hip_pinned_shadow.
It has external linkage on device side and has no initializer. It has internal
linkage on host side and has initializer or static constructor. It can be accessed
in both device code and host code.

This allows HIP runtime to implement support of HIP texture reference.

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

llvm-svn: 364381
2019-06-26 03:47:37 +00:00
Ziang Wan de94ac9357 print-supported-cpus quality of life patch.
Claim all input files so that clang does not give a warning. Add two
short-cut aliases: -mcpu=? and -mtune=?.

llvm-svn: 364362
2019-06-25 23:57:14 +00:00
Haojian Wu 7276a446ce [clangd] Narrow rename to local symbols.
Summary:
Previously, we performed rename for all kinds of symbols (local, global).

This patch narrows the scope by only renaming symbols not being used
outside of the main file (with index asisitance). Renaming global
symbols is not supported at the moment (return an error).

Reviewers: sammccall

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

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

llvm-svn: 364283
2019-06-25 08:43:17 +00:00
Gabor Marton 303c9861e9 [ASTImporter] Store import errors for Decls
Summary:
We add a new member which is a mapping from the already-imported
declarations in the "from" context to the error status of the import of
that declaration.  This map contains only the declarations that were not
correctly imported. The same declaration may or may not be included in
ImportedDecls. This map is updated continuously during imports and never
cleared (like ImportedDecls).  In Import(Decl*) we use this mapping, so
if there was a previous failed import we return with the existing error.

We add/remove from the Lookuptable in consistency with ImportedFromDecls.
When we map a decl in the 'to' context to something in the 'from'
context then and only then we add it to the lookup table. When we
remove a mapping then and only then we remove it from the lookup table.

This patch is the first in a series of patches whose aim is to further
strengthen the error handling in ASTImporter.

Reviewers: a_sidorin, a.sidorin, shafik

Subscribers: rnkovacs, dkrupp, Szelethus, gamesh411, cfe-commits

Tags: #clang

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

llvm-svn: 364279
2019-06-25 08:00:51 +00:00
Csaba Dabis c55170c031 [analyzer] JsonSupport: Escape escapes
Summary: -

Reviewers: NoQ

Reviewed By: NoQ

Subscribers: xazax.hun, baloghadamsoftware, szepet, a.sidorin,
             mikhail.ramalho, Szelethus, donat.nagy, dkrupp, cfe-commits

Tags: #clang

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

llvm-svn: 364270
2019-06-25 03:08:32 +00:00
Artem Dergachev c48be7fc1c [analyzer] Add more timers for performance profiling.
The -analyzer-stats flag now allows you to find out how much time was spent
on AST-based analysis and on path-sensitive analysis and, separately,
on bug visitors, as they're occasionally a performance problem on their own.

The total timer wasn't useful because there's anyway a total time printed out.
Remove it.

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

llvm-svn: 364266
2019-06-25 02:16:47 +00:00
Matt Arsenault 5495f78165 AMDGPU: Fix missing declaration for mbcnt builtins
llvm-svn: 364251
2019-06-24 23:34:06 +00:00
Ilya Biryukov 5e69f27ef7 [Syntax] Do not glue multiple empty PP expansions to a single mapping
Summary:
This change makes sure we have a single mapping for each macro expansion,
even if the result of expansion was empty.

To achieve that, we take information from PPCallbacks::MacroExpands into
account. Previously we relied only on source locations of expanded tokens.

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: cfe-commits

Tags: #clang

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

llvm-svn: 364236
2019-06-24 21:39:51 +00:00
Aaron Ballman a612e34c14 Augment location information when dumping the AST to JSON.
Rather than create JSON objects for source locations and ranges, we instead stream them out directly. This allows us to elide duplicate information (without JSON field reordering causing an issue) like file names and line numbers, similar to the text dump. This also adds token length information when dumping the source location.

llvm-svn: 364226
2019-06-24 20:07:11 +00:00
Saleem Abdulrasool 6281ccea02 Revert "builtins: relax __iso_volatile_{load,store}32"
This reverts commit SVN r364137.  This seems to be cause problems with
casting in C.

llvm-svn: 364147
2019-06-23 02:53:03 +00:00
Saleem Abdulrasool ebae85bc4a builtins: relax __iso_volatile_{load,store}32
This is reduced from MSVC's MSVCPRT 14.21.27702 atomic header.  Because
Windows is a LLP64 environment, `long`, `long int`, and `int` are all
synonymous.  Change the signature for `__iso_volatile_load32` and
`__iso_volatile_store32` to accept a `long int` instead.  This allows
an implicit cast of `int` to `long int` while also permitting `long`
to be accepted.

llvm-svn: 364137
2019-06-22 18:55:51 +00:00
Richard Smith 979ae80af7 PR42301: Abort cleanly if we encounter a huge source file rather than
crashing.

Ideally we wouldn't care about the size of a file so long as it fits in
memory, but in practice we have lots of hardocded assumptions that
unsigned can be used to index files, string literals, and so on.

llvm-svn: 364103
2019-06-21 20:46:22 +00:00
Alex Lorenz 459f733ef0 [clang-scan-deps] print the dependencies to stdout
and remove the need to use -MD options in the CDB

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

llvm-svn: 364088
2019-06-21 18:24:55 +00:00
Aaron Ballman 104b12980c Print more type node information when dumping the AST to JSON.
llvm-svn: 364067
2019-06-21 16:06:09 +00:00
Aaron Ballman c07cfce23a Print information about various type nodes when dumping the AST to JSON.
llvm-svn: 364043
2019-06-21 13:22:35 +00:00
Anastasia Stulova 3562edb9c4 [Sema] Fix diagnostic for addr spaces in reference binding
Extend reference binding behavior to account for address spaces.

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

llvm-svn: 364032
2019-06-21 11:36:15 +00:00
Anastasia Stulova 1da9e4c910 [Sema] Improved diagnostic for qualifiers in reference binding
Improved wording and also simplified by using printing
method from qualifiers.

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

llvm-svn: 364023
2019-06-21 10:50:02 +00:00
Sam Elliott 3e53e0e4d4 [RISC-V] Add -msave-restore and -mno-save-restore to clang driver
Summary:
The GCC RISC-V toolchain accepts `-msave-restore` and `-mno-save-restore`
to control whether libcalls are used for saving and restoring the stack within
prologues and epilogues.

Clang currently errors if someone passes -msave-restore or -mno-save-restore.
This means that people need to change build configurations to use clang. This
patch adds these flags, so that clang invocations can now match gcc.

As the RISC-V backend does not currently have a `save-restore` target feature,
we emit a warning if someone requests `-msave-restore`. LLVM does not error if
we pass the (unimplemented) target features `+save-restore` or `-save-restore`.

Reviewers: asb, luismarques

Reviewed By: asb

Subscribers: rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, kito-cheng, shiva0217, jrtc27, zzheng, edward-jones, rogfer01, MartinMosbeck, brucehoult, the_o, rkruppe, PkmX, jocewei, cfe-commits

Tags: #clang

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

llvm-svn: 364018
2019-06-21 10:03:31 +00:00
Gauthier Harnisch dea9d57d95 [clang] Small improvments after Adding APValue to ConstantExpr
Summary:
this patch has multiple small improvements related to the APValue in ConstantExpr.

changes:
 - APValue in ConstantExpr are now cleaned up using ASTContext::addDestruction instead of there own system.
 - ConstantExprBits Stores the ValueKind of the result beaing stored.
 - VerifyIntegerConstantExpression now stores the evaluated value in ConstantExpr.
 - the Constant Evaluator uses the stored value of ConstantExpr when available.

Reviewers: rsmith

Reviewed By: rsmith

Subscribers: cfe-commits

Tags: #clang

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

llvm-svn: 364011
2019-06-21 08:26:21 +00:00
Craig Topper 442702a9f9 [X86] Change LL to O in the definitions for the vp2intersect builtins.
This is needed to support OpenCL where long long is 128 bits.

This was done for the other builtins already, but I think
vp2intersect was in phabricator at the time.

llvm-svn: 363994
2019-06-20 22:19:16 +00:00
Aaron Ballman 75e23f8523 Print information about various ObjC expression nodes when dumping the AST to JSON.
llvm-svn: 363988
2019-06-20 21:45:31 +00:00
Matt Arsenault bcdbc9a115 AMDGPU: Add DS GWS sema builtins
llvm-svn: 363986
2019-06-20 21:33:57 +00:00
Richard Smith 78b239ea67 P0840R2: support for [[no_unique_address]] attribute
Summary:
Add support for the C++2a [[no_unique_address]] attribute for targets using the Itanium C++ ABI.

This depends on D63371.

Reviewers: rjmccall, aaron.ballman

Subscribers: dschuff, aheejin, cfe-commits

Tags: #clang

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

llvm-svn: 363976
2019-06-20 20:44:45 +00:00
Aaron Ballman 7f1b223a5a Print additional information about @encode expressions when dumping the AST to JSON.
llvm-svn: 363966
2019-06-20 19:11:35 +00:00
Aaron Ballman 7dbb3a8fac Print additional information on dependent scopes when dumping the AST to JSON.
llvm-svn: 363965
2019-06-20 18:55:53 +00:00
Puyan Lotfi 68f29dac4b [clang-ifs] Clang Interface Stubs, first version (second landing attempt).
This change reverts r363649; effectively re-landing r363626. At this point
clang::Index::CodegenNameGeneratorImpl has been refactored into
clang::AST::ASTNameGenerator. This makes it so that the previous circular link
dependency no longer exists, fixing the previous share lib
(-DBUILD_SHARED_LIBS=ON) build issue which was the reason for r363649.

Clang interface stubs (previously referred to as clang-ifsos) is a new frontend
action in clang that allows the generation of stub files that contain mangled
name info that can be used to produce a stub library. These stub libraries can
be useful for breaking up build dependencies and controlling access to a
library's internal symbols. Generation of these stubs can be invoked by:

clang -fvisibility=<visibility> -emit-interface-stubs \
                                -interface-stub-version=<interface format>

Notice that -fvisibility (along with use of visibility attributes) can be used
to control what symbols get generated. Currently the interface format is
experimental but there are a wide range of possibilities here.

Currently clang-ifs produces .ifs files that can be thought of as analogous to
object (.o) files, but just for the mangled symbol info. In a subsequent patch
I intend to add support for merging the .ifs files into one .ifs/.ifso file
that can be the input to something like llvm-elfabi to produce something like a
.so file or .dll (but without any of the code, just symbols).

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

llvm-svn: 363948
2019-06-20 16:59:48 +00:00
Anastasia Stulova c25ea86d43 [Sema] Diagnose addr space mismatch while constructing objects
If we construct an object in some arbitrary non-default addr space
it should fail unless either:
- There is an implicit conversion from the address space to default
/generic address space.
- There is a matching ctor qualified with an address space that is
either exactly matching or convertible to the address space of an
object.

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

llvm-svn: 363944
2019-06-20 16:23:28 +00:00
Aaron Ballman 1fffe8d6ee Dump more information about expressions involving temporaries when dumping the AST to JSON.
llvm-svn: 363943
2019-06-20 16:22:35 +00:00
Aaron Ballman 0ac17bef25 Removing a helper function that was trivial to inline into its only use; NFC.
llvm-svn: 363935
2019-06-20 15:10:45 +00:00
Aaron Ballman d91b1edf7b Dump more information about construct expressions (resolved and unresolved) when dumping the AST to JSON.
llvm-svn: 363926
2019-06-20 13:19:41 +00:00
Puyan Lotfi d5d15b4c1f [clang][AST] Refactoring ASTNameGenerator to use pimpl pattern (NFC).
The original pimpl pattern used between CodegenNameGenerator and
CodegenNameGeneratorImpl did a good job of hiding DataLayout making it so that
users of CodegenNameGenerator did not need to link with llvm core.  This is an
NFC change to neatly wrap ASTNameGenerator in a pimpl.

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

llvm-svn: 363908
2019-06-20 06:01:06 +00:00
Artem Dergachev 44820630df [analyzer] NFC: Change evalCall() to provide a CallEvent.
This changes the checker callback signature to use the modern, easy to
use interface. Additionally, this unblocks future work on allowing
checkers to implement evalCall() for calls that don't correspond to any
call-expression or require additional information that's only available
as part of the CallEvent, such as C++ constructors and destructors.

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

llvm-svn: 363893
2019-06-19 23:33:42 +00:00
Puyan Lotfi 3ff8c3b73f [clang][AST] ASTNameGenerator: A refactoring of CodegenNameGeneratorImpl (NFC).
This is a NFC refactor move of CodegenNameGeneratorImpl from clang::Index to
clang:AST (and rename to ASTNameGenerator). The purpose is to make the
highlevel mangling code more reusable inside of clang (say in places like clang
FrontendAction). This does not affect anything in CodegenNameGenerator, except
that CodegenNameGenerator will now use ASTNameGenerator (in AST).

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

llvm-svn: 363878
2019-06-19 20:51:35 +00:00
Aaron Ballman 07e6da9330 Print whether a generic selection expression is result dependent when dumping the AST to JSON.
llvm-svn: 363873
2019-06-19 20:16:55 +00:00
Matt Arsenault f46f41411b Reapply "r363684: AMDGPU: Add GWS instruction builtins"
llvm-svn: 363871
2019-06-19 19:55:49 +00:00
Aaron Ballman 709a769cdd Print out the union field being initialized by an InitListExpr when dumping the AST to JSON.
llvm-svn: 363869
2019-06-19 19:40:07 +00:00
Aaron Ballman 91f7265759 Dump the value calculated by a constant expression when dumping the AST to JSON.
llvm-svn: 363866
2019-06-19 19:12:22 +00:00
Gauthier Harnisch e1f4ba85e5 [clang] Adapt ASTMatcher to explicit(bool) specifier
Summary:
Changes:
 - add an ast matcher for deductiong guide.
 - allow isExplicit matcher for deductiong guide.
 - add hasExplicitSpecifier matcher which give access to the expression of the explicit specifier if present.

Reviewers: klimek, rsmith, aaron.ballman

Reviewed By: aaron.ballman

Subscribers: aaron.ballman, cfe-commits

Tags: #clang

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

llvm-svn: 363855
2019-06-19 18:27:56 +00:00
Alex Lorenz 8d9eb7acd5 Unify DependencyFileGenerator class and DependencyCollector interface (NFCI)
Make DependencyFileGenerator a DependencyCollector as it was intended when
DependencyCollector was introduced. The missing PPCallbacks overrides are added to
the DependencyCollector as well.

This change will allow clang-scan-deps to access the produced dependencies without
writing them out to .d files to disk, so that it will be able collate them and
report them to the user.

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

llvm-svn: 363840
2019-06-19 17:07:36 +00:00
Simon Pilgrim 6828bc5614 Revert rL363684 : AMDGPU: Add GWS instruction builtins
........
Depends on rL363678 which was reverted at rL363797

llvm-svn: 363824
2019-06-19 15:35:45 +00:00
Aaron Ballman 7556615a9d Change the way we output templates for JSON AST dumping and dump information about template arguments.
Previously, we attempted to write out template parameters and specializations to their own array, but due to the architecture of the ASTNodeTraverser, this meant that other nodes were not being written out. This now follows the same behavior as the regular AST dumper and puts all the (correct) information into the "inner" array. When we correct the AST node traverser itself, we can revisit splitting this information into separate arrays again.

llvm-svn: 363819
2019-06-19 15:24:06 +00:00
Vivek Pandya 3a0100ac30 Allow copy/move assignment operator to be coroutine as per N4775
This change fixes https://bugs.llvm.org/show_bug.cgi?id=40997.

Reviewers: GorNishanov, rsmith
Reviewed by: GorNishanov
Subscribers: cfe-commits, lewissbaker, modocache, llvm-commits

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

llvm-svn: 363804
2019-06-19 14:12:19 +00:00
Sven van Haastregt af1c230e70 [OpenCL] Split type and macro definitions into opencl-c-base.h
Using the -fdeclare-opencl-builtins option will require a way to
predefine types and macros such as `int4`, `CLK_GLOBAL_MEM_FENCE`,
etc.  Move these out of opencl-c.h into opencl-c-base.h such that the
latter can be shared by -fdeclare-opencl-builtins and
-finclude-default-header.

This changes the behaviour of -finclude-default-header when
-fdeclare-opencl-builtins is specified: instead of including the full
header, it will include the header with only the base definitions.

Differential revision: https://reviews.llvm.org/D63256

llvm-svn: 363794
2019-06-19 12:48:22 +00:00
Aaron Puchert df195d8aed Suggestions to fix -Wmissing-{prototypes,variable-declarations}
Summary:
I've found that most often the proper way to fix this warning is to add
`static`, because if the code otherwise compiles and links, the function
or variable is apparently not needed outside of the TU.

We can't provide a fix-it hint for variable declarations, because
multiple VarDecls can share the same type, and if we put static in front
of that, we affect all declared variables, some of which might have
previous declarations.

We also provide no fix-it hint for the rare case of an `extern` function
definition, because that would require removing `extern` and I have no
idea how to get the source location of the storage class specifier from
a FunctionDecl. I believe this information is only available earlier in
the AST construction from DeclSpec::getStorageClassSpecLoc(), but we
don't have that here.

Reviewed By: aaron.ballman

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

llvm-svn: 363749
2019-06-18 22:57:08 +00:00
Aaron Puchert f9c6e565de Show note for -Wmissing-prototypes for functions with parameters
Summary:
There was a search for non-prototype declarations for the function, but
we only showed the results for zero-parameter functions. Now we show the
note for functions with parameters as well, but we omit the fix-it hint
suggesting to add `void`.

Reviewed By: aaron.ballman

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

llvm-svn: 363748
2019-06-18 22:52:39 +00:00
Ilya Biryukov 5aed309a4f [Syntax] Add a helper to find expansion by its first spelled token
Summary: Used in clangd for a code tweak that expands a macro.

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: kadircet, cfe-commits

Tags: #clang

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

llvm-svn: 363698
2019-06-18 16:27:27 +00:00
Matt Arsenault 2acc717627 AMDGPU: Add GWS instruction builtins
llvm-svn: 363684
2019-06-18 14:10:01 +00:00
Fangrui Song 2d94dd812f Revert D60974 "[clang-ifs] Clang Interface Stubs, first version."
This reverts commit rC363626.

clangIndex depends on clangFrontend. r363626 adds a dependency from
clangFrontend to clangIndex, which creates a circular dependency.

This is disallowed by -DBUILD_SHARED_LIBS=on builds:

    CMake Error: The inter-target dependency graph contains the following strongly connected component (cycle):
      "clangFrontend" of type SHARED_LIBRARY
        depends on "clangIndex" (weak)
      "clangIndex" of type SHARED_LIBRARY
        depends on "clangFrontend" (weak)
    At least one of these targets is not a STATIC_LIBRARY.  Cyclic dependencies are allowed only among static libraries.

Note, the dependency on clangIndex cannot be removed because
libclangFrontend.so is linked with -Wl,-z,defs: a shared object must
have its full direct dependencies specified on the linker command line.

In -DBUILD_SHARED_LIBS=off builds, this appears to work when linking
`bin/clang-9`. However, it can cause trouble to downstream clang library
users. The llvm build system links libraries this way:

    clang main_program_object_file ... lib/libclangIndex.a ...  lib/libclangFrontend.a -o exe

libclangIndex.a etc are not wrapped in --start-group.

If the downstream application depends on libclangFrontend.a but not any
other clang libraries that depend on libclangIndex.a, this can cause undefined
reference errors when the linker is ld.bfd or gold.

The proper fix is to not include clangIndex files in clangFrontend.

llvm-svn: 363649
2019-06-18 05:52:39 +00:00
Puyan Lotfi 8df7f1a218 [clang-ifs] Clang Interface Stubs, first version.
Clang interface stubs (previously referred to as clang-ifsos) is a new frontend
action in clang that allows the generation of stub files that contain mangled
name info that can be used to produce a stub library. These stub libraries can
be useful for breaking up build dependencies and controlling access to a
library's internal symbols. Generation of these stubs can be invoked by:

clang -fvisibility=<visibility> -emit-interface-stubs \
                                -interface-stub-version=<interface format>

Notice that -fvisibility (along with use of visibility attributes) can be used
to control what symbols get generated. Currently the interface format is
experimental but there are a wide range of possibilities here.

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

llvm-svn: 363626
2019-06-17 22:46:54 +00:00
Michael Liao b8e8b1769f [clang][AST] Remove unnecessary 'const'.
llvm-svn: 363585
2019-06-17 17:47:03 +00:00
Francis Visoiu Mistrih 34667519dc [Remarks] Extend -fsave-optimization-record to specify the format
Use -fsave-optimization-record=<format> to specify a different format
than the default, which is YAML.

For now, only YAML is supported.

llvm-svn: 363573
2019-06-17 16:06:00 +00:00
Nico Weber 37b7533682 Promote -fdebug-compilation-dir from a cc1 flag to clang and clang-cl driver flags
The flag is useful when wanting to create .o files that are independent
from the absolute path to the build directory. -fdebug-prefix-map= can
be used to the same effect, but it requires putting the absolute path
to the build directory on the build command line, so it still requires
the build command line to be dependent on the absolute path of the build
directory. With this flag, "-fdebug-compilation-dir ." makes it so that
both debug info and the compile command itself are independent of the
absolute path of the build directory, which is good for build
determinism (in the sense that the build is independent of which
directory it happens in) and for caching compile results.
(The tradeoff is that the debugger needs explicit configuration to know
the build directory. See also http://dwarfstd.org/ShowIssue.php?issue=171130.2)

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

llvm-svn: 363548
2019-06-17 12:10:40 +00:00
Sven van Haastregt 9d81915fca Recommit [OpenCL] Move OpenCLBuiltins.td and remove unused include
Reland r363242 after fixing an issue with the tablegen dependence.

Patch by Pierre Gondois and Sven van Haastregt.

Differential revision: https://reviews.llvm.org/D62849

llvm-svn: 363541
2019-06-17 10:06:34 +00:00
Aaron Puchert e1dc495e63 [Clang] Harmonize Split DWARF options with llc
Summary:
With Split DWARF the resulting object file (then called skeleton CU)
contains the file name of another ("DWO") file with the debug info.
This can be a problem for remote compilation, as it will contain the
name of the file on the compilation server, not on the client.

To use Split DWARF with remote compilation, one needs to either

* make sure only relative paths are used, and mirror the build directory
  structure of the client on the server,
* inject the desired file name on the client directly.

Since llc already supports the latter solution, we're just copying that
over. We allow setting the actual output filename separately from the
value of the DW_AT_[GNU_]dwo_name attribute in the skeleton CU.

Fixes PR40276.

Reviewers: dblaikie, echristo, tejohnson

Reviewed By: dblaikie

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

llvm-svn: 363496
2019-06-15 15:38:51 +00:00
Aaron Puchert 922759a63d [Clang] Rename -split-dwarf-file to -split-dwarf-output
Summary:
This is the first in a series of changes trying to align clang -cc1
flags for Split DWARF with those of llc. The unfortunate side effect of
having -split-dwarf-output for single file Split DWARF will disappear
again in a subsequent change.

The change is the result of a discussion in D59673.

Reviewers: dblaikie, echristo

Reviewed By: dblaikie

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

llvm-svn: 363494
2019-06-15 14:07:43 +00:00
Gauthier Harnisch 83c7b61052 [clang] Add storage for APValue in ConstantExpr
Summary:
When using ConstantExpr we often need the result of the expression to be kept in the AST. Currently this is done on a by the node that needs the result and has been done multiple times for enumerator, for constexpr variables... . This patch adds to ConstantExpr the ability to store the result of evaluating the expression. no functional changes expected.

Changes:
 - Add trailling object to ConstantExpr that can hold an APValue or an uint64_t. the uint64_t is here because most ConstantExpr yield integral values so there is an optimized layout for integral values.
 - Add basic* serialization support for the trailing result.
 - Move conversion functions from an enum to a fltSemantics from clang::FloatingLiteral to llvm::APFloatBase. this change is to make it usable for serializing APValues.
 - Add basic* Import support for the trailing result.
 - ConstantExpr created in CheckConvertedConstantExpression now stores the result in the ConstantExpr Node.
 - Adapt AST dump to print the result when present.

basic* : None, Indeterminate, Int, Float, FixedPoint, ComplexInt, ComplexFloat,
the result is not yet used anywhere but for -ast-dump.

Reviewers: rsmith, martong, shafik

Reviewed By: rsmith

Subscribers: rnkovacs, hiraditya, dexonsmith, cfe-commits, llvm-commits

Tags: #clang, #llvm

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

llvm-svn: 363493
2019-06-15 10:24:47 +00:00
Gauthier Harnisch 0bb4d46b2b [clang] perform semantic checking in constant context
Summary:
Since the addition of __builtin_is_constant_evaluated the result of an expression can change based on whether it is evaluated in constant context. a lot of semantic checking performs evaluations with out specifying context. which can lead to wrong diagnostics.
for example:
```
constexpr int i0 = (long long)__builtin_is_constant_evaluated() * (1ll << 33); //#1
constexpr int i1 = (long long)!__builtin_is_constant_evaluated() * (1ll << 33); //#2
```
before the patch, #2 was diagnosed incorrectly and #1 wasn't diagnosed.
after the patch #1 is diagnosed as it should and #2 isn't.

Changes:
 - add a flag to Sema to passe in constant context mode.
 - in SemaChecking.cpp calls to Expr::Evaluate* are now done in constant context when they should.
 - in SemaChecking.cpp diagnostics for UB are not checked for in constant context because an error will be emitted by the constant evaluator.
 - in SemaChecking.cpp diagnostics for construct that cannot appear in constant context are not checked for in constant context.
 - in SemaChecking.cpp diagnostics on constant expression are always emitted because constant expression are always evaluated.
 - semantic checking for initialization of constexpr variables is now done in constant context.
 - adapt test that were depending on warning changes.
 - add test.

Reviewers: rsmith

Reviewed By: rsmith

Subscribers: cfe-commits

Tags: #clang

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

llvm-svn: 363488
2019-06-15 08:32:56 +00:00
Ziang Wan af857b93df Add --print-supported-cpus flag for clang.
This patch allows clang users to print out a list of supported CPU models using
clang [--target=<target triple>] --print-supported-cpus

Then, users can select the CPU model to compile to using
clang --target=<triple> -mcpu=<model> a.c

It is a handy feature to help cross compilation.

llvm-svn: 363464
2019-06-14 21:42:21 +00:00
Francis Visoiu Mistrih 5501dda247 [Remarks][NFC] Improve testing and documentation of -foptimization-record-passes
This adds:

* documentation to the user manual
* nicer error message
* test for the error case
* test for the gold plugin

llvm-svn: 363463
2019-06-14 21:38:57 +00:00
Reid Kleckner 49b965079b Use unsigned for bitfields to avoid sign extension
llvm-svn: 363450
2019-06-14 20:19:29 +00:00
Richard Smith da70fc0c5f PR42071: Reject weird names for non-type template parameters.
Also reject default arguments appearing in invalid locations.

llvm-svn: 363447
2019-06-14 20:01:54 +00:00
Richard Smith 14059d2a13 Remove unused SK_LValueToRValue initialization step.
In addition to being unused and duplicating code, this was also wrong
(it didn't properly mark the operand as being potentially not odr-used).

This reinstates r363340, reverted in r363352.

llvm-svn: 363430
2019-06-14 17:46:39 +00:00
Sven van Haastregt e5bd808c3e Revert "[OpenCL] Move OpenCLBuiltins.td and remove unused include"
This reverts commit r363242 as it broke some builds with

  make[2]: *** No rule to make target 'ClangOpenCLBuiltinsImpl', needed by
  'tools/clang/lib/Sema/CMakeFiles/obj.clangSema.dir/SemaLookup.cpp.o'.

llvm-svn: 363376
2019-06-14 12:14:58 +00:00
Gauthier Harnisch 796ed03b84 [C++20] add Basic consteval specifier
Summary:
this revision adds Lexing, Parsing and Basic Semantic for the consteval specifier as specified by http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1073r3.html

with this patch, the consteval specifier is treated as constexpr but can only be applied to function declaration.

Changes:
 - add the consteval keyword.
 - add parsing of consteval specifier for normal declarations and lambdas expressions.
 - add the whether a declaration is constexpr is now represented by and enum everywhere except for variable because they can't be consteval.
 - adapt diagnostic about constexpr to print constexpr or consteval depending on the case.
 - add tests for basic semantic.

Reviewers: rsmith, martong, shafik

Reviewed By: rsmith

Subscribers: eraman, efriedma, rnkovacs, cfe-commits

Tags: #clang

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

llvm-svn: 363362
2019-06-14 08:56:20 +00:00
Nico Weber 3d02b895ed Revert 363295, it caused PR42276. Also revert follow-ups 363337, 363340.
Revert 363340 "Remove unused SK_LValueToRValue initialization step."
Revert 363337 "PR23833, DR2140: an lvalue-to-rvalue conversion on a glvalue of type"
Revert 363295 "C++ DR712 and others: handle non-odr-use resulting from an lvalue-to-rvalue conversion applied to a member access or similar not-quite-trivial lvalue expression."

llvm-svn: 363352
2019-06-14 04:05:17 +00:00
Stanislav Mekhanoshin 8a8131a3f6 [AMDGPU] gfx1010 wave32 clang support
Differential Revision: https://reviews.llvm.org/D63209

llvm-svn: 363341
2019-06-13 23:47:59 +00:00
Richard Smith aca017e802 Remove unused SK_LValueToRValue initialization step.
In addition to being unused and duplicating code, this was also wrong
(it didn't properly mark the operand as being potentially not odr-used).

llvm-svn: 363340
2019-06-13 23:47:42 +00:00
Dmitri Gribenko 31d68804fd Added AST matcher for ignoring elidable constructors
Summary: Added AST matcher for ignoring elidable move constructors

Reviewers: hokein, gribozavr

Reviewed By: hokein, gribozavr

Subscribers: cfe-commits

Tags: #clang

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

Patch by Johan Vikström.

llvm-svn: 363262
2019-06-13 13:48:24 +00:00
Sven van Haastregt 95a9ee5e2f [OpenCL] Move OpenCLBuiltins.td and remove unused include
Patch by Pierre Gondois.

Differential revision: https://reviews.llvm.org/D62849

llvm-svn: 363242
2019-06-13 09:54:22 +00:00
Richard Smith 1bbad59379 For DR712: store on a MemberExpr whether it constitutes an odr-use.
llvm-svn: 363087
2019-06-11 17:50:36 +00:00
Richard Smith 715f7a1bd0 For DR712: store on a DeclRefExpr whether it constitutes an odr-use.
Begin restructuring to support the forms of non-odr-use reference
permitted by DR712.

llvm-svn: 363086
2019-06-11 17:50:32 +00:00
Nikolai Kosjar 8edd8da487 [libclang] Allow skipping warnings from all included files
Depending on the included files and the used warning flags, e.g. -
Weverything, a huge number of warnings can be reported for included
files. As processing that many diagnostics comes with a performance
impact and not all clients are interested in those diagnostics, add a
flag to skip them.

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

llvm-svn: 363067
2019-06-11 14:14:24 +00:00
Pengfei Wang 244062eece [X86] Enable intrinsics that convert float and bf16 data to each other
Scalar version :
_mm_cvtsbh_ss , _mm_cvtness_sbh

Vector version:
_mm512_cvtpbh_ps , _mm256_cvtpbh_ps
_mm512_maskz_cvtpbh_ps , _mm256_maskz_cvtpbh_ps
_mm512_mask_cvtpbh_ps , _mm256_mask_cvtpbh_ps

Patch by Shengchen Kan (skan)

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

llvm-svn: 363018
2019-06-11 01:17:28 +00:00
Reid Kleckner e78333a010 Require stdcall etc parameters to be complete on ODR use
Functions using stdcall, fastcall, or vectorcall with C linkage mangle
in the size of the parameter pack. Calculating the size of the pack
requires the parameter types to complete, which may require template
instantiation.

Previously, we would crash during IRgen when requesting the size of
incomplete or uninstantiated types, as in this reduced example:
  struct Foo;
  void __fastcall bar(struct Foo o);
  void (__fastcall *fp)(struct Foo) = &bar;

Reported in Chromium here: https://crbug.com/971245

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

llvm-svn: 363000
2019-06-10 22:53:12 +00:00
David Blaikie 8472fa6c54 DebugInfo: Add support for 'nodebug' attribute on typedefs and alias templates
Seems like a logical extension to me - and of interest because it might
help reduce the debug info size of libc++ by applying this attribute to
type traits that have a disproportionate debug info cost compared to the
benefit (& possibly harm/confusion) they cause users.

llvm-svn: 362856
2019-06-08 00:01:21 +00:00
Keno Fischer 6f48c07620 [analyzer] Add werror flag for analyzer warnings
Summary:
We're using the clang static analyzer together with a number of
custom analyses in our CI system to ensure that certain invariants
are statiesfied for by the code every commit. Unfortunately, there
currently doesn't seem to be a good way to determine whether any
analyzer warnings were emitted, other than parsing clang's output
(or using scan-build, which then in turn parses clang's output).
As a simpler mechanism, simply add a `-analyzer-werror` flag to CC1
that causes the analyzer to emit its warnings as errors instead.
I briefly tried to have this be `Werror=analyzer` and make it go
through that machinery instead, but that seemed more trouble than
it was worth in terms of conflicting with options to the actual build
and special cases that would be required to circumvent the analyzers
usual attempts to quiet non-analyzer warnings. This is simple and it
works well.

Reviewed-By: NoQ, Szelethusw
Differential Revision: https://reviews.llvm.org/D62885

llvm-svn: 362855
2019-06-07 23:34:00 +00:00
Peter Collingbourne e08e68de21 Driver, IRGen: Set partitions on GlobalValues according to -fsymbol-partition flag.
Differential Revision: https://reviews.llvm.org/D62636

llvm-svn: 362829
2019-06-07 19:10:08 +00:00
Pengfei Wang 30bcda86db [X86] -march=cooperlake (clang)
Support intel -march=cooperlake in clang

Patch by Shengchen Kan (skan)

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

llvm-svn: 362781
2019-06-07 08:53:37 +00:00
Richard Smith 84be998497 Factor out duplicated code building a MemberExpr and marking it
referenced.

This reinstates r362563, reverted in r362597.

llvm-svn: 362757
2019-06-06 23:24:18 +00:00
Richard Smith dcf17ded66 Convert MemberExpr creation and serialization to work the same way as
most / all other Expr subclasses.

This reinstates r362551, reverted in r362597, with a fix to a bug that
caused MemberExprs to sometimes have a null FoundDecl after a round-trip
through an AST file.

llvm-svn: 362756
2019-06-06 23:24:15 +00:00
Francois Ferrand e8a301f87f clang-format: better handle namespace macros
Summary:
Other macros are used to declare namespaces, and should thus be handled
similarly. This is the case for crpcut's TESTSUITE macro, or for
unittest-cpp's SUITE macro:

      TESTSUITE(Foo) {
      TEST(MyFirstTest) {
        assert(0);
      }
      } // TESTSUITE(Foo)

This patch deals with this cases by introducing a new option to specify
lists of namespace macros. Internally, it re-uses the system already in
place for foreach and statement macros, to ensure there is no impact on
performance.

Reviewers: krasimir, djasper, klimek

Reviewed By: klimek

Subscribers: acoomans, cfe-commits, klimek

Tags: #clang

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

llvm-svn: 362740
2019-06-06 20:06:23 +00:00
Yitzhak Mandelbaum 2e4a628c06 [LibTooling] Add insert/remove convenience functions for creating `ASTEdit`s.
Summary: `change()` is an all purpose function; the revision adds simple shortcuts for the specific operations of inserting (before/after) or removing source.

Reviewers: ilya-biryukov

Subscribers: cfe-commits

Tags: #clang

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

llvm-svn: 362707
2019-06-06 14:20:29 +00:00
Pengfei Wang 3a29f7c99c [X86] Add ENQCMD instructions
For more details about these instructions, please refer to the latest
ISE document:
https://software.intel.com/en-us/download/intel-architecture-instruction-set-extensions-programming-reference.

Patch by Tianqing Wang (tianqing)

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

llvm-svn: 362685
2019-06-06 08:28:42 +00:00
Jan Korous a3701caad8 [clang-format][NFC] Fix BS_Allman style example in the header docs are generated from
Differential Revision: https://reviews.llvm.org/D61729

llvm-svn: 362646
2019-06-05 20:59:48 +00:00
Erich Keane da59652c1b Avoid using NoThrow Exception Specifier in non-C++ Modes.
As reported in https://bugs.llvm.org/show_bug.cgi?id=42113, there are a
number of locations in Clang where it is assumed that exception
specifications are only valid in C++ mode. Since the original
justification for the NoThrow Exception Specifier Type was C++ related,
this patch just makes C mode use the attribute-based nothrow handling.

Additionally, I noticed that the handling of non-prototype functions
regressed the behavior of the nothrow attribute, in part because it is
was listed in the function type macro(which I did in the previous
patch).  In reality, it should only be doing so in a conditional nature,
so this patch removes it there and puts it directly in the switch to be
handled correctly.

llvm-svn: 362607
2019-06-05 14:10:39 +00:00
Anastasia Stulova 5145b1e442 [Sema] Prevent binding incompatible addr space ref to temporaries
References to arbitrary address spaces can't always be bound to
temporaries. This change extends the reference binding logic to
check that the address space of a temporary can be implicitly
converted to the address space in a reference when temporary
materialization is performed.

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

llvm-svn: 362604
2019-06-05 14:03:34 +00:00
Benjamin Kramer 9b2b8ad8b1 Revert "Factor out duplicated code building a MemberExpr and marking it" and "Convert MemberExpr creation and serialization to work the same way as"
This reverts commits r362551 and r362563. Crashes during modules selfhost.

llvm-svn: 362597
2019-06-05 11:46:57 +00:00
Nemanja Ivanovic 6321c68065 Initial support for vectorization using MASSV (IBM MASS vector library)
Part 2 (the Clang portion) of D59881.

This patch (first of two patches) enables the vectorizer to recognize the
IBM MASS vector library routines. This patch specifically adds support for
recognizing the -vector-library=MASSV option, and defines mappings from IEEE
standard scalar math functions to generic PowerPC MASS vector counterparts.
For instance, the generic PowerPC MASS vector entry for double-precision
cbrt function is __cbrtd2_massv.

The second patch will further lower the generic PowerPC vector entries to
PowerPC subtarget-specific entries.
For instance, the PowerPC generic entry cbrtd2_massv is lowered to
cbrtd2_P9 for Power9 subtarget.

The overall support for MASS vector library is presented as such in two patches
for ease of review.

Patch by Jeeva Paudel.

Differential revision: https://reviews.llvm.org/D59881

llvm-svn: 362571
2019-06-05 01:57:57 +00:00
Richard Smith 8ca5455764 Factor out duplicated code building a MemberExpr and marking it
referenced.

llvm-svn: 362563
2019-06-05 00:21:47 +00:00
Richard Smith c32ef4bc0b Convert MemberExpr creation and serialization to work the same way as
most / all other Expr subclasses.

llvm-svn: 362551
2019-06-04 21:29:28 +00:00
Richard Smith 7dcd73340b Factor out repeated code to build a DeclRefExpr and mark it referenced.
llvm-svn: 362537
2019-06-04 18:30:46 +00:00
Richard Smith 7bf8f6fa8a PR42104: Support instantiations of lambdas that implicitly capture
packs.

Two changes:
 * Track odr-use via FunctionParmPackExprs to properly handle dependent
   odr-uses of packs in generic lambdas.
 * Do not instantiate implicit captures; instead, regenerate them by
   instantiating the body of the lambda. This is necessary to
   distinguish between cases where only one element of a pack is
   captured and cases where the entire pack is captured.

This reinstates r362358 (reverted in r362375) with a fix for an
uninitialized variable use in UpdateMarkingForLValueToRValue.

llvm-svn: 362531
2019-06-04 17:17:20 +00:00
Alex Lorenz 6e2d36b60b Add clang source minimizer that reduces source to directives
that might affect the dependency list for a compilation

This commit introduces a dependency directives source minimizer to clang
that minimizes header and source files to the minimum necessary preprocessor
directives for evaluating includes. It reduces the source down to #define, #include,

The source minimizer works by lexing the input with a custom fast lexer that recognizes
the preprocessor directives it cares about, and emitting those directives in the minimized source.
It ignores source code, comments, and normalizes whitespace. It gives up and fails if seems
any directives that it doesn't recognize as valid (e.g. #define 0).

In addition to the source minimizer this patch adds a
-print-dependency-directives-minimized-source CC1 option that allows you to invoke the minimizer
from clang directly.

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

llvm-svn: 362459
2019-06-03 22:59:17 +00:00
Erich Keane bf37536a35 Make NoThrow FunctionLike, make FunctionLike include references, fix
prettyprint

__declspec(nothrow) should work on function pointers as well as function
references, so this changes it to FunctionLike.  Additionally,
FunctionLike needed to be modified to permit function references.

Finally, the TypePrinter didn't properly print the NoThrow exception
specifier, so make sure we get that right as well.

llvm-svn: 362435
2019-06-03 18:36:33 +00:00
Erich Keane 81ef625080 Permit Exception Spec mismatch with NoThrow on inherited Virtual
As reported here: https://bugs.llvm.org/show_bug.cgi?id=42100

This fairly common pattern ends up being an error in MinGW, so relax it
in all cases to a warning.

llvm-svn: 362434
2019-06-03 18:36:26 +00:00
Jennifer Yu b8fee677bf Re-check in clang support gun asm goto after fixing tests.
llvm-svn: 362410
2019-06-03 15:57:25 +00:00
Andrew Savonichev fa8cd7691a [OpenCL] Use long instead of long long in x86 builtins
Summary: According to C99 standard long long is at least 64 bits in
size. However, OpenCL C defines long long as 128 bit signed
integer. This prevents one to use x86 builtins when compiling OpenCL C
code for x86 targets. The patch changes long long to long for OpenCL
only.

Patch by: Alexander Batashev <alexander.batashev@intel.com>

Reviewers: craig.topper, Ka-Ka, eandrews, erichkeane, Anastasia

Reviewed By: Ka-Ka, erichkeane, Anastasia

Subscribers: a.elovikov, yaxunl, Anastasia, cfe-commits, ivankara, etyurin, asavonic

Tags: #clang

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

llvm-svn: 362391
2019-06-03 12:34:59 +00:00
Simon Pilgrim c716e5d6de Revert rL362358 : PR42104: Support instantiations of lambdas that implicitly capture packs.
Two changes:
 * Track odr-use via FunctionParmPackExprs to properly handle dependent
   odr-uses of packs in generic lambdas.
 * Do not instantiate implicit captures; instead, regenerate them by
   instantiating the body of the lambda. This is necessary to
   distinguish between cases where only one element of a pack is
   captured and cases where the entire pack is captured.
........
Fixes http://lab.llvm.org:8011/builders/llvm-clang-x86_64-expensive-checks-win buildbot failures

llvm-svn: 362375
2019-06-03 09:56:09 +00:00
Sven van Haastregt 79a222fcf8 [OpenCL] Declare builtin functions using TableGen
This patch adds a `-fdeclare-opencl-builtins` command line option to
the clang frontend.  This enables clang to verify OpenCL C builtin
function declarations using a fast StringMatcher lookup, instead of
including the opencl-c.h file with the `-finclude-default-header`
option.  This avoids the large parse time penalty of the header file.

This commit only adds the basic infrastructure and some of the OpenCL
builtins.  It does not cover all builtins defined by the various OpenCL
specifications.  As such, it is not a replacement for
`-finclude-default-header` yet.

RFC: http://lists.llvm.org/pipermail/cfe-dev/2018-November/060041.html

Co-authored-by: Pierre Gondois
Co-authored-by: Joey Gouly
Co-authored-by: Sven van Haastregt

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

llvm-svn: 362371
2019-06-03 09:39:11 +00:00
Richard Smith ea0c66be55 PR42104: Support instantiations of lambdas that implicitly capture
packs.

Two changes:
 * Track odr-use via FunctionParmPackExprs to properly handle dependent
   odr-uses of packs in generic lambdas.
 * Do not instantiate implicit captures; instead, regenerate them by
   instantiating the body of the lambda. This is necessary to
   distinguish between cases where only one element of a pack is
   captured and cases where the entire pack is captured.

llvm-svn: 362358
2019-06-03 06:02:10 +00:00
Richard Smith 87346a15db Transform lambda expression captures when transforming an expression to
potentially-evaluated.

This ensures that every potentially-evaluated expression is built in a
potentially-evaluated context. No functionality change intended.

llvm-svn: 362336
2019-06-02 18:53:44 +00:00
Richard Smith e518235aca Factor out commonality between variable capture initialization and
'this' capture initialization.

llvm-svn: 362317
2019-06-02 04:00:43 +00:00
Pengfei Wang cc3629d545 [X86] Add VP2INTERSECT instructions
Support intel AVX512 VP2INTERSECT instructions in clang

Patch by Xiang Zhang (xiangzhangllvm)

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

llvm-svn: 362196
2019-05-31 06:09:35 +00:00
Richard Smith b5a45bb77e Defer building 'this' captures until we have left the capturing region
and returned to the context in which 'this' should be captured.

This means we now always mark 'this' referenced from the context in
which it's actually referenced, rather than potentially from some
context nested within that.

llvm-svn: 362182
2019-05-31 01:17:04 +00:00
Richard Smith 0621a8f353 Defer capture initialization for captured regions until after we've left
the captured region scope.

This removes a case where we would build expressions (and mark
declarations odr-used) in the wrong scope.

Remove the now-unused 'capture initializer' field on sema::Capture
(except for 'this' captures, which still need to be cleaned up).

No functionality change intended (except that we now very slightly more
precisely determine whether we need to use a capture or not when another
captured region encloses an OpenMP captured region).

llvm-svn: 362179
2019-05-31 00:45:10 +00:00
Richard Smith 2fdd95c1c8 Defer capture initialization for blocks until after we've left the
function scope.

This removes one of the last few cases where we build expressions in the
wrong function scope context. No functionality change intended.

llvm-svn: 362178
2019-05-31 00:45:09 +00:00
Erich Keane d02f4a1043 Add Attribute NoThrow as an Exception Specifier Type
In response to https://bugs.llvm.org/show_bug.cgi?id=33235, it became
clear that the current mechanism of hacking through checks for the
exception specification of a function gets confused really quickly when
there are alternate exception specifiers.

This patch introcues EST_NoThrow, which is the equivilent of
EST_noexcept when caused by EST_noThrow. The existing implementation is
left in place to cover functions with no FunctionProtoType.

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

llvm-svn: 362119
2019-05-30 17:31:54 +00:00
Erich Keane d0f34fd198 Revert "clang support gnu asm goto."
This reverts commit 954ec09aed.

Reverting due to test failures as requested by Jennifer Yu.

Conflicts:
	clang/test/CodeGen/asm-goto.c

llvm-svn: 362106
2019-05-30 15:38:02 +00:00
Simon Pilgrim 9d1f8a9dd2 Fix Wdocumentation warning. NFCI.
llvm-svn: 362085
2019-05-30 10:44:36 +00:00
Simon Pilgrim df1fbbb4cc Fix MSVC "not all control paths return a value" warning.
llvm-svn: 362076
2019-05-30 09:39:45 +00:00
John McCall 2c91c3b7af Add the `objc_class_stub` attribute.
Swift requires certain classes to be not just initialized lazily on first
use, but actually allocated lazily using information that is only available
at runtime.  This is incompatible with ObjC class initialization, or at least
not efficiently compatible, because there is no meaningful class symbol
that can be put in a class-ref variable at load time.  This leaves ObjC
code unable to access such classes, which is undesirable.

objc_class_stub says that class references should be resolved by calling
a new ObjC runtime function with a pointer to a new "class stub" structure.
Non-ObjC compilers (like Swift) can simply emit this structure when ObjC
interop is required for a class that cannot be statically allocated,
then apply this attribute to the `@interface` in the generated ObjC header
for the class.

This attribute can be thought of as a generalization of the existing
`objc_runtime_visible` attribute which permits more efficient class
resolution as well as supporting the additon of categories to the class.
Subclassing these classes from ObjC is currently not allowed.

Patch by Slava Pestov!

llvm-svn: 362054
2019-05-30 04:09:01 +00:00
Jennifer Yu 954ec09aed clang support gnu asm goto.
Syntax:
  asm [volatile] goto ( AssemblerTemplate
                      :
                      : InputOperands
                      : Clobbers
                      : GotoLabels)

https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html

New llvm IR is "callbr" for inline asm goto instead "call" for inline asm
For:
asm goto("testl %0, %0; jne %l1;" :: "r"(cond)::label_true, loop);
IR:
callbr void asm sideeffect "testl $0, $0; jne ${1:l};", "r,X,X,~{dirflag},~{fpsr},~{flags}"(i32 %0, i8* blockaddress(@foo, %label_true), i8* blockaddress(@foo, %loop)) #1
          to label %asm.fallthrough [label %label_true, label %loop], !srcloc !3

asm.fallthrough:                                

Compiler need to generate:
1> a dummy constarint 'X' for each label.
2> an unique fallthrough label for each asm goto stmt " asm.fallthrough%number".


Diagnostic 
1>	duplicate asm operand name are used in output, input and label.
2>	goto out of scope.

llvm-svn: 362045
2019-05-30 01:05:46 +00:00
Akira Hatanaka f3c89b1a6b [ObjC] Fix encoding of ObjC pointer types that are pointers to typedefs
clang was encoding pointers to typedefs as if they were pointers to
structs because that is apparently what gcc is doing.

For example:

```
@class Class1;

typedef NSArray<Class1 *> MyArray;

void foo1(void) {
  const char *s0 = @encode(MyArray *); // "^{NSArray=#}"
  const char *s1 = @encode(NSArray<Class1 *> *); // "@"
}
```

This commit removes the code that was there to make clang compatible
with gcc and make clang emit the correct encoding for ObjC pointers,
which is "@".

rdar://problem/50563529

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

llvm-svn: 362034
2019-05-29 21:23:30 +00:00
Csaba Dabis 74c5fac3bb [analyzer] Remove EndPath function as it is dead code
Summary: -

Reviewers: george.karpenkov

Reviewed By: george.karpenkov

Subscribers: baloghadamsoftware, cfe-commits, xazax.hun, szepet, a.sidorin,
             mikhail.ramalho, Szelethus, donat.nagy, dkrupp

Tags: #clang

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

llvm-svn: 362030
2019-05-29 20:47:27 +00:00
Csaba Dabis d1f0ec3f64 [analyzer] ConditionBRVisitor: MemberExpr support
Summary: -

Reviewers: NoQ, george.karpenkov

Reviewed By: NoQ

Subscribers: cfe-commits, xazax.hun, baloghadamsoftware, szepet, a.sidorin,
             mikhail.ramalho, Szelethus, donat.nagy, dkrupp

Tags: #clang

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

llvm-svn: 362026
2019-05-29 20:29:02 +00:00
Csaba Dabis 9942a996d9 [analyzer] ConditionBRVisitor: Remove duplicated code
Summary: -

Reviewers: NoQ, george.karpenkov

Reviewed By: NoQ

Subscribers: cfe-commits, xazax.hun, baloghadamsoftware, szepet, a.sidorin,
             mikhail.ramalho, Szelethus, donat.nagy, dkrupp

Tags: #clang

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

llvm-svn: 362025
2019-05-29 20:18:07 +00:00
Csaba Dabis 4b0184b2d3 [analyzer] ConditionBRVisitor: Enhance to write out more information
Summary:
Add extra messages to the bug report to inform the user why the analyzer
`Taking true/false branch`.

Reviewers: NoQ, george.karpenkov

Reviewed By: NoQ

Subscribers: gerazo, gsd, dkrupp, whisperity, baloghadamsoftware, xazax.hun,
             eraman, szepet, a.sidorin, mikhail.ramalho, Szelethus,
             donat.nagy, cfe-commits

Tags: #clang

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

llvm-svn: 362020
2019-05-29 20:06:09 +00:00
Csaba Dabis 1d7ca67769 [analyzer] [NFC] PathDiagnostic: Create PathDiagnosticPopUpPiece
Summary:
This new piece is similar to our macro expansion printing in HTML reports:
On mouse-hover event it pops up on variables. Similar to note pieces it
supports `plist` diagnostics as well.

It is optional, on by default: `add-pop-up-notes=true`.

Extra: In HTML reports `background-color: LemonChiffon` was too light,
changed to `PaleGoldenRod`.

Reviewers: NoQ, alexfh

Reviewed By: NoQ

Subscribers: cfe-commits, gerazo, gsd, george.karpenkov, alexfh, xazax.hun,
             baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho,
             Szelethus, donat.nagy, dkrupp

Tags: #clang

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

llvm-svn: 362014
2019-05-29 19:21:59 +00:00
Csaba Dabis 8a88d6aaaa [analyzer] print() JSONify: SVal implementation
Summary: -

Reviewers: NoQ, xazax.hun, ravikandhadai, baloghadamsoftware, Szelethus

Reviewed By: NoQ

Subscribers: cfe-commits, szepet, rnkovacs, a.sidorin, mikhail.ramalho,
             Szelethus, donat.nagy, dkrupp

Tags: #clang

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

llvm-svn: 362008
2019-05-29 18:38:52 +00:00
Csaba Dabis dea605e090 [analyzer] print() JSONify: CFG implementation
Summary: -

Reviewers: NoQ, xazax.hun, ravikandhadai, baloghadamsoftware, Szelethus

Reviewed By: NoQ

Subscribers: cfe-commits, szepet, rnkovacs, a.sidorin, mikhail.ramalho,
             donat.nagy, dkrupp

Tags: #clang

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

llvm-svn: 362003
2019-05-29 18:29:31 +00:00
Csaba Dabis 9ee26c8d5f [analyzer][AST] print() JSONify: Stmt implementation
Summary:
This patch also adds a function called `JsonFormat()` which:
- Flattens the string so removes the new-lines.
- Escapes double quotes.

Reviewers: NoQ, xazax.hun, ravikandhadai, baloghadamsoftware, Szelethus

Reviewed By: NoQ

Subscribers: cfe-commits, szepet, rnkovacs, a.sidorin, mikhail.ramalho,
             donat.nagy, dkrupp

Tags: #clang

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

llvm-svn: 362000
2019-05-29 18:17:18 +00:00
Csaba Dabis 13e491cca5 [analyzer] print() JSONify: getNodeLabel implementation
Summary: This patch also rewrites the ProgramPoint printing.

Reviewers: NoQ, xazax.hun, ravikandhadai, baloghadamsoftware, Szelethus

Reviewed By: NoQ

Subscribers: cfe-commits, szepet, rnkovacs, a.sidorin, mikhail.ramalho,
             donat.nagy, dkrupp

Tags: #clang

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

llvm-svn: 361997
2019-05-29 18:05:53 +00:00
Francois Ferrand c5227a1f53 [clang-format] Allow configuring list of function-like macros that resolve to a type
Summary:
Adds a `TypenameMacros` configuration option that causes certain identifiers to be handled in a way similar to `typeof()`.

This is enough to:
- Prevent misinterpreting declarations of pointers to such types as expressions (`STACK_OF(int) * foo` -> `STACK_OF(int) *foo`),
- Avoid surprising line breaks in variable/struct field declarations (`STACK_OF(int)\nfoo;` -> `STACK_OF(int) foo;`, see https://bugs.llvm.org/show_bug.cgi?id=30353).

Reviewers: Typz, krasimir, djasper

Reviewed By: Typz

Subscribers: cfe-commits

Tags: #clang

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

llvm-svn: 361986
2019-05-29 16:30:47 +00:00
Csaba Dabis df0a42127c [analyzer] print() JSONify: Program state implementation
Summary: -

Reviewers: NoQ, xazax.hun, ravikandhadai, baloghadamsoftware, Szelethus

Reviewed By: NoQ

Subscribers: szepet, rnkovacs, a.sidorin, mikhail.ramalho, donat.nagy,
             dkrupp

Tags: #clang

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

llvm-svn: 361983
2019-05-29 16:22:21 +00:00
Csaba Dabis b7ca72a113 [analyzer] print() JSONify: Checker messages implementation
Summary: -

Reviewers: NoQ, xazax.hun, ravikandhadai, baloghadamsoftware, Szelethus

Reviewed By: NoQ

Subscribers: szepet, rnkovacs, a.sidorin, mikhail.ramalho, donat.nagy,
             dkrupp

Tags: #clang

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

llvm-svn: 361982
2019-05-29 16:02:33 +00:00
Csaba Dabis 35e54eb31e [analyzer] print() JSONify: Constructing objects implementation
Summary: -

Reviewers: NoQ, xazax.hun, ravikandhadai, baloghadamsoftware, Szelethus

Reviewed By: NoQ

Subscribers: szepet, rnkovacs, a.sidorin, mikhail.ramalho, donat.nagy,
             dkrupp

Tags: #clang

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

llvm-svn: 361980
2019-05-29 15:58:26 +00:00
Csaba Dabis 32981637ce [analyzer] print() JSONify: Type information implementation
Summary: -

Reviewers: NoQ, xazax.hun, ravikandhadai, baloghadamsoftware, Szelethus

Reviewed By: NoQ

Subscribers: szepet, rnkovacs, a.sidorin, mikhail.ramalho, donat.nagy,
             dkrupp

Tags: #clang

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

llvm-svn: 361979
2019-05-29 15:53:12 +00:00
Csaba Dabis 5df5eb8816 [analyzer] print() JSONify: Constraints implementation
Summary: -

Reviewers: NoQ, xazax.hun, ravikandhadai, baloghadamsoftware, Szelethus

Reviewed By: NoQ

Subscribers: szepet, rnkovacs, a.sidorin, mikhail.ramalho, donat.nagy,
             dkrupp

Tags: #clang

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

llvm-svn: 361978
2019-05-29 15:43:26 +00:00
Csaba Dabis 9ce3746604 [analyzer] print() JSONify: Environment implementation
Summary: -

Reviewers: NoQ, xazax.hun, ravikandhadai, baloghadamsoftware, Szelethus

Reviewed By: NoQ

Subscribers: szepet, rnkovacs, a.sidorin, mikhail.ramalho, donat.nagy,
             dkrupp

Tags: #clang

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

llvm-svn: 361976
2019-05-29 15:36:58 +00:00
Csaba Dabis 124cba0b81 [analyzer] print() JSONify: Store implementation
Summary: -

Reviewers: NoQ, xazax.hun, ravikandhadai, baloghadamsoftware, Szelethus

Reviewed By: NoQ

Subscribers: szepet, rnkovacs, a.sidorin, mikhail.ramalho, donat.nagy,
             dkrupp

Tags: #clang

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

llvm-svn: 361972
2019-05-29 15:25:19 +00:00
Nico Weber e3b1f5d22c clang-cl: Fix mangling of catchable types with names longer than 4kiB
The mangling used to contain the MD5 name of both the RTTI type
descriptor and the name of the copy ctor in MSVC2013, but it changed
to just the former in 2015. It looks like it changed back to the old
mangling in VS2017 version 15.7 and onwards, including VS2019 (version
16.0). VS2017 version 15.0 still has the VS2015 mangling. Versions
between 15.0 and 15.7 are't on godbolt. I found 15.4 (_MSC_VER 1911)
locally and that uses the 15.0 mangling still, but I didn't find 15.5 or
15.6, so I'm not sure where exactly it changed back.

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

llvm-svn: 361959
2019-05-29 13:48:19 +00:00
Yitzhak Mandelbaum e1312c54d3 [LibTooling] Add `before` and `after` selectors for selecting point-ranges relative to nodes.
Summary:
The `before` and `after` selectors allow users to specify a zero-length range --
a point -- at the relevant location in an AST-node's source.  Point ranges can
be useful, for example, to insert a change using an API that takes a range to be
modified (e.g. `tooling::change()`).

Reviewers: ilya-biryukov

Subscribers: cfe-commits

Tags: #clang

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

llvm-svn: 361955
2019-05-29 12:40:36 +00:00
Richard Smith 30116531b8 Defer creating fields for captures until we finish building the
capturing expression or statement.

No functionality change yet. The intent is that we will also delay
building the initialization expression until the enclosing context, so
that:
a) we build the initialization expression in the right context, and
b) we can elide captures that are not odr-used, as suggested by P0588R1.

This also consolidates some duplicated code building capture fields into
a single place.

llvm-svn: 361893
2019-05-28 23:09:46 +00:00
Richard Smith e925be1339 Simplify clang::Capture. No functionality change intended.
We don't need to pack flags into the bottom bits of pointers here; we
have plenty of trailing bits in this type.

llvm-svn: 361892
2019-05-28 23:09:45 +00:00
Richard Smith 8cb63232d9 If capturing a variable fails, add a capture anyway (and mark it
invalid) so that we can avoid repeated diagnostics for the same capture.

llvm-svn: 361891
2019-05-28 23:09:44 +00:00
Richard Smith 94ef686f57 Move code to mark a variable as odr-used adjacement to all the related
code.

No functional change intended.

llvm-svn: 361890
2019-05-28 23:09:42 +00:00
Michael J. Spencer 7e48b406ef [Driver] Fix -working-directory issues
Currently the `-working-directory` option does not actually impact the working
directory for all of the clang driver, it only impacts how files are looked up
to make sure they exist.  This means that that clang passes the wrong paths
to -fdebug-compilation-dir and -coverage-notes-file.

This patch fixes that by changing all the places in the driver where we convert
to absolute paths to use the VFS, and then calling setCurrentWorkingDirectory on
the VFS.  This also changes the default VFS for `Driver` to use a virtualized
working directory, instead of changing the process's working directory.

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

llvm-svn: 361885
2019-05-28 22:21:47 +00:00
Saleem Abdulrasool 09c2625108 Driver: support `/Zc:char8_t` and `/Zc:char8_t-`
Update the `cl` emulation to support the `/Zc:char8_t[-]?` options as per the
MSVC 2019.1 toolset.  These are aliases for `-fchar8_t` and `-fno-char8_t`.

llvm-svn: 361859
2019-05-28 18:26:00 +00:00
Ilya Biryukov b1296faee0 [CodeComplete] Set preferred type for qualified-id
Reviewers: kadircet

Reviewed By: kadircet

Subscribers: cfe-commits

Tags: #clang

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

llvm-svn: 361838
2019-05-28 15:21:03 +00:00
Adam Balogh 9ed4b316d1 [Analyzer] Replace `CXXSelfAssignmentBRVisitor` with `NoteTags`
The `cplusplus.SelfAssignment` checker has a visitor that is added
to every `BugReport` to mark the to branch of the self assignment
operator with e.g. `rhs == *this` and `rhs != *this`. With the new
`NoteTag` feature this visitor is not needed anymore. Instead the
checker itself marks the two branches using the `NoteTag`s.

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

llvm-svn: 361818
2019-05-28 13:07:09 +00:00
Volodymyr Sapsai e32ff09685 [Preprocessor] Fix crash emitting note with framework location for "file not found" error.
A filename can be remapped with a header map to point to a framework
header and we can find the corresponding framework without the header.
But if the original filename doesn't have a remapped framework name,
we'll fail to find its location and will dereference a null pointer
during diagnostics emission.

Fix by tracking remappings better and emit the note only if a framework
is found before any of the remappings.

rdar://problem/48883447

Reviewers: arphaman, erik.pilkington, jkorous

Reviewed By: arphaman

Subscribers: dexonsmith, cfe-commits

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

llvm-svn: 361779
2019-05-27 19:15:30 +00:00
Aaron Ballman e091ab1b2d When dumping the AST to JSON, dump the type information from a typeid expression with a type operand.
llvm-svn: 361769
2019-05-27 14:34:31 +00:00
Aaron Ballman bcc0cedf77 When dumping the AST to JSON, dump the argument name to a sizeof pack expression.
llvm-svn: 361766
2019-05-27 14:17:32 +00:00
Petr Hosek 2db79ef32c [Driver] Update handling of c++ and runtime directories
This is a follow up to r361432 and r361504 which addresses issues
introduced by those changes. Specifically, it avoids duplicating
file and runtime paths in case when the effective triple is the
same as the cannonical one. Furthermore, it fixes the broken multilib
setup in the Fuchsia driver and deduplicates some of the code.

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

llvm-svn: 361709
2019-05-26 03:39:07 +00:00
Richard Smith 0353e5a6cd Permit static local structured bindings to be named from arbitrary scopes inside their declaring scope.
llvm-svn: 361686
2019-05-25 01:04:17 +00:00
Artem Dergachev ef0aab3138 [analyzer] Add a prunable note for skipping vbase inits in subclasses.
When initialization of virtual base classes is skipped, we now tell the user
about it, because this aspect of C++ isn't very well-known.

The implementation is based on the new "note tags" feature (r358781).
In order to make use of it, allow note tags to produce prunable notes,
and move the note tag factory to CoreEngine.

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

llvm-svn: 361682
2019-05-24 23:37:11 +00:00
Artem Dergachev 192a7474d6 [CFG] Add branch to skip vbase inits when they're handled by superclass.
This patch adds the run-time CFG branch that would skip initialization of
virtual base classes depending on whether the constructor is called from a
superclass constructor or not. Previously the Static Analyzer was already
skipping virtual base-class initializers in such constructors, but it wasn't
skipping their arguments and their potential side effects, which was causing
pr41300 (and was generally incorrect). The previous skipping behavior is
now replaced with a hard assertion that we're not even getting there due
to how our CFG works.

The new CFG element is under a CFG build option so that not to break other
consumers of the CFG by this change. Static Analyzer support for this change
is implemented.

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

llvm-svn: 361681
2019-05-24 23:37:08 +00:00
Richard Smith fd42079255 Fix crash deserializing a CUDAKernelCallExpr with a +Asserts binary.
The assertion in setConfig read from the (uninitialized) CONFIG
expression.

llvm-svn: 361680
2019-05-24 23:26:07 +00:00
Mandeep Singh Grang 0cdc5dddca [Analyzer] Checker for non-determinism caused by iteration of unordered container of pointers
Summary: Added a checker for non-determinism caused by iterating unordered containers like std::unordered_set containing pointer elements.

Reviewers: NoQ, george.karpenkov, whisperity, Szelethus, baloghadamsoftware

Reviewed By: Szelethus

Subscribers: mgorny, xazax.hun, baloghadamsoftware, szepet, rnkovacs, a.sidorin, mikhail.ramalho, donat.nagy, dkrupp, jdoerfert, Charusso, cfe-commits

Tags: #clang

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

llvm-svn: 361664
2019-05-24 19:24:08 +00:00
Aaron Ballman fa643d7071 Add JSON dumping tests for ObjC statements; add support for dumping @catch catch-all statements.
llvm-svn: 361660
2019-05-24 18:58:29 +00:00
Aaron Ballman 4105882b87 Add support for dumping Objective C AST declaration nodes to JSON.
llvm-svn: 361652
2019-05-24 17:39:55 +00:00
Yitzhak Mandelbaum fab7205ac4 [LibTooling] Add Explanation parameter to `makeRule`.
Summary:
Conceptually, a single-case RewriteRule has a matcher, edit(s) and an (optional)
explanation. `makeRule` previously only took the matcher and edit(s). This
change adds (optional) support for the explanation.

Reviewers: ilya-biryukov

Subscribers: cfe-commits

Tags: #clang

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

llvm-svn: 361643
2019-05-24 15:11:45 +00:00
Kevin Petit aa7754cc90 [OpenCL] Add support for the cl_arm_integer_dot_product extensions
The specification is available in the Khronos OpenCL registry:

https://www.khronos.org/registry/OpenCL/extensions/arm/cl_arm_integer_dot_product.txt

Signed-off-by: Kevin Petit <kevin.petit@arm.com>
llvm-svn: 361641
2019-05-24 14:53:52 +00:00
Richard Smith 8458c9ef42 Factor out repeated code to build 'this' expressions and mark them
referenced.

llvm-svn: 361588
2019-05-24 01:35:07 +00:00
Artem Dergachev 4e53032d9b [CFG] NFC: Remove implicit conversion from CFGTerminator to Stmt *.
Turn it into a variant class instead. This conversion does indeed save some code
but there's a plan to add support for more kinds of terminators that aren't
necessarily based on statements, and with those in mind it becomes more and more
confusing to have CFGTerminators implicitly convertible to a Stmt *.

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

llvm-svn: 361586
2019-05-24 01:34:22 +00:00
Kristof Umann ac95c86511 [analyzer] List checker/plugin options in 3 categories: released, alpha, developer
Same patch as D62093, but for checker/plugin options, the only
difference being that options for alpha checkers are implicitly marked
as alpha.

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

llvm-svn: 361566
2019-05-23 22:52:09 +00:00
Kristof Umann 7e55ed84d0 [analyzer] Hide developer-only checker/package options by default
These options are now only visible under
-analyzer-checker-option-help-developer.

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

llvm-svn: 361561
2019-05-23 22:07:16 +00:00
Kristof Umann 5bc40d9b18 [analyzer] List checkers in 3 categories: released, alpha, developer
Previously, the only way to display the list of available checkers was
to invoke the analyzer with -analyzer-checker-help frontend flag. This
however wasn't really great from a maintainer standpoint: users came
across checkers meant strictly for development purposes that weren't to
be tinkered with, or those that were still in development. This patch
creates a clearer division in between these categories.

From now on, we'll have 3 flags to display the list checkers. These
lists are mutually exclusive and can be used in any combination (for
example to display both stable and alpha checkers).

-analyzer-checker-help: Displays the list for stable, production ready
                        checkers.

-analyzer-checker-help-alpha: Displays the list for in development
                              checkers. Enabling is discouraged
                              for non-development purposes.

-analyzer-checker-help-developer: Modeling and debug checkers. Modeling
                                  checkers shouldn't be enabled/disabled
                                  by hand, and debug checkers shouldn't
                                  be touched by users.

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

llvm-svn: 361558
2019-05-23 21:46:51 +00:00
Kristof Umann e8df27d925 [analyzer] Add a new frontend flag to display all checker options
Add the new frontend flag -analyzer-checker-option-help to display all
checker/package options.

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

llvm-svn: 361552
2019-05-23 20:47:28 +00:00
Nico Weber 9b2830b46e lld-link, clang: Treat non-existent input files as possible spellos for option flags
OptTable treats arguments starting with / that aren't a known option
as filenames. This means lld-link's and clang-cl's typo correction for
unknown flags didn't do spell checking for misspelled options that start
with /.

I first tried changing OptTable, but that got pretty messy, see PR41787
comments 2 and 3.

Instead, let lld-link's and clang's (including clang-cl's) "file not
found" diagnostic check if a non-existent file looks like it could be a
mis-spelled option, and if so add a "did you mean" suggestion to the
"file not found" diagnostic.

While here, make formatting of a few diagnostics a bit more
self-consistent.

Fixes PR41787.

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

llvm-svn: 361518
2019-05-23 17:58:33 +00:00
Thomas Lively eafe8ef6f2 [WebAssembly] Add multivalue and tail-call target features
Summary:
These features will both be implemented soon, so I thought I would
save time by adding the boilerplate for both of them at the same time.

Reviewers: aheejin

Subscribers: dschuff, sbc100, jgravelle-google, hiraditya, sunfish, cfe-commits, llvm-commits

Tags: #clang, #llvm

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

llvm-svn: 361516
2019-05-23 17:26:47 +00:00
Yitzhak Mandelbaum aa7a2c547e [LibTooling] Fix dangling references in RangeSelector.
Summary:
RangeSelector had a number of cases of capturing a StringRef in a lambda, which
lead to dangling references. This change converts all uses in the API of
`StringRef` to `std::string` to avoid this problem. `std::string` in the API is
a reasonable choice, because the combinators are always storing the string
beyond the life of the combinator construction.

Reviewers: ilya-biryukov, gribozavr

Subscribers: cfe-commits

Tags: #clang

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

llvm-svn: 361514
2019-05-23 17:11:33 +00:00
Erich Keane 000228183b Ensure builtins use the target default Calling Convention
r355317 changed builtins/allocation functions to use the default calling
convention in order to support platforms that use non-cdecl calling
conventions by default.

However the default calling convention is overridable on Windows 32 bit
implementations with some of the /G options. The intent is to permit the
user to set the calling convention of normal functions, however it
should NOT apply to builtins and C++ allocation functions.

This patch ensures that the builtin/allocation functions always use the
Target specific Calling Convention, ignoring the user overridden version
of said default.

llvm-svn: 361507
2019-05-23 16:05:21 +00:00
Dmitri Gribenko 39192043bb Delete default constructors, copy constructors, move constructors, copy assignment, move assignment operators on Expr, Stmt and Decl
Reviewers: ilya-biryukov, rsmith

Subscribers: cfe-commits

Tags: #clang

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

llvm-svn: 361468
2019-05-23 09:22:43 +00:00
Richard Smith 13bf9892dc Part of P1091R3: permit structured bindings to be declared 'static' and
'thread_local' in C++20.

llvm-svn: 361424
2019-05-22 19:52:55 +00:00
Yitzhak Mandelbaum 1f46d524a1 [LibTooling] Update Stencil to use RangeSelector
Add support for creating a `StencilPart` from any `RangeSelector`, which
broadens the scope of `Stencil`.

Correspondingly, deprecate Stencil's specialized combinators `node` and `sNode`
in favor of using the new `selection` combinator directly (with the appropriate
range selector).

Reviewers: sbenza

Subscribers: cfe-commits

Tags: #clang

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

llvm-svn: 361413
2019-05-22 18:03:00 +00:00
Yitzhak Mandelbaum 3ec50e292f [LibTooling] Update Transformer to use RangeSelector instead of NodePart enum.
Transformer provides an enum to indicate the range of source text to be edited.
That support is now redundant with the new (and more general) RangeSelector
library, so we remove the custom enum support in favor of supporting any
RangeSelector.

Reviewers: ilya-biryukov

Subscribers: cfe-commits

Tags: #clang

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

llvm-svn: 361392
2019-05-22 14:48:19 +00:00
Ilya Biryukov e7230ea7c9 Reland r361148 with a fix to the buildbot failure.
Reverted in r361377.
Also reland the '.gn' files (reverted in r361389).

llvm-svn: 361391
2019-05-22 14:44:45 +00:00
Sven van Haastregt e518bb4311 [OpenCL] Support pipe keyword in C++ mode
Support the OpenCL C pipe feature in C++ for OpenCL mode, to preserve
backwards compatibility with OpenCL C.

Various changes had to be made in Parse and Sema to enable
pipe-specific diagnostics, so enable a SemaOpenCL test for C++.

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

llvm-svn: 361382
2019-05-22 13:12:20 +00:00