Commit Graph

9080 Commits

Author SHA1 Message Date
Anton Zabaznov e1a64aa66c [OpenCL] Create VoidPtrTy with generic AS in C++ for OpenCL mode
This change affects 'SemaOpenCLCXX/newdelete.cl' test,
thus the patch contains adjustments in types validation of
operators new and delete

Reviewed By: Anastasia

Differential Revision: https://reviews.llvm.org/D96178
2021-02-17 12:18:46 +03:00
Michael Kruse 6c05005238 [OpenMP] Implement '#pragma omp tile', by Michael Kruse (@Meinersbur).
The tile directive is in OpenMP's Technical Report 8 and foreseeably will be part of the upcoming OpenMP 5.1 standard.

This implementation is based on an AST transformation providing a de-sugared loop nest. This makes it simple to forward the de-sugared transformation to loop associated directives taking the tiled loops. In contrast to other loop associated directives, the OMPTileDirective does not use CapturedStmts. Letting loop associated directives consume loops from different capture context would be difficult.

A significant amount of code generation logic is taking place in the Sema class. Eventually, I would prefer if these would move into the CodeGen component such that we could make use of the OpenMPIRBuilder, together with flang. Only expressions converting between the language's iteration variable and the logical iteration space need to take place in the semantic analyzer: Getting the of iterations (e.g. the overload resolution of `std::distance`) and converting the logical iteration number to the iteration variable (e.g. overload resolution of `iteration + .omp.iv`). In clang, only CXXForRangeStmt is also represented by its de-sugared components. However, OpenMP loop are not defined as syntatic sugar. Starting with an AST-based approach allows us to gradually move generated AST statements into CodeGen, instead all at once.

I would also like to refactor `checkOpenMPLoop` into its functionalities in a follow-up. In this patch it is used twice. Once for checking proper nesting and emitting diagnostics, and additionally for deriving the logical iteration space per-loop (instead of for the loop nest).

Differential Revision: https://reviews.llvm.org/D76342
2021-02-16 09:45:07 -08:00
Richard Smith 21e8bb8325 PR48606: The lifetime of a constexpr heap allocation always started
during the same evaluation.

It looks like the only case for which this matters is determining
whether mutable subobjects of a heap allocation can be modified during
constant evaluation.
2021-02-08 17:58:05 -08:00
Richard Smith c945dc4a50 PR48587: is_constant_evaluated() should not evaluate to true during a
variable's destruction if it didn't do so during construction.

The standard doesn't give any guidance as to what to do here, but this
approach seems reasonable and conservative, and has been proposed to the
standard committee.
2021-02-08 17:34:40 -08:00
Yaxun (Sam) Liu b008ea304d [CUDA][HIP] Fix device variable linkage
For -fgpu-rdc, shadow variables should not be internalized, otherwise
they cannot be accessed by other TUs. This is necessary because
the shadow variable of external device variables are always
emitted as undefined symbols, which need to resolve to a global
symbols.

Managed variables need to be emitted as undefined symbols
in device compilations.

Reviewed by: Artem Belevich

Differential Revision: https://reviews.llvm.org/D95901
2021-02-05 15:11:12 -05:00
Michael Liao 01bf529db2 Recommit of a2fdf9d4d7.
- The failures are all cc1-based tests due to the missing `-aux-triple` options,
which is always prepared by the driver in CUDA/HIP compilation.
- Add extra check on the missing aux-targetinfo to prevent crashing.

[hip][cuda] Enable extended lambda support on Windows.

- On Windows, extended lambda has extra issues due to the numbering
schemes are different between the host compilation (Microsoft C++ ABI)
and the device compilation (Itanium C++ ABI. Additional device side
lambda number is required per lambda for the host compilation to
correctly mangle the device-side lambda name.
- A hybrid numbering context `MSHIPNumberingContext` is introduced to
number a lambda for both host- and device-compilations.

Reviewed By: rnk

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

This reverts commit 4874ff0241.
2021-02-05 11:27:30 -05:00
Zequan Wu 96fb49c3ff [AST] Update LVal before evaluating lambda decl fields.
Differential Revision: https://reviews.llvm.org/D96092
2021-02-04 17:01:09 -08:00
Nico Weber 4874ff0241 Revert "[hip][cuda] Enable extended lambda support on Windows."
This reverts commit a2fdf9d4d7.
Slightly speculative, seeing several cuda tests fail on this
Windows bot: http://45.33.8.238/win/32620/step_7.txt
2021-02-04 07:10:46 -05:00
Michael Liao a2fdf9d4d7 [hip][cuda] Enable extended lambda support on Windows.
- On Windows, extended lambda has extra issues due to the numbering
  schemes are different between the host compilation (Microsoft C++ ABI)
  and the device compilation (Itanium C++ ABI. Additional device side
  lambda number is required per lambda for the host compilation to
  correctly mangle the device-side lambda name.
- A hybrid numbering context `MSHIPNumberingContext` is introduced to
  number a lambda for both host- and device-compilations.

Reviewed By: rnk

Differential Revision: https://reviews.llvm.org/D69322
2021-02-04 01:38:29 -05:00
Amy Huang d5f5deee9e Reland "[DebugInfo][CodeView] Use <lambda_n> as the display name for lambdas"
with fix to test case and stringrefs.

Currently (for codeview) lambdas have a string like `<lambda_0>` in
their mangled name, and don't have any display name. This change uses the
`<lambda_0>` as the display name, which helps distinguish between lambdas
in -gline-tables-only, since there are no linkage names there.
It also changes how we display lambda names; previously we used
`<unnamed-tag>`; now it will show `<lambda_0>`.

I added a function to the mangling context code to create this string;
for Itanium it just returns an empty string.

Bug: https://bugs.llvm.org/show_bug.cgi?id=48432

Reviewed By: rnk

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

This reverts 9b21d4b943
2021-01-28 18:44:48 -08:00
Amy Huang 9b21d4b943 Revert "[DebugInfo][CodeView] Use <lambda_n> as the display name for lambdas."
for test failures.

This reverts commit d73564c510.
2021-01-28 16:41:26 -08:00
Amy Huang d73564c510 [DebugInfo][CodeView] Use <lambda_n> as the display name for lambdas.
Currently (for codeview) lambdas have a string like `<lambda_0>` in
their mangled name, and don't have any display name. This change uses the
`<lambda_0>` as the display name, which helps distinguish between lambdas
in -gline-tables-only, since there are no linkage names there.
It also changes how we display lambda names; previously we used
`<unnamed-tag>`; now it will show `<lambda_0>`.

I added a function to the mangling context code to create this string;
for Itanium it just returns an empty string.

Bug: https://bugs.llvm.org/show_bug.cgi?id=48432

Reviewed By: rnk

Differential Revision: https://reviews.llvm.org/D95187
2021-01-28 16:30:38 -08:00
Tomas Matheson 01b9e613c2 [Clang][Codegen] Truncate initializers of union bitfield members
If an initial value is given for a bitfield that does not fit in the
bitfield, the value should be truncated. Constant folding for
expressions did not account for this truncation in the case of union
member functions, despite a warning being emitted. In some contexts,
evaluation of expressions was not enabled unless C++11, ROPI or RWPI
was enabled.

Differential Revision: https://reviews.llvm.org/D93101
2021-01-28 09:19:19 +00:00
James Y Knight a7246ba02a Itanium Mangling: In 'enable_if', omit X/E around <expr-primary>.
The Clang enable_if extension is mangled as an <extended-qualifier>,
which is supposed to contain <template-args>. However, we were
unconditionally emitting X/E around its arguments, neglecting the fact
that <expr-primary> should be emitted directly without the surrounding
X/E.

Differential Revision: https://reviews.llvm.org/D95488
2021-01-27 16:46:52 -05:00
James Y Knight 8ca33605ff Itanium Mangling: Fix handling of <expr-primary> in <template-arg>.
Previously, we were emitting an extraneous X .. E in <template-arg>
around an <expr-primary> if the template argument was constructed from
an expression (rather than an already-evaluated literal value).  In
such a case, we would then e.g. emit 'XLi0EE' instead of 'Li0E'.

We had one special-case for DeclRefExpr expressions, in particular, to
omit them the mangled-name without the surrounding X/E. However,
unfortunately, that special case also triggered for ParmVarDecl (a
subtype of VarDecl), and _incorrectly_ emitted 'L_Z .. E' instead of
the proper 'Xfp_E'.

This change causes mangleExpression itself to be responsible for
emitting X/E around non-primary expressions, which removes the
special-case, and corrects both these problems.

Differential Revision: https://reviews.llvm.org/D95487
2021-01-27 16:46:52 -05:00
James Y Knight 9c7aeaebb3 Itanium Mangling: Mangle `__alignof__` differently than `alignof`.
The two operations have acted differently since Clang 8, but were
unfortunately mangled the same. The new mangling uses new "vendor
extended expression" syntax proposed in
https://github.com/itanium-cxx-abi/cxx-abi/issues/112

GCC had the same mangling problem, https://gcc.gnu.org/PR88115, and
will hopefully be switching to the same mangling as implemented here.

Additionally, fix the mangling of `__uuidof` to use the new extension
syntax, instead of its previous nonstandard special-case.

Adjusts the demangler accordingly.

Differential Revision: https://reviews.llvm.org/D93922
2021-01-27 16:46:51 -05:00
Varun Gandhi 44f792966e [Demangle] Support demangling Swift calling convention in MS demangler.
Previously, Clang was able to mangle the Swift calling
convention but 'MicrosoftDemangle.cpp' was not able to demangle it.

Reviewed By: compnerd, rnk

Differential Revision: https://reviews.llvm.org/D95053
2021-01-27 13:24:54 -08:00
Mikhail Maltsev 30d9ca1bd9 [clang][AST] Encapsulate DeclarationNameLoc, NFCI
This change makes `DeclarationNameLoc` a proper class and refactors its
users to use getter methods instead of accessing the members directly.
The change also makes `DeclarationNameLoc` immutable (i.e., it cannot
be modified once constructed).

Reviewed By: aprantl

Differential Revision: https://reviews.llvm.org/D94596
2021-01-27 11:21:01 +00:00
Sven van Haastregt 79c727328b [clang] Fix signedness in vector bitcast evaluation
The included test case triggered a sign assertion on the result in
`Success()`.  This was caused by the APSInt created for a bitcast
having its signedness bit inverted.  The second APSInt constructor
argument is `isUnsigned`, so invert the result of
`isSignedIntegerType`.

Relanding this patch after reverting.  The test case had to be updated
to be insensitive to 32/64-bit extractelement indices.

Differential Revision: https://reviews.llvm.org/D95135
2021-01-27 09:30:26 +00:00
Petr Hosek bb9eb19829 Support for instrumenting only selected files or functions
This change implements support for applying profile instrumentation
only to selected files or functions. The implementation uses the
sanitizer special case list format to select which files and functions
to instrument, and relies on the new noprofile IR attribute to exclude
functions from instrumentation.

Differential Revision: https://reviews.llvm.org/D94820
2021-01-26 17:13:34 -08:00
Petr Hosek 1e634f3952 Revert "Support for instrumenting only selected files or functions"
This reverts commit 4edf35f11a because
the test fails on Windows bots.
2021-01-26 12:25:28 -08:00
Petr Hosek 4edf35f11a Support for instrumenting only selected files or functions
This change implements support for applying profile instrumentation
only to selected files or functions. The implementation uses the
sanitizer special case list format to select which files and functions
to instrument, and relies on the new noprofile IR attribute to exclude
functions from instrumentation.

Differential Revision: https://reviews.llvm.org/D94820
2021-01-26 11:11:39 -08:00
Nathan James d92413a45e
[clangd] Selection handles CXXBaseSpecifier
Selection now includes the virtual and access modifier as part of their range for cxx base specifiers.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D95231
2021-01-26 18:58:53 +00:00
Sven van Haastregt b16fb1ffc3 Revert "[clang] Fix signedness in vector bitcast evaluation"
This reverts commit 14947cd047 because
it broke clang-cmake-armv7-quick.
2021-01-25 12:43:30 +00:00
Sven van Haastregt 14947cd047 [clang] Fix signedness in vector bitcast evaluation
The included test case triggered a sign assertion on the result in
`Success()`.  This was caused by the APSInt created for a bitcast
having its signedness bit inverted.  The second APSInt constructor
argument is `isUnsigned`, so invert the result of
`isSignedIntegerType`.

Differential Revision: https://reviews.llvm.org/D95135
2021-01-25 12:01:42 +00:00
Kirill Bobyrev c8d2ae52c1 [clang] NFC: Remove else-after-return pattern from some files
Follow-up on D95336. A bunch of these cases were found manually, the
rest made sense to be included to eliminate llvm-else-after-return
Clang-Tidy warnings.
2021-01-25 11:14:17 +01:00
Kirill Bobyrev 7e5d41a682
[clang] NFC: Remove else if after return
Update the code to be compatible with LLVM Coding Guidelines.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D95336
2021-01-25 10:58:22 +01:00
Balázs Kéri 98a8344895 [clang][ASTImporter] Add support for importing CXXFoldExpr.
Reviewed By: shafik, martong

Differential Revision: https://reviews.llvm.org/D94786
2021-01-22 15:20:55 +01:00
George Burgess IV b270fd59f0 Revert "[clang] Change builtin object size when subobject is invalid"
This reverts commit 275f30df8a.

As noted on the code review (https://reviews.llvm.org/D92892), this
change causes us to reject valid code in a few cases. Reverting so we
have more time to figure out what the right fix{es are, is} here.
2021-01-20 11:03:34 -08:00
Hans Wennborg 8ba442bc21 Revert "Following up on PR48517, fix handling of template arguments that refer"
Combined with 'da98651 - Revert "DR2064:
decltype(E) is only a dependent', this change (5a391d3) caused verifier
errors when building Chromium. See https://crbug.com/1168494#c1 for a
reproducer.

Additionally it reverts changes that were dependent on this one, see
below.

> Following up on PR48517, fix handling of template arguments that refer
> to dependent declarations.
>
> Treat an id-expression that names a local variable in a templated
> function as being instantiation-dependent.
>
> This addresses a language defect whereby a reference to a dependent
> declaration can be formed without any construct being value-dependent.
> Fixing that through value-dependence turns out to be problematic, so
> instead this patch takes the approach (proposed on the core reflector)
> of allowing the use of pointers or references to (but not values of)
> dependent declarations inside value-dependent expressions, and instead
> treating template arguments as dependent if they evaluate to a constant
> involving such dependent declarations.
>
> This ends up affecting a bunch of OpenMP tests, due to OpenMP
> imprecisely handling instantiation-dependent constructs, bailing out
> early instead of processing dependent constructs to the extent possible
> when handling the template.
>
> Previously committed as 8c1f2d15b8, and
> reverted because a dependency commit was reverted.

This reverts commit 5a391d38ac.

It also restores clang/test/SemaCXX/coroutines.cpp to its state before
da986511fb.

Revert "[c++20] P1907R1: Support for generalized non-type template arguments of scalar type."

> Previously committed as 9e08e51a20, and
> reverted because a dependency commit was reverted. This incorporates the
> following follow-on commits that were also reverted:
>
> 7e84aa1b81 by Simon Pilgrim
> ed13d8c667 by me
> 95c7b6cadb by Sam McCall
> 430d5d8429 by Dave Zarzycki

This reverts commit 4b574008ae.

Revert "[msabi] Mangle a template argument referring to array-to-pointer decay"

> [msabi] Mangle a template argument referring to array-to-pointer decay
> applied to an array the same as the array itself.
>
> This follows MS ABI, and corrects a regression from the implementation
> of generalized non-type template parameters, where we "forgot" how to
> mangle this case.

This reverts commit 18e093faf7.
2021-01-20 15:55:35 +01:00
Stephen Kelly 0cd0eb6e0a Add API to retrieve a clade kind from ASTNodeKind
Differential Revision: https://reviews.llvm.org/D94877
2021-01-19 22:51:30 +00:00
Richard Smith 18e093faf7 [msabi] Mangle a template argument referring to array-to-pointer decay
applied to an array the same as the array itself.

This follows MS ABI, and corrects a regression from the implementation
of generalized non-type template parameters, where we "forgot" how to
mangle this case.
2021-01-19 14:38:07 -08:00
Richard Smith da986511fb Revert "DR2064: decltype(E) is only a dependent type if E is type-dependent, not
if E is merely instantiation-dependent."

This change leaves us unable to distinguish between different function
templates that differ in only instantiation-dependent ways, for example

template<typename T> decltype(int(T())) f();
template<typename T> decltype(int(T(0))) f();

We'll need substantially better support for types that are
instantiation-dependent but not dependent before we can go ahead with
this change.

This reverts commit e3065ce238.
2021-01-19 12:48:40 -08:00
Richard Smith 4b574008ae [c++20] P1907R1: Support for generalized non-type template arguments of scalar type.
Previously committed as 9e08e51a20, and
reverted because a dependency commit was reverted. This incorporates the
following follow-on commits that were also reverted:

7e84aa1b81 by Simon Pilgrim
ed13d8c667 by me
95c7b6cadb by Sam McCall
430d5d8429 by Dave Zarzycki
2021-01-18 21:05:01 -08:00
Richard Smith 5a391d38ac Following up on PR48517, fix handling of template arguments that refer
to dependent declarations.

Treat an id-expression that names a local variable in a templated
function as being instantiation-dependent.

This addresses a language defect whereby a reference to a dependent
declaration can be formed without any construct being value-dependent.
Fixing that through value-dependence turns out to be problematic, so
instead this patch takes the approach (proposed on the core reflector)
of allowing the use of pointers or references to (but not values of)
dependent declarations inside value-dependent expressions, and instead
treating template arguments as dependent if they evaluate to a constant
involving such dependent declarations.

This ends up affecting a bunch of OpenMP tests, due to OpenMP
imprecisely handling instantiation-dependent constructs, bailing out
early instead of processing dependent constructs to the extent possible
when handling the template.

Previously committed as 8c1f2d15b8, and
reverted because a dependency commit was reverted.
2021-01-18 21:05:01 -08:00
Richard Smith fbb83f18b5 PR24076, PR33655, C++ CWG 1558: Consider the instantiation-dependence of
the nested-name-specifier when determining whether a qualified type is
instantiation-dependent.

Previously reverted in 25a02c3d1a due to
causing us to reject some code. It turns out that the rejected code was
ill-formed (no diagnostic required).
2021-01-18 21:05:01 -08:00
Richard Smith e3065ce238 DR2064: decltype(E) is only a dependent type if E is type-dependent, not
if E is merely instantiation-dependent.

Previously reverted in 34e72a146111dd986889a0f0ec8767b2ca6b2913;
re-committed with a fix to an issue that caused name mangling to assert.
2021-01-18 21:05:01 -08:00
Richard Smith bc713f6a00 PR48763: Better handling for classes that inherit a default constructor.
The C++ standard wording doesn't appear to properly handle the case
where a class inherits a default constructor from a base class. Various
properties of classes are defined in terms of the corresponding property
of the default constructor, and in this case, the class does not have a
default constructor despite being default-constructible, which the
wording doesn't handle properly.

This change implements a tentative fix for these problems, which has
also been proposed to the C++ committee: if a class would inherit a
default constructor, and does not explicitly declare one, then one is
implicitly declared.
2021-01-18 18:54:04 -08:00
Adam Czachorowski 196cc96f9a [clang] Allow LifetimeExtendedTemporary to have no access specifier
The check only runs in debug mode during serialization, but
assert()-fail on:
  struct S { const int& x = 7; };
in C++ mode.

Differential Revision: https://reviews.llvm.org/D94804
2021-01-18 19:19:57 +01:00
Mikhail Maltsev 17f8c458de [clang] Use SourceLocations in unions [NFCI]
Currently, there are many instances where `SourceLocation` objects are
converted to raw representation to be stored in structs that are
used as fields of tagged unions.

This is done to make the corresponding structs trivial.
Triviality allows avoiding undefined behavior when implicitly changing
the active member of the union.

However, in most cases, we can explicitly construct an active member
using placement new. This patch adds the required active member
selections and replaces `SourceLocation`-s represented as
`unsigned int` with proper `SourceLocation`-s.

One notable exception is `DeclarationNameLoc`: the objects of this class
are often not properly initialized (so the code currently relies on
its default constructor which uses memset). This class will be fixed
in a separate patch.

Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D94237
2021-01-14 10:56:53 +00:00
Xiangling Liao f0abe2aeac [Frontend] Add pragma align natural and sort out pragma pack stack effect
- Implemente the natural align for XL on AIX
- Sort out pragma pack stack effect
- Add -fxl-pragma-stack option to enable XL on AIX pragma stack effect

Differential Revision: https://reviews.llvm.org/D87702
2021-01-13 10:53:24 -05:00
Mikhail Maltsev c1e08f0073 [clang][AST] Get rid of an alignment hack in DeclObjC.h [NFCI]
This code currently uses a union object to increase the
alignment of the type ObjCTypeParamList. The original intent of this
trick was to be able to use the expression `this + 1` to access the
beginning of a tail-allocated array of `ObjCTypeParamDecl *` pointers.

The code has since been refactored and uses `llvm::TrailingObjects` to
manage the tail-allocated array. This template takes care of
alignment, so the hack is no longer necessary.

This patch removes the union so that the `SourceRange` class can be
used directly instead of being re-implemented with raw representations
of source locations.

Reviewed By: aprantl

Differential Revision: https://reviews.llvm.org/D94224
2021-01-12 10:22:35 +00:00
Stephan Bergmann 215ed9b33c Adapt CastExpr::getSubExprAsWritten to ConstantExpr
Differential Revision: https://reviews.llvm.org/D87030
2021-01-12 09:41:03 +01:00
Adam Czachorowski d4af86581e [clangd] Fix type printing in the presence of qualifiers
When printing QualType with qualifiers like "const", or pointing to an
elaborated type, we would print garbage like:
  std::const std::vector<int>&
with the initial std:: being calculated correctly, but inserted in the
wrong place and the second std:: not removed (due to elaborated type).

This affected, among others, ExtractFunction and ExpandAuto tweaks.

This change introduces a new callback to PrintingPolicy, which allows us
to influence the printing of namespace qualifiers. In the future, the
same callback can be used to improve handling of "using namespace"
directives as well.

Fixes:
  https://github.com/clangd/clangd/issues/640 (ExtractFunction)
  https://github.com/clangd/clangd/issues/264 (ExpandAuto)
  First point of https://github.com/clangd/clangd/issues/524

Differential Revision: https://reviews.llvm.org/D94259
2021-01-08 17:00:39 +01:00
David Sherwood 38d18d9353 [SVE] Add support to vectorize_width loop pragma for scalable vectors
This patch adds support for two new variants of the vectorize_width
pragma:

1. vectorize_width(X[, fixed|scalable]) where an optional second
parameter is passed to the vectorize_width pragma, which indicates if
the user wishes to use fixed width or scalable vectorization. For
example the user can now write something like:

  #pragma clang loop vectorize_width(4, fixed)
or
  #pragma clang loop vectorize_width(4, scalable)

In the absence of a second parameter it is assumed the user wants
fixed width vectorization, in order to maintain compatibility with
existing code.
2. vectorize_width(fixed|scalable) where the width is left unspecified,
but the user hints what type of vectorization they prefer, either
fixed width or scalable.

I have implemented this by making use of the LLVM loop hint attribute:

  llvm.loop.vectorize.scalable.enable

Tests were added to

  clang/test/CodeGenCXX/pragma-loop.cpp

for both the 'fixed' and 'scalable' optional parameter.

See this thread for context: http://lists.llvm.org/pipermail/cfe-dev/2020-November/067262.html

Differential Revision: https://reviews.llvm.org/D89031
2021-01-08 11:37:27 +00:00
Jeffrey T Mott 275f30df8a [clang] Change builtin object size when subobject is invalid
Motivating example:

```
  struct { int v[10]; } t[10];

  __builtin_object_size(
      &t[0].v[11], // access past end of subobject
      1            // request remaining bytes of closest surrounding
                   // subobject
  );
```

In GCC, this returns 0. https://godbolt.org/z/7TeGs7

In current clang, however, this returns 356, the number of bytes
remaining in the whole variable, as if the `type` was 0 instead of 1.
https://godbolt.org/z/6Kffox

This patch checks for the specific case where we're requesting a
subobject's size (type 1) but the subobject is invalid.

Differential Revision: https://reviews.llvm.org/D92892
2021-01-07 12:34:07 -08:00
Balázs Kéri 0877b963ef [clang][ASTImporter] Fix a possible assertion failure `NeedsInjectedClassNameType(Decl)'.
The assertion can happen if ASTImporter imports a CXXRecordDecl in a template
and then imports another redeclaration of this declaration, while the first import is in progress.
The process of first import did not set the "described template" yet
and the second import finds the first declaration at setting the injected types.
Setting the injected type requires in the assertion that the described template is set.
The exact assertion was:
clang/lib/AST/ASTContext.cpp:4411:
clang::QualType clang::ASTContext::getInjectedClassNameType(clang::CXXRecordDecl*, clang::QualType) const:
Assertion `NeedsInjectedClassNameType(Decl)' failed.

Reviewed By: shafik

Differential Revision: https://reviews.llvm.org/D94067
2021-01-07 11:28:11 +01:00
Varun Gandhi 37e83bc6db [NFC] Move readAPValue/writeAPValue up the inheritance hierarchy
The implementation for (de)serialization of APValues can be shared
between Clang and Swift, so we prefer pushing the methods up
the inheritance hierarchy, instead of having the methods live in
ASTReader/ASTWriter. Fixes rdar://72592937.

Reviewed By: rjmccall

Differential Revision: https://reviews.llvm.org/D94196
2021-01-06 16:44:50 -08:00
Richard Smith b12e473531 Allow dependent alias template specializations in the preferred_name
attribute.

This was intended to work, but didn't match the checks because these
types are modeled as TemplateSpecializationTypes not TypedefTypes.
2021-01-05 15:33:51 -08:00
Thorsten Schütt 2fd11e0b1e Revert "[NFC, Refactor] Modernize StorageClass from Specifiers.h to a scoped enum (II)"
This reverts commit efc82c4ad2.
2021-01-04 23:17:45 +01:00
Thorsten Schütt efc82c4ad2 [NFC, Refactor] Modernize StorageClass from Specifiers.h to a scoped enum (II)
Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D93765
2021-01-04 22:58:26 +01:00
Simon Pilgrim 9f8c0d15c7 DeclCXX - Fix getAs<> null-dereference static analyzer warnings. NFCI.
getAs<> can return null if the cast is invalid, which can lead to null pointer deferences. Use castAs<> instead which will assert that the cast is valid.
2021-01-04 15:12:55 +00:00
Akira Hatanaka 34405b41d6 [CodeGen][ObjC] Destroy callee-destroyed arguments in the caller
function when the receiver is nil

Callee-destroyed arguments to a method have to be destroyed in the
caller function when the receiver is nil as the method doesn't get
executed. This fixes PR48207.

rdar://71808391

Differential Revision: https://reviews.llvm.org/D93273
2020-12-28 11:52:27 -08:00
Adrian Kuegel 25a02c3d1a Revert "PR24076, PR33655, C++ CWG 1558: Consider the instantiation-dependence of"
This reverts commit d3bf0bb189.
This causes compilation in certain cases to fail.
Reproducer TBD.
2020-12-23 12:31:52 +01:00
Arthur Eubanks 34e72a1461 Revert "DR2064: decltype(E) is only a dependent type if E is type-dependent, not"
This reverts commit 638867afd4.

This is part of 5 commits being reverted due to https://crbug.com/1161059. See bug for repro.
2020-12-22 10:18:08 -08:00
Arthur Eubanks af0dbaaa38 Revert "Following up on PR48517, fix handling of template arguments that refer"
This reverts commit 8c1f2d15b8.

This is part of 5 commits being reverted due to https://crbug.com/1161059. See bug for repro.
2020-12-22 10:18:08 -08:00
Arthur Eubanks 2080232333 Revert "[c++20] P1907R1: Support for generalized non-type template arguments of scalar type."
This reverts commit 9e08e51a20.

This is part of 5 commits being reverted due to https://crbug.com/1161059. See bug for repro.
2020-12-22 10:18:08 -08:00
Arthur Eubanks 85d4a4bcc7 Revert "Fix memory leak complicated non-type template arguments."
This reverts commit ed13d8c667.

This is part of 5 commits being reverted due to https://crbug.com/1161059. See bug for repro.
2020-12-22 10:18:07 -08:00
Richard Smith ed13d8c667 Fix memory leak complicated non-type template arguments. 2020-12-18 13:42:24 -08:00
Richard Smith 569676c057 Make Expr::HasSideEffect more precise for instantiation-dependent
expressions.

Fixes a regression in the clang-tidy test suite from making DeclRefExprs
referring to dependent declarations be instantiation-dependent.
2020-12-18 01:08:42 -08:00
Richard Smith 9e08e51a20 [c++20] P1907R1: Support for generalized non-type template arguments of scalar type. 2020-12-18 01:08:41 -08:00
Richard Smith 8c1f2d15b8 Following up on PR48517, fix handling of template arguments that refer
to dependent declarations.

Treat an id-expression that names a local variable in a templated
function as being instantiation-dependent.

This addresses a language defect whereby a reference to a dependent
declaration can be formed without any construct being value-dependent.
Fixing that through value-dependence turns out to be problematic, so
instead this patch takes the approach (proposed on the core reflector)
of allowing the use of pointers or references to (but not values of)
dependent declarations inside value-dependent expressions, and instead
treating template arguments as dependent if they evaluate to a constant
involving such dependent declarations.

This ends up affecting a bunch of OpenMP tests, due to OpenMP
imprecisely handling instantiation-dependent constructs, bailing out
early instead of processing dependent constructs to the extent possible
when handling the template.
2020-12-17 23:54:37 -08:00
Richard Smith 71886c56f3 Where possible, don't try to ask whether a template argument is
dependent until it's been converted to match its parameter.

The type of a non-type template parameter can in general affect whether
the template argument is dependent.

Note that this is not always possible. For template arguments that name
static local variables in templates, the type of the template parameter
affects whether the argument is dependent, so the query is imprecise
until we know the parameter type. For example, in:

template<typename T> void f() {
  static const int n = 5;
  typename T::template X<n> x;
}

... we don't know whether 'n' is dependent until we know whether the
corresponding template parameter is of type 'int' or 'const int&'.
2020-12-17 23:23:05 -08:00
Richard Smith 638867afd4 DR2064: decltype(E) is only a dependent type if E is type-dependent, not
if E is merely instantiation-dependent.
2020-12-17 23:23:05 -08:00
Richard Smith d3bf0bb189 PR24076, PR33655, C++ CWG 1558: Consider the instantiation-dependence of
the nested-name-specifier when determining whether a qualified type is
instantiation-dependent.
2020-12-17 21:31:23 -08:00
Valentin Clement f4c8b80318 [openmp] Remove clause from OMPKinds.def and use OMP.td info
Remove the OpenMP clause information from the OMPKinds.def file and use the
information from the new OMP.td file. There is now a single source of truth for the
directives and clauses.

To avoid generate lots of specific small code from tablegen, the macros previously
used in OMPKinds.def are generated almost as identical. This can be polished and
possibly removed in a further patch.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D92955
2020-12-17 14:08:12 -05:00
Tom Roeder 1844ab770c [ASTImporter] Add support for importing GenericSelectionExpr AST nodes.
This allows ASTs to be merged when they contain GenericSelectionExpr
nodes (this is _Generic from C11). This is needed, for example, for
CTU analysis of C code that makes use of _Generic, like the Linux
kernel.

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. Additionally, this change adds support for structural
equivalence of _Generic in the AST.

Reviewed By: martong, aaron.ballman

Differential Revision: https://reviews.llvm.org/D92600
2020-12-16 15:39:50 -08:00
Tom Roeder f31e9bcd73 Test commit: add valid punctuation to a comment. NFC. 2020-12-16 15:33:19 -08:00
Richard Smith 7e7f38f853 DR1413 and part of P1815R2: Minor improvements to Clang's determination
of type- and value-dependency.

A static data member initialized to a constant inside a class template
is no longer considered value-dependent, per DR1413. A const but not
constexpr variable of literal type (other than integer or enumeration)
is no longer considered value-dependent, per P1815R2.
2020-12-15 14:53:26 -08:00
Richard Smith 6b760a50f5 DR2100: &expr is value-dependent if expr constant-evaluates to a
dependent declaration.
2020-12-15 14:53:26 -08:00
Richard Smith c4736b91f8 Don't memcpy from an empty ArrayRef; the base pointer could be null, and
the C rules say memcpy can't accept a null pointer.

This should fix a test failure with the ubsan buildbots.
2020-12-15 14:37:52 -08:00
Baptiste Saleil 57d83c3a90 [PowerPC] Enable paired vector type and intrinsics when MMA is disabled
This patch enables the Clang type __vector_pair and its associated LLVM
intrinsics even when MMA is disabled. With this patch, the type is now controlled
by the PPC paired-vector-memops option. The builtins and intrinsics will be
renamed to drop the mma prefix in another patch.

Differential Revision: https://reviews.llvm.org/D91819
2020-12-15 15:14:11 -06:00
Richard Smith 6c365cd31e Consider reference, pointer, and pointer-to-member TemplateArguments to be different if they have different types.
For the Itanium ABI, this implements the mangling rule suggested in
https://github.com/itanium-cxx-abi/cxx-abi/issues/47, namely mangling
such template arguments as being cast to the parameter type in the case
where the template name is overloadable. This can cause a mangling
change for rare cases, where

 * the template argument declaration is converted from its declared type
   to the type of the template parameter, and
 * the template parameter either has a deduced type or is a parameter of
   a function template.

However, such changes are necessary to avoid mangling collisions. The
ABI changes can be reversed with -fclang-abi-compat=11 or earlier.

Re-commit with a fix for a couple of regressions.

Differential Revision: https://reviews.llvm.org/D91488
2020-12-15 12:00:57 -08:00
Gabor Marton 68f53960e1 [ASTImporter] Fix import of a typedef that has an attribute
The import of a typedefs with an attribute uses clang::Decl::setAttrs().
But that needs the ASTContext which we can get only from the
TranslationUnitDecl. But we can get the TUDecl only thourgh the
DeclContext, which is not set by the time of the setAttrs call.

Fix: import the attributes only after the DC is surely imported.
Btw, having the attribute import initiated from GetImportedOrCreateDecl was
fundamentally flawed. Now that is implicitly fixed.

Differential Revision: https://reviews.llvm.org/D92962
2020-12-14 18:27:05 +01:00
Raphael Isemann 22ccdb7870 Revert "Consider reference, pointer, and pointer-to-member TemplateArguments to be different if they have different types."
This reverts commit 05cdf4acf4. It breaks stage-2
compilation of LLVM, see https://reviews.llvm.org/D91488#2451534
2020-12-14 14:03:38 +01:00
Richard Smith 05cdf4acf4 Consider reference, pointer, and pointer-to-member TemplateArguments to be different if they have different types.
For the Itanium ABI, this implements the mangling rule suggested in
https://github.com/itanium-cxx-abi/cxx-abi/issues/47, namely mangling
such template arguments as being cast to the parameter type in the case
where the template name is overloadable. This can cause a mangling
change for rare cases, where

 * the template argument declaration is converted from its declared type
   to the type of the template parameter, and
 * the template parameter either has a deduced type or is a parameter of
   a function template.

However, such changes are necessary to avoid mangling collisions. The
ABI changes can be reversed with -fclang-abi-compat=11 or earlier.

Re-commit with a fix for the regression introduced last time: don't
expect parameters and arguments to line up inside an <unresolved-name>
mangling.

Differential Revision: https://reviews.llvm.org/D91488
2020-12-13 22:43:24 -08:00
Richard Smith abbd57e558 Factor out and centralize repeated 'getExpandedPackSize'. 2020-12-13 22:43:23 -08:00
Nikita Popov 8d4b139e9d Revert "Consider reference, pointer, and pointer-to-member TemplateArguments to be different if they have different types."
This reverts commit 7b3470baf8.

Causes a crash while building tramp3d-v4 from test-suite.
2020-12-12 00:04:10 +01:00
Richard Smith 7b3470baf8 Consider reference, pointer, and pointer-to-member TemplateArguments to be different if they have different types.
For the Itanium ABI, this implements the mangling rule suggested in
https://github.com/itanium-cxx-abi/cxx-abi/issues/47, namely mangling
such template arguments as being cast to the parameter type in the case
where the template name is overloadable. This can cause a mangling
change for rare cases, where

 * the template argument declaration is converted from its declared type
   to the type of the template parameter, and
 * the template parameter either has a deduced type or is a parameter of
   a function template.

However, such changes are necessary to avoid mangling collisions. The
ABI changes can be reversed with -fclang-abi-compat=11 or earlier.

Differential Revision: https://reviews.llvm.org/D91488
2020-12-11 13:26:33 -08:00
clementval 456c885df3 Revert "[openmp] Remove clause from OMPKinds.def and use OMP.td info"
This reverts commit a7b2847216.

failing buildbot on warnings
2020-12-10 10:34:59 -05:00
Valentin Clement a7b2847216 [openmp] Remove clause from OMPKinds.def and use OMP.td info
Remove the OpenMP clause information from the OMPKinds.def file and use the
information from the new OMP.td file. There is now a single source of truth for the
directives and clauses.

To avoid generate lots of specific small code from tablegen, the macros previously
used in OMPKinds.def are generated almost as identical. This can be polished and
possibly removed in a further patch.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D92955
2020-12-10 10:19:09 -05:00
Haojian Wu a053929854 [AST] Fix a constexpr-evaluator crash on error-dependent returnstmt.
When the evaluator encounters an error-dependent returnstmt, before this patch
it returned a ESR_Returned without setting the result, the callsides think this
is a successful execution, and try to access the Result which causes the crash.

The fix is to always return failed as we don't know the result of the
error-dependent return stmt.

Differential Revision: https://reviews.llvm.org/D92969
2020-12-10 10:12:15 +01:00
Richard Smith 7127fd1786 MSABI: Basic mangling for access to member subobjects in a class
non-type template parameter.

The mangling information used here comes from private communication with
Jon Caves at Microsoft.
2020-12-09 18:08:49 -08:00
Gabor Marton a5e6590b15 [ASTImporter] Support CXXDeductionGuideDecl with local typedef
CXXDeductionGuideDecl with a local typedef has its own copy of the
TypedefDecl with the CXXDeductionGuideDecl as the DeclContext of that
TypedefDecl.
```
      template <typename T> struct A {
        typedef T U;
        A(U, T);
      };
      A a{(int)0, (int)0};
```
Related discussion on cfe-dev:
http://lists.llvm.org/pipermail/cfe-dev/2020-November/067252.html

Without this fix, when we import the CXXDeductionGuideDecl (via
VisitFunctionDecl) then before creating the Decl we must import the
FunctionType. However, the first parameter's type is the afore mentioned
local typedef. So, we then start importing the TypedefDecl whose
DeclContext is the CXXDeductionGuideDecl itself. The infinite loop is
formed.
```
 #0 clang::ASTNodeImporter::VisitCXXDeductionGuideDecl(clang::CXXDeductionGuideDecl*) clang/lib/AST/ASTImporter.cpp:3543:0
 #1 clang::declvisitor::Base<std::add_pointer, clang::ASTNodeImporter, llvm::Expected<clang::Decl*> >::Visit(clang::Decl*) /home/egbomrt/WORK/llvm5/build/debug/tools/clang/include/clang/AST/DeclNodes.inc:405:0
 #2 clang::ASTImporter::ImportImpl(clang::Decl*) clang/lib/AST/ASTImporter.cpp:8038:0
 #3 clang::ASTImporter::Import(clang::Decl*) clang/lib/AST/ASTImporter.cpp:8200:0
 #4 clang::ASTImporter::ImportContext(clang::DeclContext*) clang/lib/AST/ASTImporter.cpp:8297:0
 #5 clang::ASTNodeImporter::ImportDeclContext(clang::Decl*, clang::DeclContext*&, clang::DeclContext*&) clang/lib/AST/ASTImporter.cpp:1852:0
 #6 clang::ASTNodeImporter::ImportDeclParts(clang::NamedDecl*, clang::DeclContext*&, clang::DeclContext*&, clang::DeclarationName&, clang::NamedDecl*&, clang::SourceLocation&) clang/lib/AST/ASTImporter.cpp:1628:0
 #7 clang::ASTNodeImporter::VisitTypedefNameDecl(clang::TypedefNameDecl*, bool) clang/lib/AST/ASTImporter.cpp:2419:0
 #8 clang::ASTNodeImporter::VisitTypedefDecl(clang::TypedefDecl*) clang/lib/AST/ASTImporter.cpp:2500:0
 #9 clang::declvisitor::Base<std::add_pointer, clang::ASTNodeImporter, llvm::Expected<clang::Decl*> >::Visit(clang::Decl*) /home/egbomrt/WORK/llvm5/build/debug/tools/clang/include/clang/AST/DeclNodes.inc:315:0
 #10 clang::ASTImporter::ImportImpl(clang::Decl*) clang/lib/AST/ASTImporter.cpp:8038:0
 #11 clang::ASTImporter::Import(clang::Decl*) clang/lib/AST/ASTImporter.cpp:8200:0
 #12 llvm::Expected<clang::TypedefNameDecl*> clang::ASTNodeImporter::import<clang::TypedefNameDecl>(clang::TypedefNameDecl*) clang/lib/AST/ASTImporter.cpp:165:0
 #13 clang::ASTNodeImporter::VisitTypedefType(clang::TypedefType const*) clang/lib/AST/ASTImporter.cpp:1304:0
 #14 clang::TypeVisitor<clang::ASTNodeImporter, llvm::Expected<clang::QualType> >::Visit(clang::Type const*) /home/egbomrt/WORK/llvm5/build/debug/tools/clang/include/clang/AST/TypeNodes.inc:74:0
 #15 clang::ASTImporter::Import(clang::QualType) clang/lib/AST/ASTImporter.cpp:8071:0
 #16 llvm::Expected<clang::QualType> clang::ASTNodeImporter::import<clang::QualType>(clang::QualType const&) clang/lib/AST/ASTImporter.cpp:179:0
 #17 clang::ASTNodeImporter::VisitFunctionProtoType(clang::FunctionProtoType const*) clang/lib/AST/ASTImporter.cpp:1244:0
 #18 clang::TypeVisitor<clang::ASTNodeImporter, llvm::Expected<clang::QualType> >::Visit(clang::Type const*) /home/egbomrt/WORK/llvm5/build/debug/tools/clang/include/clang/AST/TypeNodes.inc:47:0
 #19 clang::ASTImporter::Import(clang::QualType) clang/lib/AST/ASTImporter.cpp:8071:0
 #20 llvm::Expected<clang::QualType> clang::ASTNodeImporter::import<clang::QualType>(clang::QualType const&) clang/lib/AST/ASTImporter.cpp:179:0
 #21 clang::QualType clang::ASTNodeImporter::importChecked<clang::QualType>(llvm::Error&, clang::QualType const&) clang/lib/AST/ASTImporter.cpp:198:0
 #22 clang::ASTNodeImporter::VisitFunctionDecl(clang::FunctionDecl*) clang/lib/AST/ASTImporter.cpp:3313:0
 #23 clang::ASTNodeImporter::VisitCXXDeductionGuideDecl(clang::CXXDeductionGuideDecl*) clang/lib/AST/ASTImporter.cpp:3543:0
```

The fix is to first create the TypedefDecl and only then start to import
the DeclContext.
Basically, we could do this during the import of all other Decls (not
just for typedefs). But it seems, there is only one another AST
construct that has a similar cycle: a struct defined as a function
parameter:
```
int struct_in_proto(struct data_t{int a;int b;} *d);

```
In that case, however, we had decided to return simply with an error
back then because that seemed to be a very rare construct.

Differential Revision: https://reviews.llvm.org/D92209
2020-12-09 21:25:04 +01:00
Richard Smith 2a2c228c7a Add new 'preferred_name' attribute.
This attribute permits a typedef to be associated with a class template
specialization as a preferred way of naming that class template
specialization. This permits us to specify that (for example) the
preferred way to express 'std::basic_string<char>' is as 'std::string'.

The attribute is applied to the various class templates in libc++ that have
corresponding well-known typedef names.

This is a re-commit. The previous commit was reverted because it exposed
a pre-existing bug that has since been fixed / worked around; see
PR48434.

Differential Revision: https://reviews.llvm.org/D91311
2020-12-09 12:22:35 -08:00
Richard Smith 997a719d5a PR48434: Work around crashes due to deserialization cycles via typedefs.
Ensure that we can deserialize a TypedefType even while in the middle of
deserializing its TypedefDecl, by removing the need to look at the
TypedefDecl while constructing the TypedefType.

This fixes all the currently-known failures for PR48434, but it's not a
complete fix, because we can still trigger deserialization cycles, which
are not supposed to happen.
2020-12-09 12:22:35 -08:00
Richard Smith a1344779ab Revert "Add new 'preferred_name' attribute."
This change exposed a pre-existing issue with deserialization cycles
caused by a combination of attributes and template instantiations
violating the deserialization ordering restrictions; see PR48434 for
details.

A previous commit attempted to work around PR48434, but appears to have
only been a partial fix, and fixing this properly seems non-trivial.
Backing out for now to unblock things.

This reverts commit 98f76adf4e and
commit a64c26a47a.
2020-12-08 00:42:48 -08:00
Richard Smith 590e146532 Fix assertion failure due to incorrect dependence bits on a DeclRefExpr
that can only be set correctly after instantiating the initializer for a
variable.
2020-12-07 18:48:38 -08:00
Richard Smith a64c26a47a Fix deserialization cycle in preferred_name attribute.
This is really just a workaround for a more fundamental issue in the way
we deserialize attributes. See PR48434 for details.

Also fix tablegen code generator to produce more correct indentation to
resolve buildbot issues with -Werror=misleading-indentation firing
inside the generated code.
2020-12-07 16:02:05 -08:00
Erik Pilkington 9cd2413f1c [clang] Add a new nullability annotation for swift async: _Nullable_result
_Nullable_result generally like _Nullable, except when being imported into a
swift async method. rdar://70106409

Differential revision: https://reviews.llvm.org/D92495
2020-12-07 17:19:20 -05:00
Richard Smith 98f76adf4e Add new 'preferred_name' attribute.
This attribute permits a typedef to be associated with a class template
specialization as a preferred way of naming that class template
specialization. This permits us to specify that (for example) the
preferred way to express 'std::basic_string<char>' is as 'std::string'.

The attribute is applied to the various class templates in libc++ that have
corresponding well-known typedef names.

Differential Revision: https://reviews.llvm.org/D91311
2020-12-07 12:53:07 -08:00
Jinsong Ji b49b8f096c [PowerPC][Clang] Remove QPX support
Clean up QPX code in clang missed in https://reviews.llvm.org/D83915

Reviewed By: #powerpc, steven.zhang

Differential Revision: https://reviews.llvm.org/D92329
2020-12-07 10:15:39 -05:00
Duncan P. N. Exon Smith b4f4fc6872 ASTImporter: Migrate to the FileEntryRef overload of SourceManager::createFileID, NFC
Migrate `ASTImporter::Import` over to using the `FileEntryRef` overload
of `SourceManager::createFileID`. No functionality change here.

Differential Revision: https://reviews.llvm.org/D92529
2020-12-04 14:45:59 -08:00
Duncan P. N. Exon Smith 5b267fb796 ADT: Stop peeking inside AlignedCharArrayUnion, NFC
Update all the users of `AlignedCharArrayUnion` to stop peeking inside
(to look at `buffer`) so that a follow-up patch can replace it with an
alias to `std::aligned_union_t`.

This was reviewed as part of https://reviews.llvm.org/D92512, but I'm
splitting this bit out to commit first to reduce churn in case the
change to `AlignedCharArrayUnion` needs to be reverted for some
unexpected reason.
2020-12-04 11:07:42 -08:00
Richard Smith be162f4c0e PR45699: Fix crash if an unexpanded parameter pack appears in a
requires-clause.
2020-12-03 15:26:06 -08:00
Nico Weber 0cbf61be8b [mac/arm] Fix rtti codegen tests when running on an arm mac
shouldRTTIBeUnique() returns false for iOS64CXXABI, which causes
RTTI objects to be emitted hidden. Update two tests that didn't
expect this to happen for the default triple.

Also rename iOS64CXXABI to AppleARM64CXXABI, since it's used for
arm64-apple-macos triples too.

Part of PR46644.

Differential Revision: https://reviews.llvm.org/D91904
2020-12-03 09:11:03 -05:00
Richard Smith 2ac5880187 Update MS ABI mangling for union constants based on new information from
Jon Caves.
2020-12-02 12:17:52 -08:00
Richard Smith 1f40d60a3b Remove CXXBasePaths::found_decls and simplify and modernize its only
caller.

This function did not satisfy its documented contract: it only
considered the first lookup result on each base path, not all lookup
results. It also performed unnecessary memory allocations.

This change results in a minor change to our representation: we now
include overridden methods that are found by any derived-to-base path
(not involving another override) in the list of overridden methods for a
function, rather than filtering out functions from bases that are both
direct virtual bases and indirect virtual bases for which the indirect
virtual base path contains another override for the function. (That
filtering rule is part of the class-scope name lookup rules, and doesn't
really have much to do with enumerating overridden methods.) The users
of the list of overridden methods do not appear to rely on this
filtering having happened, and it's simpler to not do it.
2020-12-01 16:35:03 -08:00
Reid Kleckner 43b5b485a2 Fix GCC 5.3 compile error in ASTImporter code
Try to simplify this code a different way: use less Expected, more
outparams.
2020-11-30 16:29:29 -08:00
Gabor Marton 70eb2ce395 [ASTImporter] Support import of CXXDeductionGuideDecl
CXXDeductionGuideDecl is a FunctionDecl, but its constructor should be called
appropriately, at least to set the kind variable properly.

Differential Revision: https://reviews.llvm.org/D92109
2020-11-30 17:55:25 +01:00
Raphael Isemann 89c1a7a67d [ASTImporter] Import the default argument of NonTypeTemplateParmDecl
The test case isn't using the AST matchers for all checks as there doesn't seem to be support for
matching NonTypeTemplateParmDecl default arguments. Otherwise this is simply importing the
default arguments.

Reviewed By: martong

Differential Revision: https://reviews.llvm.org/D92106
2020-11-27 11:40:07 +01:00
Raphael Isemann 3f6c856bb5 [ASTImporter] Import the default argument of TemplateTypeParmDecl
The test case isn't using the AST matchers for all checks as there doesn't seem to be support for
matching TemplateTypeParmDecl default arguments. Otherwise this is simply importing the
default arguments.

Also updates several LLDB tests that now as intended omit the default template
arguments of several std templates.

Reviewed By: martong

Differential Revision: https://reviews.llvm.org/D92103
2020-11-26 18:01:30 +01:00
Raphael Isemann 39a5dd164c [ASTImporter] Import the default argument of TemplateTemplateParmDecl
Same idea as in D92103 and D92106, but I realised after creating those reviews that there are
also TemplateTemplateParmDecls that can have default arguments, so here's hopefully the
last patch for default template arguments.

Reviewed By: martong

Differential Revision: https://reviews.llvm.org/D92119
2020-11-26 15:12:45 +01:00
Richard Smith 3fb0879867 Refactor and simplify class scope name lookup.
This is partly in preparation for an upcoming change that can change the
order in which DeclContext lookup results are presented.

In passing, fix some obvious errors where name lookup's notion of a
"static member function" missed static member function templates, and
where its notion of "same set of declarations" was confused by the same
declarations appearing in a different order.
2020-11-25 16:25:33 -08:00
Richard Smith 23dc04981b Treat a placeholder type for class template argument deduction as
substitutable for the deduced template.

As agreed in https://github.com/itanium-cxx-abi/cxx-abi/issues/109.
2020-11-24 16:59:06 -08:00
Richard Smith c2cb61bed3 Fix mangling of substitutions for template-prefixes.
Previously we only considered using a substitution for a template-name
after already having mangled its prefix, so we'd produce nonsense
manglings like NS3_S4_IiEE where we should simply produce NS4_IiEE.

This is not ABI-compatible with previous Clang versions, and the old
behavior is restored by -fclang-abi-compat=11.0 or earlier.
2020-11-24 16:25:18 -08:00
Raphael Isemann 0c926e6d24 [ASTImporter] Make the Import() return value consistent with the map of imported decls when merging ClassTemplateSpecializationDecls
When importing a `ClassTemplateSpecializationDecl` definition into a TU with a matching
`ClassTemplateSpecializationDecl` definition and a more recent forward decl, the ASTImporter
currently will call `MapImported()` for the definitions, but will return the forward declaration
from the `ASTImporter::Import()` call.

This is triggering some assertions in LLDB when we try to fully import some DeclContexts
before we delete the 'From' AST. The returned 'To' Decl before this patch is just the most recent
forward decl but that's not the Decl with the definition to which the ASTImporter will import
the child declarations.

This patch just changes that the ASTImporter returns the definition that the imported Decl was
merged with instead of the found forward declaration.

Reviewed By: martong

Differential Revision: https://reviews.llvm.org/D92016
2020-11-24 23:46:18 +01:00
Stephen Kelly 5e1801813d Remove the IgnoreImplicitCastsAndParentheses traversal kind
Differential Revision: https://reviews.llvm.org/D91918
2020-11-23 14:27:48 +00:00
Joe Ellis 3c696a212b [AArch64][SVE] Allow lax conversion between VLATs and GNU vectors
Previously, lax conversions were only allowed between SVE vector-length
agnostic types and vector-length specific types. This meant that code
such as the following:

    #include <arm_sve.h>
    #define N __ARM_FEATURE_SVE_BITS
    #define FIXED_ATTR __attribute__ ((vector_size (N/8)))
    typedef float fixed_float32_t FIXED_ATTR;

    void foo() {
        fixed_float32_t fs32;
        svfloat64_t s64;
        fs32 = s64;
    }

was not allowed.

This patch makes a minor change to areLaxCompatibleSveTypes to allow for
lax conversions to be performed between SVE vector-length agnostic types
and GNU vectors.

Differential Revision: https://reviews.llvm.org/D91696
2020-11-23 10:47:17 +00:00
Adam Czachorowski 95ce9fbc23 [clang] Do not crash on pointer wchar_t pointer assignment.
wchar_t can be signed (thus hasSignedIntegerRepresentation() returns
true), but it doesn't have an unsigned type, which would lead to a crash
when trying to get it.

With this fix, we special-case WideChar types in the pointer assignment
code.

Differential Revision: https://reviews.llvm.org/D91625
2020-11-20 15:27:15 +01:00
Liu, Chen3 776f92e067 [X86] Add support for vex, vex2, vex3, and evex for MASM
For MASM syntax, the prefixes are not enclosed in braces.
The assembly code should like:
  "evex vcvtps2pd xmm0, xmm1"

Differential Revision: https://reviews.llvm.org/D90441
2020-11-20 16:20:19 +08:00
Simon Pilgrim 0415cf470b Fix unused variable warning. NFCI.
We're just performing a null pointer check, we don't need the actual variable.
2020-11-18 16:50:51 +00:00
Haojian Wu bd4662cd3f [AST] Enhance the const expression evaluator to support error-dependent exprs.
Fix a crash when evaluating a constexpr function which contains
recovery-exprs. https://bugs.llvm.org/show_bug.cgi?id=46837

Would be nice to have constant expression evaluator support general template
value-dependent expressions, but it requires more work.

This patch is a good start I think, to handle the error-only
value-dependent expressions.

Differential Revision: https://reviews.llvm.org/D84637
2020-11-18 15:48:06 +01:00
Joe Ellis 23a96b84a8 [AArch64][SVE] Support implicit lax vector conversions for SVE types
Lax vector conversions was behaving incorrectly for implicit casts
between scalable and fixed-length vector types. For example, this:

    #include <arm_sve.h>

    #define N __ARM_FEATURE_SVE_BITS
    #define FIXED_ATTR __attribute__((arm_sve_vector_bits(N)))

    typedef svfloat32_t fixed_float32_t FIXED_ATTR;

    void allowed_depending() {
      fixed_float32_t fs32;
      svfloat64_t s64;

      fs32 = s64;
    }

... would fail because the vectors have differing lane sizes. This patch
implements the correct behaviour for
-flax-vector-conversions={none,all,integer}. Specifically:

- -flax-vector-conversions=none prevents all lax vector conversions
  between scalable and fixed-sized vectors.
- -flax-vector-conversions=integer allows lax vector conversions between
  scalable and fixed-size vectors whose element types are integers.
- -flax-vector-conversions=all allows all lax vector conversions between
  scalable and fixed-size vectors (including those with floating point
  element types).

The implicit conversions are implemented as bitcasts.

Reviewed By: fpetrogalli

Differential Revision: https://reviews.llvm.org/D91067
2020-11-17 14:50:17 +00:00
Nathan James d44edfc109
[clang][NFC] Use SmallString instead of SmallVector<char
Simplifies code in some places and is more explicit about what is being used.
No additional includes were added here so no impact on compile time.
2020-11-17 13:02:58 +00:00
Thorsten 41b65f166b Convert ConstexprKind from Specifiers.h to a scoped enum; NFC 2020-11-16 14:10:19 -05:00
Nico Weber 46ca880fca clang: Don't assert on no_unique_address fields in @encode()
Just skip (non-bitfield) zero-sized fields, like we do with empty bases.

The class->struct conversion in the test is because -std=c++20 else deletes some default methods
due to non-accessible base dtors otherwise.

As a side-effect of writing the test, I discovered that D76801 did an ABI breaking change of sorts
for Objective-C's @encode. But it's been in for a while, so I'm not sure if we want to row back on
that or now.

Fixes PR48048.

Differential Revision: https://reviews.llvm.org/D90622
2020-11-13 11:39:10 -05:00
Richard Smith 7602ef768b Suppress trailing template arguments equivalent to default arguments
when printing the name of a member of a class template specialization.
2020-11-12 21:10:34 -08:00
Richard Smith 2d4035e493 Fix structural comparison of template template arguments to compare the
right union member.

Should fix the armv8 buildbot.
2020-11-11 19:15:21 -08:00
Richard Smith 5f12f4ff90 Suppress printing of inline namespace names in diagnostics by default,
except where they are necessary to disambiguate the target.

This substantially improves diagnostics from the standard library,
which are otherwise full of `::__1::` noise.
2020-11-11 15:05:51 -08:00
Richard Smith e7f3e2103c Suppress printing template arguments that match default template
arguments of types by default.

This somewhat improves the worst-case printing of types like
std::string, std::vector, etc., where many irrelevant default arguments
can be included in the type as printed if we've lost the type sugar.
2020-11-11 15:05:51 -08:00
Florian Hahn 1d5daed199
[Matrix] Update mangling to use paramterized vendor ext type syntax.
The Itanium CXX ABI grammer has been extended to support parameterized
vendor extended types [1].

This patch updates Clang's mangling for matrix types to use the new
extension.

[1] b359d28971

Reviewed By: rjmccall

Differential Revision: https://reviews.llvm.org/D91253
2020-11-11 21:39:22 +00:00
Richard Smith c43f8c7728 Add PrintingPolicy overload to APValue::printPretty. NFC. 2020-11-10 14:48:56 -08:00
Richard Smith 438a27f2e5 Move code to determine the type of an LValueBase out of ExprConstant and
into a member function on LValueBase. NFC.
2020-11-10 13:03:57 -08:00
Simon Pilgrim defc59734a Add a llvm_unreachable to fix MSVC unhandled enum warning. NFCI. 2020-11-10 10:43:45 +00:00
David Blaikie 724877e219 Roll otherwise-unused variable into assert 2020-11-09 23:27:47 -08:00
Richard Smith b637148ecb [c++20] For P0732R2 / P1907R1: Basic code generation and name
mangling support for non-type template parameters of class type and
template parameter objects.

The Itanium side of this follows the approach I proposed in
https://github.com/itanium-cxx-abi/cxx-abi/issues/47 on 2020-09-06.

The MSVC side of this was determined empirically by observing MSVC's
output.

Differential Revision: https://reviews.llvm.org/D89998
2020-11-09 22:10:27 -08:00
Melanie Blower c511963d5a [clang] Fix length threshold for MicrosoftMangle md5 hash
Reviewers: rnk, dblaikie

Differential Revision: https://reviews.llvm.org/D90714
2020-11-07 07:40:24 -08:00
Matt Morehouse a6d15d4070 Undo Revert "Ignore template instantiations if not in AsIs mode"
MaskRay already fixed the ASan bug.
2020-11-03 13:59:01 -08:00
Matt Morehouse 72531ae6e6 Revert "Ignore template instantiations if not in AsIs mode"
This reverts commit 53df3beb62 due to
check-asan failure on the buildbot.
2020-11-03 13:57:31 -08:00
Baptiste Saleil daa127d77e [PowerPC] Add MMA builtin decoding and definitions
Add MMA builtin decoding. These builtins use the new PowerPC-specific types __vector_pair and __vector_quad.
So to avoid pervasive changes, we use custom type descriptors and custom decoding for these builtins.
We also use custom code generation to expand builtin calls with pointers to simpler intrinsic calls with non-pointer types.

Differential Revision: https://reviews.llvm.org/D81748
2020-11-03 15:08:46 -06:00
Stephen Kelly 53df3beb62 Ignore template instantiations if not in AsIs mode
Summary:
IgnoreUnlessSpelledInSource mode should ignore these because they are
not written in the source.  This matters for example when trying to
replace types or values which are templated.  The new test in
TransformerTest.cpp in this commit demonstrates the problem.

In existing matcher code, users can write
`unless(isInTemplateInstantiation())` or `unless(isInstantiated())` (the
user must know which to use).  The point of the
TK_IgnoreUnlessSpelledInSource mode is to allow the novice to avoid such
details.  This patch changes the IgnoreUnlessSpelledInSource mode to
skip over implicit template instantiations.

This patch does not change the TK_AsIs mode.

Note: An obvious attempt at an alternative implementation would simply
change the shouldVisitTemplateInstantiations() in ASTMatchFinder.cpp to
return something conditional on the operational TraversalKind.  That
does not work because shouldVisitTemplateInstantiations() is called
before a possible top-level traverse() matcher changes the operational
TraversalKind.

Reviewers: sammccall, aaron.ballman, gribozavr2, ymandel, klimek

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D80961
2020-11-02 20:21:48 +00:00
Stephen Kelly 537cc6dd2b Rename CXXUnresolvedConstructExpr::arg_size for consistency
Make it possible to use argumentCountIs and hasArgument with
CXXUnresolvedConstructExpr.

Differential Revision: https://reviews.llvm.org/D90553
2020-11-02 20:21:48 +00:00
Mark de Wever b46fddf75f [CodeGen] Implement [[likely]] and [[unlikely]] for while and for loop.
The attribute has no effect on a do statement since the path of execution
will always include its substatement.

It adds a diagnostic when the attribute is used on an infinite while loop
since the codegen omits the branch here. Since the likelihood attributes
have no effect on a do statement no diagnostic will be issued for
do [[unlikely]] {...} while(0);

Differential Revision: https://reviews.llvm.org/D89899
2020-10-31 17:51:29 +01:00
Richard Smith dd8297b066 PR42513: Fix handling of function definitions lazily instantiated from
friends.

When determining whether a function has a template instantiation
pattern, look for other declarations of that function that were
instantiated from a friend function definition, rather than assuming
that checking for member specialization information on whichever
declaration name lookup found will be sufficient.
2020-10-30 18:35:12 -07:00
Cullen Rhodes 58d3f0ea49 [clang][aarch64] Address various fixed-length SVE vector operations
This patch adds tests and support for operations on SVE vectors created
by the 'arm_sve_vector_bits' attribute, described by the Arm C Language
Extensions (ACLE, version 00bet6, section 3.7.3.3) for SVE [1].

This covers the following:
* VLSTs support the same forms of element-wise initialization as GNU
  vectors.
* VLSTs support the same built-in C and C++ operators as GNU vectors.
* Conditional and binary expressions containing GNU and SVE vectors
  (fixed or sizeless) are invalid since the ambiguity around the result
  type affects the ABI.

No functional changes were required to support vector initialization and
operators. The functional changes are to address unsupported conditional and
binary expressions.

[1] https://developer.arm.com/documentation/100987/latest

Reviewed By: fpetrogalli

Differential Revision: https://reviews.llvm.org/D88233
2020-10-30 15:10:54 +00:00
Erich Keane ec809e4cfe PR47372: Fix Lambda invoker calling conventions
As mentioned in the defect, the lambda static invoker does not follow
the calling convention of the lambda itself, which seems wrong. This
patch ensures that the calling convention of operator() is passed onto
the invoker and conversion-operator type.

This is accomplished by extracting the calling-convention determination
code out into a separate function in order to better reflect the 'thiscall'
work, as well as somewhat better support the future implementation of
https://devblogs.microsoft.com/oldnewthing/20150220-00/?p=44623

For any target (basically just win32) that has a different free and
static function calling convention, this generates BOTH alternatives.
This required some work to get the Windows mangler to work correctly for
this, as well as some tie-breaking for the unary operators.

Differential Revision: https://reviews.llvm.org/D89559
2020-10-30 06:39:55 -07:00
Stephen Kelly 52ff86d255 [AST] Fix traversal over CXXConstructExpr in Syntactic mode
Summary:
Skip over elidable nodes, and ensure that intermediate
CXXFunctionalCastExpr nodes are also skipped if they are semantic.

Reviewers: klimek, ymandel

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D82278
2020-10-30 12:14:41 +00:00
Christopher Di Bella 425a83a5f0 [Sema] adds basic -Wfree-nonheap-object functionality
Checks to make sure that stdlib's (std::)free is being appropriately
used. Presently checks for the following misuses:

- free(&stack_object)
- free(stack_array)

Differential Revision: https://reviews.llvm.org/D89988
2020-10-28 16:18:23 -07:00
Baptiste Saleil 40dd4d5233 [Clang][PowerPC] Add __vector_pair and __vector_quad types
Define the __vector_pair and __vector_quad types that are used to manipulate
the new accumulator registers introduced by MMA on PowerPC. Because these two
types are specific to PowerPC, they are defined in a separate new file so it
will be easier to add other PowerPC specific types if we need to in the future.

Differential Revision: https://reviews.llvm.org/D81508
2020-10-28 13:19:20 -05:00
Nathan James b698ad00cb
[clang][NFC] Rearrange Comment Token and Lexer fields to reduce padding
Rearrange the fields to reduce the size of the classes

Reviewed By: gribozavr2

Differential Revision: https://reviews.llvm.org/D90127
2020-10-27 00:03:43 +00:00
Richard Smith a5c7b46862 Fix checking for C++98 ICEs in C++11-and-later mode to not consider use
of a reference to be acceptable.
2020-10-26 16:59:48 -07:00
Zequan Wu e56e7bd469 Revert "Revert "Ensure that checkInitIsICE is called exactly once for every variable""
This reverts commit a2ac64dd90.
2020-10-26 12:08:57 -07:00
Zequan Wu a2ac64dd90 Revert "Ensure that checkInitIsICE is called exactly once for every variable"
This causing `Assertion Result && "Could not evaluate expression"' failed` at https://bugs.chromium.org/p/chromium/issues/detail?id=1142009

This reverts commit 76c0092665.
2020-10-26 11:59:55 -07:00
Nico Weber c686dfd617 Unconfuse gcc5.3 after 2e204e2391 / D87528
The local variable CmpResult added in that change shadowed the
type CmpResult, which confused an older gcc. Rename the variable
CmpResult to APFloatCmpResult.
2020-10-26 12:55:38 -04:00
Melanie Blower 2e204e2391 [clang] Enable support for #pragma STDC FENV_ACCESS
Reviewers: rjmccall, rsmith, sepavloff

Differential Revision: https://reviews.llvm.org/D87528
2020-10-25 06:46:25 -07:00
Richard Smith 7b3515880c For P0732R2, P1907R1: ensure that template parameter objects don't refer
to disallowed objects or have non-constant destruction.
2020-10-24 22:11:43 -07:00
Richard Smith cb9b9842d3 PR47954 / DR2126: permit temporary objects that are lifetime-extended by
variables that are usable in constant expressions to themselves be
usable in constant expressions.
2020-10-23 14:29:18 -07:00
Richard Smith 2b7dfdd319 Fix typo in diagnostic name.
No functionality change intended.
2020-10-23 13:21:21 -07:00
Duncan P. N. Exon Smith 74a8783480 SourceManager: Clarify that FileInfo always has a ContentCache, NFC
It turns out that `FileInfo` *always* has a ContentCache. Clarify that
in the code:
- Update the private version of `SourceManager::createFileID` to take a
  `ContentCache&` instead of `ContentCache*`, and rename it to
  `createFileIDImpl` for clarity.
- Change `FileInfo::getContentCache` to return a reference.

Differential Revision: https://reviews.llvm.org/D89554
2020-10-23 12:38:53 -04:00