Erich Keane [Fri, 27 Oct 2017 18:32:23 +0000 (18:32 +0000)]
Filter out invalid 'target' items from being passed to LLVM
Craig noticed that CodeGen wasn't properly ignoring the
values sent to the target attribute. This patch ignores
them.
This patch also sets the 'default' for this checking to
'supported', since only X86 has implemented the support
for checking valid CPU names and Feature Names.
One test was changed to i686, since it uses a lakemont,
which would otherwise be prohibited in x86_64.
Alex Lorenz [Fri, 27 Oct 2017 18:19:11 +0000 (18:19 +0000)]
[refactor] Describe refactorings in the operation classes
This commit changes the way that the refactoring operation classes are
structured:
- Users have to call `initiate` instead of constructing an instance of the
class. The `initiate` is now supposed to have custom initiation logic, and
you don't need to subclass the builtin requirements.
- A new `describe` function returns a structure with the id, title and the
description of the refactoring operation.
The refactoring action classes are now placed into one common place in
RefactoringActions.cpp instead of being separate.
Don Hinton [Fri, 27 Oct 2017 17:02:33 +0000 (17:02 +0000)]
New lldb python module for managing diagnostic breakpoints
Summary:
Can be used to set breakpoints for either the diagnostics actually
emitted for the current compilation, a particular DiagID, or all
DiagIDs for a particular warning.
Nico Weber [Thu, 26 Oct 2017 23:26:29 +0000 (23:26 +0000)]
Use -fuse-init-array if no gcc installation is found.
clang currently uses .init_array instead of .ctors on Linux if it detects gcc
4.7+. Make it so that it also uses .init_array if no gcc installation is found
at all – if there's no old gcc, there's nothing we need to be compatible with.
icecc for example runs clang in a very small chroot, so before this change
clang would use .ctors if run under icecc. And lld currently silently mislinks
inputs with .ctors sections, so before this clang + icecc + lld would produce
broken binaries. (But this seems like a good change independent of that lld
bug.)
Craig Topper [Thu, 26 Oct 2017 23:06:19 +0000 (23:06 +0000)]
[X86] Make -march=i686 an alias of -march=pentiumpro
I think the only reason they are different is because we don't set tune_i686 for -march=i686 to match GCC. But GCC 4.9.0 seems to have changed this behavior and they do set it now. So I think they can aliases now.
Craig Topper [Thu, 26 Oct 2017 21:28:33 +0000 (21:28 +0000)]
[X86][Driver] Move all of the X86 feature flags to one spot in the Options.td file and pair them up with their negations.
It looks like at one time Options.td was in alphabetical order, but that looks to have long been broken. The result is that it all the no- x86 options got separated from their other friends for no good reason.
This patch puts them all together in one place with the no- paired with its none negated version.
I've kept all the SSE and AVX/AVX512 bits together since they represent a somewhat linear progression of features. The rest I just put in alphabetical order after.
Vedant Kumar [Thu, 26 Oct 2017 21:27:24 +0000 (21:27 +0000)]
[CGBlocks] Improve line info in backtraces containing *_helper_block
Instead of only setting a non-zero debug location on the return
instruction in *_helper_block functions, set a proper location on all
instructions within these functions. Pick the start location of the
block literal expr for maximum clarity.
The debugger does not step into *_helper_block functions during normal
single-stepping because we mark their parameters as artificial. This is
what we want (the functions are implicitly generated and uninteresting
to most users). The stepping behavior is unchanged by this patch.
Adrian Prantl [Thu, 26 Oct 2017 20:08:52 +0000 (20:08 +0000)]
Simplify codegen and debug info generation for block context parameters.
The exisiting code goes out of its way to put block parameters into an
alloca only at -O0, and then describes the funciton argument with a
dbg.declare, which is undocumented in the LLVM-CFE contract and does
not actually behave as intended after LLVM r642022.
This patch just generates the alloca unconditionally, the mem2reg pass
will eliminate it at -O1 and up anyway and points the dbg.declare to
the alloca as intended (which mem2reg will then correctly rewrite into
a dbg.value).
This reapplies r316684 with some dead code removed.
Adrian Prantl [Thu, 26 Oct 2017 18:16:05 +0000 (18:16 +0000)]
Simplify codegen and debug info generation for block context parameters.
The exisiting code goes out of its way to put block parameters into an
alloca only at -O0, and then describes the funciton argument with a
dbg.declare, which is undocumented in the LLVM-CFE contract and does
not actually behave as intended after LLVM r642022.
This patch just generates the alloca unconditionally, the mem2reg pass
will eliminate it at -O1 and up anyway and points the dbg.declare to
the alloca as intended (which mem2reg will then correctly rewrite into
a dbg.value).
Dave Lee [Thu, 26 Oct 2017 15:53:37 +0000 (15:53 +0000)]
Add objcCategoryImplDecl matcher
Summary:
Add `objcCategoryImplDecl` which matches ObjC category definitions
(`@implementation`). This matcher complements `objcCategoryDecl` (`@interface`)
which was added in D30854.
Roman Lebedev [Thu, 26 Oct 2017 13:18:14 +0000 (13:18 +0000)]
[Sema] -Wzero-as-null-pointer-constant: don't warn for system macros other than NULL.
Summary:
The warning was initially introduced in D32914 by @thakis,
and the concerns were raised there, and later in rL302247
and PR33771.
I do believe that it makes sense to relax the diagnostic
e.g. in this case, when the expression originates from the
system header, which can not be modified. This prevents
adoption for the diagnostic for codebases which use pthreads
(`PTHREAD_MUTEX_INITIALIZER`), gtest, etc.
As @malcolm.parsons suggests, it *may* make sense to also
not warn for the template types, but it is not obvious to
me how to do that in here.
Though, it still makes sense to complain about `NULL` macro.
Aaron Ballman [Thu, 26 Oct 2017 12:19:02 +0000 (12:19 +0000)]
Add a new attribute definition spelling, Clang<"attr">, that expands to two attribute spellings: GNU<"attr"> and CXX11<"clang", "attr">. This is similar to how the GCC spelling works and is intended to be used for attributes introduced for Clang.
Changes all existing attributes that currently use GNU<"attr"> and CXX11<"clang", "attr> spellings to instead use the Clang<"attr"> spelling.
No additional tests are necessary because the existing tests already use both spellings for the attributes converted to the new spelling. No functional changes are expected.
Eric Liu [Thu, 26 Oct 2017 10:38:14 +0000 (10:38 +0000)]
[Tooling] A new framework for executing clang frontend actions.
Summary:
This defines a `clang::tooling::ToolExecutor` interface that can be extended to support different execution plans including standalone execution on a given set of TUs or parallel execution on all TUs in a codebase.
In order to enable multiprocessing execution, tool actions are expected to output result into a `ToolResults` interface provided by executors. The `ToolResults` interface abstracts how results are stored e.g. in-memory for standalone executions or on-disk for large-scale execution.
New executors can be registered as `ToolExecutorPlugin`s via the `ToolExecutorPluginRegistry`. CLI tools can use `createExecutorFromCommandLineArgs` to create a specific registered executor according to the command-line arguments.
This patch also implements `StandaloneToolExecutor` which has the same behavior as the current `ClangTool` interface, i.e. execute frontend actions on a given set of TUs. At this point, it's simply a wrapper around `ClangTool` at this point.
This is still experimental but expected to replace the existing `ClangTool` interface so that specific tools would not need to worry about execution.
Benjamin Kramer [Thu, 26 Oct 2017 08:41:28 +0000 (08:41 +0000)]
Fix overloaded static functions in SemaCodeComplete
https://bugs.llvm.org/show_bug.cgi?id=33904
Happens when static function is accessed via the class variable. That leads to incorrect overloads number because the variable is considered as the first argument.
struct Bar {
static void foo(); static void foo(int);
};
int main() {
Bar b;
b.foo(/*complete here*/); // did not work before
Bar::foo(/*complete here*/); // worked fine
}
George Karpenkov [Wed, 25 Oct 2017 21:49:46 +0000 (21:49 +0000)]
[Analyzer] [Tests] Do not discard output from CmpRuns.py when running integration tests
Contrary to the deleted comment, in most cases CmpRuns.py produces a
fairly small amount of output, which is useful to see straight away to
see what has changed when executing the integration tests.
Erich Keane [Wed, 25 Oct 2017 20:23:13 +0000 (20:23 +0000)]
Ignore implicity casts for zero-as-null-pointer-constant warning
The repro in https://bugs.llvm.org/show_bug.cgi?id=34362
caused the left nullptr to be cast to a int* implicitly, which
resulted diagnosing this falsely.
Darwin uses char * for the variadic list type (va_list). We use the PPC
SVR4 ABI for PPC, which uses a structure type for the va_list. When
constructing the GEP, we would fail due to the incorrect handling for
the va_list. Correct this to use the right type.
Ensure that we check the ivar containing decl for the DLL storage
attribute rather than the ivar itself as the dll storage is associated
to the interface decl not the ivar decl.
Akira Hatanaka [Tue, 24 Oct 2017 23:38:14 +0000 (23:38 +0000)]
[Sema][ObjC] Look for either objc_bridge or objc_bridge_mutable when
determining whether a RecordDecl is CFError.
CFErrorRef used to be declared with "objc_bridge(NSError)" but is now
declared with "objc_bridge_mutable(NSError)". Look for either when
checking whether a RecordDecl is CFError.
Erich Keane [Tue, 24 Oct 2017 23:12:01 +0000 (23:12 +0000)]
Correct behavior of fastcall when default CC is set.
Fastcall doesn't support variadic function calls, so
setting the default calling convention to Fastcall would
result in incorrect code being emitted for these conditions.
This patch adds a 'variadic' test to the default calling conv
test, as well as fixes the behavior of fastcall.
Roman Lebedev [Tue, 24 Oct 2017 21:05:43 +0000 (21:05 +0000)]
[Sema] Document+test the -Wsign-compare change for enums in C code [NFC]
rL316268 / D39122 has fixed PR35009, and now when in C,
these three(?) diagnostics properly use the enum's underlying
datatype.
While it was fixed, the test coverage was clearly insufficient,
because the -Wsign-compare change didn't show up in any of the
tests, until it was reported in the post-commit mail for rL316268.
So add the test for the -Wsign-compare diagnostic for enum
for C code, and while there, document this in the release notes.
The fix itself was obviously correct, so unless we want to silence
this new diagnosed case, i deem this commit to be NFC.
Yaxun Liu [Tue, 24 Oct 2017 19:14:43 +0000 (19:14 +0000)]
CodeGen: Fix missing debug loc due to alloca
Builder save/restores insertion pointer when emitting addr space cast
for alloca, but does not save/restore debug loc, which causes verifier
failure for certain call instructions.
Alex Lorenz [Tue, 24 Oct 2017 17:18:45 +0000 (17:18 +0000)]
[refactor] Initial outline of implementation of "extract function" refactoring
This commit adds an initial, skeleton outline of the "extract function"
refactoring. The extracted function doesn't capture variables / rewrite code
yet, it just basically does a simple copy-paste.
The following initiation rules are specified:
- extraction can only be done for executable code in a function/method/block.
This means that you can't extract a global variable initialize into a function
right now.
- simple literals and references are not extractable.
This commit also adds support for full source ranges to clang-refactor's test
mode.
Erik Verbruggen [Tue, 24 Oct 2017 13:46:58 +0000 (13:46 +0000)]
Do not add a colon chunk to the code completion of class inheritance access modifiers
With enabled CINDEXTEST_CODE_COMPLETE_PATTERNS env option (which enables
IncludeCodePatterns in completion options) code completion after colon
currently suggests access modifiers with 2 completion chunks which is
incorrect.
Example:
class A : <Cursor>B
{
}
Currently we get 'NotImplemented:{TypedText public}{Colon :} (40)'
but the correct line is just 'NotImplemented:{TypedText public} (40)'
The fix introduces more specific scope that occurs between ':' and '{'
It allows us to determine when we don't need to add ':' as a second
chunk to the public/protected/private access modifiers.
Peter Smith [Tue, 24 Oct 2017 09:51:55 +0000 (09:51 +0000)]
[AArch64] Fix PR34625 -mtune without -mcpu should not set -target-cpu
When -mtune is used on AArch64 the -target-cpu is passed the value of the
cpu given to -mtune. As well as setting micro-architectural features of the
-mtune cpu, this will also add the architectural features such as support
for instructions. This can result in the backend using instructions that
are supported in the -mtune cpu but not supported in the target
architecture. For example use of the v8.1-a LSE extensions with -march=v8.
This change removes the setting of -target-cpu for -mtune, the -mcpu must
be used to set -target-cpu. This has the effect of removing all non-hard
coded benefits of mtune but it does produce correct output when -mtune cpu
with a later architecture than v8 is used.
Tim Shen [Tue, 24 Oct 2017 03:11:02 +0000 (03:11 +0000)]
[test] Fix clang-test for FreeBSD and NetBSD
Lit tries to inject the shared library paths, but no action is taken
when platform.system() is not recognized, results in an environment
variable with an empty name, which is illegal.
The patch fixes this mechanism for FreeBSD and NetBSD, and gives an
warning on other platforms, so that the latecomers don't have to spend
time on debugging lit.
Jordan Rose [Tue, 24 Oct 2017 02:17:07 +0000 (02:17 +0000)]
Unnamed bitfields don't block constant evaluation of constexpr ctors
C++14 [dcl.constexpr]p4 states that in the body of a constexpr
constructor,
> every non-variant non-static data member and base class sub-object
shall be initialized
However, [class.bit]p2 notes that
> Unnamed bit-fields are not members and cannot be initialized.
Therefore, we should make sure to filter them out of the check that
all fields are initialized.
Fixing this makes the constant evaluator a bit smarter, and
specifically allows constexpr constructors to avoid tripping
-Wglobal-constructors when the type contains unnamed bitfields.
Erich Keane [Tue, 24 Oct 2017 01:39:56 +0000 (01:39 +0000)]
Fix template parameter default args missed if redecled
This bug was found via self-build on lld, and worked around
here: https://reviews.llvm.org/rL316180
The issue is that the 'using' causes the lookup to pick up the
first decl. However, when setting inherited default parameters,
we only update 'forward', not 'backward'. SO, only the newest param
list has all the information about the default arguments.
This patch ensures that the list of parameters we look through checks
the newest decl's template parameter list so it doesn't miss a default.
[analyzer] Fix handling of labels in getLValueElement
In getLValueElement Base may represent the address of a label
(as in the newly-added test case), in this case it's not a loc::MemRegionVal
and Base.castAs<loc::MemRegionVal>() triggers an assert, this diff makes
getLValueElement return UnknownVal instead.
Volodymyr Sapsai [Mon, 23 Oct 2017 22:01:41 +0000 (22:01 +0000)]
[Sema] Add support for flexible array members in Obj-C.
Allow Obj-C ivars with incomplete array type but only as the last ivar.
Also add a requirement for ivars that contain a flexible array member to
be at the end of class too. It is possible to add in a subclass another
ivar at the end but we'll emit a warning in this case. Also we'll emit a
warning if a variable sized ivar is declared in class extension or in
implementation because subclasses won't know they should avoid adding
new ivars.
In ARC incomplete array objects are treated as __unsafe_unretained so
require them to be marked as such.
Prohibit synthesizing ivars with flexible array members because order of
synthesized ivars is not obvious and tricky to control. Spelling out
ivar explicitly gives control to developers and helps to avoid surprises
with unexpected ivar ordering.
For C and C++ changed diagnostic to tell explicitly a field is not the
last one and point to the next field. It is not as useful as in Obj-C
but it is an improvement and it is consistent with Obj-C. For C for
unions emit more specific err_flexible_array_union instead of generic
err_field_incomplete.
Petr Hosek [Mon, 23 Oct 2017 21:31:05 +0000 (21:31 +0000)]
[Driver] Use ld.lld directly for Fuchsia rather than passing flavor
Passing a flavor to LLD requires command line argument, but if these
are being passed through a response file, this will fail because LLD
needs to know which driver to use before processing the response file.
Use ld.lld directly instead to avoid this issue.
Jonas Hahnfeld [Mon, 23 Oct 2017 19:01:35 +0000 (19:01 +0000)]
[OpenMP] Avoid VLAs for some reductions on array sections
In some cases the compiler can deduce the length of an array section
as constants. With this information, VLAs can be avoided in place of
a constant sized array or even a scalar value if the length is 1.
Example:
int a[4], b[2];
pragma omp parallel reduction(+: a[1:2], b[1:1])
{ }
For chained array sections, this optimization is restricted to cases
where all array sections except the last have a constant length 1.
This trivially guarantees that there are no holes in the memory region
that needs to be privatized.
Example:
int c[3][4];
pragma omp parallel reduction(+: c[1:1][1:2])
{ }
This relands commit r316229 that I reverted in r316235 because it
failed on some bots. During investigation I found that this was because
Clang and GCC evaluate the two arguments to emplace_back() in
ReductionCodeGen::emitSharedLValue() in a different order, hence
leading to a different order of generated instructions in the final
LLVM IR. Fix this by passing in the arguments from temporary variables
that are evaluated in a defined order.
Nico Weber [Mon, 23 Oct 2017 15:54:44 +0000 (15:54 +0000)]
clang-cl: Expose --version.
This is for consistency with lld-link, see https://reviews.llvm.org/D38972
Also give --version a help text so it shows up in --help / /? output (for
both clang-cl and regular clang).
Richard Smith [Mon, 23 Oct 2017 03:58:34 +0000 (03:58 +0000)]
For better compatibility with C++11 and C++14, emit a nondiscardable definition
of a static constexpr data member if it's defined 'constexpr' out of line, not
only if it's defined 'constexpr' in the class.
Faisal Vali [Sun, 22 Oct 2017 14:45:08 +0000 (14:45 +0000)]
[C++17] Fix PR34970 - tweak overload resolution for class template deduction-guides in line with WG21's p0620r0.
In order to identify the copy deduction candidate, I considered two approaches:
- attempt to determine whether an implicit guide is a copy deduction candidate by checking certain properties of its subsituted parameter during overload-resolution.
- using one of the many bits (WillHaveBody) from FunctionDecl (that CXXDeductionGuideDecl inherits from) that are otherwise irrelevant for deduction guides
After some brittle gymnastics w the first strategy, I settled on the second, although to avoid confusion and to give that bit a better name, i turned it into a member of an anonymous union.
Given this identification 'bit', the tweak to overload resolution was a simple reordering of the deduction guide checks (in SemaOverload.cpp::isBetterOverloadCandidate), in-line with Jason Merrill's p0620r0 drafting which made it into the working paper. Concordant with that, I made sure the copy deduction candidate is always added.
References:
See https://bugs.llvm.org/show_bug.cgi?id=34970
See http://wg21.link/p0620r0
Masud Rahman [Sat, 21 Oct 2017 20:53:49 +0000 (20:53 +0000)]
[libclang, bindings]: add spelling location
o) Add a 'Location' class that represents the four properties of a
physical location
o) Enhance 'SourceLocation' to provide 'expansion' and 'spelling'
locations, maintaining backwards compatibility with existing code by
forwarding the four properties to 'expansion'.
o) Update the implementation to use 'clang_getExpansionLocation'
instead of the deprecated 'clang_getInstantiationLocation', which
has been present since 2011.
o) Update the implementation of 'clang_getSpellingLocation' to actually
obtain spelling location instead of file location.
Aaron Ballman [Sat, 21 Oct 2017 20:28:58 +0000 (20:28 +0000)]
Fix a typo with -fno-double-square-bracket-attributes and add a test to demonstrate that it works as expected in C++11 mode. Additionally corrected the handling of -fdouble-square-bracket-attributes to be properly passed down to the cc1 option.
Roman Lebedev [Sat, 21 Oct 2017 16:44:03 +0000 (16:44 +0000)]
[Sema] Fixes for enum handling for tautological comparison diagnostics
Summary:
As Mattias Eriksson has reported in PR35009, in C, for enums, the underlying type should
be used when checking for the tautological comparison, unlike C++, where the enumerator
values define the value range. So if not in CPlusPlus mode, use the enum underlying type.
Also, i have discovered a problem (a crash) when evaluating tautological-ness of the following comparison:
```
enum A { A_a = 0 };
if (a < 0) // expected-warning {{comparison of unsigned enum expression < 0 is always false}}
return 0;
```
This affects both the C and C++, but after the first fix, only C++ code was affected.
That was also fixed, while preserving (i think?) the proper diagnostic output.
And while there, attempt to enhance the test coverage.
Yes, some tests got moved around, sorry about that :)
Aaron Ballman [Sat, 21 Oct 2017 16:43:01 +0000 (16:43 +0000)]
Fixing broken attribute documentation for __attribute__((noescape)); a code block was missing and the existing code block was missing a mandatory newline.