Commit Graph

7898 Commits

Author SHA1 Message Date
Balazs Keri 9cf39dfb38 [ASTImporter] Improve import of FileID.
Summary:
Even if the content cache has a directory and filename, it may be a virtual file.
The old code returned with error in this case, but it is worth to try to handle
the file as it were a memory buffer.

Reviewers: a.sidorin, shafik, martong, a_sidorin

Reviewed By: shafik

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

Tags: #clang

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

llvm-svn: 355000
2019-02-27 16:31:48 +00:00
Tom Roeder 521f004e99 [ASTImporter] Add support for importing ChooseExpr AST nodes.
Summary:
This allows ASTs to be merged when they contain ChooseExpr (the GNU
__builtin_choose_expr construction). This is needed, for example, for
cross-CTU analysis of C code that makes use of __builtin_choose_expr.

The node is already supported in the AST, but it didn't have a matcher
in ASTMatchers. So, this change adds the matcher and adds support to
ASTImporter.

This was originally reviewed and approved in
https://reviews.llvm.org/D58292 and submitted as r354832. It was
reverted in r354839 due to failures on the Windows CI builds.

This version fixes the test failures on Windows, which were caused by
differences in template expansion between versions of clang on different
OSes. The version of clang built with MSVC and running on Windows never
expands the template in the C++ test in ImportExpr.ImportChooseExpr in
clang/unittests/AST/ASTImporter.cpp, but the version on Linux does for
the empty arguments and -fms-compatibility.

So, this version of the patch drops the C++ test for
__builtin_choose_expr, since that version was written to catch
regressions of the logic for isConditionTrue() in the AST import code
for ChooseExpr, and those regressions are also caught by
ASTImporterOptionSpecificTestBase.ImportChooseExpr, which does work on
Windows.

Reviewers: shafik, a_sidorin, martong, aaron.ballman, rnk, a.sidorin

Subscribers: cfe-commits, jdoerfert, rnkovacs, aaron.ballman

Tags: #clang

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

llvm-svn: 354916
2019-02-26 19:26:41 +00:00
Yaxun Liu d83c74028d [OpenCL] Fix assertion due to blocks
A recent change caused assertion in CodeGenFunction::EmitBlockCallExpr when a block is called.

There is code

  Func = CGM.getOpenCLRuntime().getInvokeFunction(E->getCallee());
getCalleeDecl calls Expr::getReferencedDeclOfCallee, which does not handle
BlockExpr and returns nullptr, which causes isa to assert.

This patch fixes that.

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

llvm-svn: 354893
2019-02-26 16:20:41 +00:00
Reid Kleckner 1144084cb2 Revert r354832 "[ASTImporter] Add support for importing ChooseExpr AST nodes."
Test does not pass on Windows

llvm-svn: 354839
2019-02-26 02:22:22 +00:00
Tom Roeder 9a72870122 [ASTImporter] Add support for importing ChooseExpr AST nodes.
Summary:
This allows ASTs to be merged when they contain ChooseExpr (the GNU
__builtin_choose_expr construction). This is needed, for example, for
cross-CTU analysis of C code that makes use of __builtin_choose_expr.

The node is already supported in the AST, but it didn't have a matcher
in ASTMatchers. So, this change adds the matcher and adds support to
ASTImporter.

Reviewers: shafik, a_sidorin, martong, aaron.ballman

Subscribers: aaron.ballman, rnkovacs, jdoerfert, cfe-commits

Tags: #clang

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

llvm-svn: 354832
2019-02-25 23:24:58 +00:00
Alexander Kornienko 5858764f31 Reapply "Make static counters in ASTContext non-static." with fixes.
This reverts commit e50038e4dc.

llvm-svn: 354827
2019-02-25 22:22:09 +00:00
Michael Kruse 0336c75c36 [OpenMP 5.0] Parsing/sema support for from clause with mapper modifier.
This patch implements the parsing and sema support for the OpenMP
'from'-clause with potential user-defined mappers attached.
User-defined mappers are a new feature in OpenMP 5.0. A 'from'-clause
can have an explicit or implicit associated mapper, which instructs the
compiler to generate and use customized mapping functions. An example is
shown below:

    struct S { int len; int *d; };
    #pragma omp declare mapper(id: struct S s) map(s, s.d[0:s.len])
    struct S ss;
    #pragma omp target update from(mapper(id): ss) // use the mapper with name 'id' to map ss from device

Contributed-by: Lingda Li <lildmh@gmail.com>

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

llvm-svn: 354817
2019-02-25 20:34:15 +00:00
Vlad Tsyrklevich e50038e4dc Revert "Make static counters in ASTContext non-static."
This reverts commit r354795, I suspect it is causing test failures
on MSan sanitizer bots.

llvm-svn: 354812
2019-02-25 19:53:13 +00:00
Alexander Kornienko 00c22db89f Make static counters in ASTContext non-static.
Summary:
Fixes a data race and makes it possible to run clang-based tools in
multithreaded environment with TSan.

Reviewers: ilya-biryukov, riccibruno

Reviewed By: riccibruno

Subscribers: riccibruno, jfb, cfe-commits

Tags: #clang

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

llvm-svn: 354795
2019-02-25 16:08:46 +00:00
Michael Liao 8676f12ac6 [NFC] Minor coding style (indent) fix.
llvm-svn: 354741
2019-02-24 03:07:32 +00:00
Michael Kruse 01f670df8f [OpenMP 5.0] Parsing/sema support for to clause with mapper modifier.
This patch implements the parsing and sema support for OpenMP to clause
with potential user-defined mappers attached. User defined mapper is a
new feature in OpenMP 5.0. A to/from clause can have an explicit or
implicit associated mapper, which instructs the compiler to generate and
use customized mapping functions. An example is shown below:

    struct S { int len; int *d; };
    #pragma omp declare mapper(id: struct S s) map(s, s.d[0:s.len])
    struct S ss;
    #pragma omp target update to(mapper(id): ss) // use the mapper with name 'id' to map ss to device

Contributed-by: <lildmh@gmail.com>

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

llvm-svn: 354698
2019-02-22 22:29:42 +00:00
Richard Smith 5178c6b60a Use _Q as MS ABI mangling for char8_t.
Thanks to Yuriy Solodkyy for letting us know the mangling here.

llvm-svn: 354633
2019-02-21 23:04:35 +00:00
Leonard Chan ce1d4f1bec [Fixed Point Arithmetic] Fixed Point Comparisons
This patch implements fixed point comparisons with other fixed point types and
integers. This also provides constant expression evaluation for them.

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

llvm-svn: 354621
2019-02-21 20:50:09 +00:00
Michael Kruse 4304e9d143 [OpenMP 5.0] Parsing/sema support for map clause with mapper modifier.
This patch implements the parsing and sema support for OpenMP map
clauses with potential user-defined mapper attached. User defined mapper
is a new feature in OpenMP 5.0. A map clause can have an explicit or
implicit associated mapper, which instructs the compiler to generate
extra data mapping. An example is shown below:

    struct S { int len; int *d; };
    #pragma omp declare mapper(id: struct S s) map(s, s.d[0:s.len])
    struct S ss;
    #pragma omp target map(mapper(id) tofrom: ss) // use the mapper with name 'id' to map ss

Contributed-by: Lingda Li <lildmh@gmail.com>

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

llvm-svn: 354347
2019-02-19 16:38:20 +00:00
Gabor Marton e331e63af2 [ASTImporter] Find previous friend function template
Reviewers: a_sidorin, shafik, a.sidorin

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

Tags: #clang

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

llvm-svn: 354267
2019-02-18 13:09:27 +00:00
Bruno Ricci 41d4e56d5b [NFC] Add a llvm_unreachable to silence a warning in SubstObjCTypeArgsVisitor
All cases in the switch are covered. NFC.

llvm-svn: 354233
2019-02-17 19:18:38 +00:00
Bruno Ricci 46148f2053 Recommit "[AST] Factor out the logic of the various Expr::Ignore*"
(Originally commited in r354215 and reverted in r354216 because of a
 missed failing clang-tidy test (fix in r354228))

Now that the implementation of all of the Expr::Ignore* is in Expr.cpp
we can try to remove some duplication. Do this by separating the logic
of the Expr::Ignore* from the iterative loop.

This is NFC, except for one change: IgnoreParenImpCasts now skips,
among other things, everything that IgnoreImpCasts skips. This means
FullExpr are now skipped by IgnoreParenImpCasts. This was likely an
oversight when FullExpr was added to the nodes skipped by IgnoreImpCasts.

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

Reviewed By: aaron.ballman (with comments from void and rnk)

llvm-svn: 354232
2019-02-17 18:50:51 +00:00
Bruno Ricci d403800959 Revert "[AST] Factor out the logic of the various Expr::Ignore*"
This breaks some clang-tidy checks. For some reason they were
not included in check-clang ?

llvm-svn: 354216
2019-02-17 13:47:29 +00:00
Bruno Ricci 3985172b4f [AST] Factor out the logic of the various Expr::Ignore*
Now that the implementation of all of the Expr::Ignore* is in Expr.cpp
we can try to remove some duplication. Do this by separating the logic of
the Expr::Ignore* from the iterative loop.

This is NFC, except for one change: IgnoreParenImpCasts now skips, among
other things, everything that IgnoreImpCasts skips. This means FullExpr
are now skipped by IgnoreParenImpCasts. This was likely an oversight when
FullExpr was added to the nodes skipped by IgnoreImpCasts.

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

Reviewed By: aaron.ballman (with comments from void and rnk)

llvm-svn: 354215
2019-02-17 13:32:39 +00:00
Erik Pilkington eac7c3ffaf [Sema] Diagnose floating point conversions based on target semantics
...instead of just comparing rank. Also, fix a bad warning about
_Float16, since its declared out of order in BuiltinTypes.def,
meaning comparing rank using BuiltinType::getKind() is incorrect.

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

llvm-svn: 354190
2019-02-16 01:11:47 +00:00
Volodymyr Sapsai bcb4f7208d [ObjC generics] Fix applying `__kindof` to the type parameter.
Fixes the warning about incompatible pointer types on assigning to a
subclass of type argument an expression of type `__kindof TypeParam`.

We already have a mechanism in `ASTContext::canAssignObjCInterfaces`
that handles `ObjCObjectType` with `__kindof`. But it wasn't triggered
because during type substitution `__kindof TypeParam` was represented as
`AttributedType` with attribute `ObjCKindOf` and equivalent type
`TypeArg`. For assignment type checking we use canonical types so
attributed type was desugared and the attribute was ignored.

The fix is in checking transformed `AttributedType` and pushing
`__kindof` down into `ObjCObjectType` when necessary.

rdar://problem/38514910

Reviewers: ahatanak, erik.pilkington, doug.gregor

Reviewed By: doug.gregor

Subscribers: jkorous, dexonsmith, manmanren, jordan_rose, doug.gregor, cfe-commits

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

llvm-svn: 354189
2019-02-16 01:01:08 +00:00
Volodymyr Sapsai 78b84cf991 [ObjC] For type substitution in generics use a regular recursive type visitor.
Switch to the inheritance-based visitor from the lambda-based visitor to
allow both preorder and postorder customizations during type
transformation. NFC intended.

Reviewers: ahatanak, erik.pilkington

Reviewed By: erik.pilkington

Subscribers: jkorous, dexonsmith, cfe-commits

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

llvm-svn: 354180
2019-02-15 22:14:58 +00:00
Volodymyr Sapsai 4b512c36b6 [ObjC] Fix non-canonical types preventing type arguments substitution.
`QualType::substObjCTypeArgs` doesn't go past non-canonical types and as
the result misses some of the substitutions like `ObjCTypeParamType`.

Update `SimpleTransformVisitor` to traverse past the type sugar.

Reviewers: ahatanak, erik.pilkington

Reviewed By: erik.pilkington

Subscribers: jkorous, dexonsmith, cfe-commits

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

llvm-svn: 354164
2019-02-15 20:17:45 +00:00
Gabor Marton 302f300a7a [ASTImporter] Import every Decl in lambda record
Summary:
Previously only the fields were imported. Now every Decl is imported.
This way the destructor decl is not missing after import.

Patch by balazske (Balázs Kéri)

Reviewers: a.sidorin, shafik

Reviewed By: shafik

Subscribers: balazske, cfe-commits, Szelethus, martong, dkrupp

Tags: #clang

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

llvm-svn: 354120
2019-02-15 12:04:05 +00:00
Richard Smith a6e8d5e554 PR40642: Fix determination of whether the final statement of a statement
expression is a discarded-value expression.

Summary:
We used to get this wrong in three ways:

1) During parsing, an expression-statement followed by the }) ending a
   statement expression was always treated as producing the value of the
   statement expression. That's wrong for ({ if (1) expr; })
2) During template instantiation, various kinds of statement (most
   statements not appearing directly in a compound-statement) were not
   treated as discarded-value expressions, resulting in missing volatile
   loads (etc).
3) In all contexts, an expression-statement with attributes was not
   treated as producing the value of the statement expression, eg
   ({ [[attr]] expr; }).

Also fix incorrect enforcement of OpenMP rule that directives can "only
be placed in the program at a position where ignoring or deleting the
directive would result in a program with correct syntax". In particular,
a label (be it goto, case, or default) should not affect whether
directives are permitted.

Reviewers: aaron.ballman, rjmccall

Subscribers: cfe-commits

Tags: #clang

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

llvm-svn: 354090
2019-02-15 00:27:53 +00:00
Gabor Marton 458d1457fb [ASTImporter] Check visibility/linkage of functions and variables
Summary:
During import of a global variable with external visibility the lookup
will find variables (with the same name) but with static visibility.
Clearly, we cannot put them into the same redecl chain.  The same is
true in case of functions.  In this fix we filter the lookup results and
consider only those which have the same visibility as the decl we
currently import.

We consider two decls in two anonymous namsepaces to have the same
visibility only if they are imported from the very same translation
unit.

Reviewers: a_sidorin, shafik, a.sidorin

Reviewed By: shafik

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

Tags: #clang

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

llvm-svn: 354027
2019-02-14 13:07:03 +00:00
Clement Courbet 8c3343dfd5 [Builtins] Treat `bcmp` as a builtin.
Summary:
This makes it consistent with `memcmp` and `__builtin_bcmp`.

Also see the discussion in https://reviews.llvm.org/D56593.

Reviewers: jyknight

Subscribers: kristina, cfe-commits

Tags: #clang

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

llvm-svn: 354023
2019-02-14 12:00:34 +00:00
Yaxun Liu c18e9ecd4f [CUDA][HIP] Use device side kernel and variable names when registering them
__hipRegisterFunction and __hipRegisterVar need to accept device side kernel and variable names
so that HIP runtime can associate kernel stub functions in host code with kernel symbols in fat binaries,
and associate shadow variables in host code with device variables in fat binaries.

Currently, clang assumes kernel functions and device variables have the same name as the kernel
stub functions and shadow variables. However, when host is compiled in windows with MSVC C++
ABI and device is compiled with Itanium C++ ABI (e.g. AMDGPU), kernels and device symbols in fat
binary are mangled differently than host.

This patch gets the device side kernel and variable name by mangling them in the mangle context
of aux target.

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

llvm-svn: 354004
2019-02-14 02:00:09 +00:00
Stephan Bergmann 84dcc8f36f Look through typedefs in getFunctionTypeWithExceptionSpec
Fixes https://bugs.llvm.org/show_bug.cgi?id=40658

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

llvm-svn: 353931
2019-02-13 09:39:17 +00:00
Fangrui Song 9ac13a1244 Use llvm::is_contained. NFC
llvm-svn: 353635
2019-02-10 05:54:57 +00:00
Eli Friedman 041adb0ed0 Fix buildbot failure from r353569.
I assumed lvalue-to-rvalue conversions of array type would never
happen, but apparently clang-tidy tries in some cases.

llvm-svn: 353598
2019-02-09 02:22:17 +00:00
Eli Friedman 3bf72d7d64 [Sema] Make string literal init an rvalue.
This allows substantially simplifying the expression evaluation code,
because we don't have to special-case lvalues which are actually string
literal initialization.

This currently throws away an optimization where we would avoid creating
an array APValue for string literal initialization.  If we really want
to optimize this case, we should fix APValue so it can store simple
arrays more efficiently, like llvm::ConstantDataArray.  This shouldn't
affect the memory usage for other string literals.  (Not sure if this is
a blocker; I don't think string literal init is common enough for this
to be a serious issue, but I could be wrong.)

The change to test/CodeGenObjC/encode-test.m is a weird side-effect of
these changes: we currently don't constant-evaluate arrays in C, so the
strlen call shouldn't be folded, but lvalue string init managed to get
around that check.  I this this is fine.

Fixes https://bugs.llvm.org/show_bug.cgi?id=40430 .

llvm-svn: 353569
2019-02-08 21:18:46 +00:00
Akira Hatanaka 67b1b451b5 Pass the base element type of an array type to the visit method instead
of the array type itself.

This fixes a bug found by inspection that was introduced in r353459. I
don't have a test case for this since we don't yet have types that would
make the containing C struct non-trivial to copy/move but wouldn't make
it non-trivial to default-initialize or destruct.

llvm-svn: 353556
2019-02-08 19:46:53 +00:00
Gabor Marton fc638d64e8 [AST] Fix structural inequivalence of operators
Summary: Operators kind was not checked, so we reported e.g. op- to be equal with op+

Reviewers: shafik, a_sidorin, aaron.ballman

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

Tags: #clang

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

llvm-svn: 353504
2019-02-08 08:55:32 +00:00
Akira Hatanaka 5fbdccd834 [Sema][ObjC] Disallow non-trivial C struct fields in unions.
This patch fixes a bug where clang doesn’t reject union fields of
non-trivial C struct types. For example:

```
// This struct is non-trivial under ARC.
struct S0 {
  id x;
};

union U0 {
  struct S0 s0; // clang should reject this.
  struct S0 s1; // clang should reject this.
};

void test(union U0 a) {
  // Previously, both 'a.s0.x' and 'a.s1.x' were released in this
  // function.
}
```

rdar://problem/46677858

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

llvm-svn: 353459
2019-02-07 20:21:46 +00:00
Richard Smith 520a37f52f [modules] Fix handling of initializers for templated global variables.
For global variables with unordered initialization that are instantiated
within a module, we previously did not emit the global (or its
initializer) at all unless it was used in the importing translation unit
(and sometimes not even then!), leading to misbehavior and link errors.

We now emit the initializer for an instantiated global variable with
unordered initialization with side-effects in a module into every
translation unit that imports the module. This is unfortunate, but
mostly matches the behavior of a non-modular compilation and seems to be
the best that we can reasonably do.

llvm-svn: 353240
2019-02-05 23:37:13 +00:00
Bruno Ricci e64aee87a0 [AST] Update the comments of the various Expr::Ignore* + Related cleanups
The description of what the various Expr::Ignore* do has drifted from the
actual implementation.

Inspection reveals that IgnoreParenImpCasts() is not equivalent to doing
IgnoreParens() + IgnoreImpCasts() until reaching a fixed point, but
IgnoreParenCasts() is equivalent to doing IgnoreParens() + IgnoreCasts()
until reaching a fixed point. There is also a fair amount of duplication
in the various Expr::Ignore* functions which increase the chance of further
future inconsistencies. In preparation for the next patch which will factor
out the implementation of the various Expr::Ignore*, do the following cleanups:

Remove Stmt::IgnoreImplicit, in favor of Expr::IgnoreImplicit. IgnoreImplicit
is the only function among all of the Expr::Ignore* which is available in Stmt.
There are only a few users of Stmt::IgnoreImplicit. They can just use instead
Expr::IgnoreImplicit like they have to do for the other Ignore*.

Move Expr::IgnoreImpCasts() from Expr.h to Expr.cpp. This made no difference
in the run-time with my usual benchmark (-fsyntax-only on all of Boost).

While we are at it, make IgnoreParenNoopCasts take a const reference to the
ASTContext for const correctness.

Update the comments to match what the Expr::Ignore* are actually doing.
I am not sure that listing exactly what each Expr::Ignore* do is optimal,
but it certainly looks better than the current state which is in my opinion
between misleading and just plain wrong.

The whole patch is NFC (if you count removing Stmt::IgnoreImplicit as NFC).

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

Reviewed By: aaron.ballman

llvm-svn: 353006
2019-02-03 19:50:56 +00:00
Bruno Ricci 64bebe980a [ASTDump] Add a flag indicating whether a CXXThisExpr is implicit
There is currently no way to distinguish implicit from explicit
CXXThisExpr in the AST dump output.

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

Reviewed By: steveire

llvm-svn: 353003
2019-02-03 18:20:27 +00:00
Stephen Kelly c49330152e [AST] Extract ASTNodeTraverser class from ASTDumper
Summary:
This new traverser class allows clients to re-use the traversal logic
which was previously part of ASTDumper.  This means that alternative
visit logic may be implemented, such as

* Dump to alternative data formats such as JSON
* Implement AST Matcher parent/child visitation matching AST dumps

Reviewers: aaron.ballman

Subscribers: jfb, cfe-commits

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

llvm-svn: 352989
2019-02-03 14:06:54 +00:00
Eric Fiselier 24a2a48bc2 Fix handling of usual deallocation functions in various configuratios.
Clang allows users to enable or disable various types of allocation
and deallocation regardless of the C++ dialect. When extended new/delete
overloads are enabled in older dialects, we need to treat them as if
they're usual.

Also, disabling one usual deallocation form shouldn't
disable any others. For example, disabling aligned allocation in C++2a
should have no effect on destroying delete.

llvm-svn: 352980
2019-02-03 03:44:31 +00:00
Akira Hatanaka a50489754a [Sema][ObjC] Allow declaring ObjC pointer members with non-trivial
ownership qualifications in C++ unions under ARC.

An ObjC pointer member with non-trivial ownership qualifications causes
all of the defaulted special functions of the enclosing union to be
defined as deleted, except when the member has an in-class initializer,
the default constructor isn't defined as deleted.

rdar://problem/34213306

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

llvm-svn: 352949
2019-02-02 02:23:40 +00:00
Eric Fiselier de9ffab1ca Don't use ASTContext in DeclOpenMP.h because it's still incomplete.
llvm-svn: 352919
2019-02-01 21:19:20 +00:00
Michael Kruse 251e1488e1 [OpenMP 5.0] Parsing/sema support for "omp declare mapper" directive.
This patch implements parsing and sema for "omp declare mapper"
directive. User defined mapper, i.e., declare mapper directive, is a new
feature in OpenMP 5.0. It is introduced to extend existing map clauses
for the purpose of simplifying the copy of complex data structures
between host and device (i.e., deep copy). An example is shown below:

    struct S {  int len;  int *d; };
    #pragma omp declare mapper(struct S s) map(s, s.d[0:s.len]) // Memory region that d points to is also mapped using this mapper.

Contributed-by: Lingda Li <lildmh@gmail.com>

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

llvm-svn: 352906
2019-02-01 20:25:04 +00:00
Stephen Kelly ee7e4cf48f [ASTDump] Inline traverse methods into class
This API will be extracted into a new template class.  This change will
make the follow-up commit easier to review.

llvm-svn: 352676
2019-01-30 21:48:32 +00:00
Erik Pilkington 9c3b588db9 Add a new builtin: __builtin_dynamic_object_size
This builtin has the same UI as __builtin_object_size, but has the
potential to be evaluated dynamically. It is meant to be used as a
drop-in replacement for libraries that use __builtin_object_size when
a dynamic checking mode is enabled. For instance,
__builtin_object_size fails to provide any extra checking in the
following function:

  void f(size_t alloc) {
    char* p = malloc(alloc);
    strcpy(p, "foobar"); // expands to __builtin___strcpy_chk(p, "foobar", __builtin_object_size(p, 0))
  }

This is an overflow if alloc < 7, but because LLVM can't fold the
object size intrinsic statically, it folds __builtin_object_size to
-1. With __builtin_dynamic_object_size, alloc is passed through to
__builtin___strcpy_chk.

rdar://32212419

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

llvm-svn: 352665
2019-01-30 20:34:53 +00:00
Stephen Kelly 7e880b0262 [ASTDump] Make method definition order matches declaration order
This will make follow-up changes easier to review.

llvm-svn: 352663
2019-01-30 20:06:52 +00:00
Stephen Kelly 0808a25182 [ASTDump] Re-arrange method declarations to group Visit together
This will make follow-up commits easier to review.

llvm-svn: 352661
2019-01-30 20:03:47 +00:00
Stephen Kelly 6d110d6afe [ASTDump] Rename methods which are conceptually Visits
This is consistent with the TextNodeDumper, and is the appropriate name
for the traverser class which will be extracted.

llvm-svn: 352657
2019-01-30 19:49:49 +00:00
Stephen Kelly d8aeb55e64 [ASTDump] NFC: Inline vestigial methods
This was a porting aid.

llvm-svn: 352656
2019-01-30 19:41:04 +00:00
Stephen Kelly b6318c923e [ASTDump] Move Decl node dumping to TextNodeDumper
Reviewers: aaron.ballman

Subscribers: jfb, cfe-commits

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

llvm-svn: 352655
2019-01-30 19:32:48 +00:00
Roman Lebedev 4f9e3ce070 [ASTDumper][OpenMP] CapturedDecl has a 'nothrow' bit
Summary:
Was trying to understand how complicated it would be to write
a clang-tidy `openmp-exception-escape`-ish check once D57100 lands.

Just so it happens, all the data is already there,
it is just conveniently omitted from AST dump.

Reviewers: aaron.ballman, steveire, ABataev

Reviewed By: ABataev

Subscribers: ABataev, guansong, cfe-commits

Tags: #openmp, #clang

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

llvm-svn: 352631
2019-01-30 15:41:20 +00:00
Stephen Kelly aecce85da6 NFC: Move GenericSelectionExpr dump to NodeDumper
Reviewers: aaron.ballman

Subscribers: cfe-commits

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

llvm-svn: 352558
2019-01-29 22:58:28 +00:00
Stephen Kelly fbf40f4500 NFC: Implement GenericSelectionExpr::Association dump with Visitor
Reviewers: aaron.ballman

Subscribers: cfe-commits

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

llvm-svn: 352552
2019-01-29 22:22:55 +00:00
Matt Arsenault 58fc8082a8 OpenCL: Use length modifier for warning on vector printf arguments
Re-enable format string warnings on printf.

The warnings are still incomplete. Apparently it is undefined to use a
vector specifier without a length modifier, which is not currently
warned on. Additionally, type warnings appear to not be working with
the hh modifier, and aren't warning on all of the special restrictions
from c99 printf.

llvm-svn: 352540
2019-01-29 20:49:54 +00:00
Bruno Ricci 1ec7fd35ce Re-commit "[AST] Introduce GenericSelectionExpr::Association"
This time with a fix to make gcc 4.8 happy.

llvm-svn: 352486
2019-01-29 12:57:11 +00:00
Mikael Holmen c1c97aa22d Remove unused variable to silence compiler warning
llvm-svn: 352456
2019-01-29 06:53:31 +00:00
Shafik Yaghmour 96b3d2094f [ASTImporter] Fix handling of overriden methods during ASTImport
Summary:
When importing classes we may add a CXXMethodDecl more than once to a CXXRecordDecl when handling overrides. This patch will fix the cases we currently know about and handle the case where we are only dealing with declarations.

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

llvm-svn: 352436
2019-01-28 21:55:33 +00:00
Bruno Ricci 586d949b9c Revert "[AST] Introduce GenericSelectionExpr::Association"
This breaks GCC 4.8.4. Reported by email by Hans Wennborg.

llvm-svn: 352403
2019-01-28 18:40:26 +00:00
Roman Lebedev 23019f946d [clang][OpenMP] OMPFlushClause is synthetic, no such clause exists
Summary:
As discussed in https://reviews.llvm.org/D57112#inline-506781,
'flush' clause does not exist in the OpenMP spec, it can not be
specified, and `OMPFlushClause` class is just a helper class.

Therefore `OPENMP_CLAUSE()` in `clang/Basic/OpenMPKinds.def`
should not contain 'flush' "clause".

I have simply removed the `OPENMP_CLAUSE(flush, OMPFlushClause)`
from `clang/Basic/OpenMPKinds.def`, grepped for `OPENMP_CLAUSE`
and added `OPENMP_CLAUSE(flush, OMPFlushClause)` back to the **every**
place where `OPENMP_CLAUSE` is defined and `clang/Basic/OpenMPKinds.def`
is then included.

So as-is, this patch is a NFC. Possibly, some of these
`OPENMP_CLAUSE(flush, OMPFlushClause)` should be dropped,
i don't really know.

Test plan: `ninja check-clang`

Reviewers: ABataev

Reviewed By: ABataev

Subscribers: guansong, arphaman, cfe-commits

Tags: #openmp

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

llvm-svn: 352390
2019-01-28 17:04:11 +00:00
Bruno Ricci 9feaecf22c [AST] Introduce GenericSelectionExpr::Association
Introduce a new class GenericSelectionExpr::Association which bundle together
an association expression and its TypeSourceInfo.

An iterator GenericSelectionExpr::AssociationIterator is additionally added to
make it possible to iterate over ranges of Associations. This iterator is a
kind of proxy iterator which abstract over how exactly the expressions and the
TypeSourceInfos are stored.

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

Reviewed By: aaron.ballman

Reviewers: aaron.ballman, steveire, dblaikie, mclow.lists
llvm-svn: 352369
2019-01-28 14:18:11 +00:00
Anastasia Stulova c61eaa5920 Rename getTypeQualifiers to getMethodQualifiers.
Use more descriptive name for the method qualifiers getter.

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

llvm-svn: 352349
2019-01-28 11:37:49 +00:00
Bruno Ricci db07683d86 [AST] Pack GenericSelectionExpr
Store the controlling expression, the association expressions and the
corresponding TypeSourceInfos as trailing objects.

Additionally use the bit-fields of Stmt to store one SourceLocation,
saving one additional pointer. This saves 3 pointers in total per
GenericSelectionExpr.

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

Reviewed By: aaron.ballman

Reviewers: aaron.ballman, steveire
llvm-svn: 352276
2019-01-26 14:15:10 +00:00
Bruno Ricci 94498c70ae [AST][NFC] Various cleanups to GenericSelectionExpr
Various cleanups to GenericSelectionExpr factored out of D57104. In particular:

1. Move the friend declaration to the top.
2. Introduce a constant ResultDependentIndex instead of the magic "-1".
3. clang-format
4. Group the member function together so that they can be removed as one block
   by D57106.

NFC.

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

Reviewed By: aaron.ballman

llvm-svn: 352275
2019-01-26 13:58:15 +00:00
Simon Pilgrim 1f4b979483 Fix "control reaches end of non-void function" warning. NFCI.
llvm-svn: 352192
2019-01-25 11:36:51 +00:00
George Karpenkov 42c9473ede [AST] Add a method to get a call type from an ObjCMessageExpr
Due to references, expression type does not always correspond to an
expected method return type (e.g. for a method returning int & the
expression type of the call would still be int).
We have a helper method for getting the expected type on CallExpr, but
not on ObjCMessageExpr.

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

llvm-svn: 352147
2019-01-25 01:23:37 +00:00
Gabor Marton 41f2046642 [ASTImporter] Fix inequality of functions with different attributes
Summary:
FunctionType::ExtInfo holds such properties of a function which are needed
mostly for code gen. We should not compare these bits when checking for
structural equivalency.
Checking ExtInfo caused false ODR errors during CTU analysis (of tmux).

Reviewers: a_sidorin, a.sidorin, shafik

Subscribers: rnkovacs, dkrupp, Szelethus, cfe-commits

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

llvm-svn: 352050
2019-01-24 14:47:44 +00:00
Leonard Chan 009f9e8231 [Sema] Fix Modified Type in address_space AttributedType
This is a fix for https://reviews.llvm.org/D51229 where we pass the
address_space qualified type as the modified type of an AttributedType. This
change now instead wraps the AttributedType with either the address_space
qualifier or a DependentAddressSpaceType.

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

llvm-svn: 351997
2019-01-24 00:11:35 +00:00
Raphael Isemann 1c5d23f140 [ASTImporter] Fix importing OperatorDelete from CXXConstructorDecl
Summary:
Shafik found out that importing a CXXConstructorDecl will create a translation unit that
causes Clang's CodeGen to crash. The reason for that is that we don't copy the OperatorDelete
from the CXXConstructorDecl when importing. This patch fixes it and adds a test case for that.

Reviewers: shafik, martong, a_sidorin, a.sidorin

Reviewed By: martong, a_sidorin

Subscribers: rnkovacs, cfe-commits

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

llvm-svn: 351849
2019-01-22 17:59:45 +00:00
Serge Guelton be88539b85 Replace llvm::isPodLike<...> by llvm::is_trivially_copyable<...>
As noted in https://bugs.llvm.org/show_bug.cgi?id=36651, the specialization for
isPodLike<std::pair<...>> did not match the expectation of
std::is_trivially_copyable which makes the memcpy optimization invalid.

This patch renames the llvm::isPodLike trait into llvm::is_trivially_copyable.
Unfortunately std::is_trivially_copyable is not portable across compiler / STL
versions. So a portable version is provided too.

Note that the following specialization were invalid:

    std::pair<T0, T1>
    llvm::Optional<T>

Tests have been added to assert that former specialization are respected by the
standard usage of llvm::is_trivially_copyable, and that when a decent version
of std::is_trivially_copyable is available, llvm::is_trivially_copyable is
compared to std::is_trivially_copyable.

As of this patch, llvm::Optional is no longer considered trivially copyable,
even if T is. This is to be fixed in a later patch, as it has impact on a
long-running bug (see r347004)

Note that GCC warns about this UB, but this got silented by https://reviews.llvm.org/D50296.

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

llvm-svn: 351701
2019-01-20 21:19:56 +00:00
Stephen Kelly 8805f67da9 [ASTDump] NFC: Convert iterative loops to cxx_range_for
This is coming up a lot in reviews. Better just to change them all at
once.

llvm-svn: 351647
2019-01-19 09:57:59 +00:00
Stephen Kelly aaebc5f2c5 [ASTDump] NFC: Use `const auto` in cxx_range_for loops
This is coming up a lot in reviews. Better just to do them all at once.

llvm-svn: 351646
2019-01-19 09:57:51 +00:00
Stephen Kelly 25f18bfd4f Move decl context dumping to TextNodeDumper
Summary: Only an obscure case is moved.

Reviewers: aaron.ballman

Subscribers: cfe-commits

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

llvm-svn: 351637
2019-01-19 09:05:55 +00:00
Chandler Carruth 2946cd7010 Update the file headers across all of the LLVM projects in the monorepo
to reflect the new license.

We understand that people may be surprised that we're moving the header
entirely to discuss the new license. We checked this carefully with the
Foundation's lawyer and we believe this is the correct approach.

Essentially, all code in the project is now made available by the LLVM
project under our new license, so you will see that the license headers
include that license only. Some of our contributors have contributed
code under our old license, and accordingly, we have retained a copy of
our old license notice in the top-level files in each project and
repository.

llvm-svn: 351636
2019-01-19 08:50:56 +00:00
Johannes Doerfert ac991bbb44 Emit !callback metadata and introduce the callback attribute
With commit r351627, LLVM gained the ability to apply (existing) IPO
  optimizations on indirections through callbacks, or transitive calls.
  The general idea is that we use an abstraction to hide the middle man
  and represent the callback call in the context of the initial caller.
  It is described in more detail in the commit message of the LLVM patch
  r351627, the llvm::AbstractCallSite class description, and the
  language reference section on callback-metadata.

  This commit enables clang to emit !callback metadata that is
  understood by LLVM. It does so in three different cases:
    1) For known broker functions declarations that are directly
       generated, e.g., __kmpc_fork_call for the OpenMP pragma parallel.
    2) For known broker functions that are identified by their name and
       source location through the builtin detection, e.g.,
       pthread_create from the POSIX thread API.
    3) For user annotated functions that carry the "callback(callee, ...)"
       attribute. The attribute has to include the name, or index, of
       the callback callee and how the passed arguments can be
       identified (as many as the callback callee has). See the callback
       attribute documentation for detailed information.

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

llvm-svn: 351629
2019-01-19 05:36:54 +00:00
Stephen Kelly 1e07f4e2e7 [ASTDump] NFC: Move variable into if() statement
llvm-svn: 351605
2019-01-18 22:15:09 +00:00
Stephen Kelly 4e35baa842 [ASTDump] NFC: Remove redundant condition
These conditions are duplicated from the dumpDeclContext function called
within the if(). This is presumably an attempt to avoid calling the
function in the case it will do nothing.

That may have made sense in the past if the code was different, but it
doesn't make sense now.

llvm-svn: 351604
2019-01-18 22:15:05 +00:00
Stephen Kelly f4129fd58b [ASTDump] NFC: Remove non-needed braces
llvm-svn: 351603
2019-01-18 22:14:59 +00:00
Stephen Kelly bbd08cce79 [ASTDump] Mark null params with a tag rather than a child node
Reviewers: aaron.ballman

Subscribers: cfe-commits

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

llvm-svn: 351601
2019-01-18 22:00:16 +00:00
Stephen Kelly 5110ebd9fe [ASTDump] Mark BlockDecls which capture this with a tag
Summary:
Removal of the child node makes it easier to separate traversal from
output generation.

Reviewers: aaron.ballman

Subscribers: cfe-commits

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

llvm-svn: 351600
2019-01-18 21:55:24 +00:00
Stephen Kelly 149119dc5f [ASTDump] Mark variadic declarations with a tag instead of child node
Summary:
This makes it easier to separate traversal of the AST from output
generation.

Reviewers: aaron.ballman

Subscribers: cfe-commits

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

llvm-svn: 351597
2019-01-18 21:38:30 +00:00
Leonard Chan d3f3e16293 [Fixed Point Arithmetic] Fixed Point Addition Constant Expression Evaluation
This patch includes logic for constant expression evaluation of fixed point additions.

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

llvm-svn: 351593
2019-01-18 21:04:25 +00:00
Erich Keane 8e77216c1a [NFC] Fix wParentheses warning in ASTContext getFixedPointSemantics
Change-Id: I862f00a548236872fe24f7da8eb2bf7917e123ff
llvm-svn: 351576
2019-01-18 19:31:54 +00:00
Leonard Chan 86285d2e17 [Fixed Point Arithmetic] Add APFixedPoint to APValue
This adds APFixedPoint to the union of values that can be represented with an APValue.

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

llvm-svn: 351368
2019-01-16 18:53:05 +00:00
Leonard Chan 2044ac89aa [Fixed Point Arithmetic] Fixed Point Addition
This patch covers addition between fixed point types and other fixed point
types or integers, using the conversion rules described in 4.1.4 of N1169.

Usual arithmetic rules do not apply to binary operations when one of the
operands is a fixed point type, and the result of the operation must be
calculated with the full precision of the operands, so we should not perform
any casting to a common type.

This patch does not include constant expression evaluation for addition of
fixed point types. That will be addressed in another patch since I think this
one is already big enough.

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

llvm-svn: 351364
2019-01-16 18:13:59 +00:00
Stephen Kelly a4fd381dc2 Re-order type param children of ObjC nodes
Reviewers: aaron.ballman

Subscribers: cfe-commits

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

llvm-svn: 351272
2019-01-15 23:07:30 +00:00
Stephen Kelly e80e4cbd20 NFC: Some cleanups that I missed in the previous commit
llvm-svn: 351271
2019-01-15 23:05:11 +00:00
Stephen Kelly 42d9950073 Re-order overrides in FunctionDecl dump
Output all content which is local to the FunctionDecl before traversing
to child AST nodes.

This is necessary so that all of the part which is local to the
FunctionDecl can be split into a different method.

Reviewers: aaron.ballman

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

llvm-svn: 351269
2019-01-15 22:50:37 +00:00
Stephen Kelly b418937793 NFC: Replace iterator loop with cxx_range_for
llvm-svn: 351268
2019-01-15 22:45:46 +00:00
Stephen Kelly fbf424e101 Implement BlockDecl::Capture dump in terms of visitors
Reviewers: aaron.ballman

Subscribers: cfe-commits

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

llvm-svn: 351239
2019-01-15 20:41:37 +00:00
Stephen Kelly 3cdd1a7d47 NFC: Implement OMPClause dump in terms of visitors
Reviewers: aaron.ballman

Subscribers: cfe-commits

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

llvm-svn: 351236
2019-01-15 20:31:31 +00:00
Stephen Kelly 0e050fa542 Implement CXXCtorInitializer dump in terms of Visitor
Reviewers: aaron.ballman

Subscribers: cfe-commits

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

llvm-svn: 351235
2019-01-15 20:17:33 +00:00
Stephen Kelly d83fe89497 NFC: Move Decl node handling to TextNodeDumper
Reviewers: aaron.ballman

Subscribers: cfe-commits

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

llvm-svn: 351175
2019-01-15 09:35:52 +00:00
Stephen Kelly f08ca204ac [ASTDump] NFC: Move dump of type nodes to NodeDumper
Reviewers: aaron.ballman

Subscribers: cfe-commits

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

llvm-svn: 351172
2019-01-15 09:30:00 +00:00
Stephen Kelly 58c6504543 [ASTDump] NFC: Move dumping of QualType node to TextNodeDumper
Reviewers: aaron.ballman

Subscribers: cfe-commits

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

llvm-svn: 351116
2019-01-14 20:15:29 +00:00
Stephen Kelly bc2438d014 [ASTDump] NFC: Canonicalize handling of TypeLocInfo
Summary: No need to avoid the Visit method.

Reviewers: aaron.ballman

Subscribers: cfe-commits

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

llvm-svn: 351115
2019-01-14 20:13:09 +00:00
Stephen Kelly 449fa76d05 [ASTDump] NFC: Move Type Visit implementation to TextNodeDumper
Reviewers: aaron.ballman

Subscribers: cfe-commits

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

llvm-svn: 351114
2019-01-14 20:11:02 +00:00
Stephen Kelly 4b5e7cd416 NFC: Fix nits I missed before
llvm-svn: 351112
2019-01-14 19:50:34 +00:00
Anastasia Stulova d1986d1b5a [OpenCL] Set generic addr space of 'this' in special class members.
Set address spaces of 'this' param correctly for implicit special
class members.

This also changes initialization conversion sequence to separate
address space conversion from other qualifiers in case of binding
reference to a temporary. In this case address space conversion  
should happen after the binding (unlike for other quals). This is
needed to materialize it correctly in the alloca address space.

Initial patch by Mikael Nilssoni!

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

llvm-svn: 351053
2019-01-14 11:44:22 +00:00
Stephen Kelly 07b76d23b4 [ASTDump] NFC: Move dump of individual Stmts to TextNodeDumper
Reviewers: aaron.ballman

Subscribers: cfe-commits

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

llvm-svn: 351014
2019-01-12 16:53:27 +00:00
Stephen Kelly 63a6f3acbd Implement TemplateArgument dumping in terms of Visitor
Summary: Split the output streaming from the traversal to other AST nodes.

Reviewers: aaron.ballman

Subscribers: cfe-commits

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

llvm-svn: 351012
2019-01-12 16:35:37 +00:00
Stephen Kelly 9bc90a2829 [ASTDump] Change parameter to StringRef
llvm-svn: 351011
2019-01-12 15:45:05 +00:00
Stephen Kelly de82b5bef1 NFC: Port loop to cxx_range_for
llvm-svn: 350984
2019-01-12 00:42:59 +00:00
Stephen Kelly db8fac140e Implement Attr dumping in terms of visitors
Remove now-vestigial dumpType and dumpBareDeclRef methods. The old
tablegen generated code used to expect them to be present, but the new
generated code has no such requirement.

Reviewers: aaron.ballman

Subscribers: mgorny, cfe-commits

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

llvm-svn: 350958
2019-01-11 19:16:01 +00:00
Stephen Kelly 0df805db73 [ASTDump] Add utility for dumping a label with child nodes
Summary:
Use it to add optional label nodes to Stmt dumps.  This preserves
behavior of InitExprList dump:

// CHECK-NEXT: `-InitListExpr {{.+}} <col:13, col:15> 'U [3]'
// CHECK-NEXT:   |-array_filler: InitListExpr {{.+}} <col:15> 'U' field Field {{.+}} 'i' 'int'
// CHECK-NEXT:   `-InitListExpr {{.+}} <col:14> 'U' field Field {{.+}} 'i' 'int'
// CHECK-NEXT:     `-IntegerLiteral {{.+}} <col:14> 'int' 1

Reviewers: aaron.ballman

Subscribers: cfe-commits

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

llvm-svn: 350957
2019-01-11 19:11:17 +00:00
Erich Keane 473cfda1f4 Fix a pair of Wfallthrough warnings in ScanfFormatString.
Change-Id: Ia73a34fdd93fc974224583505f9e6432493cb0da
llvm-svn: 350941
2019-01-11 18:01:40 +00:00
Brian Gesiak 5488ab4ddd [AST] Remove ASTContext from getThisType (NFC)
Summary:
https://reviews.llvm.org/D54862 removed the usages of `ASTContext&` from
within the `CXXMethodDecl::getThisType` method. Remove the parameter
altogether, as well as all usages of it. This does not result in any
functional change because the parameter was unused since
https://reviews.llvm.org/D54862.

Test Plan: check-clang

Reviewers: akyrtzi, mikael

Reviewed By: mikael

Subscribers: mehdi_amini, dexonsmith, cfe-commits

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

llvm-svn: 350914
2019-01-11 01:54:53 +00:00
Stephen Kelly 1224321623 NFC: Change case of identifiers
llvm-svn: 350890
2019-01-10 20:58:21 +00:00
Bruno Ricci 4939165d7c [AST] Move back BasePathSize to the bit-fields of CastExpr
The number of trailing CXXBaseSpecifiers in CastExpr was moved from
CastExprBitfields to a trailing object in r338489 (D50050). At this time these
bit-fields classes were only 32 bits wide. However later r345459 widened these
bit-field classes to 64 bits.

The reason for this change was that on 64 bit archs alignment requirements
caused 4 bytes of padding after the Stmt sub-object in nearly all expression
classes. Reusing this padding yielded an >10% reduction in the size used by all
statement/expressions when parsing all of Boost (on a 64 bit arch). This
increased the size of statement/expressions for 32 bits archs, but this can be
mitigated by moving more data to the bit-fields of Stmt (and moreover most
people now care about 64 bits archs as a host).

Therefore move back the number of CXXBaseSpecifiers in CastExpr to the
bit-fields of Stmt. This in effect mostly revert r338489 while keeping the
added test.

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

Reviewed By: lebedev.ri

Reviewers: lebedev.ri, rjmccall
llvm-svn: 350741
2019-01-09 16:41:33 +00:00
Bruno Ricci d7628d9993 [AST] Store the results in OverloadExpr in a trailing array
Use the newly available space in the bit-fields of Stmt to pack
OverloadExpr, UnresolvedLookupExpr and UnresolvedMemberExpr.

Additionally store the results in the overload set in a trailing array.
This saves 1 pointer + 8 bytes per UnresolvedLookupExpr and
UnresolvedMemberExpr.

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

Reviewed By: rjmccall

llvm-svn: 350732
2019-01-09 15:43:19 +00:00
Stephen Kelly d186dbc041 [ASTDump] NFC: Move dumpDeclRef to NodeDumper
Reviewers: aaron.ballman

Subscribers: cfe-commits

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

llvm-svn: 350677
2019-01-08 23:11:24 +00:00
Stephen Kelly b6d674f6fe Implement the TreeStructure interface through the TextNodeDumper
Summary:
This way, when the generic ASTTraverser is extracted from ASTDumper,
there can't be any problem related to ordering of class members, a
concern that was raised in https://reviews.llvm.org/D55337.

This will also preserve the property that the generic traverser does not
enforce any coupling between the NodeDumper and the TreeStructure.

 https://godbolt.org/z/PEtT1_

Reviewers: aaron.ballman, erichkeane

Subscribers: cfe-commits

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

llvm-svn: 350665
2019-01-08 22:32:48 +00:00
Bruno Ricci 030dab4115 [AST][NFC] Pack CXXScalarValueInitExpr
Use the newly available space in the bit-fields of Stmt.
This saves one pointer per CXXScalarValueInitExpr. NFC.

llvm-svn: 350635
2019-01-08 16:08:54 +00:00
Bruno Ricci 2e6dc538be [AST] Pack CXXDependentScopeMemberExpr
Use the newly available space in the bit-fields of Stmt. Additionally store
FirstQualifierFoundInScope as a trailing object since it is most of the time
null (non-null for 2 of the 35446 CXXDependentScopeMemberExpr when parsing
all of Boost).

It would be possible to move the data for the nested-name-specifier to a
trailing object too to save another 2 pointers, however doing so did actually
regress the time taken to parse all of Boost slightly.

This saves 8 bytes + 1 pointer per CXXDependentScopeMemberExpr in the vast
majority of cases.

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

Reviewed By: rjmccall

llvm-svn: 350625
2019-01-08 14:17:00 +00:00
Stephen Kelly 54272e5b66 NFC: Replace asserts with if() in SourceLocation accessors
Summary:
Nowhere else in the AST classes assert on these kinds of accessors.

This way, we can call the accessors and check the validity of the result
instead of externally duplicating the conditions.  This generality will
make it possible to introspect instances for source locations:

 http://ec2-18-191-7-3.us-east-2.compute.amazonaws.com:10240/z/iiaWhw

Reviewers: aaron.ballman

Subscribers: cfe-commits

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

llvm-svn: 350573
2019-01-07 21:57:30 +00:00
Bruno Ricci 9b6dfac5ad [AST] Store some data of CXXNewExpr as trailing objects
Store the optional array size expression, optional initialization expression
and optional placement new arguments in a trailing array. Additionally store
the range for the parenthesized type-id in a trailing object if needed since
in the vast majority of cases the type is not parenthesized (not a single new
expression in the translation unit of SemaDecl.cpp has a parenthesized type-id).

This saves 2 pointers per CXXNewExpr in all cases, and 2 pointers + 8 bytes
per CXXNewExpr in the common case where the type is not parenthesized.

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

Reviewed By: rjmccall

llvm-svn: 350527
2019-01-07 15:04:45 +00:00
Bruno Ricci 49ee964e19 [AST][NFC] Pack DependentScopeDeclRefExpr and CXXUnresolvedConstructExpr
Use the newly available space in the bit-fields of Stmt.
This saves 1 pointer per DependentScopeDeclRefExpr/CXXUnresolvedConstructExpr.

Additionally rename "TypeSourceInfo *Type;" to "TypeSourceInfo *TSI;"
as was done in D56022 (r350003) (but this is an internal detail anyway),
and clang-format both classes. NFC.

llvm-svn: 350525
2019-01-07 14:27:04 +00:00
Richard Smith 8ce732b46f DR674, PR38883, PR40238: Qualified friend lookup should look for a
template specialization if there is no matching non-template function.

This exposed a couple of related bugs:
 - we would sometimes substitute into a friend template instead of a
   suitable non-friend declaration; this would now crash because we'd
   decide the specialization of the friend is a redeclaration of itself
 - ADL failed to properly handle the case where an invisible local
   extern declaration redeclares an invisible friend

Both are fixed herein: in particular, we now never make invisible
friends or local extern declarations visible to name lookup unless
they are the only declaration of the entity. (We already mostly did
this for local extern declarations.)

llvm-svn: 350505
2019-01-07 06:00:46 +00:00
Anastasia Stulova 4cebc9db04 [Basic] Extend DiagnosticEngine to store and format Qualifiers.
Qualifiers can now be streamed into the DiagnosticEngine using
regular << operator. If Qualifiers are empty 'unqualified' will
be printed in the diagnostic otherwise regular qual syntax is
used.

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

llvm-svn: 350386
2019-01-04 11:50:36 +00:00
Aaron Ballman d23e9bc5af Diagnose an unused result from a call through a function pointer whose return type is marked [[nodiscard]].
When a function returns a type and that type was declared [[nodiscard]], we diagnose any unused results from that call as though the function were marked nodiscard. The same behavior should apply to calls through a function pointer.

This addresses PR31526.

llvm-svn: 350317
2019-01-03 14:24:31 +00:00
Richard Trieu b3e902f4c3 Add vtable anchor to classes.
llvm-svn: 350143
2018-12-29 02:02:30 +00:00
Reid Kleckner 3ab5a9cd1c [MS] Mangle return adjusting thunks with the public access specifier
MSVC does this, so we should too.

Fixes PR40138

llvm-svn: 350071
2018-12-26 20:07:52 +00:00
Reid Kleckner 423b65333d Ignore ConstantExpr in IgnoreParens
Summary:
This moves it up from IgnoreParenImpCasts to IgnoreParens, so that more
helpers ignore it. For most clients, this ensures that these helpers
behave the same with and without C++17 enabled, which is what appears to
introduce these new expression nodes.

Fixes PR39881

Reviewers: void, rsmith

Subscribers: cfe-commits

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

llvm-svn: 350068
2018-12-26 17:44:40 +00:00
Bruno Ricci ddb8f6b83a [AST] Store the arguments of CXXConstructExpr in a trailing array
Store the arguments of CXXConstructExpr in a trailing array. This is very
similar to the CallExpr case in D55771, with the exception that there is
only one derived class (CXXTemporaryObjectExpr) and that we compute the
offset to the trailing array instead of storing it.

This saves one pointer per CXXConstructExpr and CXXTemporaryObjectExpr.

Reviewed By: rjmccall

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

llvm-svn: 350003
2018-12-22 14:39:30 +00:00
Bruno Ricci 21636ab80c [AST][NFC] Remove stale comment in CXXRecordDecl::is(Virtually)DerivedFrom.
The "this" capture was removed in r291939.

llvm-svn: 349948
2018-12-21 20:23:07 +00:00
Bruno Ricci c4ba546ab8 [AST][NFC] Fix Wsign-compare warning introduced in CXXOperatorCallExpr
llvm-svn: 349934
2018-12-21 17:54:51 +00:00
Bruno Ricci feb1923c7a [AST][NFC] Pack CXXOperatorCallExpr
Use the space available in the bit-fields of Stmt.
This saves 8 bytes per CXXOperatorCallExpr. NFC.

llvm-svn: 349924
2018-12-21 16:51:57 +00:00
Bruno Ricci c5885cffc5 [AST] Store the callee and argument expressions of CallExpr in a trailing array.
Since CallExpr::setNumArgs has been removed, it is now possible to store the
callee expression and the argument expressions of CallExpr in a trailing array.
This saves one pointer per CallExpr, CXXOperatorCallExpr, CXXMemberCallExpr,
CUDAKernelCallExpr and UserDefinedLiteral.

Given that CallExpr is used as a base of the above classes we cannot use
llvm::TrailingObjects. Instead we store the offset in bytes from the this pointer
to the start of the trailing objects and manually do the casts + arithmetic.

Some notes:

1.) I did not try to fit the number of arguments in the bit-fields of Stmt.
    This leaves some space for future additions and avoid the discussion about
    whether x bits are sufficient to hold the number of arguments.

2.) It would be perfectly possible to recompute the offset to the trailing
    objects before accessing the trailing objects. However the trailing objects
    are frequently accessed and benchmarks show that it is slightly faster to
    just load the offset from the bit-fields. Additionally, because of 1),
    we have plenty of space in the bit-fields of Stmt.

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

Reviewed By: rjmccall

llvm-svn: 349910
2018-12-21 15:20:32 +00:00
Bruno Ricci 5fc4db7579 [AST][NFC] Pass the AST context to one of the ctor of DeclRefExpr.
All of the other constructors already take a reference to the AST context.
This avoids calling Decl::getASTContext in most cases. Additionally move
the definition of the constructor from Expr.h to Expr.cpp since it is calling
DeclRefExpr::computeDependence. NFC.

llvm-svn: 349901
2018-12-21 14:10:18 +00:00
Reid Kleckner 0a6096bab2 [mingw] Don't mangle thiscall like fastcall etc
GCC does not mangle it when it is not explicit in the source.  The
mangler as currently written cannot differentiate between explicit and
implicit calling conventions, so we can't match GCC. Explicit thiscall
conventions are rare, so mangle as if the convention was implicit to be
as ABI compatible as possible.

Also fixes some tests using %itanium_abi_triple in some configurations
as a side effect.

Fixes PR40107.

llvm-svn: 349872
2018-12-21 01:40:29 +00:00
Clement Courbet fb2c74d98c [Sema] Better static assert diagnostics for expressions involving temporaries/casts/....
Summary:
Handles expressions such as:
 - `std::is_const<T>()`
 - `std::is_const<T>()()`;
 - `std::is_same(decltype(U()), V>::value`;

Reviewers: aaron.ballman, Quuxplusone

Subscribers: cfe-commits, llvm-commits

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

llvm-svn: 349729
2018-12-20 09:05:15 +00:00
Kelvin Li ef57943e3f [OPENMP] parsing and sema support for 'close' map-type-modifier
A map clause with the close map-type-modifier is a hint to 
prefer that the variables are mapped using a copy into faster 
memory.

Patch by Ahsan Saghir (saghir)

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

llvm-svn: 349551
2018-12-18 22:18:41 +00:00
Tan S. B. 9f935e8749 [ExprConstant] Handle compound assignment when LHS has integral type and RHS has floating point type
Fixes PR39858

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

llvm-svn: 349444
2018-12-18 07:38:06 +00:00
Reid Kleckner d2f98772d0 Update Microsoft name mangling scheme for exception specifiers in the type system
Summary:
The msvc exception specifier for noexcept function types has changed
from the prior default of "Z" to "_E" if the function cannot throw when
compiling with /std:C++17.

Patch by Zachary Henkel!

Reviewers: zturner, rnk

Reviewed By: rnk

Subscribers: cfe-commits

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

llvm-svn: 349414
2018-12-17 23:10:43 +00:00
Gabor Marton 54058b5055 [ASTImporter] Add importer specific lookup
Summary:
There are certain cases when normal C/C++ lookup (localUncachedLookup)
does not find AST nodes. E.g.:

Example 1:

  template <class T>
  struct X {
    friend void foo(); // this is never found in the DC of the TU.
  };

Example 2:

  // The fwd decl to Foo is not found in the lookupPtr of the DC of the
  // translation unit decl.
  struct A { struct Foo *p; };

In these cases we create a new node instead of returning with the old one.
To fix it we create a new lookup table which holds every node and we are
not interested in any C++ specific visibility considerations.
Simply, we must know if there is an existing Decl in a given DC.

Reviewers: a_sidorin, a.sidorin

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

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

llvm-svn: 349351
2018-12-17 13:53:12 +00:00
Gabor Marton 7df342a4d1 [ASTImporter] Fix redecl chain of classes and class templates
Summary:
The crux of the issue that is being fixed is that lookup could not find
previous decls of a friend class. The solution involves making the
friend declarations visible in their decl context (i.e. adding them to
the lookup table).
Also, we simplify `VisitRecordDecl` greatly.

This fix involves two other repairs (without these the unittests fail):
(1) We could not handle the addition of injected class types properly
when a redecl chain was involved, now this is fixed.
(2) DeclContext::removeDecl failed if the lookup table in Vector form
did not contain the to be removed element. This caused troubles in
ASTImporter::ImportDeclContext. This is also fixed.

Reviewers: a_sidorin, balazske, a.sidorin

Subscribers: rnkovacs, dkrupp, Szelethus, cfe-commits

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

llvm-svn: 349349
2018-12-17 12:42:12 +00:00
Reid Kleckner f5f6290899 Mangle calling conventions into function pointer types where GCC does
Summary:
GCC 5.1 began mangling these Windows calling conventions into function
types, since they can be used for overloading. They've always been
mangled in the MS ABI, but they are new to the Itanium mangler. Note
that the calling convention doesn't appear as part of the main
declaration, it only appears on function parameter types and other
types.

Fixes PR39860

Reviewers: rjmccall, efriedma

Subscribers: cfe-commits

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

llvm-svn: 349212
2018-12-14 23:42:59 +00:00
Erich Keane 24a0f04f77 Add AddressSpace mangling to MS mode
All of the symbols demangle on llvm-undname and demangler.com. This
address space qualifier is useful for when we want to use opencl C++ in
Windows mode. Additionally, C++ address-space using functions will now
be usable on windows.

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

Change-Id: Ife4506613c3cce778a783456d62117fbf7d83c26
llvm-svn: 349209
2018-12-14 23:17:34 +00:00
Eric Fiselier 261875054e [Clang] Add __builtin_launder
Summary:
This patch adds `__builtin_launder`, which is required to implement `std::launder`. Additionally GCC provides `__builtin_launder`, so thing brings Clang in-line with GCC.

I'm not exactly sure what magic `__builtin_launder` requires, but  based on previous discussions this patch applies a `@llvm.invariant.group.barrier`. As noted in previous discussions, this may not be enough to correctly handle vtables.

Reviewers: rnk, majnemer, rsmith

Reviewed By: rsmith

Subscribers: kristina, Romain-Geissler-1A, erichkeane, amharc, jroelofs, cfe-commits, Prazek

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

llvm-svn: 349195
2018-12-14 21:11:28 +00:00
Richard Trieu 0f25c747a3 Fix up diagnostics.
Move some diagnostics around between Diagnostic*Kinds.td files.  Diagnostics
used in multiple places were moved to DiagnosticCommonKinds.td.  Diagnostics
listed in the wrong place (ie, Sema diagnostics listed in
DiagnosticsParseKinds.td) were moved to the correct places.  One diagnostic
split into two so that the diagnostic string is in the .td file instead of in
code.  Cleaned up the diagnostic includes after all the changes.

llvm-svn: 349125
2018-12-14 03:35:10 +00:00
Mikael Nilsson 9d2872db74 [OpenCL] Add generic AS to 'this' pointer
Address spaces are cast into generic before invoking the constructor.

Added support for a trailing Qualifiers object in FunctionProtoType.

Note: This recommits the previously reverted patch, 
      but now it is commited together with a fix for lldb.

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

llvm-svn: 349019
2018-12-13 10:15:27 +00:00
Eric Fiselier 5cdc2cda28 [AST] Store "UsesADL" information in CallExpr.
Summary:
Currently the Clang AST doesn't store information about how the callee of a CallExpr was found. Specifically if it was found using ADL.

However, this information is invaluable to tooling. Consider a tool which renames usages of a function. If the originally CallExpr was formed using ADL, then the tooling may need to additionally qualify the replacement.
Without information about how the callee was found, the tooling is left scratching it's head. Additionally, we want to be able to match ADL calls as quickly as possible, which means avoiding computing the answer on the fly.

This patch changes `CallExpr` to store whether it's callee was found using ADL. It does not change the size of any AST nodes.


Reviewers: fowles, rsmith, klimek, shafik

Reviewed By: rsmith

Subscribers: aaron.ballman, riccibruno, calabrese, titus, cfe-commits

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

llvm-svn: 348977
2018-12-12 21:50:55 +00:00
Hubert Tong 147b743602 [ExprConstant] Improve memchr/memcmp for type mismatch and multibyte element types
Summary:
`memchr` and `memcmp` operate upon the character units of the object
representation; that is, the `size_t` parameter expresses the number of
character units. The constant folding implementation is updated in this
patch to account for multibyte element types in the arrays passed to
`memchr`/`memcmp` and, in the case of `memcmp`, to account for the
possibility that the arrays may have differing element types (even when
they are byte-sized).

Actual inspection of the object representation is not implemented.
Comparisons are done only between elements with the same object size;
that is, `memchr` will fail when inspecting at least one character unit
of a multibyte element. The integer types are assumed to have two's
complement representation with 0 for `false`, 1 for `true`, and no
padding bits.

`memcmp` on multibyte elements will only be able to fold in cases where
enough elements are equal for the answer to be 0.

Various tests are added to guard against incorrect folding for cases
that miscompile on some system or other prior to this patch. At the same
time, the unsigned 32-bit `wchar_t` testing in
`test/SemaCXX/constexpr-string.cpp` is restored.

Reviewers: rsmith, aaron.ballman, hfinkel

Reviewed By: rsmith

Subscribers: cfe-commits

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

llvm-svn: 348938
2018-12-12 16:53:43 +00:00
Mikael Nilsson 90646732bf Revert "[OpenCL] Add generic AS to 'this' pointer"
Reverting because the patch broke lldb.

llvm-svn: 348931
2018-12-12 15:06:16 +00:00
Mikael Nilsson 78de84719b [OpenCL] Add generic AS to 'this' pointer
Address spaces are cast into generic before invoking the constructor.

Added support for a trailing Qualifiers object in FunctionProtoType.

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

llvm-svn: 348927
2018-12-12 14:11:59 +00:00
Gabor Marton be77a9846d [ASTImporter] Remove import of definition from GetAlreadyImportedOrNull
Summary: a_sidorin

Reviewers: a.sidorin

Subscribers: rnkovacs, dkrupp, Szelethus, cfe-commits

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

llvm-svn: 348923
2018-12-12 11:22:55 +00:00
Erich Keane ef65d6c5c4 Replace Const-Member checking with non-recursive version.
As reported in PR39946, these two implementations cause stack overflows
to occur when a type recursively contains itself.  While this only
happens when an incomplete version of itself is used by membership (and
thus an otherwise invalid program), the crashes might be surprising.

The solution here is to replace the recursive implementation with one
that uses a std::vector as a queue.  Old values are kept around to
prevent re-checking already checked types.

Change-Id: I582bb27147104763d7daefcfee39d91f408b9fa8
llvm-svn: 348899
2018-12-11 21:54:52 +00:00
Stephen Kelly 677e3aec9e Revert "Change InitListExpr dump to label and pointer"
This reverts commit r348794.

llvm-svn: 348799
2018-12-10 21:20:05 +00:00
Stephen Kelly 1be0bea084 Fix nits
llvm-svn: 348798
2018-12-10 21:04:04 +00:00
Stephen Kelly 43835951f4 Re-order content of template parameter dumps
Reviewers: aaron.ballman

Subscribers: cfe-commits

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

llvm-svn: 348797
2018-12-10 21:03:00 +00:00
Stephen Kelly 266dc19e4e Re-order content in OMPDeclareReductionDecl dump
Reviewers: aaron.ballman

Subscribers: cfe-commits

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

llvm-svn: 348795
2018-12-10 20:53:39 +00:00