Chris Bieneman [Thu, 16 May 2019 22:06:07 +0000 (22:06 +0000)]
Add Clang shared library with C++ exports
Summary:
This patch adds a libClang_shared library on *nix systems which exports the entire C++ API. In order to support this on Windows we should really refactor llvm-shlib and share code between the two.
This also uses a slightly different method for generating the shared library, which I should back-port to llvm-shlib. Instead of linking the static archives and passing linker flags to force loading the whole libraries, this patch creates object libraries for every library (which has no cost in the build system), and link the object libraries.
Kristina Brooks [Thu, 16 May 2019 21:13:49 +0000 (21:13 +0000)]
Reland "[Clang][PP] Add the __FILE_NAME__ builtin macro"
This relands commit rL360833 which caused issues on Win32
bots due to path handling/normalization differences. Now
this uses `sys::path::filename` which should handle
additional edge cases on Win32.
Original commit:
"[Clang][PP] Add the __FILE_NAME__ builtin macro"
This patch adds the __FILE_NAME__ macro that expands to the
last component of the path, similar to __FILE__ except with
a guarantee that only the last path component (without the
separator) will be rendered.
I intend to follow through with discussion of this with WG14
as a potential inclusion in the C standard or failing that,
try to discuss this with GCC developers since this extension
is desired by GCC and Clang users/developers alike.
Eric Fiselier [Thu, 16 May 2019 21:04:15 +0000 (21:04 +0000)]
Implement __builtin_LINE() et. al. to support source location capture.
Summary:
This patch implements the source location builtins `__builtin_LINE(), `__builtin_FUNCTION()`, `__builtin_FILE()` and `__builtin_COLUMN()`. These builtins are needed to implement [`std::experimental::source_location`](https://rawgit.com/cplusplus/fundamentals-ts/v2/main.html#reflection.src_loc.creation).
With the exception of `__builtin_COLUMN`, GCC also implements these builtins, and Clangs behavior is intended to match as closely as possible.
Craig Topper [Thu, 16 May 2019 18:28:17 +0000 (18:28 +0000)]
[X86] Stop implicitly enabling avx512vl when avx512bf16 is enabled.
Previously we were doing this so that the 256 bit selectw builtin could be used in the implementation of the 512->256 bit conversion intrinsic.
After this commit we now use a masked convert builtin that will emit the intrinsic call and the 256-bit select from custom code in CGBuiltin. Then the header only needs to call that one intrinsic.
Stephen Kelly [Thu, 16 May 2019 17:57:38 +0000 (17:57 +0000)]
Move TraversalKind enum to ast_type_traits
Summary:
Make it usable outside of ASTMatchFinder. This will make it possible to
use this enum to control whether certain implicit nodes are skipped
while AST dumping for example.
As for other floating-point rounding builtins that can be optimized
when build with -fno-math-errno, this patch adds support for lround
and llround. It currently only optimize for AArch64 backend.
Serge Guelton [Thu, 16 May 2019 12:40:00 +0000 (12:40 +0000)]
Fix isInSystemMacro in presence of macro and pasted token
When a warning is raised from the expansion of a system macro that
involves pasted token, there was still situations were they were not
skipped, as showcased by this issue:
https://bugzilla.redhat.com/show_bug.cgi?id=1472437
[builtin] Fixed definitions of builtins that rely on the int/long long type is 32/64 bits
Summary:
The definition of the builtins __builtin_bswap32, __builtin_bitreverse32, __builtin_rotateleft32 and __builtin_rotateright32 rely on that the int type is 32 bits wide on the target.
The defintions of the builtins __builtin_bswap64, __builtin_bitreverse64, __builtin_rotateleft64, and __builtin_rotateright64 rely on that the long long type is 64 bits wide.
On targets where this is not the case (e.g. AVR) clang will generate faulty code (wrong llvm assembler intrinsics).
This patch add support for using 'Z' (the int32_t type) in Bultins.def. The builtins above are changed to be based on the int32_t type instead of the int type, and the int64_t type instead of the long long type.
The AVR backend (experimental) have a native int type that is only 16 bits wide. The supplied testcase will therefore fail if running the testcase on trunk as clang will convert e.g. __builtin_bitreverse32 into llvm.bitreverse.i16 on AVR.
Kristina Brooks [Thu, 16 May 2019 00:52:41 +0000 (00:52 +0000)]
[Clang][PP] Add the __FILE_NAME__ builtin macro.
This patch adds the `__FILE_NAME__` macro that expands to the
last component of the path, similar to `__FILE__` except with
a guarantee that only the last path component (without the
separator) will be rendered.
I intend to follow through with discussion of this with WG14
as a potential inclusion in the C standard or failing that,
try to discuss this with GCC developers since this extension
is desired by GCC and Clang users/developers alike.
Richard Smith [Wed, 15 May 2019 23:36:14 +0000 (23:36 +0000)]
Make tentative parsing to detect template-argument-lists less aggressive
(and less wrong).
It's not correct to assume that X<something, Type> is always a
template-id; there are a few cases where the comma takes us into a
non-expression syntactic context in which 'Type' might be permissible.
Stop doing that.
This slightly regresses our error recovery on the cases where the
construct is intended to be a template-id. We typically do still manage
to diagnose a missing 'template' keyword, but we realize this too late
to properly recover from the error.
Kristof Umann [Wed, 15 May 2019 19:47:26 +0000 (19:47 +0000)]
[analyzer] Add a test for plugins using checker dependencies
Also, I moved the existing analyzer plugin to test/ as well, in order not to
give the illusion that the analyzer supports plugins -- it's capable of handling
them, but does not _support_ them.
Gabor Marton [Wed, 15 May 2019 10:29:48 +0000 (10:29 +0000)]
[ASTImporter] Use llvm::Expected and Error in the importer API
Summary:
This is the final phase of the refactoring towards using llvm::Expected
and llvm::Error in the ASTImporter API.
This involves the following:
- remove old Import functions which returned with a pointer,
- use the Import_New functions (which return with Err or Expected) everywhere
and handle their return value
- rename Import_New functions to Import
This affects both Clang and LLDB.
Artem Dergachev [Wed, 15 May 2019 01:19:19 +0000 (01:19 +0000)]
[analyzer] MIGChecker: Add support for os_ref_retain().
Suppress MIG checker false positives that occur when the programmer increments
the reference count before calling a MIG destructor, and the MIG destructor
literally boils down to decrementing the reference count.
Leonard Chan [Tue, 14 May 2019 21:17:21 +0000 (21:17 +0000)]
[NewPM] Port HWASan and Kernel HWASan
Port hardware assisted address sanitizer to new PM following the same guidelines as msan and tsan.
Changes:
- Separate HWAddressSanitizer into a pass class and a sanitizer class.
- Create new PM wrapper pass for the sanitizer class.
- Use the getOrINsert pattern for some module level initialization declarations.
- Also enable kernel-kwasan in new PM
- Update llvm tests and add clang test.
Eric Christopher [Tue, 14 May 2019 19:40:42 +0000 (19:40 +0000)]
Temporarily revert "Change -gz and -Wa,--compress-debug-sections to use gABI compression (SHF_COMPRESSED)"
This affects users of older (pre 2.26) binutils in such a way that they can't necessarily
work around it as it doesn't support the compress option on the command line. Reverting
to unblock them and we can revisit whether to make this change now or fix how we want
to express the option.
Reid Kleckner [Tue, 14 May 2019 19:02:39 +0000 (19:02 +0000)]
Update ASTMerge FileCheck test expectations
I belive many of these diagnostics changed from errors to warnings in
r357394. I've simply mechanically updated the tests, but whoever owns
this code should probably audit for unintented behavior changes. I
wasn't able to find a flag to make these warnings errors again.
Reid Kleckner [Tue, 14 May 2019 18:51:07 +0000 (18:51 +0000)]
Restore test files accidentally deleted in r354839
I think there must be a bug in git-llvm causing parent directories to be
deleted when the diff deletes files in a subdirectory. Perhaps it is
Windows-only.
There has been a behavior change, so some of these tests now fail. I
have marked them XFAIL and will fix them in a follow-up to separate the
changes.
Russell Gallop [Tue, 14 May 2019 14:01:40 +0000 (14:01 +0000)]
[Driver][Windows] Add dependent lib argument for profile instr generate
This is needed so lld-link can find clang_rt.profile when self hosting
on Windows with PGO. Using clang-cl as a linker knows to add the library
but self hosting, using -DCMAKE_LINKER=<...>/lld-link.exe doesn't.
Richard Smith [Tue, 14 May 2019 00:27:16 +0000 (00:27 +0000)]
PR41817: Fix regression in r359260 that caused the MS compatibility
extension allowing a "static" declaration to follow an "extern"
declaration to stop working.
Richard Smith [Mon, 13 May 2019 23:35:21 +0000 (23:35 +0000)]
[c++20] P1064R0: Allow virtual function calls in constant expression
evaluation.
This reinstates r360559, reverted in r360580, with a fix to avoid
crashing if evaluation-for-overflow mode encounters a virtual call on an
object of a class with a virtual base class, and to generally not try to
resolve virtual function calls to objects whose (notional) vptrs are not
readable. (The standard rules are unclear here, but this seems like a
reasonable approach.)
Volodymyr Sapsai [Mon, 13 May 2019 22:40:11 +0000 (22:40 +0000)]
[X86] Make `x86intrin.h`, `immintrin.h` includable with `-fno-gnu-inline-asm`.
Currently `immintrin.h` includes `pconfigintrin.h` and `sgxintrin.h`
which contain inline assembly. It causes failures when building with the
flag `-fno-gnu-inline-asm`.
Fix by excluding functions with inline assembly when this extension is
disabled. So far there was no need to support `_pconfig_u32`,
`_enclu_u32`, `_encls_u32`, `_enclv_u32` on platforms that require
`-fno-gnu-inline-asm`. But if developers start using these functions,
they'll have compile-time undeclared identifier errors which is
preferrable to runtime errors.
Aaron Ballman [Mon, 13 May 2019 21:39:55 +0000 (21:39 +0000)]
Introduce the ability to dump the AST to JSON.
This adds the -ast-dump=json cc1 flag (in addition to -ast-dump=default, which is the default if no dump format is specified), as well as some initial AST dumping functionality and tests.
Jan Korous [Mon, 13 May 2019 17:52:09 +0000 (17:52 +0000)]
[clang][ASTContext] Call setAttached for comments attached to a declaration
This is a bug affecting performance when compiling with -Wdocumentation.
In Sema::ActOnDocumentable we're checking whether there are any comments unattached to declaration at the end of comment list whenever we encounter new documentable declaration.
Since this property of RawComment was never set we were trying to find comments every time and that involves at least a couple expensive SourceLocation decompositions.
Richard Smith [Sun, 12 May 2019 09:39:08 +0000 (09:39 +0000)]
Reject attempts to call non-static member functions on objects outside
their lifetime in constant expressions.
This is undefined behavior per [class.cdtor]p2.
We continue to allow this for objects whose values are not visible
within the constant evaluation, because there's no way we can tell
whether the access is defined or not, existing code relies on the
ability to make such calls, and every other compiler allows such
calls.
Simon Pilgrim [Sat, 11 May 2019 20:21:59 +0000 (20:21 +0000)]
Revert rL360499 and rL360464 from cfe/trunk:
Reject attempts to call non-static member functions on objects outside
their lifetime in constant expressions.
This is undefined behavior per [class.cdtor]p2.
We continue to allow this for objects whose values are not visible
within the constant evaluation, because there's no way we can tell
whether the access is defined or not, existing code relies on the
ability to make such calls, and every other compiler allows such
calls.
........
Fix handling of objects under construction during constant expression
evaluation.
It's not enough to just track the LValueBase that we're evaluating, we
need to also track the path to the objects whose constructors are
running.
........
Fixes windows buildbots
Richard Smith [Sat, 11 May 2019 02:00:06 +0000 (02:00 +0000)]
Reject attempts to call non-static member functions on objects outside
their lifetime in constant expressions.
This is undefined behavior per [class.cdtor]p2.
We continue to allow this for objects whose values are not visible
within the constant evaluation, because there's no way we can tell
whether the access is defined or not, existing code relies on the
ability to make such calls, and every other compiler allows such
calls.
Amara Emerson [Fri, 10 May 2019 23:24:20 +0000 (23:24 +0000)]
[Darwin] Introduce a new flag, -fapple-link-rtlib that forces linking of the builtins library.
This driver flag is useful when users want to link against the compiler's
builtins, but nothing else, and so use flags like -nostdlib.
Darwin can't use -nolibc & nostdlib++ like other platforms on because we
disable all runtime lib linking with -static, which we still want to have
an option to link with the builtins.
Akira Hatanaka [Fri, 10 May 2019 21:54:16 +0000 (21:54 +0000)]
[CodeGen][ObjC] Emit invoke instead of call to call `objc_release` when
necessary.
Prior to r349952, clang used to call objc_msgSend when sending a release
messages, emitting an invoke instruction instead of a call instruction
when it was necessary to catch an exception. That changed in r349952
because runtime function objc_release is called as a nounwind function,
which broke programs that were overriding the dealloc method and
throwing an exception from it. This patch restores the behavior prior to
r349952.
Erik Pilkington [Fri, 10 May 2019 17:52:26 +0000 (17:52 +0000)]
[Sema] Mark array element destructors referenced during initialization
This fixes a crash where we would neglect to mark a destructor referenced for an
__attribute__((no_destory)) array. The destructor is needed though, since if an
exception is thrown we need to cleanup the elements.
Nico Weber [Fri, 10 May 2019 13:56:56 +0000 (13:56 +0000)]
Add name comments for bools passed to getObjCEncodingForTypeImpl()
No behavior change. Medium term, probably want to use a bitmask instead
of 8 distinct bool parameters, but let's make the call sites easier to
read first.
Nikolai Kosjar [Fri, 10 May 2019 10:25:35 +0000 (10:25 +0000)]
[Preamble] Stop circular inclusion of main file when building preamble
If a header file was processed for the second time, we could end up with a
wrong conditional stack and skipped ranges:
In the particular example, if the header guard is evaluated the second time and
it is decided to skip the conditional block, the corresponding "#endif" is
never seen since the preamble does not include it and we end up in the
Tok.is(tok::eof) case with a wrong conditional stack.
Detect the circular inclusion, emit a diagnostic and stop processing the
inclusion.
Akira Hatanaka [Fri, 10 May 2019 02:16:37 +0000 (02:16 +0000)]
Assume `__cxa_allocate_exception` returns an under-aligned memory on
Darwin if the version of libc++abi isn't new enough to include the fix
in r319123
This patch resurrects r264998, which was committed to work around a bug
in libc++abi that was causing _cxa_allocate_exception to return a memory
that wasn't double-word aligned.
In addition, this patch makes clang issue a warning if the type of the
thrown object requires an alignment that is larger than the minimum
guaranteed by the target C++ runtime.
Fangrui Song [Fri, 10 May 2019 02:08:21 +0000 (02:08 +0000)]
Change -gz and -Wa,--compress-debug-sections to use gABI compression (SHF_COMPRESSED)
Since July 15, 2015 (binutils-gdb commit 19a7fe52ae3d0971e67a134bcb1648899e21ae1c, included in 2.26), gas
--compress-debug-sections=zlib (gcc -gz) means zlib-gabi:
SHF_COMPRESSED. Before that it meant zlib-gnu (.zdebug).
clang's -gz was introduced in rC306115 (Jun 2017) to indicate zlib-gnu. It
is 2019 now and it is not unreasonable to assume users of the new
feature to have new linkers (ld.bfd/gold >= 2.26, lld >= rLLD273661).
Change clang's default accordingly to improve standard conformance.
zlib-gnu becomes out of fashion and gets poorer toolchain support.
Its mangled names confuse tools and are more likely to cause problems.
Alex Lorenz [Thu, 9 May 2019 20:35:41 +0000 (20:35 +0000)]
NFC, make XFAIL work on macOS correctly for test/Driver/XRay/xray-instrument-os.c
The test 'test/Driver/XRay/xray-instrument-os.c' is supposed to XFAIL on -darwin triples.
However, LLVM can be configured to be built with a -macos triple instead, which is equivalent
to -darwin. This commit updates the XFAIL condition to also XFAIL with a -macos host triple.
Alexey Bataev [Thu, 9 May 2019 18:44:53 +0000 (18:44 +0000)]
[OPENMP]Fix PR41767: diagnose DSA for variables in clauses with default(none).
If the combined directive has default(none) clause and has clauses for
inner directive that reference some variables, for which data-sharing
attributes are not specified, the error messages should be emitted for
such variables.
Alexey Bataev [Thu, 9 May 2019 18:14:57 +0000 (18:14 +0000)]
[OPENMP]Fix PR41768: check DSA for globals with default(none) clauses.
If the default(none) was specified for the construct, we might miss
diagnostic for the globals without explicitly specified data-sharing
attributes. Patch fixes this problem.