Craig Topper [Tue, 14 Nov 2017 08:48:28 +0000 (08:48 +0000)]
[NewPassManager] Pass the -fdebug-pass-manager flag setting into the Analysis managers to match what we do in opt
Summary: Currently the -fdebug-pass-manager flag for clang doesn't enable the debug logging in the analysis managers. This is different than what the switch does when passed to opt.
Chandler Carruth [Tue, 14 Nov 2017 01:59:18 +0000 (01:59 +0000)]
[PM] Wire up support for the bounds checking sanitizer with the new PM.
Not much interesting here. Mostly wiring things together.
One thing worth noting is that the approach is substantially different
from the old PM. Here, the -O0 case works fundamentally differently in
that we just directly build the pipeline without any callbacks or other
cruft. In some ways, this is nice and clean. However, I don't like that
it causes the sanitizers to be enabled with different changes at
different times. =/ Suggestions for a better way to do this are welcome.
Zachary Turner [Mon, 13 Nov 2017 23:33:29 +0000 (23:33 +0000)]
Revert "Update test_debuginfo.pl script to point to new tree location."
This reverts the aforementioned patch and 2 subsequent follow-ups,
as some buildbots are still failing 2 tests because of it.
Investigation is ongoing into the cause of the failures.
Sanjay Patel [Mon, 13 Nov 2017 22:11:49 +0000 (22:11 +0000)]
[CodeGen] fix const-ness of cbrt and fma
cbrt() is always constant because it can't overflow or underflow. Therefore, it can't set errno.
fma() is not always constant because it can overflow or underflow. Therefore, it can set errno.
But we know that it never sets errno on GNU / MSVC, so make it constant in those environments.
Devin Coughlin [Mon, 13 Nov 2017 17:35:29 +0000 (17:35 +0000)]
[analyzer] ObjCGenerics: Don't warn on cast conversions involving explicit cast
The ObjCGenerics checker warns on a cast when there is no subtyping relationship
between the tracked type of the value and the destination type of the cast. It
does this even if the cast was explicitly written. This means the user can't
write an explicit cast to silence the diagnostic.
This commit treats explicit casts involving generic types as an indication from
the programmer that the Objective-C type system is not rich enough to express
the needed invariant. On explicit casts, the checker now removes any existing
information inferred about the type arguments. Further, it no longer assumes
the casted-to specialized type because the invariant the programmer specifies
in the cast may only hold at a particular program point and not later ones. This
prevents a suppressing cast from requiring a cascade of casts down the
line.
Teresa Johnson [Mon, 13 Nov 2017 15:38:33 +0000 (15:38 +0000)]
[ThinLTO] Handle -fdebug-pass-manager for backend invocations via clang
Recommit of r317951 and r317951 along with what I believe should fix
the remaining buildbot failures - the target triple should be specified
for both the ThinLTO pre-thinlink compile and backend (post-thinlink)
compile to ensure it is consistent.
Original description:
The LTO Config field wasn't being set when invoking a ThinLTO backend
via clang (i.e. for distributed builds).
Michal Gorny [Sat, 11 Nov 2017 20:01:41 +0000 (20:01 +0000)]
[python] [tests] Fix test_linkage for unique external linkage
Starting with r314037, anonymous namespaces no longer give
unique-external linkage to variables. However, this linkage can still be
achieved by using a type which is not exterally visible,
e.g. through being declared in an anonymous namespace but used outside
it. Fix the test to take advantage of that.
Faisal Vali [Sat, 11 Nov 2017 18:02:29 +0000 (18:02 +0000)]
Adjust r316292 - remove the anonymous union for sharing a bitfield in FunctionDecl.
The anonymous union did NOT save us storage, but instead behaved as if we added an additional integer data member to FunctionDecl.
For additional context, the anonymous union renders the bit fields as non-adjacent and prevents them from sharing the same 'memory location' (i.e. bit-storage) by requiring the anonymous union object to be appropriately aligned.
This was confirmed through discussion with Richard Smith in Albuquerque (ISO C++ Meeting)
Gor Nishanov [Sat, 11 Nov 2017 17:00:43 +0000 (17:00 +0000)]
[coroutines] Promote cleanup.dest.slot allocas to registers to avoid storing it in the coroutine frame
Summary:
We don't want to store cleanup dest slot saved into the coroutine frame (as some of the cleanup code may
access them after coroutine frame destroyed).
This is an alternative to https://reviews.llvm.org/D37093
It is possible to do this for all functions, but, cursory check showed that in -O0, we get slightly longer function (by 1-3 instructions), thus, we are only limiting cleanup.dest.slot elimination to coroutines.
Jake Ehrlich [Sat, 11 Nov 2017 01:15:41 +0000 (01:15 +0000)]
Add CLANG_DEFAULT_OBJCOPY to allow Clang to use llvm-objcopy for dwarf fission
llvm-objcopy is getting to where it can be used in non-trivial ways
(such as for dwarf fission in clang). It now supports dwarf fission but
this feature hasn't been thoroughly tested yet. This change allows
people to optionally build clang to use llvm-objcopy rather than GNU
objcopy. By default GNU objcopy is still used so nothing should change.
Richard Trieu [Sat, 11 Nov 2017 00:54:25 +0000 (00:54 +0000)]
Handle lambda captures of variable length arrays in profiling and printing.
From http://reviews.llvm.org/D4368 these cases were thought to not be reachable
and the checks removed before the rest of the code was committed in r216649.
However, these cases are reachable and the checks are added back.
Zachary Turner [Fri, 10 Nov 2017 20:57:57 +0000 (20:57 +0000)]
[debuginfo-tests] Make debuginfo-tests work in a standard configuration.
Previously, debuginfo-tests was expected to be checked out into
clang/test and then the tests would automatically run as part of
check-clang. This is not a standard workflow for handling
external projects, and it brings with it some serious drawbacks
such as the inability to depend on things other than clang, which
we will need going forward.
The goal of this patch is to migrate towards a more standard
workflow. To ease the transition for build bot maintainers,
this patch tries not to break the existing workflow, but instead
simply deprecate it to give maintainers a chance to update
the build infrastructure.
Michal Gorny [Fri, 10 Nov 2017 16:44:12 +0000 (16:44 +0000)]
[python] [tests] Rewrite to use standard unittest module
Rewrite the tests from using plain 'assert' mixed with some nosetests
methods to the standard unittest module layout. Improve the code
to use the most canonical assertion methods whenever possible.
This has a few major advantages:
- the code uses standard methods now, resulting in a reduced number
of WTFs whenever someone with basic Python knowledge gets to read it,
- completely unnecessary dependency on nosetests is removed since
the standard library supplies all that is necessary for the tests
to run,
- the tests can be run via any test runner, including the one built-in
in Python,
- the failure output for most of the tests is improved from 'assertion
x == y failed' to actually telling the values.
Alexey Bataev [Fri, 10 Nov 2017 15:39:50 +0000 (15:39 +0000)]
[OpenMP] diagnose assign to firstprivate const, patch by Joel E. Denny
Summary:
[OpenMP] diagnose assign to firstprivate const
Clang does not diagnose assignments to const variables declared
firstprivate. Furthermore, codegen is broken such that, at run time,
such assignments simply have no effect. For example, the following
prints 0 not 1:
int main() {
const int i = 0;
#pragma omp parallel firstprivate(i)
{ i=1; printf("%d\n", i); }
return 0;
}
This commit makes these assignments a compile error, which is
consistent with other OpenMP compilers I've tried (pgcc 17.4-0, gcc
6.3.0).
Summary:
This change implements the changes required in both clang and
compiler-rt to allow building XRay-instrumented binaries in Darwin. For
now we limit this to x86_64. We also start building the XRay runtime
library in compiler-rt for osx.
A caveat to this is that we don't have the tests set up and running
yet, which we'll do in a set of follow-on changes.
This patch uses the monorepo layout for the coordinated change across
multiple projects.
Craig Topper [Fri, 10 Nov 2017 05:20:32 +0000 (05:20 +0000)]
[X86] Reduce the number of FMA builtins needed by the frontend by adding negates to operands of the fmadd and fmaddsub builtins.
The backend should be able to combine the negates to create fmsub, fnmadd, and fnmsub. faddsub converting to fsubadd still needs work I think, but should be very doable.
This matches what we already do for the masked builtins.
This only covers the packed builtins. Scalar builtins will be done after FMA4 is fixed.
Steven Wu [Fri, 10 Nov 2017 01:32:47 +0000 (01:32 +0000)]
[Driver] Make clang/cc conforms to UNIX standard
Summary:
This is basically reverting r261774 with a tweak for clang-cl. UNIX
standard states:
When c99 encounters a compilation error that causes an object file not
to be created, it shall write a diagnostic to standard error and
continue to compile other source code operands, but it shall not perform
the link phase and it shall return a non-zero exit status
The same goes for c89 or cc. And they are all alias or shims pointing to
clang on Darwin.
The original commit was intended for CUDA so the error message doesn't
get emit twice for both host and device. It seems that the clang driver
has been changed to model the CUDA dependency differently. Now the
driver behaves the same without this commit.
[analyzer] do not crash when trying to convert an APSInt to an unexpected type
This is the issue breaking the postgresql bot, purely by chance exposed
through taint checker, somehow appearing after
https://reviews.llvm.org/D38358 got committed.
The backstory is that the taint checker requests SVal for the value of
the pointer, and analyzer has a "fast path" in the getter to return a
constant when we know that the value is constant.
Unfortunately, the getter requires a cast to get signedness correctly,
and for the pointer `void *` the cast crashes.
This is more of a band-aid patch, as I am not sure what could be done
here "correctly", but it should be applied in any case to avoid the
crash.
Patches the solver to assume that bitwise OR of an unsigned value with a
constant always produces a value larger-or-equal than the constant, and
bitwise AND with a constant always produces a value less-or-equal than
the constant.
This patch is especially useful in the context of using bitwise
arithmetic for error code encoding: the analyzer would be able to state
that the error code produced using a bitwise OR is non-zero.
Ben Hamilton [Thu, 9 Nov 2017 16:01:16 +0000 (16:01 +0000)]
[VirtualFileSystem] InMemoryFileSystem::addFile(): Type and Perms
Summary:
This implements a FIXME in InMemoryFileSystem::addFile(), allowing
clients to specify User, Group, Type, and/or Perms when creating a
file in an in-memory filesystem.
Sam McCall [Thu, 9 Nov 2017 10:37:39 +0000 (10:37 +0000)]
[Tooling] Use FixedCompilationDatabase when `compile_flags.txt` is found.
Summary:
This is an alternative to JSONCompilationDatabase for simple projects that
don't use a build system such as CMake.
(You can also drop one in ~, to make your tools use e.g. C++11 by default)
There's no facility for varying flags per-source-file or per-machine.
Possibly this could be accommodated backwards-compatibly using cpp, but even if
not the simplicity seems worthwhile for the cases that are addressed.
Tested with clangd, works great! (requires clangd restart)
Craig Topper [Thu, 9 Nov 2017 04:10:46 +0000 (04:10 +0000)]
[X86] Rename the VEX scalar fma builtins to end with a '3' to match gcc
I think we need to use different builtins for the FMA4 instructions since those instructions zero the upper bits and FMA3 instructions pass the bits through.
So this moves the existing builtins to be the FMA3 versions. New versions will be added for FMA4.
Vedant Kumar [Thu, 9 Nov 2017 02:33:40 +0000 (02:33 +0000)]
[Coverage] Emit deferred regions in headers
There are some limitations with emitting regions in macro expansions
because we don't gather file IDs within the expansions. Fix the check
that prevents us from emitting deferred regions in expansions to make an
exception for headers, which is something we can handle.
Vedant Kumar [Thu, 9 Nov 2017 02:33:38 +0000 (02:33 +0000)]
[Coverage] Emit a gap area after if conditions
The area immediately after the closing right-paren of an if condition
should have a count equal to the 'then' block's count. Use a gap region
to set this count, so that region highlighting for the 'then' block
remains precise.
This solves a problem we have with wrapped segments. Consider:
1| if (false)
2| foo();
Without a gap area starting after the condition, the wrapped segment
from line 1 would make it look like line 2 is executed, when it's not.
Alex Lorenz [Wed, 8 Nov 2017 22:44:34 +0000 (22:44 +0000)]
[ObjC] Fix function signature handling for blocks literals with attributes
Block literals can have a type with attributes in its signature, e.g.
ns_returns_retained. The code that inspected the type loc of the block when
declaring its parameters didn't account for this fact, and only looked through
paren type loc. This commit ensures that getAsAdjusted is used instead of
IgnoreParens to find the block's FunctionProtoTypeLoc. This ensures that
block parameters are declared correctly in the block and avoids the
'undeclared identifier' error.
Alex Lorenz [Wed, 8 Nov 2017 21:33:15 +0000 (21:33 +0000)]
[ObjC] Boxed strings should use the nullability from stringWithUTF8String's return type
Objective-C NSString has a class method stringWithUTF8String that creates a new
NSString from a C string. Objective-C box expression @(...) can be used to
create an NSString instead of invoking the stringWithUTF8String method directly
(The compiler lowers it down to the invocation though). This commit ensures that
the type of @(string-value) gets the same nullability attributes as the return
type of stringWithUTF8String to ensure that the diagnostics are consistent
between the two.
Add CoreOption flag to "-coverage" option to make it available for clang-cl
Summary:
The -coverage option is not a CoreOption, so it is not available to clang-cl.
This patch adds the CoreOption flag to "-coverage" to allow it to be used with clang-cl.
Masud Rahman [Wed, 8 Nov 2017 19:17:27 +0000 (19:17 +0000)]
[bindings] fix TLS test failure
Since cfe commit r237337, '__declspec(thread)' and 'thread_local' have
been the same since MSVC 2015. i.e. they are both considered to supply
a dynamic TLS kind, not a static TLS kind.
This test originally did not specify which version of MS compatibility
to assume. As a result, the test was brittle, since changing the
default compatibility version could break the test.
This commit adds a specific version when building up the flags used to
parse the translation unit, and tests both versions.
Artem Dergachev [Wed, 8 Nov 2017 17:27:58 +0000 (17:27 +0000)]
[analyzer] Fix a crash on logical operators with vectors.
Do not crash when trying to compute x && y or x || y where x and y are
of a vector type.
For now we do not seem to properly model operations with vectors. In particular,
operations && and || on a pair of vectors are not short-circuit, unlike regular
logical operators, so even our CFG is incorrect.
Avoid the crash, add respective FIXME tests for later.
Clang's completion output is non-deterministic, causing test failures
with turned on LLVM_REVERSE_ITERATION.
The workaround is to use CHECK-DAGs for now, will remove them when
PR35244 gets fixed.
Ilya Biryukov [Wed, 8 Nov 2017 10:39:09 +0000 (10:39 +0000)]
Avoid printing some redundant name qualifiers in completion
Summary:
Adjusted PrintingPolicy inside code completion to avoid printing some
redundant name qualifiers.
Before this change, typedefs that were written unqualified in source
code were printed with qualifiers in completion. For example, in the
following code
struct foo {
typedef int type;
type method();
};
completion item for `method` had return type of `foo::type`, even
though the original code used `type` without qualifiers.
After this change, the completion item has return type `type`, as
originally written in the source code.
Note that this change does not suppress qualifiers written by the
user. For example, in the following code
typedef int type;
struct foo {
typedef int type;
::type method(foo::type);
};
completion item for `method` has return type of `::type` and
parameter type of `foo::type`, as originally written in the source
code.
Justin Lebar [Tue, 7 Nov 2017 22:10:54 +0000 (22:10 +0000)]
[NVPTX] Implement __nvvm_atom_add_gen_d builtin.
Summary:
This just seems to have been an oversight. We already supported the f64
atomic add with an explicit scope (e.g. "cta"), but not the scopeless
version.
George Rokos [Tue, 7 Nov 2017 18:27:04 +0000 (18:27 +0000)]
Clang/libomptarget map interface flag renaming - NFC patch
This patch renames some of the flag names of the clang/libomptarget map interface. The old names are slightly misleading, whereas the new ones describe in a better way what each flag is about.
Only the macros within the enumeration are renamed, there is no change in functionality therefore there are no updated regression tests.