Commit Graph

9210 Commits

Author SHA1 Message Date
Nico Weber c7aaa2efef [clang] Add range accessor for ObjCAtTryStmt catch_stmts and use it
No behavior change.

Differential Revision: https://reviews.llvm.org/D112543
2021-10-27 08:57:05 -04:00
Nico Weber 7c10c9d8e8 [clang] Convert ObjCAtTryStmt to llvm::TrailingObjects
And make it final while here.

No behavior change.

Differential Revision: https://reviews.llvm.org/D112542
2021-10-27 08:57:05 -04:00
Luke Petre a9db0a804a [AST] Fix the EndLoc calculation for ObjCObjectPointer
There is an issue where the AST code does not compute the correct SourceRange
for a ObjCObjectPointer.

From Richard Smith (ie @zygoloid) in discord:

I think the problem is that we set an invalid location for the * (because there
isn't one): https://github.com/llvm/llvm-project/blob/main/clang/lib/Sema/SemaType.cpp#L1121
And then we use the default getLocalSourceRangeImpl for a PointerLikeTypeLoc
that just assumes the * location is the type's end location:
https://github.com/llvm/llvm-project/blob/main/clang/include/clang/AST/TypeLoc.h#L1293
Possibly we should be special-casing that here:
https://github.com/llvm/llvm-project/blob/main/clang/lib/AST/TypeLoc.cpp#L228

My change:

introduces a AST dump test to show the issue in the first commit
special cases ObjCObjectPointerType in the second commit to correctly compute
the end location
2021-10-26 14:03:29 -04:00
Mike Rice d8699391a4 [OPENMP51]Initial parsing/sema for append_args clause for 'declare variant'
Adds initial parsing and sema for the 'append_args' clause.

Note that an AST clause is not created as it instead adds its values
to the OMPDeclareVariantAttr.

Differential Revision: https://reviews.llvm.org/D111854
2021-10-25 09:38:50 -07:00
Kazu Hirata 16ceb44e62 [clang] Use llvm::{count,count_if,find_if,all_of,none_of} (NFC) 2021-10-25 09:14:45 -07:00
Kadir Cetinkaya ffa96f022c
[clang] Fix range for forward-declared enums
This used to span just the `[[enum foo]] : bar;` in the absence of a
body. This patch expands the range to cover the base specifier, so that the
various consumers can detect the full range of the decl.

Differential Revision: https://reviews.llvm.org/D111259
2021-10-25 13:16:14 +02:00
Bradley Smith 0ce46a1d43 [AArch64][Driver][SVE] Allow -msve-vector-bits=<n>+ syntax to mean no maximum vscale
This patch splits the existing SveVectorBits LangOpt into VScaleMin and
VScaleMax LangOpts such that we can represent such an option. The cc1
option has also been split into -mvscale-{min,max}=<n> options so that the
cc1 arguments better reflect the vscale_range IR attribute.

Differential Revision: https://reviews.llvm.org/D111790
2021-10-25 11:10:52 +00:00
Kazu Hirata 7cc8fa2dd2 Use llvm::is_contained (NFC) 2021-10-24 09:32:57 -07:00
Balázs Kéri 4ff103c024 [clang][ASTImporter] Fix for importing functions with EST_Unevaluated prototype.
Fix for importing functions where the TypeSourceInfo is set and the
exception specification information contains reference to the function
declaration itself.

Reviewed By: martong, steakhal

Differential Revision: https://reviews.llvm.org/D112013
2021-10-22 09:42:41 +02:00
Volodymyr Sapsai d9eca3320a [modules] Fix tracking ObjCInterfaceType decl when there are multiple definitions.
With the old approach we were updating `ObjCInterfaceType.Decl` to the
last encountered definition. But during loading modules
`ASTDeclReader::VisitObjCInterfaceDecl` keeps the *first* encountered
definition. So with multiple definitions imported there would be a
disagreement between expected definition in `ObjCInterfaceType.Decl` and
actual definition `ObjCInterfaceDecl::getDefinition` which can lead to
incorrect diagnostic.

Fix by not tracking definition in `ObjCInterfaceType` explicitly but by
getting it from redeclaration chain.

Partially reverted 919fc50034 keeping the
modified test case as the correct behavior is achieved in a different
way.

Differential Revision: https://reviews.llvm.org/D110452
2021-10-21 12:08:06 -07:00
David Blaikie aee4925507 Recommit: Compress formatting of array type names (int [4] -> int[4])
Based on post-commit review discussion on
2bd8493847 with Richard Smith.

Other uses of forcing HasEmptyPlaceHolder to false seem OK to me -
they're all around pointer/reference types where the pointer/reference
token will appear at the rightmost side of the left side of the type
name, so they make nested types (eg: the "int" in "int *") behave as
though there is a non-empty placeholder (because the "*" is essentially
the placeholder as far as the "int" is concerned).

This was originally committed in 277623f4d5

Reverted in f9ad1d1c77 due to breakages
outside of clang - lldb seems to have some strange/strong dependence on
"char [N]" versus "char[N]" when printing strings (not due to that name
appearing in DWARF, but probably due to using clang to stringify type
names) that'll need to be addressed, plus a few other odds and ends in
other subprojects (clang-tools-extra, compiler-rt, etc).
2021-10-21 11:34:43 -07:00
Kazu Hirata dccfaddc6b [clang] Use StringRef::contains (NFC) 2021-10-21 08:58:19 -07:00
Jon Chesterfield 7ff4f48adb Relax assert in ExprConstant to a return None.
Fixes a compiler assert on passing a compile time integer to atomic builtins.

Assert introduced in D61522
Function changed from ->bool to ->Optional in D76646
Simplifies call sites to getIntegerConstantExpr to elide the now-redundant
isValueDependent checks.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D112159
2021-10-21 13:09:56 +01:00
Alfonso Gregory 2caf7571e1 [Clang][AST] Resolve FIXME: Remove ObjCObjectPointer from
isSpecifierType

There is no reason to have this here, (since all tests pass) and it
isn't even a specifier anyway. We can just treat it as a pointer
instead.

Differential Revision: https://reviews.llvm.org/D110068
2021-10-20 10:32:46 -07:00
Kazu Hirata d245f2e859 [clang] Use llvm::erase_if (NFC) 2021-10-17 13:50:29 -07:00
Kazu Hirata 10726992fa Use llvm::erase_value (NFC) 2021-10-16 23:31:21 -07:00
David Blaikie f9ad1d1c77 Revert "Compress formatting of array type names (int [4] -> int[4])"
Looks like lldb has some issues with this - somehow it causes lldb to
treat a "char[N]" type as an array of chars (prints them out
individually) but a "char [N]" is printed as a string. (even though the
DWARF doesn't have this string in it - it's something to do with the
string lldb generates for itself using clang)

This reverts commit 277623f4d5.
2021-10-14 14:49:25 -07:00
David Blaikie 277623f4d5 Compress formatting of array type names (int [4] -> int[4])
Based on post-commit review discussion on
2bd8493847 with Richard Smith.

Other uses of forcing HasEmptyPlaceHolder to false seem OK to me -
they're all around pointer/reference types where the pointer/reference
token will appear at the rightmost side of the left side of the type
name, so they make nested types (eg: the "int" in "int *") behave as
though there is a non-empty placeholder (because the "*" is essentially
the placeholder as far as the "int" is concerned).
2021-10-14 14:23:32 -07:00
Arthur Eubanks d0a5f61c4f [clang] Support -clear-ast-before-backend without -disable-free
Previously without -disable-free, -clear-ast-before-backend would crash in ~ASTContext() due to various reasons.
This works around that by doing a lot of the cleanup ahead of the destructor so that the destructor doesn't actually do any manual cleanup if we've already cleaned up beforehand.

This actually does save a measurable amount of memory with -clear-ast-before-backend, although at an almost unnoticeable runtime cost:
https://llvm-compile-time-tracker.com/compare.php?from=5d755b32f2775b9219f6d6e2feda5e1417dc993b&to=58ef1c7ad7e2ad45f9c97597905a8cf05a26258c&stat=max-rss

Previously we weren't doing any cleanup with -disable-free, so I tried measuring the impact of always doing the cleanup and didn't measure anything noticeable on llvm-compile-time-tracker.

Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D111767
2021-10-14 13:43:53 -07:00
Mike Rice fb4c451001 [OPENMP51]Initial parsing/sema for adjust_args clause for 'declare variant'
Adds initial parsing and sema for the 'adjust_args' clause.

Note that an AST clause is not created as it instead adds its expressions
to the OMPDeclareVariantAttr.

Differential Revision: https://reviews.llvm.org/D99905
2021-10-13 09:34:09 -07:00
David Blaikie 39093279f2 Improve printing of const variable sized arrays
Follow-on from 40acc0adad with help from
Richard Smith on how to provoke this particular case.
2021-10-12 19:04:53 -07:00
Kazu Hirata 57b40b5f34 [AST, CodeGen, Driver] Use llvm::is_contained (NFC) 2021-10-12 09:19:49 -07:00
Nathan Sidwell 444ec0957c [clang] p0388 array list initialization overloads
This is the second part of p0388, dealing with overloads of list
initialization to incomplete array types.  It extends the handling
added in D103088 to permit incomplete arrays.  We have to record that
the conversion involved an incomplete array, and so (re-add) a bit flag
into the standard conversion sequence object.  Comparing such
conversion sequences requires knowing (a) the number of array elements
initialized and (b) whether the initialization is of an incomplete array.

This also updates the web page to indicate p0388 is implemented (there
is no feature macro).

Differential Revision: https://reviews.llvm.org/D103908
2021-10-12 07:35:21 -07:00
Nathan Sidwell dcd74716f9 [clang] p0388 conversion to incomplete array
This implements the new implicit conversion sequence to an incomplete
(unbounded) array type.  It is mostly Richard Smith's work, updated to
trunk, testcases added and a few bugs fixed found in such testing.

It is not a complete implementation of p0388.

Differential Revision: https://reviews.llvm.org/D102645
2021-10-12 07:35:20 -07:00
Yonghong Song c5fb1a0953 Revert "[Clang] Ignore BTFTag attr if used as a type attribute"
This reverts commit b875343873.

Per discussion in https://reviews.llvm.org/D111199, instead to make
existing btf_tag attribute as a type-or-decl attribute, we will
make existing btf_tag attribute as a decl only attribute, and
introduce btf_type_tag as a type only attribute. This will make
it easy for cases like typedef where an attribute may be applied
as either a type attribute or a decl attribute.
2021-10-11 15:34:26 -07:00
Qiu Chaofan 85e565898f [Clang] Enable _Complex __ibm128 type
fae0dfa implemented the new __ibm128 type, this patch enables its
complex form.

Reviewed By: rjmccall

Differential Revision: https://reviews.llvm.org/D109948
2021-10-09 10:48:44 +08:00
Qiu Chaofan 8a714722e2 [NFC] [Clang] Use global enum for explicit float mode
Currently, there're multiple float types that can be represented by
__attribute__((mode(xx))). It's parsed, and then a corresponding type is
created if available.

This refactor moves the enum for mode into a global enum class visible
to ASTContext.

Reviewed By: aaron.ballman, erichkeane

Differential Revision: https://reviews.llvm.org/D111391
2021-10-09 10:39:10 +08:00
Richard Smith 64e9044ea4 Fix unintended fall-through.
Unfortunately I've not found a way to exercise this code that doesn't
crash elsewhere yet, due to unrelated bugs in how Sema incorrectly
instantiates lambdas in function template signatures.
2021-10-08 14:25:17 -07:00
Richard Smith 7ac308fb8f PR52073: Fix equivalence computation for lambda-expressions.
Distinct lambda expressions are always considered non-equivalent, so two
token-for-token identical function declarations whose signatures involve
lambda-expressions declare distinct functions.
2021-10-08 13:54:01 -07:00
John McCall 5ab6ee7599 Fix a variety of bugs with nil-receiver checks when targeting
non-Darwin ObjC runtimes:

- Use the same logic the Darwin runtime does for inferring that a
  receiver is non-null and therefore doesn't require null checks.
  Previously we weren't skipping these for non-super dispatch.

- Emit a null check when there's a consumed parameter so that we can
  destroy the argument if the call doesn't happen.  This mostly
  involves extracting some common logic from the Darwin-runtime code.

- Generate a zero aggregate by zeroing the same memory that was used
  in the method call instead of zeroing separate memory and then
  merging them with a phi.  This uses less memory and avoids unnecessary
  copies.

- Emit zero initialization, and generate zero values in phis, using
  the proper zero-value routines instead of assuming that the zero
  value of the result type has a bitwise-zero representation.
2021-10-08 05:44:06 -04:00
Qiu Chaofan 00c0ce0655 [NFC] [Clang] Remove pre-computed complex float types
As discussed in D109948, pre-computing all complex float types is not
necessary and brings extra overhead. This patch removes these defined
types, and construct them in-place when needed.

Reviewed By: teemperor

Differential Revision: https://reviews.llvm.org/D111387
2021-10-08 15:52:16 +08:00
Volodymyr Sapsai 9fad9de5c0 [modules] Fix IRGen assertion on accessing ObjC ivar inside a method.
When have ObjCInterfaceDecl with the same name in 2 different modules,
hitting the assertion

> Assertion failed: (Index < RL->getFieldCount() && "Ivar is not inside record layout!"),
> function lookupFieldBitOffset, file llvm-project/clang/lib/AST/RecordLayoutBuilder.cpp, line 3434.

on accessing an ivar inside a method. The assertion happens because
ivar belongs to one module while its containing interface belongs to
another module and then we fail to find the ivar inside the containing
interface. We already keep a single ObjCInterfaceDecl definition in
redecleration chain and in this case containing interface was correct.
The issue is with ObjCIvarDecl. IVar decl for IRGen is taken from
ObjCIvarRefExpr that is created in `Sema::BuildIvarRefExpr` using ivar
decl returned from `Sema::LookupIvarInObjCMethod`. And ivar lookup
returns a wrong decl because basically we take the first ObjCIvarDecl
found in `ASTReader::FindExternalVisibleDeclsByName` (called by
`DeclContext::lookup`). And in `ASTReader.Lookups` lookup table for a
wrong module comes first because `ASTReader::finishPendingActions`
processes `PendingUpdateRecords` in reverse order and the first
encountered ObjCIvarDecl will end up the last in `ASTReader.Lookups`.

Fix by merging ObjCIvarDecl from different modules correctly and by
using a canonical one in IRGen.

rdar://82854574

Differential Revision: https://reviews.llvm.org/D110280
2021-10-07 17:09:31 -07:00
Balázs Kéri b7ac68d01e [clang][ASTImporter] Simplify code of attribute import [NFC].
The code of `ASTImporter::Import(const Attr *)` was repetitive,
it is now simplified. (There is still room for improvement but
probably only after big changes.)

Reviewed By: martong, steakhal

Differential Revision: https://reviews.llvm.org/D110810
2021-10-07 13:07:21 +02:00
Richard Smith 141df74456 Add missing diagnostic for use of _reserved name in extern "C"
declaration.

Names starting with an underscore are reserved at the global scope, so
cannot be used as the name of an extern "C" symbol in any scope because
such usages conflict with a name at global scope.
2021-10-06 15:13:06 -07:00
Richard Smith 7063b76b02 PR50644: Do not warn on a declaration of `operator"" _foo`.
Also do not warn on `#define _foo` or `#undef _foo`.

Only global scope names starting with _[a-z] are reserved, not the use
of such an identifier in any other context.
2021-10-06 15:13:05 -07:00
Michael Kruse 2130117f92 [Clang][OpenMP] Allow loop-transformations with template parameters.
Clang would reject

    #pragma omp for
    #pragma omp tile sizes(P)
    for (int i = 0; i < 128; ++i) {}

where P is a template parameter, but the loop itself is not
template-dependent. Because P context-dependent, the TransformedStmt
cannot be generated and therefore is nullptr (until the template is
instantiated by TreeTransform). The OMPForDirective would still expect
the a loop is the dependent context and trigger an error.

Fix by introducing a NumGeneratedLoops field to OMPLoopTransformation.
This is used to distinguish the case where no TransformedStmt will be
generated at all (e.g. #pragma omp unroll full) and template
instantiation is needed. In the latter case, delay resolving the
iteration space like when the for-loop itself is template-dependent
until the template instatiation.

A more radical solution would always delay the iteration space analysis
until template instantiation, but would also break many test cases.

Reviewed By: ABataev

Differential Revision: https://reviews.llvm.org/D111124
2021-10-06 12:21:04 -05:00
Michael Kruse f37e8b0b83 [Clang][OpenMP] Infix OMPLoopTransformationDirective abstract class. NFC.
Insert OMPLoopTransformationDirective between OMPLoopBasedDirective and the loop transformations OMPTileDirective and OMPUnrollDirective. This simplifies handling of loop transformations not requiring distinguishing between OMPTileDirective and OMPUnrollDirective anymore.

Reviewed By: ABataev

Differential Revision: https://reviews.llvm.org/D111119
2021-10-06 10:49:07 -05:00
Kamau Bridgeman 8737c74fab [PowerPC][MMA] Allow MMA builtin types in pre-P10 compilation units
This patch allows the use of __vector_quad and __vector_pair, PPC MMA builtin
types, on all PowerPC 64-bit compilation units. When these types are
made available the builtins that use them automatically become available
so semantic checking for mma and pair vector memop __builtins is also
expanded to ensure these builtin function call are only allowed on
Power10 and new architectures. All related test cases are updated to
ensure test coverage.

Reviewed By: #powerpc, nemanjai

Differential Revision: https://reviews.llvm.org/D109599
2021-10-05 07:59:32 -05:00
Corentin Jabot 424733c12a Implement if consteval (P1938)
Modify the IfStmt node to suppoort constant evaluated expressions.

Add a new ExpressionEvaluationContext::ImmediateFunctionContext to
keep track of immediate function contexts.

This proved easier/better/probably more efficient than walking the AST
backward as it allows diagnosing nested if consteval statements.
2021-10-05 08:04:14 -04:00
Balázs Kéri bcefea80a4 [clang][ASTImporter] Add import of thread safety attributes.
Attributes of "C/C++ Thread safety attributes" section in Attr.td
are added to ASTImporter. The not added attributes from this section
do not need special import handling.

Reviewed By: martong

Differential Revision: https://reviews.llvm.org/D110528
2021-10-05 13:08:31 +02:00
serge-sans-paille 0f0e31cf51 Update inline builtin handling to honor gnu inline attribute
Per the GCC info page:

    If the function is declared 'extern', then this definition of the
    function is used only for inlining.  In no case is the function
    compiled as a standalone function, not even if you take its address
    explicitly.  Such an address becomes an external reference, as if
    you had only declared the function, and had not defined it.

Respect that behavior for inline builtins: keep the original definition, and
generate a copy of the declaration suffixed by '.inline' that's only referenced
in direct call.

This fixes holes in c3717b6858.

Differential Revision: https://reviews.llvm.org/D111009
2021-10-04 22:26:25 +02:00
James King 56e72a40c1 Update `DynTypedNode` to support the conversion of `TypeLoc`s.
This provides better support for `TypeLoc`s to allow `TypeLoc`-related
matchers to feature stricter typing and to avoid relying on the dynamic
casting of `TypeLoc`s in matchers.

Reviewed By: ymandel, tdl-g, sbenza

Differential Revision: https://reviews.llvm.org/D110586
2021-10-04 19:25:24 +00:00
Jay Foad d933adeaca [APInt] Stop using soft-deprecated constructors and methods in clang. NFC.
Stop using APInt constructors and methods that were soft-deprecated in
D109483. This fixes all the uses I found in clang.

Differential Revision: https://reviews.llvm.org/D110808
2021-10-04 09:38:11 +01:00
Dávid Bolvanský b1fcca3884 Fixed warnings in LLVM produced by -Wbitwise-instead-of-logical 2021-10-03 13:04:18 +02:00
Balázs Kéri cad9ff531c [clang][ASTImporter] Import ConstructorUsingShadowDecl correctly.
Fix import of ConstructorUsingShadowDecl and add tests.

Reviewed By: martong

Differential Revision: https://reviews.llvm.org/D110398
2021-10-01 11:41:08 +02:00
Gabor Marton a3a0b06626 [clang][ASTImporter] Import InheritedConstructor and ConstructorUsingShadowDecl.
Reviewed By: martong

Differential Revision: https://reviews.llvm.org/D110395
2021-10-01 10:16:11 +02:00
Balazs Benics e5e0e00831 [NFC] Cleanup the overload of ASTImporter::import()
This patch aims to address the comment of a previous review:
https://reviews.llvm.org/D109237#inline-1040678

The original problem was the following:
  `T` is substituted by `clang::Type`

  Expected<T *> import(T *From) {
    auto ToOrErr = Importer.Import(From);
    //             ^^^^^^^^^^^^^^^^^^^^^
    if (!ToOrErr)
      return ToOrErr.takeError();
    return cast_or_null<T>(*ToOrErr);
    //     ^^^^^^^^^^^^^^^^^^^^^^^^^
  }

`Importer.Import()` operates on `const Type *`, thus returns `const Type *`.
Later, at the return statement, we will try to construct an `Expected<Type*>`
from a `const Type *`, which failed with a miserable error message.

In all other cases `importer.Import()` results in a non-const version,
so everything works out just fine, but for `clang::type`s, we should
really return a const version.

So, in case of `T` is a subclass of `clang::Type`, it will return a
`Exprected<const T*>` instead.

Reviewed By: martong

Differential Revision: https://reviews.llvm.org/D109269
2021-09-30 11:53:08 +02:00
Erich Keane 1cd3ae0198 Fix missing return from 9324cc2ca9
No idea how my local machine missed this, but I saw no warning for it,
it seems to have been lost in some level of translating this back for
upstreaming.
2021-09-28 07:30:06 -07:00
serge-sans-paille bd379915de Refine the constraint for isInlineBuiltinDeclaration
Require it to be always_inline, to more closely match how _FORITFY_SOURCE
behaves.

This avoids generation of `.inline` suffixed functions - these should always be
inlined.
2021-09-28 16:07:33 +02:00
Erich Keane 9324cc2ca9 Change __builtin_sycl_unique_stable_name to just use an Itanium mangling
After significant problems in our downstream with the previous
implementation, the SYCL standard has opted to make using macros/etc to
change kernel-naming-lambdas in any way UB (even passively). As a
result, we are able to just emit the itanium mangling.

However, this DOES require a little work in the CXXABI, as the microsoft
and itanium mangler use different numbering schemes for lambdas.  This
patch adds a pair of mangling contexts that use the normal 'itanium'
mangling strategy to fill in the "DeviceManglingNumber" used previously
by CUDA.

Differential Revision: https://reviews.llvm.org/D110281
2021-09-28 06:41:03 -07:00