Commit Graph

266 Commits

Author SHA1 Message Date
Serge Pavlov 4e4f926e83 Remove test AST/const-fpfeatures-diag.c
This test is going to be removed because using dynamic rounding mode
in initializers is changing. It also causes build failures in some
cases, so remove it now.
2020-09-30 11:07:55 +07:00
John McCall 984744a131 Fix a variety of minor issues with ObjC method mangling:
- Fix a memory leak accidentally introduced yesterday by using CodeGen's
  existing mangling context instead of creating a new context afresh.

- Move GNU-runtime ObjC method mangling into the AST mangler; this will
  eventually be necessary to support direct methods there, but is also
  just the right architecture.

- Make the Apple-runtime method mangling work properly when given an
  interface declaration, fixing a bug (which had solidified into a test)
  where mangling a category method from the interface could cause it to
  be mangled as if the category name was a class name.  (Category names
  are namespaced within their class and have no global meaning.)

- Fix a code cross-reference in dsymutil.

Based on a patch by Ellis Hoag.
2020-09-29 19:51:53 -04:00
Johannes Doerfert 4fc69ab002 Revert "[OpenMP][FIX] Verify compatible types for declare variant calls"
This reverts commit c942095790.

One of the tests broke, revert to investigate.
2020-09-29 00:37:11 -05:00
Johannes Doerfert c942095790 [OpenMP][FIX] Verify compatible types for declare variant calls
Especially for templates we need to check at some point if the base
function matches the specialization we might call instead. Before this
lead to the replacement of `std::sqrt(int(2))` calls with one that
converts the argument to a `std::complex<int>`, clearly not the desired
behavior.

Reported as PR47655

Reviewed By: JonChesterfield

Differential Revision: https://reviews.llvm.org/D88384
2020-09-28 23:26:21 -05:00
Serge Pavlov f91b9c0f98 Run test on particular target only
The test `AST/const-fpfeatures-diag.c` requires setting strict FP
semantics, so it fails on targets where support of such semantic
is limited.
2020-09-26 20:26:34 +07:00
Serge Pavlov 6314f412a8 [FPEnv] Evaluate constant expressions under non-default rounding modes
The change implements evaluation of constant floating point expressions
under non-default rounding modes. The main objective was to support
evaluation of global variable initializers, where constant rounding mode
may be specified by `#pragma STDC FENV_ROUND`.

Differential Revision: https://reviews.llvm.org/D87822
2020-09-26 17:59:39 +07:00
Saleem Abdulrasool 58cdbf518b Sema: add support for `__attribute__((__swift_private__))`
This attribute allows declarations to be restricted to the framework
itself, enabling Swift to remove the declarations when importing
libraries.  This is useful in the case that the functions can be
implemented in a more natural way for Swift.

This is based on the work of the original changes in
8afaf3aad2

Differential Revision: https://reviews.llvm.org/D87720
Reviewed By: Aaron Ballman
2020-09-25 22:33:53 +00:00
Saleem Abdulrasool 296d8832a3 Sema: add support for `__attribute__((__swift_newtype__))`
Add the `swift_newtype` attribute which allows a type definition to be
imported into Swift as a new type.  The imported type must be either an
enumerated type (enum) or an object type (struct).

This is based on the work of the original changes in
8afaf3aad2

Differential Revision: https://reviews.llvm.org/D87652
Reviewed By: Aaron Ballman
2020-09-24 15:17:35 +00:00
Serge Pavlov 8a86261c51 [FPEnv] Use typed accessors in FPOptions
Previously methods `FPOptions::get*` returned unsigned value even if the
corresponding property was represented by specific enumeration type. With
this change such methods return actual type of the property. It also
allows printing value of a property as text rather than integer code.

Differential Revision: https://reviews.llvm.org/D87812
2020-09-18 14:16:43 +07:00
Raul Tambre e09107ab80 [Sema] Introduce BuiltinAttr, per-declaration builtin-ness
Instead of relying on whether a certain identifier is a builtin, introduce BuiltinAttr to specify a declaration as having builtin semantics.

This fixes incompatible redeclarations of builtins, as reverting the identifier as being builtin due to one incompatible redeclaration would have broken rest of the builtin calls.
Mostly-compatible redeclarations of builtins also no longer have builtin semantics. They don't call the builtin nor inherit their attributes.
A long-standing FIXME regarding builtins inside a namespace enclosed in extern "C" not being recognized is also addressed.

Due to the more correct handling attributes for builtin functions are added in more places, resulting in more useful warnings.
Tests are updated to reflect that.

Intrinsics without an inline definition in intrin.h had `inline` and `static` removed as they had no effect and caused them to no longer be recognized as builtins otherwise.

A pthread_create() related test is XFAIL-ed, as it relied on it being recognized as a builtin based on its name.
The builtin declaration syntax is too restrictive and doesn't allow custom structs, function pointers, etc.
It seems to be the only case and fixing this would require reworking the current builtin syntax, so this seems acceptable.

Fixes PR45410.

Reviewed By: rsmith, yutsumi

Differential Revision: https://reviews.llvm.org/D77491
2020-09-17 19:28:57 +03:00
Johannes Doerfert 5c1084e884 [OpenMP] Context selector extensions for template functions
With this extension the effects of `omp begin declare variant` will be
applied to template function declarations. The behavior is opt-in and
controlled by the `extension(allow_templates)` trait. While generally
useful, this will enable us to implement complex math function calls by
overloading the templates of the standard library with the ones in
libc++.

Reviewed By: JonChesterfield

Differential Revision: https://reviews.llvm.org/D85735
2020-09-16 13:37:10 -05:00
Johannes Doerfert c4b7a1da9d [OpenMP] Context selector extensions for return value overloading
This extension allows to declare variants in between `omp begin/end
declare variant` that do not match the type of the existing function
with that name. Without this extension we would not find a base function
(with a compatible type), therefore create a new one, which would
cause conflicting declarations. With this extension we will not create
"missing" base functions, which basically renders these specializations
harmless. They will be generated but never called.

Reviewed By: JonChesterfield

Differential Revision: https://reviews.llvm.org/D85878
2020-09-16 13:37:09 -05:00
Johannes Doerfert 5c63ae156e [OpenMP] Support nested OpenMP context selectors (declare variant)
Due to `omp begin/end declare variant`, OpenMP context selectors can be
nested. This patch adds initial support for this so we can use it for
target math variants. We should improve the detection of "equivalent"
scores and user conditions, we should also revisit the data structures
of the OMPTraitInfo object, however, both are not pressing issues right
now.

Reviewed By: JonChesterfield

Differential Revision: https://reviews.llvm.org/D85877
2020-09-16 13:37:09 -05:00
Johannes Doerfert 05fd04eda4 [OpenMP][FIX] Do not drop a '$' while demangling declare variant names
Reviewed By: ABataev

Differential Revision: https://reviews.llvm.org/D85876
2020-09-16 13:37:09 -05:00
Johannes Doerfert 6a02932bec [OpenMP][FIX] Do not crash trying to print a missing (demangled) user condition
Reviewed By: JonChesterfield

Differential Revision: https://reviews.llvm.org/D85875
2020-09-16 13:37:08 -05:00
Saleem Abdulrasool 77a01d9498 Sema: add support for `__attribute__((__swift_bridge__))`
This extends semantic analysis of attributes for Swift interoperability
by introducing the `swift_bridge` attribute.  This attribute enables
bridging Objective-C types to Swift specific types.

This is based on the work of the original changes in
8afaf3aad2

Differential Revision: https://reviews.llvm.org/D87532
Reviewed By: Aaron Ballman
2020-09-16 17:54:57 +00:00
Saleem Abdulrasool 7d26d6a1b0 Sema: add support for `__attribute__((__swift_bridged_typedef__))`
Extend the semantic attributes that clang processes for Swift to include
`swift_bridged_typedef`.  This attribute enables typedefs to be bridged
into Swift with a bridged name.

This is based on the work of the original changes in
8afaf3aad2

Differential Revision: https://reviews.llvm.org/D87396
Reviewed By: Aaron Ballman
2020-09-15 20:15:34 +00:00
Serge Pavlov f1cd6593da [AST][FPEnv] Keep FP options in trailing storage of CastExpr
This is recommit of 6c8041aa0f, reverted in de044f7562 because of some
fails. Original commit message is below.

This change allow a CastExpr to have optional FPOptionsOverride object,
stored in trailing storage. Of all cast nodes only ImplicitCastExpr,
CStyleCastExpr, CXXFunctionalCastExpr and CXXStaticCastExpr are allowed
to have FPOptions.

Differential Revision: https://reviews.llvm.org/D85960
2020-09-14 12:15:21 +07:00
Serge Pavlov de044f7562 Revert "[AST][FPEnv] Keep FP options in trailing storage of CastExpr"
This reverts commit 6c8041aa0f.
It caused some fails on buildbots.
2020-09-12 17:06:42 +07:00
Serge Pavlov 9c651c231f Missing change from previous commit 2020-09-12 15:11:09 +07:00
Serge Pavlov 6c8041aa0f [AST][FPEnv] Keep FP options in trailing storage of CastExpr
This change allow a CastExpr to have optional FPOptionsOverride object,
stored in trailing storage. Of all cast nodes only ImplicitCastExpr,
CStyleCastExpr, CXXFunctionalCastExpr and CXXStaticCastExpr are allowed
to have FPOptions.

Differential Revision: https://reviews.llvm.org/D85960
2020-09-12 14:30:44 +07:00
Raphael Isemann 23f700c785 Revert "[clang] Prevent that Decl::dump on a CXXRecordDecl deserialises further declarations."
This reverts commit 0478720157. This probably
doesn't work when forcing deserialising while dumping (which the ASTDumper
optionally supports).
2020-09-07 14:50:13 +02:00
Raphael Isemann 0478720157 [clang] Prevent that Decl::dump on a CXXRecordDecl deserialises further declarations.
Decl::dump is primarily used for debugging to visualise the current state of a
declaration. Usually Decl::dump just displays the current state of the Decl and
doesn't actually change any of its state, however since commit
457226e02a the method actually started loading
additional declarations from the ExternalASTSource. This causes that calling
Decl::dump during a debugging session now actually does permanent changes to the
AST and will cause the debugged program run to deviate from the original run.

The change that caused this behaviour is the addition of
`hasConstexprDestructor` (which is called from the TextNodeDumper) which
performs a lookup into the current CXXRecordDecl to find the destructor. All
other similar methods just return their respective bit in the DefinitionData
(which obviously doesn't have such side effects).

This just changes the node printer to emit "unknown_constexpr" in case a
CXXRecordDecl is dumped that could potentially call into the ExternalASTSource
instead of the usually empty string/"constexpr". For CXXRecordDecls that can
safely be dumped the old behaviour is preserved

Reviewed By: bruno

Differential Revision: https://reviews.llvm.org/D80878
2020-09-07 12:31:30 +02:00
Serge Pavlov a633da5391 [FPEnv] Partially implement #pragma STDC FENV_ROUND
This change implements pragma STDC FENV_ROUND, which is introduced by
the extension to standard (TS 18661-1). The pragma is implemented only
in frontend, it sets apprpriate state of FPOptions stored in Sema. Use
of these bits in constant evaluation adn/or code generator is not in the
scope of this change.

Parser issues warning on unsuppored pragma when it encounteres pragma
STDC FENV_ROUND, however it makes syntax checks and updates Sema state
as if the pragma were supported.

Primary purpose of the partial implementation is to facilitate
development of non-default floating poin environment. Previously a
developer cannot set non-default rounding mode in sources, this mades
preparing tests for say constant evaluation  substantially complicated.

Differential Revision: https://reviews.llvm.org/D86921
2020-09-04 16:47:10 +07:00
Alexey Bataev bedc841a50 [OPENMP]Fix PR47158, case 3: allow devic_typein nested declare target region.
OpenMP 5.0 supports nested declare target regions. So, in general,it is
allow to mark a declarationas declare target with different device_type
or link type. Patch adds support for such kind of nesting.

Differential Revision: https://reviews.llvm.org/D86239
2020-08-24 09:58:37 -04:00
Michael Forster a5b8757506 Introduce ns_error_domain attribute.
ns_error_domain can be used by, e.g. NS_ERROR_ENUM, in order to
identify a global declaration representing the domain constant.

Introduces the attribute, Sema handling, diagnostics, and test case.

This is cherry-picked from a14779f504
and adapted to updated Clang APIs.

Reviewed By: gribozavr2, aaron.ballman

Differential Revision: https://reviews.llvm.org/D84005
2020-08-13 15:05:12 +02:00
Haojian Wu dc7b1e9db5 [AST] Fix the CXXFoldExpr source range when parentheses range is invalid.
The CXXFoldExpr's range is invalid if the cxxfoldexpr is formed via the
Concept's TypeContraints (because the parentheses are not written in the
source code). We fallback to use the range from the pattern.

Differential Revision: https://reviews.llvm.org/D85645
2020-08-12 09:20:23 +02:00
Haojian Wu 626d0f5818 [Concepts] Dump template arguments for immediately declared constraint.
The template arguments were dumped as part of the TemplateTypeParmDecl, which
was incorrect.

Differential Revision: https://reviews.llvm.org/D85282
2020-08-10 09:11:55 +02:00
Alexey Bataev 4a7aedb843 [OPENMP]Simplify representation for atomic, critical, master and section
constrcut.

Several constructs may be represented wityout relying on CapturedStmt.
It saves memory and improves compilation speed.
2020-08-07 09:58:23 -04:00
Richard Smith ed5a18fc03 PR30738: Implement two-phase name lookup for fold-expressions. 2020-08-06 16:56:39 -07:00
Alexey Bataev 0af7835eae [OPENMP]Redesign of OMPExecutableDirective/OMPDeclarativeDirective representation.
Summary:
Introduced OMPChildren class to handle all associated clauses, statement
and child expressions/statements. It allows to represent some directives
more correctly (like flush, depobj etc. with pseudo clauses, ordered
depend directives, which are standalone, and target data directives).
Also, it will make easier to avoid using of CapturedStmt in directives,
if required (atomic, tile etc. directives).
Also, it simplifies serialization/deserialization of the
executable/declarative directives.
Reduces number of allocation operations for mapper declarations.

Reviewers: jdoerfert

Subscribers: yaxunl, guansong, jfb, cfe-commits, sstefan1, aaron.ballman, caomhin

Tags: #clang

Differential Revision: https://reviews.llvm.org/D83261
2020-08-06 12:25:19 -04:00
Haojian Wu 1c0a0dfa02 [Concepts] Include the found concept decl when dumping the ConceptSpecializationExpr
Differential Revision: https://reviews.llvm.org/D85124
2020-08-04 15:58:12 +02:00
Nathan Ridge 4ede396849 [clang] Include trailing-requires-clause in FunctionDecl's source range
Fixes https://github.com/clangd/clangd/issues/476

Differential Revision: https://reviews.llvm.org/D85108
2020-08-04 02:52:01 -04:00
Alexey Bader 8d27be8dba [OpenCL] Add global_device and global_host address spaces
This patch introduces 2 new address spaces in OpenCL: global_device and global_host
which are a subset of a global address space, so the address space scheme will be
looking like:

```
generic->global->host
                          ->device
             ->private
             ->local
constant
```

Justification: USM allocations may be associated with both host and device memory. We
want to give users a way to tell the compiler the allocation type of a USM pointer for
optimization purposes. (Link to the Unified Shared Memory extension:
https://github.com/intel/llvm/blob/sycl/sycl/doc/extensions/USM/cl_intel_unified_shared_memory.asciidoc)

Before this patch USM pointer could be only in opencl_global
address space, hence a device backend can't tell if a particular pointer
points to host or device memory. On FPGAs at least we can generate more
efficient hardware code if the user tells us where the pointer can point -
being able to distinguish between these types of pointers at compile time
allows us to instantiate simpler load-store units to perform memory
transactions.

Patch by Dmitry Sidorov.

Reviewed By: Anastasia

Differential Revision: https://reviews.llvm.org/D82174
2020-07-29 17:24:53 +03:00
Nathan Ridge 89247792c5 [clang] Fix ConceptSpecializationExpr::getEndLoc()
Summary:
It returned an invalid location in case of a constrained-parameter
with no explicit arguments.

Reviewers: hokein

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D84613
2020-07-29 02:44:26 -04:00
Haojian Wu c0bd9fa137 [Concepts] Fix ast dump for immediately declared constraint.
Reviewed By: nridge

Differential Revision: https://reviews.llvm.org/D84461
2020-07-28 12:10:03 +02:00
Serge Pavlov 70e7aa4a4e [AST][FPEnv] Keep FP options in trailing storage of CallExpr
This change allow a CallExpr to have optional FPOptionsOverride object,
stored in trailing storage. The implementaion is made similar to the way
used in BinaryOperator.

Differential Revision: https://reviews.llvm.org/D84343
2020-07-24 12:04:19 +07:00
Haojian Wu 706a4353e8 [AST][RecoveryExpr] Error-dependent expression should not be treat as a nullptr pointer constant.
If an expression is contains-error and its type is unknown (dependent), we
don't treat it as a null pointer constant.

Fix a recovery-ast crash on C.

Differential Revision: https://reviews.llvm.org/D84222
2020-07-22 10:03:51 +02:00
Haojian Wu 7af852dcbf [AST][RecoveryExpr] Preserve the invalid "undef_var" initializer.
And don't invalidate the VarDecl if the type is known.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D81395
2020-07-21 09:38:09 +02:00
Haojian Wu 70e2c7ad2e [AST][RecoveryExpr] Add recovery-ast tests for C language, NFC.
some examples are working already.

Differential Revision: https://reviews.llvm.org/D84146
2020-07-20 15:33:59 +02:00
Haojian Wu 684e416ef1 [AST][RecoveryExpr] Preserve the AST for invalid conditions.
Adjust an existing diagnostic test, which is an improvement of secondary diagnostic.

Differential Revision: https://reviews.llvm.org/D81163
2020-07-20 14:58:36 +02:00
Haojian Wu 17ef788df5 [AST][RecoveryExpr] Preserve the AST for invalid class constructions.
Differential Revision: https://reviews.llvm.org/D81090
2020-07-20 13:11:15 +02:00
Jan Korous 5e8b4be9f8 [AST][NFC] Simplify a regression test
Differential Revision: https://reviews.llvm.org/D83438
2020-07-16 12:07:18 -07:00
Ilya Golovenko a130cf8ae8
[clang] Fix printing of lambdas with capture expressions
Patch by @walrus !

Reviewers: lattner, kadircet

Reviewed By: kadircet

Subscribers: riccibruno, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D83855
2020-07-16 12:50:25 +02:00
Jan Korous e81f9cd213 [AST][test] Add regression test forPointerExprEvaluator::VisitCXXNewExpr
This assert was failing:
assert(CAT && "unexpected type for array initializer");

until this patch landed:
9a7eda1bec
PR45350: Handle unsized array CXXConstructExprs in constant evaluation
2020-07-09 12:11:08 -07:00
Bruno Ricci 7a7d50e1f0
[clang][NFC] Also test for serialization in test/AST/ast-dump-APValue-*
This does not actually exercise the serialization of APValue, but it
will at least prevent a regression in the future. NFC.
2020-07-08 16:39:11 +01:00
Haojian Wu 96a5cfff20 [AST][RecoveryExpr] Fix the value category for recovery expr.
RecoveryExpr was always lvalue, but it is wrong if we use it to model
broken function calls, function call expression has more compliated rules:

- a call to a function whose return type is an lvalue reference yields an lvalue;
- a call to a function whose return type is an rvalue reference yields an xvalue;
- a call to a function whose return type is nonreference type yields a prvalue;

This patch makes the recovery-expr align with the function call if it is
modeled a broken call.

Differential revision: https://reviews.llvm.org/D83201
2020-07-08 13:55:07 +02:00
Bruno Ricci f63e3ea558
[clang] Rework how and when APValues are dumped
Currently APValues are dumped as a single string. This becomes quickly
completely unreadable since APValue is a tree-like structure. Even a simple
example is not pretty:

  struct S { int arr[4]; float f; };
  constexpr S s = { .arr = {1,2}, .f = 3.1415f };
  // Struct  fields: Array: Int: 1, Int: 2, 2 x Int: 0, Float: 3.141500e+00

With this patch this becomes:

  -Struct
   |-field: Array size=4
   | |-elements: Int 1, Int 2
   | `-filler: 2 x Int 0
   `-field: Float 3.141500e+00

Additionally APValues are currently only dumped as part of visiting a
ConstantExpr. This patch also dump the value of the initializer of constexpr
variable declarations:

  constexpr int foo(int a, int b) { return a + b - 42; }
  constexpr int a = 1, b = 2;
  constexpr int c = foo(a, b) > 0 ? foo(a, b) : foo(b, a);
  // VarDecl 0x62100008aec8 <col:3, col:57> col:17 c 'const int' constexpr cinit
  // |-value: Int -39
  // `-ConditionalOperator 0x62100008b4d0 <col:21, col:57> 'int'
  // <snip>

Do the above by moving the dump functions to TextNodeDumper which already has
the machinery to display trees. The cases APValue::LValue, APValue::MemberPointer
and APValue::AddrLabelDiff are left as they were before (unimplemented).

We try to display multiple elements on the same line if they are considered to
be "simple". This is to avoid wasting large amounts of vertical space in an
example like:

  constexpr int arr[8] = {0,1,2,3,4,5,6,7};
  // VarDecl 0x62100008bb78 <col:3, col:42> col:17 arr 'int const[8]' constexpr cinit
  // |-value: Array size=8
  // | |-elements: Int 0, Int 1, Int 2, Int 3
  // | `-elements: Int 4, Int 5, Int 6, Int 7

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

Reviewed By: aaron.ballman
2020-07-06 22:03:08 +01:00
Bruno Ricci c10295e1bd
[clang][NFC] Add a missing /dev/null in test/AST/ast-dump-lambda.cpp 2020-07-03 13:59:23 +01:00
Bruno Ricci 54eb42537e
[clang][NFC] Also test for serialization in test/AST/ast-dump-comment.cpp 2020-07-03 13:59:23 +01:00