Commit Graph

57156 Commits

Author SHA1 Message Date
Fangrui Song 527b0f8c74 [Driver] Allow -mnop-mcount for SystemZ and -mfentry for X86 and SystemZ
gcc/config/{i386,s390} support -mnop-mcount. We currently only support
-mnop-mcount for SystemZ. The function attribute "mnop-mcount" is
ignored on other targets.

gcc/config/{i386,s390} support -mfentry. We currently only support
-mfentry for X86 and SystemZ. TargetOpcode::FENTRY_CALL is not handled
on other targets.

  % clang -target aarch64 -pg -mfentry a.c -c
  fatal error: error in backend: Not supported instr: <MCInst 21>

-mfentry, -mrecord-mcount, and -mnop-mcount were invented for Linux
ftrace. Linux uses $(call cc-option-yn,-mrecord-mcount) to detect if the
specific feature is available. Reject unsupported features so that Linux
build system will not wrongly consider them available and cause
build/runtime failures.

Note, GCC has stricter checks that we do not implement, e.g. -fpic/-fpie
-fnop-mcount is not allowed on x86, -fpic/-fpie -mfentry is not allowed
on x86-32.
2019-12-22 00:01:42 -08:00
Fangrui Song 0792ef7256 [Driver] Verify -mrecord-mcount in Driver, instead of CodeGen after D71627
GCC's x86 and s390 ports support -mrecord-mcount. Other ports reject the
option.

  aarch64-linux-gnu-gcc: error: unrecognized command line option ‘-mrecord-mcount’

Allowing this option can cause failures when building Linux kernel for
aarch64, powerpc64, etc, which will think the feature is available if
the clang command returns 0.
2019-12-21 22:47:24 -08:00
Yaxun (Sam) Liu 7376d9eb38 [NFC] Separate getLastArgIntValue to Basic
getLastArgIntValue is a useful utility function to get command line argument as an integer.
Currently it is in Frontend so that it can only be used by clang -cc1. Move it to basic so
that it can also be used by clang driver.

Differential Revision: https://reviews.llvm.org/D71080
2019-12-21 20:39:31 -05:00
Michael Liao 7cee288586 Fix `-Wunused-variable` warning. NFC. 2019-12-21 11:10:35 -05:00
Mark de Wever 70d592d68c [Analyzer] Use a reference in a range-based for
This avoids unneeded copies when using a range-based for loops.

This avoids new warnings due to D68912 adds -Wrange-loop-analysis to -Wall.

Differential Revision: https://reviews.llvm.org/D70869
2019-12-21 14:52:29 +01:00
Mark de Wever be1a9b3863 [Wdocumentation] Implement \anchor
Differential revision: https://reviews.llvm.org/D69223
2019-12-21 14:52:21 +01:00
Stephen Kelly 5a79cfa32d Customize simplified dumping and matching of LambdaExpr
Reviewers: aaron.ballman

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D71680
2019-12-21 11:02:11 +00:00
Stephen Kelly 0378f3a903 Revert "Customize simplified dumping and matching of LambdaExpr"
This reverts commit 494b1318ca.
2019-12-20 21:33:31 +00:00
Stephen Kelly 494b1318ca Customize simplified dumping and matching of LambdaExpr
Reviewers: aaron.ballman

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D71680
2019-12-20 21:13:23 +00:00
Gabor Horvath 59878ec809 [analyzer] Add path notes to FuchsiaHandleCheck.
Differential Revision: https://reviews.llvm.org/D70725
2019-12-20 12:40:41 -08:00
Gabor Horvath 82923c71ef [analyzer] Add Fuchsia Handle checker
The checker can diagnose handle use after releases, double releases, and
handle leaks.

Differential Revision: https://reviews.llvm.org/D70470
2019-12-20 12:33:16 -08:00
Sid Manning d567b0ba84 Avoid unsupported LLD options
Differential Revision: https://reviews.llvm.org/D70919
2019-12-20 14:18:10 -06:00
Gabor Horvath fe17b30a79 [attributes][analyzer] Add annotations for handles.
These annotations will be used in an upcomming static analyzer check
that finds handle leaks, use after releases, and double releases.

Differential Revision: https://reviews.llvm.org/D70469
2019-12-20 11:47:55 -08:00
Kamlesh Kumar 304d1304b7 Apply the alignment specifier attribute to anonymous unions and structs. 2019-12-20 14:42:37 -05:00
Pierre Habouzit 42f9d0c0be [objc_direct] Tigthen checks for direct methods
Because the name of a direct method must be agreed upon by the caller
and the implementation, certain bad practices that one can get away with
when using dynamism are fatal with direct methods.

To avoid really weird and unscruttable linker error, tighten the
front-end error reporting.

Rule 1:
  Direct methods can only have at most one declaration in an @interface
  container. Any redeclaration is strictly forbidden.

  Today some amount of redeclaration is tolerated between the main
  interface and categories for dynamic methods, but we can't have that.

Rule 2:
  Direct method implementations can only be declared in a matching
  @interface container: when implemented in the primary @implementation
  then the declaration must be in the primary @interface or an
  extension, and when implemented in a category, the declaration must be
  in the @interface for the same category.

Also fix another issue with ObjCMethod::getCanonicalDecl(): when an
implementation lives in the primary @interface, then its canonical
declaration can be in any extension, even when it's not an accessor.

Add Sema tests to cover the new errors, and CG tests to beef up testing
around function names for categories and extensions.

Radar-Id: <rdar://problem/58054563>

Differential Revision: https://reviews.llvm.org/D71694
2019-12-20 10:57:36 -08:00
mydeveloperday 2f209ccfbe [clang-format] C# formatting a class with inheritance followed by an attribute specifier assume its a braces initializer
Summary:
https://bugs.llvm.org/show_bug.cgi?id=44340

The rule that prevents `... {} [[....]]`  being treated as a braced initializer for C++ causes problems for C# with attributes, causing it to be incorrectly classified and then messing up the subsequent formatting. (see bug for details of formatting)

Reviewers: mitchell-stellar, klimek, sammccall

Reviewed By: mitchell-stellar

Subscribers: cfe-commits

Tags: #clang-format, #clang

Differential Revision: https://reviews.llvm.org/D71769
2019-12-20 17:07:00 +00:00
Dmitri Gribenko 73f423e739 Parenthesized a logical expression.
This change fixes a warning on the ppc64be buildbot.
2019-12-20 14:36:21 +01:00
Dmitri Gribenko 9caf12e849 Use isa instead of dyn_cast 2019-12-20 14:36:21 +01:00
Kadir Cetinkaya c2377eae28
[clang][Tooling] Prefer -x over -std when interpolating
Summary:
Currently interpolation logic prefers -std over -x. But the latter is a
more strong signal, so this patch inverts the order and only makes use of -std
if -x didn't exist.

Fixes https://github.com/clangd/clangd/issues/185

Thanks @sammccall for tracking this down!

Reviewers: sammccall

Subscribers: ilya-biryukov, usaxena95, cfe-commits, sammccall

Tags: #clang

Differential Revision: https://reviews.llvm.org/D71727
2019-12-20 11:10:36 +01:00
Karl-Johan Karlsson e8efac4b15 [clang] Fix the canonicalization of paths in -fdiagnostics-absolute-paths
In the current implementation of clang the canonicalization of paths in
diagnostic messages (when using -fdiagnostics-absolute-paths) only works
if the symbolic link is in the directory part of the filename, not if
the file itself is a symbolic link to another file.

This patch adds support to canonicalize the complete path including the
file.

Reviewers: rsmith, hans, rnk, ikudrin

Reviewed By: rnk

Differential Revision: https://reviews.llvm.org/D70527
2019-12-20 09:16:33 +01:00
Richard Smith de21704ba9 CWG2352: Allow qualification conversions during reference binding.
The language wording change forgot to update overload resolution to rank
implicit conversion sequences based on qualification conversions in
reference bindings. The anticipated resolution for that oversight is
implemented here -- we order candidates based on qualification
conversion, not only on top-level cv-qualifiers.

For OpenCL/C++, this allows reference binding between pointers with
differing (nested) address spaces. This makes the behavior of reference
binding consistent with that of implicit pointer conversions, as is the
purpose of this change, but that pre-existing behavior for pointer
conversions is itself probably not correct. In any case, it's now
consistently the same behavior and implemented in only one place.
2019-12-19 18:37:55 -08:00
Richard Smith f4a45c2ce4 Fix crash on init-capture packs where the type of the initializer is non-dependent. 2019-12-19 15:20:10 -08:00
Artem Dergachev b284005072 [analyzer] Add a syntactic security check for ObjC NSCoder API.
Method '-[NSCoder decodeValueOfObjCType:at:]' is not only deprecated
but also a security hazard, hence a loud check.

Differential Revision: https://reviews.llvm.org/D71728
2019-12-19 14:54:29 -08:00
Tim Northover 85cb560b8a ConstrainedFP: use API compatible with opaque pointers.
This just updates an IRBuilder interface to take Functions instead of
Values so the type can be derived, and fixes some callsites in Clang to
call the updated API.
2019-12-19 21:50:47 +00:00
Richard Smith df2e2ab07b Implement latest C++ feature test macro recommendations.
We don't yet advertise init capture packs, because I found some bugs
while testing it. We reject-valid and then crash on both of these:

template<int ...a> auto x = [...y = a] {};
template<int ...a> auto x = [y = a...] {};
2019-12-19 12:59:13 -08:00
Warren Ristow 7fcd9e3f70 [X86] Mark various pointer arguments in builtins as const
Enabling `-Wcast-qual` identified many casts in various system headers
that were dropping the `const` qualifier.  Fixing those missing
qualifiers pointed out that a few of the definitions of the builtins
did not properly identify their arguments as `const` pointers.  This
commit fixes those builtin definitions, and the system header files
so that they no longer drop the qualifier.

Differential Revision: https://reviews.llvm.org/D71718
2019-12-19 11:42:11 -08:00
shafik 6a7df3a3f9 [ASTImporter][LLDB] Modifying ImportDeclContext(...) to ensure that we complete each FieldDecl of a RecordDecl when we are importing the definiton
This fix was motivated by a crashes in expression parsing during code generation in which we had a RecordDecl that had incomplete FieldDecl. During code generation when computing the layout for the RecordDecl we crash because we have several incomplete FieldDecl.

This fixes the issue by assuring that during ImportDefinition(...) for a RecordDecl we also import the definitions for each FieldDecl.

Differential Revision: https://reviews.llvm.org/D71378
2019-12-19 11:16:54 -08:00
Jonas Paulsson 2520bef865 [Clang FE, SystemZ] Recognize -mrecord-mcount CL option.
Recognize -mrecord-mcount from the command line and add a function attribute
"mrecord-mcount" when passed.

Only valid on SystemZ (when used with -mfentry).

Review: Ulrich Weigand
https://reviews.llvm.org/D71627
2019-12-19 08:51:55 -08:00
Hans Wennborg dde7b6bcda Re-land "Add an -fno-temp-file flag for compilation"
This time making sure to initialize FrontendOptions::UseTemporary.

Patch by Zachary Henkel!

Differential revision: https://reviews.llvm.org/D70615
2019-12-19 13:34:52 +01:00
Artem Dergachev f0ced2ddb4 [analysis] Re-discard type sugar when casting values retrieved from the Store.
Canonicalization was accidentally omitted in 6d3f43ec.
2019-12-18 18:00:57 -08:00
Jordan Rupprecht 553a727f5f [clang] Remove -Wexperimental-float-control.
Summary: Per D62731, the behavior of clang with `-frounding-math` is no worse than when the rounding flag was completely ignored, so remove this unnecessary warning.

Reviewers: mibintc, chandlerc, echristo, rjmccall, kpn, erichkeane, rsmith, andrew.w.kaylor

Reviewed By: mibintc

Subscribers: merge_guards_bot, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D71671
2019-12-18 16:51:55 -08:00
Francis Visoiu Mistrih 07b8f8e5f5 [Remarks][Driver] Place temporary remark files next to temporary object files
On Darwin, when used for generating a linked binary from a source file
(through an intermediate object file), the driver will invoke `cc1` to
generate a temporary object file. The temporary remark file will now be
emitted next to the object file, which will then be picked up by
`dsymutil` and emitted in the .dSYM bundle.

This is available for all formats except YAML since by default, YAML
doesn't need a section and the remark file will be lost.
2019-12-18 16:42:02 -08:00
Thomas Lively 71eb8023d8 [WebAssembly] Add avgr_u intrinsics and require nuw in patterns
Summary:
The vector pattern `(a + b + 1) / 2` was previously selected to an
avgr_u instruction regardless of nuw flags, but this is incorrect in
the case where either addition may have an unsigned wrap. This CL
changes the existing pattern to require both adds to have nuw flags
and adds builtin functions and intrinsics for the avgr_u instructions
because the corrected pattern is not representable in C.

Reviewers: aheejin

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

Tags: #clang, #llvm

Differential Revision: https://reviews.llvm.org/D71648
2019-12-18 15:31:38 -08:00
Vedant Kumar 5094e6dad6 Revert concepts changes from D41910
These changes caused LibcxxVariantDataFormatterTestCase in lldb to fail
with an assert:

Assertion failed: (Idx < size() && "Out-of-bounds Bit access."),
function operator[], file
/Users/buildslave/jenkins/workspace/lldb-cmake/llvm-project/llvm/include/llvm/ADT/SmallBitVector.h,
line 452.

In:

7  clang-10                 0x00000001094b79d9 isAtLeastAsSpecializedAs(clang::Sema&, clang::SourceLocation, clang::FunctionTemplateDecl*, clang::FunctionTemplateDecl*, clang::TemplatePartialOrderingContext, unsigned int) + 1865
8  clang-10                 0x00000001094b7111 clang::Sema::getMoreSpecializedTemplate(clang::FunctionTemplateDecl*, clang::FunctionTemplateDecl*, clang::SourceLocation, clang::TemplatePartialOrderingContext, unsigned int, unsigned int) + 97
9  clang-10                 0x000000010939bf88 clang::isBetterOverloadCandidate(clang::Sema&, clang::OverloadCandidate const&, clang::OverloadCandidate const&, clang::SourceLocation, clang::OverloadCandidateSet::CandidateSetKind) + 1128

Revert "[Concepts] Fix incorrect move out of temporary in D41910"

This reverts commit 11d5fa6e87.

Revert "[Concepts] Fix crash in D41910"

This reverts commit 12038be20e.

Revert "[Concepts] Constrained partial specializations and function overloads."

This reverts commit fc0731b98a.
2019-12-18 15:02:39 -08:00
Stephen Kelly 98e8f774eb Add method to ignore invisible AST nodes
Reviewers: aaron.ballman

Subscribers: mgorny, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70613
2019-12-18 22:33:23 +00:00
Francis Visoiu Mistrih d79b11fefb [Remarks][Driver] Run dsymutil when remarks are enabled
When clang is invoked with a source file without -c or -S, it creates a
cc1 job, a linker job and if debug info is requested, a dsymutil job. In
case of remarks, we should also create a dsymutil job to avoid losing
the remarks that will be generated in a tempdir that gets removed.

Differential Revision: https://reviews.llvm.org/D71675
2019-12-18 14:31:41 -08:00
Francis Visoiu Mistrih a8c678cb9a [Remarks][Driver][NFC] Make shouldEmitRemarks more available in the Driver
Move the function to Driver.h so that it can be re-used in other places.
2019-12-18 14:31:41 -08:00
Artem Dergachev bce1cce6bf [analyzer] Teach MismatchedDealloc about initWithBytesNoCopy with deallocator.
MallocChecker warns when memory is passed into -[NSData initWithBytesNoCopy]
but isn't allocated by malloc(), because it will be deallocated by free().
However, initWithBytesNoCopy has an overload that takes an arbitrary block
for deallocating the object. If such overload is used, it is no longer
necessary to make sure that the memory is allocated by malloc().
2019-12-18 14:19:17 -08:00
Richard Smith 3ced23976a Refactor CompareReferenceRelationship and its callers in preparation for
implementing the resolution of CWG2352.

No functionality change, except that we now convert the referent of a
reference binding to the underlying type of the reference in more cases;
we used to happen to preserve the type sugar from the referent if the
only type change was in the cv-qualifiers.

This exposed a bug in how we generate code for trivial assignment
operators: if the type sugar (particularly the may_alias attribute)
got lost during reference binding, we'd use the "wrong" TBAA information
for the load during the assignment.
2019-12-18 14:05:57 -08:00
Akira Hatanaka a6d57a8cd4 Use hasOffsetApplied to initialize member HasOffsetApplied
This is NFC since none of the constructor calls in trunk pass
hasOffsetApplied=true.
2019-12-18 13:56:59 -08:00
Reid Kleckner 71f9c30b53 Move TypeSourceInfo to Type.h
TypeSourceInfo is a thin wrapper around TypeLocs. Notionally, the best
place for it to live would be TypeLoc.h, but Decl.h requires it to be
complete, so it needs to be lower in the dependency graph. Type.h seems
like the next best place.

By itself, this change has no impact on build time, because it doesn't
remove a single dependency edge from a .cpp file to a .h file, but it is
an incremental step towards making the AST headers less interdependent.

Reviewers: rsmith

Differential Revision: https://reviews.llvm.org/D71427
2019-12-18 13:47:00 -08:00
Artem Dergachev badba5118f [analyzer] NonnullGlobalConstants: Add support for kCFNull.
It's a singleton in CoreFoundation that always contains a non-null CFNullRef.
2019-12-18 12:08:15 -08:00
Saar Raz 11d5fa6e87 [Concepts] Fix incorrect move out of temporary in D41910
Moves out of temporaries caused warnings that failed builds.
2019-12-18 21:43:53 +02:00
Saar Raz 12038be20e [Concepts] Fix crash in D41910
Differential Revision: https://reviews.llvm.org/D41910
2019-12-18 21:31:33 +02:00
Jonas Paulsson ca520592c0 [Clang FE, SystemZ] Don't add "true" value for the "mnop-mcount" attribute.
Let the "mnop-mcount" function attribute simply be present or non-present.
Update SystemZ backend as well to use hasFnAttribute() instead.

Review: Ulrich Weigand
https://reviews.llvm.org/D71669
2019-12-18 11:04:13 -08:00
Saar Raz fc0731b98a [Concepts] Constrained partial specializations and function overloads.
Added support for constraint satisfaction checking and partial ordering of constraints in constrained partial specialization and function template overloads.

Phabricator: D41910
2019-12-18 21:01:31 +02:00
Amy Huang a85f5efd95 Add support for the MS qualifiers __ptr32, __ptr64, __sptr, __uptr.
Summary:
This adds parsing of the qualifiers __ptr32, __ptr64, __sptr, and __uptr and
lowers them to the corresponding address space pointer for 32-bit and 64-bit pointers.
(32/64-bit pointers added in https://reviews.llvm.org/D69639)

A large part of this patch is making these pointers ignore the address space
when doing things like overloading and casting.

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

Reviewers: rnk, rsmith

Subscribers: jholewinski, jvesely, nhaehnle, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D71039
2019-12-18 10:41:12 -08:00
Mitch Phillips b19d87b16f Revert "Add an -fno-temp-file flag for compilation"
This reverts commit d129aa1d53.

This broke the MSan buildbots. More information available in the
original PR: https://reviews.llvm.org/D70615
2019-12-18 09:05:09 -08:00
Hans Wennborg d129aa1d53 Add an -fno-temp-file flag for compilation
Our build system does not handle randomly named files created during
the build well. We'd prefer to write compilation output directly
without creating a temporary file. Function parameters already
existed to control this behavior but were not exposed all the way out
to the command line.

Patch by Zachary Henkel!

Differential revision: https://reviews.llvm.org/D70615
2019-12-18 15:07:43 +01:00
Ilya Biryukov c1bbefef9d [Syntax] Use a hash table to search for tokens by their location
This is both more efficient and avoids corner cases in
`SourceManager::isBeforeInTranslationUnit`.

The change is trivial and clearly a performance improvement on the hot
path of building the syntax tree, so sending without review.
2019-12-18 12:24:00 +01:00
Ilya Biryukov 1ad15046dc [Syntax] Allow to mutate syntax trees
Summary:
This patch adds facilities to mutate the syntax trees and produce
corresponding text replacements.

The public interface of the syntax library now includes facilities to:
    1. perform type-safe modifications of syntax trees,
    2. compute textual replacements to apply the modifications,
    3. create syntax trees not backed by the source code.

For each of the three, we only add a few example transformations in this
patch to illustrate the idea, support for more kinds of nodes and
transformations will be done in follow-up patches.

The high-level mutation operations are implemented on top of operations
that allow to arbitrarily change the trees. They are considered to be
implementation details and are not available to the users of the
library.

Reviewers: sammccall, gribozavr2

Reviewed By: gribozavr2

Subscribers: merge_guards_bot, mgorny, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D64573
2019-12-18 12:19:03 +01:00
Gabor Marton bc5b7e21e3 recommit: [ASTImporter] Friend class decl should not be visible in its context
Summary:
In the past we had to use DeclContext::makeDeclVisibleInContext to make
friend declarations available for subsequent lookup calls and this way
we could chain (redecl) the structurally equivalent decls.
By doing this we created an AST that improperly made declarations
visible in some contexts, so the AST was malformed.
Since we use the importer specific lookup this is no longer necessary,
because with that we can find every previous nodes.

Reviewers: balazske, a_sidorin, a.sidorin, shafik

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D71020
2019-12-18 11:43:46 +01:00
Sven van Haastregt 308b8b76ce [OpenCL] Add builtin function extension handling
Provide a mechanism to attach OpenCL extension information to builtin
functions, so that their use can be restricted according to the
extension(s) the builtin is part of.

Patch by Pierre Gondois and Sven van Haastregt.

Differential Revision: https://reviews.llvm.org/D71476
2019-12-18 10:13:51 +00:00
Gabor Horvath ea93d7d642 [CFG] Add an option to expand CXXDefaultInitExpr into aggregate initialization
This is useful for clients that are relying on linearized CFGs for evaluating
subexpressions and want the default initializer to be evaluated properly.

The upcoming lifetime analysis is using this but it might also be useful
for the static analyzer at some point.

Differential Revision: https://reviews.llvm.org/D71642
2019-12-17 17:56:06 -08:00
Artem Dergachev 6d3f43ec61 [analysis] Discard type qualifiers when casting values retrieved from the Store.
This canonicalizes the representation of unknown pointer symbols,
which reduces the overall confusion in pointer cast representation.

Patch by Vince Bridgers!

Differential Revision: https://reviews.llvm.org/D70836
2019-12-17 15:00:41 -08:00
Mark de Wever b750486c5d [Driver] Avoid copies in range-based for loops
This avoids new warnings due to D68912 adds -Wrange-loop-analysis to -Wall.

Differential Revision: https://reviews.llvm.org/D71527
2019-12-17 21:56:04 +01:00
Mark de Wever 3ec6128dae [Sema] Fixes -Wrange-loop-analysis warnings
This avoids new warnings due to D68912 adds -Wrange-loop-analysis to -Wall.

Differential Revision: https://reviews.llvm.org/D71529
2019-12-17 21:54:32 +01:00
Mark de Wever 385339034f [Frontend] Fixes -Wrange-loop-analysis warnings
This avoids new warnings due to D68912 adds -Wrange-loop-analysis to -Wall.

Differential Revision: https://reviews.llvm.org/D71530
2019-12-17 21:52:47 +01:00
Alexey Bataev b6e7084e25 [OPENMP50]Add parsing/sema analysis for nontemporal clause.
Add basic support for parsing/sema analysis of the nontemporal clause in
simd-based directives.
2019-12-17 14:46:32 -05:00
Jonas Paulsson 599d1cc07a [Clang FE, SystemZ] Recognize -mpacked-stack CL option
Recognize -mpacked-stack from the command line and add a function attribute
"mpacked-stack" when passed. This is needed for building the Linux kernel.

If this option is passed for any other target than SystemZ, an error is
generated.

Review: Ulrich Weigand
https://reviews.llvm.org/D71441
2019-12-17 11:26:17 -08:00
Pierre Habouzit a4e1819c16 [objc_direct] fix uniquing when re-declaring a readwrite-direct property
ObjCMethodDecl::getCanonicalDecl() for re-declared readwrite properties,
only looks in the ObjCInterface for the declaration of the setter
method, which it won't find.

When the method is a property accessor, we must look in extensions for a
possible redeclaration.

Radar-Id: rdar://problem/57991337

Differential Revision: https://reviews.llvm.org/D71588
2019-12-17 11:07:48 -08:00
Nico Weber 55c55f8eb8 Revert "[ASTImporter] Friend class decl should not be visible in its context"
This reverts commit 4becf68c6f.
Breaks building on Windows, see comments on D71020
2019-12-17 13:43:50 -05:00
Alex Lorenz 25ce33a6e4 [driver][darwin] Pass -platform_version flag to the linker instead of the -<platform>_version_min flag
In Xcode 11, ld added a new flag called -platform_version that can be used instead of the old -<platform>_version_min flags.
The new flag allows Clang to pass the SDK version from the driver to the linker.
This patch adopts the new -platform_version flag in Clang, and starts using it by default,
unless a linker version < 520 is passed to the driver.

Differential Revision: https://reviews.llvm.org/D71579
2019-12-17 10:26:32 -08:00
Erich Keane 1ed832e424 Reland [NFC-I] Remove hack for fp-classification builtins
The FP-classification builtins (__builtin_isfinite, etc) use variadic
packs in the definition file to mean an overload set.  Because of that,
floats were converted to doubles, which is incorrect. There WAS a patch
to remove the cast after the fact.

THis patch switches these builtins to just be custom type checking,
calls the implicit conversions for the integer members, and makes sure
the correct L->R casts are put into place, then does type checking like
normal.

A future direction (that wouldn't be NFC) would consider making
conversions for the floating point parameter legal.

Note: The initial patch for this missed that certain systems need to
still convert half to float, since they dont' support that type.
2019-12-17 06:58:29 -08:00
Gabor Marton 4becf68c6f [ASTImporter] Friend class decl should not be visible in its context
Summary:
In the past we had to use DeclContext::makeDeclVisibleInContext to make
friend declarations available for subsequent lookup calls and this way
we could chain (redecl) the structurally equivalent decls.
By doing this we created an AST that improperly made declarations
visible in some contexts, so the AST was malformed.
Since we use the importer specific lookup this is no longer necessary,
because with that we can find every previous nodes.

Reviewers: balazske, a_sidorin, a.sidorin, shafik

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D71020
2019-12-17 14:48:55 +01:00
Sven van Haastregt df5a905aa8 [OpenCL] Add ExtVectorElementExpr constant evaluation (PR42387)
Add constexpr evaluation for ExtVectorElementExpr nodes by evaluating
the underlying vector expression.  Add basic folding for the case that
Evaluate does not return an LValue.

Differential Revision: https://reviews.llvm.org/D71133
2019-12-17 11:10:06 +00:00
Raphael Isemann ccfab8e459 [ObjC][DWARF] Emit DW_AT_APPLE_objc_direct for methods marked as __attribute__((objc_direct))
Summary:
With DWARF5 it is no longer possible to distinguish normal methods and methods with `__attribute__((objc_direct))` by just looking at the debug information
as they are both now children of the of the DW_TAG_structure_type that defines them (before only the `__attribute__((objc_direct))` methods were children).

This means that in LLDB we are no longer able to create a correct Clang AST of a module by just looking at the debug information. Instead we would
need to call the Objective-C runtime to see which of the methods have a `__attribute__((objc_direct))` and then add the attribute to our own Clang AST
depending on what the runtime returns. This would mean that we either let the module AST be dependent on the Objective-C runtime (which doesn't
seem right) or we retroactively add the missing attribute to the imported AST in our expressions.

A third option is to annotate methods with `__attribute__((objc_direct))` as `DW_AT_APPLE_objc_direct` which is what this patch implements. This way
LLDB doesn't have to call the runtime for any `__attribute__((objc_direct))` method and the AST in our module will already be correct when we create it.

Reviewers: aprantl, SouraVX

Reviewed By: aprantl

Subscribers: hiraditya, cfe-commits, llvm-commits

Tags: #clang, #llvm, #debug-info

Differential Revision: https://reviews.llvm.org/D71201
2019-12-17 09:40:36 +01:00
Martin Storsjö ee0a3b5c77 [MinGW] Implicitly add .exe suffix if not provided
GCC implicitly adds an .exe suffix if it is given an output file name,
but the file name doesn't contain a suffix, and there are certain
users of GCC that rely on this behaviour (and run into issues when
trying to use Clang instead of GCC). And MSVC's cl.exe also does the
same (but not link.exe).

However, GCC only does this when actually running on windows, not when
operating as a cross compiler.

As GCC doesn't have this behaviour when cross compiling, we definitely
shouldn't introduce the behaviour in such cases (as it would break
at least as many cases as this fixes).

Differential Revision: https://reviews.llvm.org/D71400
2019-12-17 10:08:39 +02:00
Richard Smith eea8ba097c Check whether the destination is a complete type in a static_cast (or
C-style cast) to an enumeration type.

We previously forgot to check this, and happened to get away with it
(with bad diagnostics) only because we misclassified incomplete
enumeration types as not being unscoped enumeration types. This also
fixes the misclassification.
2019-12-16 18:33:35 -08:00
Richard Smith f495de43bd [c++20] P1959R0: Remove support for std::*_equality. 2019-12-16 17:49:45 -08:00
Richard Smith 4e9f1379b9 If constant evaluation fails due to an unspecified pointer comparison,
produce a note saying that rather than the default "evaluation failed"
note.
2019-12-16 17:49:45 -08:00
Richard Smith 4b00299958 [c++20] Add deprecation warnings for the expression forms deprecated by P1120R0.
This covers:
 * usual arithmetic conversions (comparisons, arithmetic, conditionals)
   between different enumeration types
 * usual arithmetic conversions between enums and floating-point types
 * comparisons between two operands of array type

The deprecation warnings are on-by-default (in C++20 compilations); it
seems likely that these forms will become ill-formed in C++23, so
warning on them now by default seems wise.

For the first two bullets, off-by-default warnings were also added for
all the cases where we didn't already have warnings (covering language
modes prior to C++20). These warnings are in subgroups of the existing
-Wenum-conversion (except that the first case is not warned on if either
enumeration type is anonymous, consistent with our existing
-Wenum-conversion warnings).
2019-12-16 17:49:45 -08:00
Sam Clegg 0a1e349a79 [WebAssembly] Setting export_name implies llvm.used
This change updates the clang front end to add symbols to llvm.used
when they have explicit export_name attribute.

Differential Revision: https://reviews.llvm.org/D71493
2019-12-16 14:48:38 -08:00
Brian Gesiak 376cf43729 [coroutines][PR41909] Generalize fix from D62550
Summary:
In https://reviews.llvm.org/D62550 @rsmith pointed out that there are
many situations in which a coroutine body statement may be
transformed/rebuilt as part of a template instantiation, and my naive
check whether the coroutine was a generic lambda was insufficient.

This is indeed true, as I've learned by reading more of the
TreeTransform code. Most transformations are written in a way that
doesn't assume the resulting types are not dependent types. So the
assertion in 'TransformCoroutineBodyStmt', that the promise type must no
longer be dependent, is out of place.

This patch removes the assertion, spruces up some code comments, and
adds a test that would have failed with my naive check from
https://reviews.llvm.org/D62550.

Reviewers: GorNishanov, rsmith, lewissbaker

Reviewed By: rsmith

Subscribers: junparser, EricWF, rsmith, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70579
2019-12-16 17:43:04 -05:00
Erich Keane 3f22b4721e Revert "[NFC-I] Remove hack for fp-classification builtins"
This reverts commit b1e542f302.

The original 'hack' didn't chop out fp-16 to double conversions, so
systems that use FP16ConversionIntrinsics end up in IR-CodeGen with an
i16 type isntead of a float type (like PPC64-BE).  The bots noticed
this.

Reverting until I figure out how to fix this
2019-12-16 14:01:51 -08:00
Erich Keane b1e542f302 [NFC-I] Remove hack for fp-classification builtins
The FP-classification builtins (__builtin_isfinite, etc) use variadic
packs in the definition file to mean an overload set.  Because of that,
floats were converted to doubles, which is incorrect. There WAS a patch
to remove the cast after the fact.

THis patch switches these builtins to just be custom type checking,
calls the implicit conversions for the integer members, and makes sure
the correct L->R casts are put into place, then does type checking like
normal.

A future direction (that wouldn't be NFC) would consider making
conversions for the floating point parameter legal.
2019-12-16 12:22:55 -08:00
Thomas Lively 3a93756dfb [WebAssembly] Replace SIMD int min/max builtins with patterns
Summary:
The instructions were originally implemented via builtins and
intrinsics so users would have to explicitly opt-in to using
them. This was useful while were validating whether these instructions
should have been merged into the spec proposal. Now that they have
been, we can use normal codegen patterns, so the intrinsics and
builtins are no longer useful.

Reviewers: aheejin

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

Tags: #clang, #llvm

Differential Revision: https://reviews.llvm.org/D71500
2019-12-16 11:48:49 -08:00
Alexey Bataev 411e81a4e3 [OPENMP50]Add if clause in target teams idistribute simd directive.
According to OpenMP 5.0, if clause can be used in for simd directive. If
condition in the if clause if false, the non-vectorized version of the
loop must be executed.
2019-12-16 13:20:57 -05:00
Teresa Johnson 878ab6df03 [TLI] Support for per-Function TLI that overrides available libfuncs
Summary:

Follow-on to D66428 and D71193, to build the TLI per-function so
that -fno-builtin* handling can be migrated to use function attributes.
See discussion on D61634 for background. This is an enabler for fixing
handling of these options for LTO, for example.

With D71193, the -fno-builtin* flags are converted to function
attributes, so we can now set this information per-function on the TLI.

In this patch, the TLI constructor is changed to take a Function, which
can be used to override the available builtins. The TLI is augmented
with an array that can be used to specify which builtins are not
available for the corresponding function. The available function checks
are changed to consult this override before checking the underlying
module level baseline TLII. New code is added to set this override
array based on the attributes.

I also removed the code that sets availability in the TLII in clang from
the options, which is no longer needed.

I removed a per-Triple caching of TLII objects in the analysis object,
as it is based on the Module's Triple which is the same for all
functions in any case. Is there a case where we would be compiling
multiple Modules with different Triples in one compilation?

Finally, I have changed the legacy analysis wrapper to create and use
the new PM analysis class (TargetLibraryAnalysis) in getTLI. This is
consistent with the behavior of getTTI for the legacy
TargetTransformInfo analysis. This change means that getTLI now creates
a new TLI on each call (although that should be very cheap as we cache
the module level TLII, and computing the per-function
attribute based availability should also be reasonably efficient).
I measured the compile time for a large C++ file with tens of thousands
of functions and as expected there was no increase.

Reviewers: chandlerc, hfinkel, gchatelet

Subscribers: mehdi_amini, dexonsmith, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D67923
2019-12-16 09:19:30 -08:00
Alexey Bataev fd0c91bab1 [OPENMP50]Add if clause in target teams distribute parallel for simd directive.
According to OpenMP 5.0, if clause can be used in for simd directive. If
condition in the if clause if false, the non-vectorized version of the
loop must be executed.
2019-12-16 10:33:56 -05:00
Ulrich Weigand 9f99aba1cf [clang][SystemZ] Add support for -march=native
Handle -march=native in systemz::getSystemZTargetCPU, similar to
how this is done on other platforms.  Also change the return type
to std::string instead of const char *.
2019-12-16 16:11:32 +01:00
Kirill Bobyrev 3b9715cb21 [NFC] Fix typos in Clangd and Clang
Reviewed by: Jim

Differential Revision: https://reviews.llvm.org/D71455
2019-12-16 10:54:40 +01:00
Richard Smith bc633a42dd Mark the major papers for C++20 consistent comparisons as "done", and
start publishing the corresponding feature-test macro.
2019-12-15 22:20:06 -08:00
Richard Smith 4a4e90a823 [c++20] Compute exception specifications for defaulted comparisons.
This requires us to essentially fully form the body of the defaulted
comparison, but from an unevaluated context. Naively this would require
generating the function definition twice; instead, we ensure that the
function body is implicitly defined before performing the check, and
walk the actual body where possible.
2019-12-15 22:02:31 -08:00
Richard Smith fbf60b7dbe Properly compute whether statement expressions can throw, rather than
conservatively assuming they always can.

Also fix cases where we would not consider the computation of a VLA type
when determining whether an expression can throw. We don't yet properly
determine whether a VLA can throw, but no longer incorrectly claim it
can never throw.
2019-12-15 22:02:31 -08:00
Richard Smith 0ec1e99001 Resolve exception specifications after marking the corresponding
function as referenced, not before.

No functionality change intended. This is groundwork for computing the
exception specification of a defaulted comparison, for which we'd like
to use the implicit body where possible.
2019-12-15 22:02:30 -08:00
Mark de Wever 29e78ec679 [AST] Use a reference in a range-based for
This avoids unneeded copies when using a range-based for loops.

This avoids new warnings due to D68912 adds -Wrange-loop-analysis to -Wall.

Differential Revision: https://reviews.llvm.org/D71526
2019-12-15 21:17:07 +01:00
Raphael Isemann aa4558497f [clang] Improve LLVM-style RTTI support in ExternalASTSource/ExternalSemaSource
Summary:
We currently have some very basic LLVM-style RTTI support in the ExternalASTSource class hierarchy
based on the `SemaSource` bool( to discriminate it form the ExternalSemaSource). As ExternalASTSource
is supposed to be subclassed we should have extendable LLVM-style RTTI in this class hierarchy to make life easier
for projects building on top of Clang.

Most notably the current RTTI implementation forces LLDB to implement RTTI for its
own ExternalASTSource class (ClangExternalASTSourceCommon) by keeping a global set of
ExternalASTSources that are known to be ClangExternalASTSourceCommon. Projects
using Clang currently have to dosimilar workarounds to get RTTI support for their subclasses.

This patch turns this into full-fledged LLVM-style RTTI based on a static `ID` variable similar to
other LLVM class hierarchies. Also removes the friend declaration from ExternalASTSource to
its child class that was only used to grant access to the `SemaSource` member.

Reviewers: aprantl, dblaikie, rjmccall

Reviewed By: aprantl

Subscribers: riccibruno, labath, lhames, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D71397
2019-12-15 18:11:01 +01:00
Borsik Gabor 273e674252 [analyzer] Add support for namespaces to GenericTaintChecker
This patch introduces the namespaces for the configured functions and
also enables the use of the member functions.

I added an optional Scope field for every configured function. Functions
without Scope match for every function regardless of the namespace.
Functions with Scope will match if the full name of the function starts
with the Scope.
Multiple functions can exist with the same name.

Differential Revision: https://reviews.llvm.org/D70878
2019-12-15 12:11:22 +01:00
John McCall 2ac702aaf0 Move ASTRecordWriter into its own header; NFC.
Similar motivations to the movement of ASTRecordReader:
AbstractBasicWriter.h already has quite a few dependencies,
and it's going to get pretty large as we generate more and more
into it.  Meanwhile, most clients don't depend on this detail of
the implementation and shouldn't need to be recompiled.

I've also made OMPClauseWriter private, like it belongs.
2019-12-14 03:28:23 -05:00
John McCall c2f18315ff Move ASTRecordReader into its own header; NFC.
AbstractBasicReader.h has quite a few dependencies already,
and that's only likely to increase.  Meanwhile, ASTRecordReader
is really an implementation detail of the ASTReader that is only
used in a small number of places.

I've kept it in a public header for the use of projects like Swift
that might want to plug in to Clang's serialization framework.

I've also moved OMPClauseReader into an implementation file,
although it can't be made private because of friendship.
2019-12-14 03:28:23 -05:00
John McCall d505e57cc2 Abstract serialization: TableGen the (de)serialization code for Types.
The basic technical design here is that we have three levels
of readers and writers:

- At the lowest level, there's a `Basic{Reader,Writer}` that knows
  how to emit the basic structures of the AST.  CRTP allows this to
  be metaprogrammed so that the client only needs to support a handful
  of primitive types (e.g. `uint64_t` and `IdentifierInfo*`) and more
  complicated "inline" structures such as `DeclarationName` can just
  be emitted in terms of those primitives.

  In Clang's binary-serialization code, these are
  `ASTRecord{Reader,Writer}`.  For now, a large number of basic
  structures are still emitted explicitly by code on those classes
  rather than by either TableGen or CRTP metaprogramming, but I
  expect to move more of these over.

- In the middle, there's a `Property{Reader,Writer}` which is
  responsible for processing the properties of a larger object.  The
  object-level reader/writer asks the property-level reader/writer to
  project out a particular property, yielding a basic reader/writer
  which will be used to read/write the property's value, like so:

  ```
    propertyWriter.find("count").writeUInt32(node->getCount());
  ```

  Clang's binary-serialization code ignores this level (it uses
  the basic reader/writer as the property reader/writer and has the
  projection methods just return `*this`) and simply relies on the
  roperties being read/written in a stable order.

- At the highest level, there's an object reader/writer (e.g.
  `Type{Reader,Writer}` which emits a logical object with properties.
  Think of this as writing something like a JSON dictionary literal.

I haven't introduced support for bitcode abbreviations yet --- it
turns out that there aren't any operative abbreviations for types
besides the QualType one --- but I do have some ideas of how they
should work.  At any rate, they'll be necessary in order to handle
statements.

I'm sorry for not disentangling the patches that added basic and type
reader/writers; I made some effort to, but I ran out of energy after
disentangling a number of other patches from the work.

Negligible impact on module size, time to build a set of about 20
fairly large modules, or time to read a few declarations out of them.
2019-12-14 00:17:01 -05:00
John McCall 3ce3d23fac Standardize the reader methods in ASTReader; NFC.
There are three significant changes here:

- Most of the methods to read various embedded structures (`APInt`,
  `NestedNameSpecifier`, `DeclarationName`, etc.) have been moved
  from `ASTReader` to `ASTRecordReader`.  This cleans up quite a
  bit of code which was passing around `(F, Record, Idx)` arguments
  everywhere or doing explicit indexing, and it nicely parallels
  how it works on the writer side.  It also sets us up to then move
  most of these methods into the `BasicReader`s that I'm introducing
  as part of abstract serialization.

  As part of this, several of the top-level reader methods (e.g.
  `readTypeRecord`) have been converted to use `ASTRecordReader`
  internally, which is a nice readability improvement.

- I've standardized most of these method names on `readFoo` rather
  than `ReadFoo` (used in some of the helper structures) or `GetFoo`
  (used for some specific types for no apparent reason).

- I've changed a few of these methods to return their result instead
  of reading into an argument passed by reference.  This is partly
  for general consistency and partly because it will make the
  metaprogramming easier with abstract serialization.
2019-12-14 00:16:48 -05:00
Fangrui Song 074323c846 [Driver] Default to -momit-leaf-frame-pointer for AArch64
This matches https://gcc.gnu.org/onlinedocs/gcc/AArch64-Options.html

> -momit-leaf-frame-pointer
> -mno-omit-leaf-frame-pointer
>
>   Omit or keep the frame pointer in leaf functions. The former behavior is the default.

-mno-omit-leaf-frame-pointer is currently a no-op because
TargetOptions::DisableFramePointerElim is only considered for non-leaf
functions.

Reviewed By: efriedma

Differential Revision: https://reviews.llvm.org/D71167
2019-12-13 18:48:34 -08:00
Richard Smith c5b890e922 PR44268: Fix crash if __builtin_object_size is applied to a heap
allocation.
2019-12-13 18:41:54 -08:00
Richard Smith 38c3b5d562 [c++20] Improve phrasing of diagnostic for missing #include <compare>. 2019-12-13 18:41:54 -08:00
Artem Dergachev f450dd63a1 [analyzer] CStringChecker: Fix a crash on unknown value passed to strlcat.
Checkers should always account for unknown values.

Also use a slightly more high-level API that naturally avoids the problem.
2019-12-13 18:00:24 -08:00
Fangrui Song e4fce659a7 [Driver] Use .init_array for all gcc installations and simplify Generic_ELF -fno-use-init-array rules
D39317 made clang use .init_array when no gcc installations is found.
This change changes all gcc installations to use .init_array .

GCC 4.7 by default stopped providing .ctors/.dtors compatible crt files,
and stopped emitting .ctors for __attribute__((constructor)).
.init_array should always work.

FreeBSD rules are moved to FreeBSD.cpp to make Generic_ELF rules clean.

Reviewed By: rnk

Differential Revision: https://reviews.llvm.org/D71434
2019-12-13 14:06:51 -08:00
Alexey Bataev 8035bb4a65 [OPENMP]Fix skipping of functions body.
When parsing the code with OpenMP and the function's body must be
skipped, need to skip also OpenMP annotation tokens. Otherwise the
counters for braces/parens are unbalanced and parsing fails.
2019-12-13 16:51:46 -05:00
Akira Hatanaka a0a670614a Call objc_retainBlock before passing a block as a variadic argument
Copy the block to the heap before passing it to the callee in case the
block escapes in the callee.

rdar://problem/55683462

Differential Revision: https://reviews.llvm.org/D71431
2019-12-13 13:10:07 -08:00
Erich Keane 348f22eac8 Correct gcc vector splat conversion from float to int-vector
In looking into some other code, I came across this issue where a
float converted to a gcc integer vector via a splat causes it to miss
the float-to-integral cast, which causes some REALLY strange codegen
bugs.

The AST looked like:
`-ImplicitCastExpr <col:13>
'gcc_int_2':'__attribute__((__vector_size__(2 * sizeof(int)))) int' <VectorSplat>
        `-ImplicitCastExpr <col:13> 'float' <LValueToRValue>
                  `-DeclRefExpr <col:13> 'float' lvalue ParmVar
                  0x556f16a5dc90 'f' 'float'

Despite the type of the VectorSplat cast as printed, it ended up
becoming a vector of float, which caused non-matching instructions. For
example, IntVector + a float constant resulted in:

add <2 x i32> %8, <2 x float> <float 3.000000e+00, float 3.000000e+00>

This patch corrects the conversion so that the float is first converted
to an integral, THEN splatted.
2019-12-13 12:27:31 -08:00
Sam McCall 22f8125088 [Tooling/Syntax] Helpers to find spelled tokens touching a location.
Summary: Useful when positions are used to target nodes, with before/after ambiguity.

Reviewers: ilya-biryukov, kbobyrev

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D71356
2019-12-13 16:57:03 +01:00
Nicola Zaghen 97572775d2 Reland [DataLayout] Fix occurrences that size and range of pointers are assumed to be the same.
GEP index size can be specified in the DataLayout, introduced in D42123. However, there were still places
in which getIndexSizeInBits was used interchangeably with getPointerSizeInBits. This notably caused issues
with Instcombine's visitPtrToInt; but the unit tests was incorrect, so this remained undiscovered.

This fixes the buildbot failures.

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

Patch by Joseph Faulls!
2019-12-13 14:30:21 +00:00
Anastasia Stulova ed8dadb37c [Sema] Improve diagnostic about addr spaces for overload candidates
Allow sending address spaces into diagnostics to simplify and improve
error reporting. Improved wording of diagnostics for address spaces
in overloading.

Tags: #clang

Differential Revision: https://reviews.llvm.org/D71111
2019-12-13 12:35:18 +00:00
Alexey Bataev 5ad52587ec [OPENMP50]Fix possible conflict when emitting an alias for the functions
in declare variant.

If the types of the fnction are not equal, but match, at the codegen
thei may have different types. This may lead to compiler crash.
2019-12-12 15:48:33 -05:00
Teresa Johnson c8e0bb3b2c [LTO] Support for embedding bitcode section during LTO
Summary:
This adds support for embedding bitcode in a binary during LTO. The libLTO gains supports the `-lto-embed-bitcode` flag. The option allows users of the LTO library to embed a bitcode section. For example, LLD can pass the option via `ld.lld -mllvm=-lto-embed-bitcode`.

This feature allows doing something comparable to `clang -c -fembed-bitcode`, but on the (LTO) linker level. Having bitcode alongside native code has many use-cases. To give an example, the MacOS linker can create a `-bitcode_bundle` section containing bitcode. Also, having this feature built into LLVM is an alternative to 3rd party tools such as [[ https://github.com/travitch/whole-program-llvm | wllvm ]] or [[ https://github.com/SRI-CSL/gllvm | gllvm ]]. As with these tools, this feature simplifies creating "whole-program" llvm bitcode files, but in contrast to wllvm/gllvm it does not rely on a specific llvm frontend/driver.

Patch by Josef Eisl <josef.eisl@oracle.com>

Reviewers: #llvm, #clang, rsmith, pcc, alexshap, tejohnson

Reviewed By: tejohnson

Subscribers: tejohnson, mehdi_amini, inglorion, hiraditya, aheejin, steven_wu, dexonsmith, dang, cfe-commits, llvm-commits, #llvm, #clang

Tags: #clang, #llvm

Differential Revision: https://reviews.llvm.org/D68213
2019-12-12 12:34:19 -08:00
Alexey Bataev 0ee89c1bad [OPENMP50]Improve checks for declare variant functions compatibility.
Added check for functions compatibility in C and removed restriction
for functions with no prototypes in declare variant constrcut.
2019-12-12 15:18:19 -05:00
Erich Keane 654c0daef7 Suppress -Wwarn-unused-variables when we don't know the constructor
This warning is supposed to be suppressed when the
constructor/destructor are non-trivial, since it might be a RAII type.
However, if the type has a trivial destructor and the constructor hasn't
been resolved (since it is called with dependent arguments), we were
still warning.

This patch suppresses the warning if the type could possibly have a
be a non-trivial constructor call.  Note that this does not take the
arity of the constructors into consideration, so it might suppress
the warning in cases where it isn't possible to call a non-trivial
constructor.
2019-12-12 11:34:17 -08:00
Warren Ristow bcae3a77af [PS4] Predefine the __SCE__ macro for the x86_64-scei-ps4 triple 2019-12-12 11:00:09 -08:00
Fangrui Song b2b5cac3ec Default to -fuse-init-array
Very few ELF platforms still use .ctors/.dtors now.  Linux (glibc: 1999-07),
DragonFlyBSD, FreeBSD (2012-03) and Solaris have supported .init_array
for many years. Some architectures like AArch64/RISC-V default to
.init_array . GNU ld and gold can even convert .ctors to .init_array .

It makes more sense to flip the CC1 default, and only uses
-fno-use-init-array on platforms that don't support .init_array .
For example, OpenBSD did not support DT_INIT_ARRAY before Aug 2016
(86fa57a279)

I may miss some ELF platforms that still use .ctors, but their
maintainers can easily diagnose such problems.

Reviewed By: rnk

Differential Revision: https://reviews.llvm.org/D71393
2019-12-12 10:32:56 -08:00
Gabor Marton 25234fd69e [ASTImporter] Support functions with placeholder return types ...
Summary:
Support functions with placeholder return types even in cases when the type is
declared in the body of the function.
Example: auto f() { struct X{}; return X(); }

Reviewers: balazske, a_sidorin, a.sidorin, shafik

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70819
2019-12-12 17:49:03 +01:00
Guillaume Chatelet 0508c994f0 [clang] Turn -fno-builtin flag into an IR Attribute
Summary:
This is a follow up on https://reviews.llvm.org/D61634#1742154 to turn the clang driver -fno-builtin flag into an IR attribute.
I also investigated pushing the attribute earlier on (in Sema) but it looks like this patch is simple and will cover all function calls.

Reviewers: aaron.ballman, courbet

Subscribers: cfe-commits, tejohnson

Tags: #clang

Differential Revision: https://reviews.llvm.org/D71193
2019-12-12 17:21:12 +01:00
Guillaume Chatelet dbc5acf8ce [Alignment][NFC] Adding Align compatible methods to IntrinsicInst/IRBuilder
Summary:
This is patch is part of a series to introduce an Alignment type.
See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html
See this patch for the introduction of the type: https://reviews.llvm.org/D64790

Reviewers: courbet

Subscribers: hiraditya, cfe-commits, llvm-commits

Tags: #clang, #llvm

Differential Revision: https://reviews.llvm.org/D71420
2019-12-12 16:22:15 +01:00
Momchil Velikov 600d123c6f [ARM][CMSE] Add CMSE header and builtins
This is patch C2 as mentioned in RFC
http://lists.llvm.org/pipermail/cfe-dev/2019-March/061834.html

This adds CMSE builtin functions, and introduces arm_cmse.h header which has
useful macros, functions, and data types for end-users of CMSE.

Patch by Javed Absar.

Diferential Revision: https://reviews.llvm.org/D70817
2019-12-12 15:01:14 +00:00
Tyker 9c8cfa09d7 [Diagnsotics] Small Improvement on -Wmisleading-indentation
Reviewers: aaron.ballman

Reviewed By: aaron.ballman

Subscribers: xbolva00

Differential Revision: https://reviews.llvm.org/D71083
2019-12-12 14:52:47 +01:00
Sam McCall 3f8da5d091 [Tooling/Syntax] Helpers to find spelled tokens touching a location.
Summary: Useful when positions are used to target nodes, with before/after ambiguity.

Reviewers: ilya-biryukov, kbobyrev

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D71356
2019-12-12 12:59:50 +01:00
Nicola Zaghen f798eb21ec Temporarily Revert "[DataLayout] Fix occurrences that size and range of pointers are assumed to be the same."
This reverts commit 5f6208778f.

This caused failures in Transforms/PhaseOrdering/scev-custom-dl.ll
const: Assertion `getBitWidth() == CR.getBitWidth() && "ConstantRange types don't agree!"' failed.
2019-12-12 10:29:54 +00:00
Nicola Zaghen 5f6208778f [DataLayout] Fix occurrences that size and range of pointers are assumed to be the same.
GEP index size can be specified in the DataLayout, introduced in D42123. However, there were still places
in which getIndexSizeInBits was used interchangeably with getPointerSizeInBits. This notably caused issues
with Instcombine's visitPtrToInt; but the unit tests was incorrect, so this remained undiscovered.

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

Patch by Joseph Faulls!
2019-12-12 10:07:01 +00:00
Ilya Biryukov be14a22b47 [Syntax] Build nodes for simple cases of top level declarations
Summary:
More complicated nodes (e.g. template declarations) will be implemented
in the follow-up patches.

Reviewers: gribozavr2

Reviewed By: gribozavr2

Subscribers: merge_guards_bot, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70856
2019-12-12 08:04:22 +01:00
Reid Kleckner 5d986953c8 [IR] Split out target specific intrinsic enums into separate headers
This has two main effects:
- Optimizes debug info size by saving 221.86 MB of obj file size in a
  Windows optimized+debug build of 'all'. This is 3.03% of 7,332.7MB of
  object file size.
- Incremental step towards decoupling target intrinsics.

The enums are still compact, so adding and removing a single
target-specific intrinsic will trigger a rebuild of all of LLVM.
Assigning distinct target id spaces is potential future work.

Part of PR34259

Reviewers: efriedma, echristo, MaskRay

Reviewed By: echristo, MaskRay

Differential Revision: https://reviews.llvm.org/D71320
2019-12-11 18:02:14 -08:00
Francis Visoiu Mistrih 60590b149b [Remarks][Driver] Ask for line tables when remarks are enabled
Serialized remarks contain debug locations for each remark, by storing a
file path, a line, and a column.

Also, remarks support being embedded in a .dSYM bundle using a separate
section in object files, that is found by `dsymutil` through the debug
map.

In order for tools to map addresses to source and display remarks in the
source, we need line tables, and in order for `dsymutil` to find the
object files containing the remark section, we need to keep the debug
map around.

Differential Revision: https://reviews.llvm.org/D71325
2019-12-11 17:59:46 -08:00
Gabor Horvath 9fdcae7c81 [analyzer] Do not cache out on some shared implicit AST nodes
Some AST nodes which stands for implicit initialization is shared. The analyzer
will do the same evaluation on the same nodes resulting in the same state. The
analyzer will "cache out", i.e. it thinks that it visited an already existing
node in the exploded graph. This is not true in this case and we lose coverage.
Since these nodes do not really require any processing from the analyzer
we just omit them from the CFG.

Differential Revision: https://reviews.llvm.org/D71371
2019-12-11 17:15:12 -08:00
Michael Spencer 5bcd34a03f Revert "[clang][clang-scan-deps] Aggregate the full dependency information."
This reverts commit f978ea4983.

It broke clang-ppc64be-linux, but not sure why yet.
2019-12-11 16:35:55 -08:00
Johannes Doerfert b3c06db456 [OpenMP] Use the OpenMP-IR-Builder
This is a follow up patch to use the OpenMP-IR-Builder, as discussed on
the mailing list ([1] and later) and at the US Dev Meeting'19.

[1] http://lists.flang-compiler.org/pipermail/flang-dev_lists.flang-compiler.org/2019-May/000197.html

Reviewers: kiranchandramohan, ABataev, RaviNarayanaswamy, gtbercea, grokos, sdmitriev, JonChesterfield, hfinkel, fghanim

Subscribers: ppenzin, penzn, llvm-commits, cfe-commits, jfb, guansong, bollu, hiraditya, mgorny

Tags: #clang

Differential Revision: https://reviews.llvm.org/D69922
2019-12-11 16:51:13 -06:00
Michael Spencer f978ea4983 [clang][clang-scan-deps] Aggregate the full dependency information.
Differential Revision: https://reviews.llvm.org/D70268
2019-12-11 14:40:51 -08:00
Richard Smith db4c7adfa3 Suppress false-positive -Wuninitialized warnings in the constructor of a
templated but non-template class.
2019-12-11 14:26:28 -08:00
Richard Smith e0e07a7e41 Fix detection of __attribute__((may_alias)) to properly look through
type sugar.

We previously missed the attribute in a lot of cases in C++, because
there's often other type sugar there (eg, ElaboratedType).
2019-12-11 14:04:37 -08:00
Alexey Bataev 0b9789456b [OPENMP50]Add if clause in teams distribute parallel for simd directive.
According to OpenMP 5.0, if clause can be used in for simd directive. If
condition in the if clause if false, the non-vectorized version of the
loop must be executed.
2019-12-11 16:11:41 -05:00
Sam Clegg 881d877846 [WebAssembly] Add new `export_name` clang attribute for controlling wasm export names
This is equivalent to the existing `import_name` and `import_module`
attributes which control the import names in the final wasm binary
produced by lld.

This maps the existing

This attribute currently requires a string rather than using the
symbol name for a couple of reasons:

1. Avoid confusion with static and dynamic linking which is
   based on symbol name.  Exporting a function from a wasm module using
   this directive is orthogonal to both static and dynamic linking.
2. Avoids name mangling.

Differential Revision: https://reviews.llvm.org/D70520
2019-12-11 11:54:57 -08:00
Gabor Horvath 5882e6f36f [analyzer] Escape symbols conjured into specific regions during a conservative EvalCall
This patch introduced additional PointerEscape callbacks after conservative
calls for output parameters. This should not really affect the current
checkers but the upcoming FuchsiaHandleChecker relies on this heavily.

Differential Revision: https://reviews.llvm.org/D71224
2019-12-11 11:44:10 -08:00
Artem Dergachev b01012b7c8 [analyzer] LocalizationChecker: Fix a crash on synthesized accessor stubs.
The checker was trying to analyze the body of every method in Objective-C
@implementation clause but the sythesized accessor stubs that were introduced
into it by 2073dd2d have no bodies.
2019-12-11 11:22:36 -08:00
Artem Dergachev 2b3f2071ec [analyzer] CStringChecker: Fix overly eager assumption that memcmp args overlap.
While analyzing code `memcmp(a, NULL, n);', where `a' has an unconstrained
symbolic value, the analyzer was emitting a warning about the *first* argument
being a null pointer, even though we'd rather have it warn about the *second*
argument.

This happens because CStringChecker first checks whether the two argument
buffers are in fact the same buffer, in order to take the fast path.
This boils down to assuming `a == NULL' to true. Then the subsequent check
for null pointer argument "discovers" that `a' is null.

Don't take the fast path unless we are *sure* that the buffers are the same.
Otherwise proceed as normal.

Differential Revision: https://reviews.llvm.org/D71322
2019-12-11 11:22:36 -08:00
Artem Dergachev 134faae042 [analyzer] CStringChecker: Improve warning messages.
Differential Revision: https://reviews.llvm.org/D71321
2019-12-11 11:22:36 -08:00
Alexey Bataev d8c31d4198 [OPENMP50]Fix capturing of if condition in target parallel for simd
directive.

Fixed capturing of the if condition if no modifer was specified in this
condition. Previously could capture it only in outer region and it could
lead to a compiler crash.
2019-12-11 13:18:39 -05:00
Alexey Bataev 7b774b7cd4 [OPENMP50]Add if clause in teams distribute simd directive.
According to OpenMP 5.0, if clause can be used in for simd directive. If
condition in the if clause if false, the non-vectorized version of the
loop must be executed.
2019-12-11 12:30:18 -05:00
Russell Gallop df494f7512 [Support] Add TimeTraceScope constructor without detail arg
This simplifies code where no extra details are required
Also don't write out detail when it is empty.

Differential Revision: https://reviews.llvm.org/D71347
2019-12-11 14:32:21 +00:00
Adam Balogh 855d21a03a [Analyzer] Iterator Checkers: Replace `UnknownVal` in comparison result by a conjured value
Sometimes the return value of a comparison operator call is
`UnkownVal`. Since no assumptions can be made on `UnknownVal`,
this leeds to keeping impossible execution paths in the
exploded graph resulting in poor performance and false
positives. To overcome this we replace unknown results of
iterator comparisons by conjured symbols.

Differential Revision: https://reviews.llvm.org/D70244
2019-12-11 15:24:06 +01:00
Adam Balogh 6e9c58946e [Analyzer] Iterator Modeling: Print Container Data and Iterator Positions when printing the Program State
Debugging the Iterator Modeling checker or any of the iterator checkers
is difficult without being able to see the relations between the
iterator variables and their abstract positions, as well as the abstract
symbols denoting the begin and the end of the container.

This patch adds the checker-specific part of the Program State printing
to the Iterator Modeling checker.
2019-12-11 14:20:17 +01:00
Alexey Bader cb30ad728f [SYCL] Add support for auxiliary triple specification to Frontend
Summary:
Add host predefined macros to compilation for SYCL device, which is
required for pre-processing host specific includes (e.g. system
headers).

Reviewers: ABataev, jdoerfert

Subscribers: ebevhan, Anastasia, cfe-commits, keryell, Naghasan, Fznamznon

Tags: #clang

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

Signed-off-by: Alexey Bader <alexey.bader@intel.com>
2019-12-11 12:40:43 +03:00
Nicolai Hähnle f21c081b78 CodeGen: Allow annotations on globals in non-zero address space
Summary:
Attribute annotations are recorded in a special global composite variable
that points to annotation strings and the annotated objects.

As a restriction of the LLVM IR type system, those pointers are all
pointers to address space 0, so let's insert an addrspacecast when the
annotated global is in a non-0 address space.

Since this addrspacecast is only reachable from the global annotations
object, this should allow us to represent annotations on all globals
regardless of which addrspacecasts are usually legal for the target.

Reviewers: rjmccall

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D71208
2019-12-11 13:24:32 +01:00
Adam Balogh afb13afcf2 [Analyzer][NFC] Iterator Checkers - Separate iterator modeling and the actual checkers
A monolithic checker class is hard to maintain. This patch splits it up
into a modeling part, the three checkers and a debug checker. The common
functions are moved into a library.

Differential Revision: https://reviews.llvm.org/D70320
2019-12-11 13:06:19 +01:00
Sjoerd Meijer 0216854917 [Clang] Pragma vectorize_width() implies vectorize(enable)
Let's try this again; this has been reverted/recommited a few times. Last time
this got reverted because for this loop:

  void a() {
    #pragma clang loop vectorize(disable)
    for (;;)
      ;
  }

vectorisation was incorrectly enabled and the vectorize.enable metadata was set
due to a logic error. But with this fixed, we now imply vectorisation when:

1) vectorisation is enabled, which means: VectorizeWidth > 1,
2) and don't want to add it when it is disabled or enabled, otherwise we would
   be incorrectly setting it or duplicating the metadata, respectively.

This should fix PR27643.

Differential Revision: https://reviews.llvm.org/D69628
2019-12-11 10:37:40 +00:00
Simon Tatham bd0f271c9e [ARM][MVE] Add intrinsics for immediate shifts. (reland)
This adds the family of `vshlq_n` and `vshrq_n` ACLE intrinsics, which
shift every lane of a vector left or right by a compile-time
immediate. They mostly work by expanding to the IR `shl`, `lshr` and
`ashr` operations, with their second operand being a vector splat of
the immediate.

There's a fiddly special case, though. ACLE specifies that the
immediate in `vshrq_n` can take values up to //and including// the bit
size of the vector lane. But LLVM IR thinks that shifting right by the
full size of the lane is UB, and feels free to replace the `lshr` with
an `undef` half way through the optimization pipeline. Hence, to keep
this legal in source code, I have to detect it at codegen time.
Logical (unsigned) right shifts by the element size are handled by
simply emitting the zero vector; arithmetic ones are converted into a
shift of one bit less, which will always give the same output.

In order to do that check, I also had to enhance the tablegen
MveEmitter so that it can cope with converting a builtin function's
operand into a bare integer to pass to a code-generating subfunction.
Previously the only bare integers it knew how to handle were flags
generated from within `arm_mve.td`.

Reviewers: dmgreen, miyuki, MarkMurrayARM, ostannard

Reviewed By: dmgreen, MarkMurrayARM

Subscribers: echristo, hokein, rdhindsa, kristof.beyls, hiraditya, cfe-commits, llvm-commits

Tags: #clang, #llvm

Differential Revision: https://reviews.llvm.org/D71065
2019-12-11 10:10:09 +00:00
Alexey Lapshin 21bc895866 [DWARF5][SplitDwarf] Set default state for -fsplit-dwarf-inlining to be false.
The -fsplit-dwarf-inlining option does not conform to DWARF5 standard.
It creates children for Skeleton compilation unit. We need default behavior
to be DWARF5 compatible. Thus set default state for -fsplit-dwarf-inlining
into "false".

Differential Revision: https://reviews.llvm.org/D71304
2019-12-11 12:18:46 +03:00
Ilya Biryukov f7c8ace4a5 [CodeComplete] Fix a crash in preferred type and signature help
Summary: Null type pointers could be dereferenced in some cases.

Reviewers: kadircet, sammccall

Reviewed By: sammccall

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D71329
2019-12-11 09:43:28 +01:00
Richard Smith ffe612922c [c++20] Implement P1946R0: allow defaulted comparisons to take their
arguments by value.
2019-12-10 19:54:35 -08:00
Richard Smith 8e0c9e21bf [c++20] Delete defaulted comparison functions if they would invoke an
inaccessible comparison function.
2019-12-10 19:28:30 -08:00
Richard Smith 2e48be09b0 Fix mishandling of invalid-but-non-empty nested name specifiers in name
classification.

We were accidentally treating invalid scope specs as being empty,
resulting in our trying to form an ADL-only call with a qualified
callee, which tripped up an assert later on.
2019-12-10 17:55:30 -08:00
Richard Smith bc24014b97 [c++20] Implement P1185R2 (as modified by P2002R0).
For each defaulted operator<=> in a class that doesn't explicitly
declare any operator==, also inject a matching implicit defaulted
operator==.
2019-12-10 17:24:27 -08:00
Erik Pilkington d5e66f0e06 NFC: Get rid of an unused parameter to CGObjCMac::EmitSelectorAddr. 2019-12-10 16:54:48 -08:00
Gabor Horvath 8434fbbee6 Revert "[analyzer] Keep track of escaped locals"
It was a step in the right direction but it is not clear how can this
fit into the checker API at this point. The pre-escape happens in the
analyzer core and the checker has no control over it. If the checker
is not interestd in a pre-escape it would need to do additional work
on each escape to check if the escaped symbol is originated from an
"uninteresting" pre-escaped memory region. In order to keep the
checker API simple we abandoned this solution for now.

We will reland this once we have a better answer for what to do on the
checker side.

This reverts commit f3a28202ef.
2019-12-10 16:42:03 -08:00
Eric Christopher f4a7d5659d Remove debugging printf and reformat code. 2019-12-10 15:04:45 -08:00
Alexey Bataev 02d04d569e [OPENMP50]Do not mark the function as used if referenced only in declare
variant directive.

If the function is used only in declare variant directive as a variant
function, it should not be marked as used to prevent emission of the
target-specific functions. Build the reference in the unevaluated
context.
2019-12-10 16:30:14 -05:00
Richard Smith 68009c245d [c++20] Return type deduction for defaulted three-way comparisons. 2019-12-10 13:03:12 -08:00
Alexey Bataev ef94cd1cf8 [OPENMP50]Add if clause in target simd directive.
According to OpenMP 5.0, if clause can be used in for simd directive. If
condition in the if clause if false, the non-vectorized version of the
loop must be executed.
2019-12-10 15:33:18 -05:00
Mark de Wever b6d386f6f9 [Wdocumentation] Use C2x/C++14 deprecated attribute
This replaces the non-standard __attribute__((deprecated)) with the
standard [[deprecated]] when compiling in C2x/C++14 mode.

Discovered while looking at https://bugs.llvm.org/show_bug.cgi?id=43753

Differential Revision: https://reviews.llvm.org/D71141
2019-12-10 21:16:18 +01:00
Mark de Wever b972f2d05e [Wdocumentation] Properly place deprecated attribute
It is now placed before the function:
- allows to replace __attribute__((deprecated)) with [[deprecated]].
- required for trailing returns.

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

Differential Revision: https://reviews.llvm.org/D71140
2019-12-10 21:16:12 +01:00
Mark de Wever 85fff898bb [Wdocumentation] Use the command marker.
Use the proper marker for -Wdocumentation-deprecated-sync instead of
hard-coded the backslash.

Discovered while looking at https://bugs.llvm.org/show_bug.cgi?id=43753

Differential Revision: https://reviews.llvm.org/D71139
2019-12-10 21:16:07 +01:00
Yaxun (Sam) Liu 21b43885b8 Fix bug 44190 - wrong code with #pragma pack(1)
5b330e8d61 caused
a regression on s390:

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

we need to copy if if either the argument is non-byval or the argument is underaligned.

Differential Revision: https://reviews.llvm.org/D71282
2019-12-10 13:56:34 -05:00
Kevin P. Neal 6515c524b0 [FPEnv] clang support for constrained FP builtins
Change the IRBuilder and clang so that constrained FP intrinsics will be
emitted for builtins when appropriate. Only non-target-specific builtins
are affected in this patch.

Differential Revision: https://reviews.llvm.org/D70256
2019-12-10 13:09:12 -05:00
Alexey Bataev da17a53173 [OPENMP50]Add if clause in target parallel for simd directive.
According to OpenMP 5.0, if clause can be used in for simd directive. If
condition in the if clause is false, the non-vectorized version of the
loop must be executed.
2019-12-10 12:28:32 -05:00
Gabor Horvath f3a28202ef [analyzer] Keep track of escaped locals
We want to escape all symbols that are stored into escaped regions.
The problem is, we did not know which local regions were escaped. Until now.
This should fix some false positives like the one in the tests.

Differential Revision: https://reviews.llvm.org/D71152
2019-12-10 08:51:33 -08:00
Yonghong Song d77ae1552f [DebugInfo] Support to emit debugInfo for extern variables
Extern variable usage in BPF is different from traditional
pure user space application. Recent discussion in linux bpf
mailing list has two use cases where debug info types are
required to use extern variables:
  - extern types are required to have a suitable interface
    in libbpf (bpf loader) to provide kernel config parameters
    to bpf programs.
    https://lore.kernel.org/bpf/CAEf4BzYCNo5GeVGMhp3fhysQ=_axAf=23PtwaZs-yAyafmXC9g@mail.gmail.com/T/#t
  - extern types are required so kernel bpf verifier can
    verify program which uses external functions more precisely.
    This will make later link with actual external function no
    need to reverify.
    https://lore.kernel.org/bpf/87eez4odqp.fsf@toke.dk/T/#m8d5c3e87ffe7f2764e02d722cb0d8cbc136880ed

This patch added clang support to emit debuginfo for extern variables
with a TargetInfo hook to enable it. The debuginfo for the
extern variable is emitted only if that extern variable is
referenced in the current compilation unit.

Currently, only BPF target enables to generate debug info for
extern variables. The emission of such debuginfo is disabled for C++
 at this moment since BPF only supports a subset of C language.
Emission with C++ can be enabled later if an appropriate use case
is identified.

-fstandalone-debug permits us to see more debuginfo with the cost
of bloated binary size. This patch did not add emission of extern
variable debug info with -fstandalone-debug. This can be
re-evaluated if there is a real need.

Differential Revision: https://reviews.llvm.org/D70696
2019-12-10 08:09:51 -08:00
Guillaume Chatelet 1b2842bf90 [Alignment][NFC] CreateMemSet use MaybeAlign
Summary:
This is patch is part of a series to introduce an Alignment type.
See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html
See this patch for the introduction of the type: https://reviews.llvm.org/D64790

Reviewers: courbet

Subscribers: arsenm, jvesely, nhaehnle, hiraditya, cfe-commits, llvm-commits

Tags: #clang, #llvm

Differential Revision: https://reviews.llvm.org/D71213
2019-12-10 15:17:44 +01:00
Jim Lin 9c39663798 Only Remove implicit conversion for the target that support fp16
Remove implicit conversion that promotes half to double
for the target that support fp16. If the target doesn't
support fp16, fp16 will be converted to fp16 intrinsic.
2019-12-10 19:15:11 +08:00
Johannes Doerfert eb3e81f43f [OpenMP][NFCI] Introduce llvm/IR/OpenMPConstants.h
Summary:
The new OpenMPConstants.h is a location for all OpenMP related constants
(and helpers) to live.

This patch moves the directives there (the enum OpenMPDirectiveKind) and
rewires Clang to use the new location.

Initially part of D69785.

Reviewers: kiranchandramohan, ABataev, RaviNarayanaswamy, gtbercea, grokos, sdmitriev, JonChesterfield, hfinkel, fghanim

Subscribers: jholewinski, ppenzin, penzn, llvm-commits, cfe-commits, jfb, guansong, bollu, hiraditya, mgorny

Tags: #clang, #llvm

Differential Revision: https://reviews.llvm.org/D69853
2019-12-10 00:10:09 -06:00
Jim Lin cefac9dfaa Remove implicit conversion that promotes half to other larger precision types for fp classification builtins
Summary:
It shouldn't promote half to double or any larger precision types for fp classification builtins.
Because fp classification builtins would get incorrect result with promoted argument.
For example, __builtin_isnormal with a subnormal half value should return false, but it is not.
That the subnormal half value is promoted to a normal double value.

Reviewers: aaron.ballman

Reviewed By: aaron.ballman

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D71049
2019-12-10 13:24:21 +08:00
Francis Visoiu Mistrih ae09dd86a9 [Remarks][Driver] Error on -foptimization-record-file with multiple -arch options
This adds a check for the usage of -foptimization-record-file with
multiple -arch options. This is not permitted since it would require us
to rename the file requested by the user to avoid overwriting it for the
second cc1 invocation.
2019-12-09 20:39:26 -08:00
Richard Smith 848934c67d [c++20] Fix handling of unqualified lookups from a defaulted comparison
function.

We need to perform unqualified lookups from the context of a defaulted
comparison, but not until we implicitly define the function, at which
point we can't do those lookups any more. So perform the lookup from the
end of the class containing the =default declaration and store the
lookup results on the defaulted function until we synthesize the body.
2019-12-09 17:40:36 -08:00
Eric Christopher 9c6b7f68b8 Revert "[ARM][MVE] Add intrinsics for immediate shifts."
and two follow-on commits: one warning fix and one functionality.

As it's breaking at least the lto bot:

http://lab.llvm.org:8011/builders/clang-with-lto-ubuntu/builds/15132/steps/test-stage1-compiler/logs/stdio

This reverts commits:

 8d70f3c933
 ff4dceef92
 d97b3e3e65
2019-12-09 16:47:38 -08:00
Reid Kleckner 9803178a78 Avoid Attr.h includes, CodeGen edition
This saves around 20 includes of Attr.h. Not much.
2019-12-09 16:17:18 -08:00
Richard Smith e6e6e34b95 [c++20] Defaulted comparison support for array members. 2019-12-09 14:54:06 -08:00
Pierre Habouzit 1646bb8664 Also synthesize _cmd and self for properties
Patch by: Pierre Habouzit

Differential Revision: https://reviews.llvm.org/D71226
2019-12-09 14:30:01 -08:00
Craig Topper 505aa2410d [Attr] Move ParsedTargetAttr out of the TargetAttr class
Need to forward declare it in ASTContext.h for D68627, so it can't be a nested struct.

Differential Revision: https://reviews.llvm.org/D71159
2019-12-09 12:40:41 -08:00
Richard Smith 56bba012d9 [c++20] Fix incorrect assumptions in checks for comparison category types.
In the presence of modules, we can have multiple lookup results for the
same entity, and we need to re-check for completeness each time we
consider a type.
2019-12-09 12:18:33 -08:00
Puyan Lotfi d694594d76 [clang][IFS] Allow 2 output files when using -o and -c with clang IFS stubs.
This patch allows for -o to be used with -c when compiling with clang
interface stubs enabled. This is because the second file will be an
intermediate ifs stubs file that is the text stub analog of the .o file.
Both get produces in this case, so two files.

Why are we doing this? Because we want to support the case where
interface stubs are used bu first invoking clang like so:

clang -c <other flags> -emit-interface-stubs foo.c -o foo.o
...
clang -emit-interface-stubs <.o files> -o libfoo.so

This should generate N .ifs files, and one .ifso file. Prior to this
patch, using -o with the -c invocation was not possible. Currently the
clang driver supports generating a a.out/.so file at the same time as a
merged ifs file / ifso file, but this is done by checking that the final
job is the IfsMerge job. When -c is used, the final job is a Compile job
so what this patch does is check to figure out of the job type is
TY_IFS_CPP.

Differential Revision: https://reviews.llvm.org/D70763
2019-12-09 14:47:17 -05:00
Fangrui Song ec71238916 Fix clang -Wcovered-switch-default after llvmorg-10-init-11484-g6626e5a06a9
We need to place llvm_unreachable after switch to work around the GCC
warning.
2019-12-09 11:32:22 -08:00
Peter Collingbourne bab9849963 Reland 198fbcb8, "Driver: Don't look for libc++ headers in the install directory on Android.", which was reverted in b3249027.
Fixed the test case to set --sysroot, which lets it succeed in the case where
a directory named "/usr/include/c++/v1" or "/usr/local/include/c++/v1" exists.

Original commit message:
> The NDK uses a separate set of libc++ headers in the sysroot. Any headers
> in the installation directory are not going to work on Android, not least
> because they use a different name for the inline namespace (std::__1 instead
> of std::__ndk1).
>
> This effectively makes it impossible to produce a single toolchain that is
> capable of targeting both Android and another platform that expects libc++
> headers to be installed in the installation directory, such as Mac.
>
> In order to allow this scenario to work, stop looking for headers in the
> install directory on Android.

Differential Revision: https://reviews.llvm.org/D71154
2019-12-09 10:08:02 -08:00
Haojian Wu ff4dceef92 Fix the compiler warnings: "-Winconsistent-missing-override", "-Wunused-variable"
for d97b3e3e65
2019-12-09 17:09:07 +01:00
Simon Tatham d97b3e3e65 [ARM][MVE] Add intrinsics for immediate shifts.
Summary:
This adds the family of `vshlq_n` and `vshrq_n` ACLE intrinsics, which
shift every lane of a vector left or right by a compile-time
immediate. They mostly work by expanding to the IR `shl`, `lshr` and
`ashr` operations, with their second operand being a vector splat of
the immediate.

There's a fiddly special case, though. ACLE specifies that the
immediate in `vshrq_n` can take values up to //and including// the bit
size of the vector lane. But LLVM IR thinks that shifting right by the
full size of the lane is UB, and feels free to replace the `lshr` with
an `undef` half way through the optimization pipeline. Hence, to keep
this legal in source code, I have to detect it at codegen time.
Logical (unsigned) right shifts by the element size are handled by
simply emitting the zero vector; arithmetic ones are converted into a
shift of one bit less, which will always give the same output.

In order to do that check, I also had to enhance the tablegen
MveEmitter so that it can cope with converting a builtin function's
operand into a bare integer to pass to a code-generating subfunction.
Previously the only bare integers it knew how to handle were flags
generated from within `arm_mve.td`.

Reviewers: dmgreen, miyuki, MarkMurrayARM, ostannard

Reviewed By: MarkMurrayARM

Subscribers: kristof.beyls, hiraditya, cfe-commits, llvm-commits

Tags: #clang, #llvm

Differential Revision: https://reviews.llvm.org/D71065
2019-12-09 15:44:09 +00:00
Michael Liao 6626e5a06a Fix compilation warning from GCC7. NFC. 2019-12-09 10:11:27 -05:00
Sam McCall 94603ec11b [Parser] Don't crash on MS assembly if target desc/asm parser isn't linked in.
Summary:
Instead, emit a diagnostic and return an empty ASM node, as we do if the target
is missing.

Filter this diagnostic out in clangd, where it's not meaningful.

Fixes https://github.com/clangd/clangd/issues/222

Reviewers: kadircet

Subscribers: mgorny, ilya-biryukov, jkorous, arphaman, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D71189
2019-12-09 14:34:31 +01:00
Sam McCall 966fac1941 [clang][Tooling] Fix potential UB in ExpandResponseFilesCompilationDatabase
Summary:
`vector::assign` will cause UB at here.

fixes: https://github.com/clangd/clangd/issues/223

Reviewers: kadircet, sammccall, hokein

Reviewed By: sammccall

Subscribers: merge_guards_bot, ilya-biryukov, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D71172
2019-12-09 12:24:23 +01:00
Sven van Haastregt f3e6a61232 [OpenCL] Handle address space conversions for constexpr (PR44177)
The AST for the constexpr.cl test contains address space conversion
nodes to cast through the implicit generic address space.  These
caused the evaluator to reject the input as constexpr in C++ for
OpenCL mode, whereas the input was considered constexpr in plain C++
mode as the AST won't have address space cast nodes then.

Fixes PR44177.

Differential Revision: https://reviews.llvm.org/D71015
2019-12-09 11:09:16 +00:00
Richard Smith cafc7416ba [c++20] Synthesis of defaulted comparison functions.
Array members are not yet handled. In addition, defaulted comparisons
can't yet find comparison operators by unqualified lookup (only by
member lookup and ADL). These issues will be fixed in follow-on changes.
2019-12-08 23:21:52 -08:00
Bryan Chan 74e6ce2529 [Frontend] Allow OpenMP offloading to aarch64
Summary:
D30644 added OpenMP offloading to AArch64 targets, then D32035 changed the
frontend to throw an error when offloading is requested for an unsupported
target architecture. However the latter did not include AArch64 in the list
of supported architectures, causing the following unit tests to fail:

    libomptarget :: api/omp_get_num_devices.c
    libomptarget :: mapping/pr38704.c
    libomptarget :: offloading/offloading_success.c
    libomptarget :: offloading/offloading_success.cpp

Reviewers: pawosm01, gtbercea, jdoerfert, ABataev

Subscribers: kristof.beyls, guansong, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70804
2019-12-08 14:45:16 -05:00
David Zarzycki b32490270b Revert "Driver: Don't look for libc++ headers in the install directory on Android."
This reverts commit 198fbcb817.

This breaks Fedora 31.
2019-12-08 16:41:46 +02:00
Jonas Hahnfeld 071dca24ce [OpenMP] Require trivially copyable type for mapping
A trivially copyable type provides a trivial copy constructor and a trivial
copy assignment operator. This is enough for the runtime to memcpy the data
to the device. Additionally there must be no virtual functions or virtual
base classes and the destructor is guaranteed to be trivial, ie performs
no action.
The runtime does not require trivial default constructors because on alloc
the memory is undefined. Thus, weaken the warning to be only issued if the
mapped type is not trivially copyable.

Differential Revision: https://reviews.llvm.org/D71134
2019-12-07 13:31:46 +01:00
Peter Collingbourne 198fbcb817 Driver: Don't look for libc++ headers in the install directory on Android.
The NDK uses a separate set of libc++ headers in the sysroot. Any headers
in the installation directory are not going to work on Android, not least
because they use a different name for the inline namespace (std::__1 instead
of std::__ndk1).

This effectively makes it impossible to produce a single toolchain that is
capable of targeting both Android and another platform that expects libc++
headers to be installed in the installation directory, such as Mac.

In order to allow this scenario to work, stop looking for headers in the
install directory on Android.

Differential Revision: https://reviews.llvm.org/D71154
2019-12-06 18:24:23 -08:00
Richard Smith 5253d9138e [c++20] Determine whether a defaulted comparison should be deleted or
constexpr.
2019-12-06 16:32:48 -08:00
Reid Kleckner eff08f4097 Revert "[Sema][X86] Consider target attribute into the checks in validateOutputSize and validateInputSize."
This reverts commit e1578fd2b7.

It introduces a dependency on Attr.h which I am removing from
ASTContext.h.
2019-12-06 15:42:14 -08:00
Craig Topper e1578fd2b7 [Sema][X86] Consider target attribute into the checks in validateOutputSize and validateInputSize.
The validateOutputSize and validateInputSize need to check whether
AVX or AVX512 are enabled. But this can be affected by the
target attribute so we need to factor that in.

This patch copies some of the code from CodeGen to create an
appropriate feature map that we can pass to the function. Probably
need some refactoring here to share more code with Codegen. Is
there a good place to do that? Also need to support the cpu_specific
attribute as well.

Differential Revision: https://reviews.llvm.org/D68627
2019-12-06 15:30:59 -08:00
Reid Kleckner 60573ae6fe Remove Expr.h include from ASTContext.h, NFC
ASTContext.h is popular, prune its includes. Expr.h brings in Attr.h,
which is also expensive.

Move BlockVarCopyInit to Expr.h to accomplish this.
2019-12-06 15:30:49 -08:00
Stephen Kelly 0a717d5b5d Make it possible control matcher traversal kind with ASTContext
Summary:
This will eventually allow traversal of an AST while ignoring invisible
AST nodes.  Currently it depends on the available enum values for
TraversalKinds.  That can be extended to ignore all invisible nodes in
the future.

Reviewers: klimek, aaron.ballman

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D61837
2019-12-06 23:11:32 +00:00
Alex Lorenz f3efd69574 [ObjC] Make sure that the implicit arguments for direct methods have been setup
This commit sets the Self and Imp declarations for ObjC method declarations,
in addition to the definitions. It also fixes
a bunch of code in clang that had wrong assumptions about when getSelfDecl() would be set:

- CGDebugInfo::getObjCMethodName and AnalysisConsumer::getFunctionName would assume that it was
  set for method declarations part of a protocol, which they never were,
  and that self would be a Class type, which it isn't as it is id for a protocol.

Also use the Canonical Decl to index the set of Direct methods so that
when calls and implementations interleave, the same llvm::Function is
used and the same symbol name emitted.

Radar-Id: rdar://problem/57661767

Patch by: Pierre Habouzit

Differential Revision: https://reviews.llvm.org/D71091
2019-12-06 14:28:28 -08:00
Artem Dergachev 040c39d50f [analyzer] Fix false positive on introspection of a block's internal layout.
When implementation of the block runtime is available, we should not
warn that block layout fields are uninitialized simply because they're
on the stack.
2019-12-06 13:24:20 -08:00
Alexey Bataev 779a180d96 [OPENMP50]Add if clause in distribute simd directive.
According to OpenMP 5.0, if clause can be used in for simd directive. If
condition in the if clause if false, the non-vectorized version of the
loop must be executed.
2019-12-06 14:49:49 -05:00
Richard Smith dbd1129724 Stop checking whether std::strong_* has ::equivalent members.
Any attempt to use these would be a bug, so we shouldn't even look for
them.
2019-12-06 11:35:41 -08:00
Matt Arsenault 2cc11941a2 clang/AMDGPU: Fix default for frame-pointer attribute
Enabling optimization should allow frame pointer elimination.
2019-12-07 00:09:10 +05:30
Michael Liao f2ace9d600 Add `QualType::hasAddressSpace`. NFC.
- Add that as a shorthand of <T>.getQualifiers().hasAddressSpace().
- Simplify related code.
2019-12-06 13:08:55 -05:00
Raphael Isemann 164e0fc5c7 [ASTImporter] Implicitly declare parameters for imported ObjCMethodDecls
Summary:
When Sema encounters a ObjCMethodDecl definition it declares the implicit parameters for the ObjCMethodDecl.
When importing such a method with the ASTImporter we need to do the same for the imported method
otherwise we will crash when generating code (where CodeGen expects that this was called by Sema).

Note I had to implement Objective-C[++] support in Language.cpp as this is the first test for Objective-C and this
would otherwise just hit this 'not implemented' assert when running the unit test.

Reviewers: martong, a.sidorin, shafik

Reviewed By: martong

Subscribers: rnkovacs, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D71112
2019-12-06 18:50:32 +01:00
Zahira Ammarguellat a3b2552575 Fix for PR44000. Optimization record for bytecode input missing.
Review is here:  https://reviews.llvm.org/D70691
2019-12-06 07:48:42 -05:00
Richard Smith 759909506c Fix crash if a user-defined conversion is applied in the middle of a
rewrite of an operator in terms of operator<=>.
2019-12-05 18:44:15 -08:00
Saar Raz e7c2466781 [Concepts] Fix build failures in D41569
Fix build failures in previous commit.
2019-12-06 01:53:18 +02:00
Saar Raz fdf80e86a5 [Concepts] Constraint Enforcement & Diagnostics
Part of the C++20 concepts implementation effort.
- Associated constraints (requires clauses, currently) are now enforced when instantiating/specializing templates and when considering partial specializations and function overloads.
- Elaborated diagnostics give helpful insight as to why the constraints were not satisfied.
Phabricator: D41569

Re-commit, after fixing some memory bugs.
2019-12-06 01:34:20 +02:00
Richard Smith b220662a45 Properly convert all declaration non-type template arguments when
forming non-type template parameter values.

This reverts commit 93cc9dddd8,
which reverted commit 11d1052785.

We now always form `&x` when forming a pointer to a function rather than
trying to use function-to-pointer decay. This matches the behavior of
the old code in this case, but not the intent as described by the
comments.
2019-12-05 14:32:36 -08:00
Adrian Prantl 338588d7cf Debug Info: Apply a default location for cleanups if none is available.
This unbreaks the debuginfo-tests testsuite by replacing the assertion
with a default location. There are cleanups in helper functions that
don't have a valid source location such as block copy helpers and it's
not worth tracking each of them down.

rdar://57630879
2019-12-05 13:30:23 -08:00
Adrian Prantl ce7d35988d Debug Info: Assert that location is available for cleanups
rdar://57630879

Differential Revision: https://reviews.llvm.org/D71042
2019-12-05 12:45:10 -08:00
Adrian Prantl a1a9aa17b4 Set a source location for Objective-C accessor stubs
even when there is no explicit synthesize statement.

This fixes a regression introduced in https://reviews.llvm.org/D68108
that could lead to missing debug locations in cleanup code in
synthesized Objective-C++ properties.

rdar://57630879

Differential Revision: https://reviews.llvm.org/D71084
2019-12-05 12:45:10 -08:00
cchen 47d6094d7f [OpenMP50] Add parallel master construct
Reviewers: ABataev, jdoerfert

Reviewed By: ABataev

Subscribers: rnk, jholewinski, guansong, arphaman, jfb, cfe-commits, sandoval, dreachem

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70726
2019-12-05 14:35:27 -05:00
Alexey Bataev 52812f2ade [OPENMP50]Add support for if clause for simd part in distribute parallel for simd directive.
According to OpenMP 5.0, the if clause can be applied to simd
subdirective in the combined directives.
2019-12-05 13:23:15 -05:00
Balázs Kéri a9f10ebffa [ASTImporter] Various source location and range import fixes.
Summary:
ASTImporter contained wrong or missing imports of SourceLocation
and SourceRange for some objects. At least a part of such errors
is fixed now.
Source location import fixes in namespace, enum, record,
class template specialization declarations and DeclRefExpr,
UnresolvedLookupExpr, UnresolvedMemberExpr, NestedNameSpecifierLoc.

Reviewers: martong, a.sidorin, shafik

Reviewed By: shafik

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D60499
2019-12-05 17:44:13 +01:00
Alexey Bataev 5c517a6b13 [OPENMP50]Add support for if clause for simd part in parallel master taskloop simd directive.
According to OpenMP 5.0, the if clause can be applied to simd
subdirective in the combined directives.
2019-12-05 11:32:33 -05:00
Scott Linder d96ea47c75 [AMDGPU][HIP] Improve opt-level handling
Summary:
The HIP toolchain invokes `llc` without an explicit opt-level, meaning
it always uses the default (-O2). This makes it impossible to use -O1,
for example. The HIP toolchain also coerces -Os/-Oz to -O2 even when
invoking opt, and it coerces -Og to -O2 rather than -O1.

Forward the opt-level to `llc` as well as `opt`, and only coerce levels
where it is required.

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70987
2019-12-05 11:27:12 -05:00
Alexey Bataev 853961f21a [OPENMP50]Add support for if clause for simd part in master taskloop simd directive.
According to OpenMP 5.0, the if clause can be applied to simd
subdirective in the combined directives.
2019-12-05 10:12:20 -05:00
Hans Wennborg 18b72d337e Also check /Fo when deciding on the .gcna / .gcda filename (PR44208)
Differential revision: https://reviews.llvm.org/D71012
2019-12-05 13:57:04 +01:00
Victor Lomuller 11a9bae8f6 [AST] Enable expression of OpenCL language address spaces an attribute
Summary:
Enable a way to set OpenCL language address space using attributes
in addition to existing keywords.

Signed-off-by: Victor Lomuller victor@codeplay.com

Reviewers: aaron.ballman, Anastasia

Subscribers: yaxunl, ebevhan, cfe-commits, Naghasan

Tags: #clang

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

Signed-off-by: Alexey Bader <alexey.bader@intel.com>
2019-12-05 12:24:06 +03:00
Melanie Blower 7f9b513847 Reapply af57dbf12e "Add support for options -frounding-math, ftrapping-math, -ffp-model=, and -ffp-exception-behavior="
Patch was reverted because https://bugs.llvm.org/show_bug.cgi?id=44048
        The original patch is modified to set the strictfp IR attribute
        explicitly in CodeGen instead of as a side effect of IRBuilder.
        In the 2nd attempt to reapply there was a windows lit test fail, the
        tests were fixed to use wildcard matching.

        Differential Revision: https://reviews.llvm.org/D62731
2019-12-05 03:48:04 -08:00
Balázs Kéri 7eafde981c [Checkers] Added support for freopen to StreamChecker.
Summary: Extend StreamChecker with a new evaluation function for API call 'freopen'.

Reviewers: NoQ, baloghadamsoftware, Szelethus, martong

Reviewed By: baloghadamsoftware, martong

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D69948
2019-12-05 11:08:44 +01:00
David L. Jones 93cc9dddd8 Revert "Properly convert all declaration non-type template arguments when"
This reverts commit 11d1052785.

This change is problematic with function pointer template parameters. For
example, building libcxxabi with futexes (-D_LIBCXXABI_USE_FUTEX) produces this
diagnostic:

    In file included from .../llvm-project/libcxxabi/src/cxa_guard.cpp:15:
    .../llvm-project/libcxxabi/src/cxa_guard_impl.h:416:54: error: address of function 'PlatformThreadID' will always evaluate to 'true' [-Werror,-Wpointer-bool-conversion]
        has_thread_id_support(this->thread_id_address && GetThreadIDArg),
                                                      ~~ ^~~~~~~~~~~~~~
    .../llvm-project/libcxxabi/src/cxa_guard.cpp:38:26: note: in instantiation of member function '__cxxabiv1::(anonymous namespace)::InitByteFutex<&__cxxabiv1::(anonymous namespace)::PlatformFutexWait, &__cxxabiv1::(anonymous namespace)::PlatformFutexWake, &__cxxabiv1::(anonymous namespace)::PlatformThreadID>::InitByteFutex' requested here
      SelectedImplementation imp(raw_guard_object);
                             ^
    .../llvm-project/libcxxabi/src/cxa_guard_impl.h:416:54: note: prefix with the address-of operator to silence this warning
        has_thread_id_support(this->thread_id_address && GetThreadIDArg),
                                                         ^
                                                         &
    1 error generated.

The diagnostic is incorrect: adding the address-of operator also fails ("cannot
take the address of an rvalue of type 'uint32_t (*)()' (aka 'unsigned int
(*)()')").
2019-12-04 22:12:15 -08:00
Richard Smith 11d1052785 Properly convert all declaration non-type template arguments when
forming non-type template parameter values.
2019-12-04 18:55:24 -08:00
Richard Smith a1d2611c04 [c++17] Fix assert / wrong code when passing a noexcept pointer to
member function to a non-noexcept pointer to member non-type template
parameter.
2019-12-04 18:55:23 -08:00
Puyan Lotfi 4ef9110b8d [clang][IFS] Ignoring -Xlinker/-Xclang arguments in InterfaceStubs pass for now.
Many of the inputs to clang driver toolchain tools can be things other
than files such as -Xclang and -Xlinker arguments. For now we don't take
such tool pass-through type arguments (although having an -Xifs would be nice to
have to replace things like -emit-merged-ifs). So because for the moment
we are not doing any sort of argument pass-through, I am going to have
InterfaceStubs Merger ignore any non-file type input arguments.

Differential Revision: https://reviews.llvm.org/D70838
2019-12-04 20:03:57 -05:00
Artem Dergachev 3c50f2544f [analyzer] Fix more ObjC accessor body farms after 2073dd2d.
Fix a crash when constructing a body farm for accessors of a property
that is declared and @synthesize'd in different (but related) interfaces
with the explicit ivar syntax.

This is a follow-up for 0b58b80e.
2019-12-04 16:29:08 -08:00
Puyan Lotfi 07e445103e [clang][IFS] Adding support for new clang interface stubs decl types.
NamespaceAliasDecl UnresolvedUsingTypenameDecl CXXDeductionGuideDecl
ConstructorUsingShadowDecl

Differential Revision: https://reviews.llvm.org/D70728
2019-12-04 19:10:47 -05:00
Reid Kleckner 33f6d465d7 Revert "[OpenMP50] Add parallel master construct, by Chi Chun Chen."
This reverts commit 713dab21e2.

Tests do not pass on Windows.
2019-12-04 14:50:06 -08:00
Soumi Manna 9c29aed698 Bug 43965 - Value of _MSVC_LANG doesn't match MSVC++ VS2019 /std:c++latest mode
Summary:
The patch adds correct value of _MSVC_LANG to match with MSVC++ VS2019 /std:c++latest mode.

    Bugzilla - Bug 43965
    https://bugs.llvm.org/show_bug.cgi?id=43965

    The value for a MS specific macro differs from Microsoft starting with VS2019 in /std:c++latest mode.

    -bash-4.2$ cat msvclang.cpp
    _MSVC_LANG

    -bash-4.2$ cl /std:c++latest -E msvclang.cpp
    Microsoft (R) C/C++ Optimizing Compiler Version 19.20.27508.1 for x64
    Copyright (C) Microsoft Corporation.  All rights reserved.

    /std:c++latest is provided as a preview of language features from the latest C++
    working draft, and we're eager to hear about bugs and suggestions for improvements.
    However, note that these features are provided as-is without support, and subject
    to changes or removal as the working draft evolves. See
    https://go.microsoft.com/fwlink/?linkid=2045807 for details.

    msvclang.cpp

    201705L

    -bash-4.2$ clang-cl /std:c++latest -E  msvclang.cpp
    201704L

Reviewers: rnk

Reviewed By: rnk

Differential Revision: https://reviews.llvm.org/D70996
2019-12-04 14:39:41 -08:00
Alexey Bataev 61205821ca [OPENMP50]Add support for if clause for simd part in taskloop simd
directive.

According to OpenMP 5.0, the `if` clause can be applied to simd
subdirective in the combined directive.
2019-12-04 15:50:39 -05:00
Melanie Blower 5412913631 Revert " Reapply af57dbf12e "Add support for options -frounding-math, ftrapping-math, -ffp-model=, and -ffp-exception-behavior=""
This reverts commit cdbed2dd85.
Build break on Windows (lit fail)
2019-12-04 12:21:23 -08:00
James Y Knight 90fce46fa6 Fix crash-on-invalid-code in lambda constant evaluation.
If the lambda used 'this' without without capturing it, an error was
emitted, but the constant evaluator would still attempt to lookup the
capture, and failing to find it, dereference a null pointer.

This only happens in C++17 (as that's when lambdas were made
potentially-constexpr). Therefore, I also updated the
lambda-expressions.cpp test to run in both C++14 and C++17 modes.
2019-12-04 15:12:17 -05:00
cchen 713dab21e2 [OpenMP50] Add parallel master construct, by Chi Chun Chen.
Reviewers: ABataev, jdoerfert

Reviewed By: ABataev

Subscribers: jholewinski, guansong, arphaman, jfb, cfe-commits, sandoval, dreachem

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70726
2019-12-04 14:53:17 -05:00
Melanie Blower cdbed2dd85 Reapply af57dbf12e "Add support for options -frounding-math, ftrapping-math, -ffp-model=, and -ffp-exception-behavior="
Patch was reverted because https://bugs.llvm.org/show_bug.cgi?id=44048
        The original patch is modified to set the strictfp IR attribute
        explicitly in CodeGen instead of as a side effect of IRBuilder

        Differential Revision: https://reviews.llvm.org/D62731
2019-12-04 11:32:33 -08:00
Vedant Kumar f208b70fbc Revert "[Coverage] Revise format to reduce binary size"
This reverts commit e18531595b.

On Windows, there is an error:

http://lab.llvm.org:8011/builders/sanitizer-windows/builds/54963/steps/stage%201%20check/logs/stdio

error: C:\b\slave\sanitizer-windows\build\stage1\projects\compiler-rt\test\profile\Profile-x86_64\Output\instrprof-merging.cpp.tmp.v1.o: Failed to load coverage: Malformed coverage data
2019-12-04 10:35:14 -08:00
Vedant Kumar e18531595b [Coverage] Revise format to reduce binary size
Revise the coverage mapping format to reduce binary size by:

1. Naming function records and marking them `linkonce_odr`, and
2. Compressing filenames.

This shrinks the size of llc's coverage segment by 82% (334MB -> 62MB)
and speeds up end-to-end single-threaded report generation by 10%. For
reference the compressed name data in llc is 81MB (__llvm_prf_names).

Rationale for changes to the format:

- With the current format, most coverage function records are discarded.
  E.g., more than 97% of the records in llc are *duplicate* placeholders
  for functions visible-but-not-used in TUs. Placeholders *are* used to
  show under-covered functions, but duplicate placeholders waste space.

- We reached general consensus about giving (1) a try at the 2017 code
  coverage BoF [1]. The thinking was that using `linkonce_odr` to merge
  duplicates is simpler than alternatives like teaching build systems
  about a coverage-aware database/module/etc on the side.

- Revising the format is expensive due to the backwards compatibility
  requirement, so we might as well compress filenames while we're at it.
  This shrinks the encoded filenames in llc by 86% (12MB -> 1.6MB).

See CoverageMappingFormat.rst for the details on what exactly has
changed.

Fixes PR34533 [2], hopefully.

[1] http://lists.llvm.org/pipermail/llvm-dev/2017-October/118428.html
[2] https://bugs.llvm.org/show_bug.cgi?id=34533

Differential Revision: https://reviews.llvm.org/D69471
2019-12-04 10:10:55 -08:00
Yaxun (Sam) Liu 7d0e1117c9 [HIP] Remove opencl.amdgcn.lib
Differential Revision: https://reviews.llvm.org/D70980
2019-12-04 12:39:44 -05:00
Kadir Cetinkaya b3b3778303
Reapply "[llvm][Support] Take in CurrentDirectory as a parameter in ExpandResponseFiles"
Attemps to fix windows buildbots.
2019-12-04 17:00:47 +01:00
Kadir Cetinkaya 0f12f9096e
Revert "[llvm][Support] Take in CurrentDirectory as a parameter in ExpandResponseFiles"
This reverts commit 75656005db.
2019-12-04 15:58:01 +01:00
Michael Liao fa9dd410a9 [opencl] Fix address space deduction on array variables.
Summary:

- The deduced address space needs applying to its element type as well.

Reviewers: Anastasia

Subscribers: yaxunl, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70981
2019-12-04 09:37:50 -05:00
Kadir Cetinkaya 75656005db
[llvm][Support] Take in CurrentDirectory as a parameter in ExpandResponseFiles
Summary:
This is a follow-up to D70769 and D70222, which allows propagation of
current directory down to ExpandResponseFiles for handling of relative paths.

Previously clients had to mutate FS to achieve that, which is not thread-safe
and can even be thread-hostile in the case of real file system.

Reviewers: sammccall

Subscribers: hiraditya, cfe-commits, llvm-commits

Tags: #clang, #llvm

Differential Revision: https://reviews.llvm.org/D70857
2019-12-04 15:13:12 +01:00
Kadir Cetinkaya 45ef055d4f
[clang][Tooling] Add support for .rsp files in compile_commands.json
Summary:
Add support for .rsp files.

Fixes https://github.com/clangd/clangd/issues/81

Patch By: liu hui(@lh123)

Reviewers: sammccall, ilya-biryukov, hokein, kadircet

Reviewed By: kadircet

Subscribers: merge_guards_bot, mgorny, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits

Tags: #clang-tools-extra, #clang

Differential Revision: https://reviews.llvm.org/D70222
2019-12-04 15:13:12 +01:00
Anastasia Stulova e6522a96f5 [OpenCL] Allow addr space qualifiers on lambda call expressions
The addr space qualifier can be added optionally for lambdas after
the attributes. They will alter the default addr space of lambda
call operator that is in generic address space by default for OpenCL.

Syntax:

[ captures ] ( params ) specifiers exception attr opencl_addrspace
                    -> ret { body }

Example:

[&] (int i) mutable __global { ... };

On the call into lambda a compatibility check will be performed to
determine whether address space of lambda object and its call operator
are compatible. This will follow regular addr space conversion rules
and there will be no difference to how addr spaces work in method
qualifiers.

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70242
2019-12-04 12:25:20 +00:00
Hans Wennborg 92ce2aff68 Actually delay processing DelayedDllExportClasses until the outermost class is finished (PR40006)
This was already the intention of DelayedDllExportClasses, but code such as
this would break it:

template<typename> struct Tmpl {};
struct Outer {
    struct Inner {
        __declspec(dllexport) Inner() = default;
        unsigned int x = 0;
    };
    Tmpl<Inner> y;
};

ActOnFinishCXXNonNestedClass() would get called when the instantiation of
Templ<Inner> is finished, even though the compiler is still not finished with
Outer, causing the compile fail.

This hooks into Sema::{Push,Pop}ParsingClass() to avoid calling
ActOnFinishCXXNonNestedClass() for template instantiations while a class is
being parsed.

Differential revision: https://reviews.llvm.org/D70905
2019-12-04 13:13:41 +01:00
Akira Hatanaka d8136f14f1 [CodeGen][ObjC] Emit a primitive store to store a __strong field in
ExpandTypeFromArgs

This fixes a bug in IRGen where a call to `llvm.objc.storeStrong` was
being emitted to initialize a __strong field of an uninitialized
temporary struct, which caused crashes at runtime.

rdar://problem/51807365
2019-12-03 23:44:30 -08:00
Petr Hosek 9c3f9b9c12 [Clang] Define Fuchsia C++ABI
Currently, it is a modified version of the Itanium ABI, with the only
change being that constructors and destructors return 'this'.

Differential Revision: https://reviews.llvm.org/D70575
2019-12-03 18:35:57 -08:00
Michael Liao 59312cb0b8 Fix warning on unused variable. NFC. 2019-12-03 21:16:10 -05:00
Elizabeth Andrews 878a24ee24 Reapply "Fix crash on switch conditions of non-integer types in templates"
This patch reapplies commit 759948467e. Patch was reverted due to a
clang-tidy test fail on Windows. The test has been modified. There
are no additional code changes.

Patch was tested with ninja check-all on Windows and Linux.

Summary of code changes:

Clang currently crashes for switch statements inside a template when the
condition is a non-integer field member because contextual implicit
conversion is skipped when parsing the condition. This conversion is
however later checked in an assert when the case statement is handled.
The conversion is skipped when parsing the condition because
the field member is set as type-dependent based on its containing class.
This patch sets the type dependency based on the field's type instead.

This patch fixes Bug 40982.
2019-12-03 15:27:19 -08:00
Akira Hatanaka f139ae3d93 [NFC] Pass a reference to CodeGenFunction to methods of LValue and
AggValueSlot

This reapplies 8a5b7c3570 after a null
dereference bug in CGOpenMPRuntime::emitUserDefinedMapper.

Original commit message:

This is needed for the pointer authentication work we plan to do in the
near future.

a63a81bd99/clang/docs/PointerAuthentication.rst
2019-12-03 15:22:13 -08:00
Reid Kleckner 705a6aef35 [MS] Emit exported complete/vbase destructors
Summary:
Fixes PR44205

I checked, and deleting destructors are not affected.

Reviewers: hans

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70931
2019-12-03 14:46:32 -08:00
Akira Hatanaka 9f37c0e703 Revert "[NFC] Pass a reference to CodeGenFunction to methods of LValue and"
This reverts commit 8a5b7c3570. This seems
to have broken UBSan because of a null dereference.
2019-12-03 13:08:01 -08:00
Michael Liao 59e69fefab Fix warning on extra ';'. NFC. 2019-12-03 16:02:55 -05:00