Yaxun Liu [Mon, 19 Jun 2017 17:03:41 +0000 (17:03 +0000)]
CodeGen: Cast temporary variable to proper address space
In C++ all variables are in default address space. Previously change has been
made to cast automatic variables to default address space. However that is
not sufficient since all temporary variables need to be casted to default
address space.
This patch casts all temporary variables to default address space except those
for passing indirect arguments since they are only used for load/store.
This patch only affects target having non-zero alloca address space.
Summary:
This fixes the missing space before the designated initializer when `Cpp11BracedListStyle=false` :
const struct A a = { .a = 1, .b = 2 };
^
Also, wrapping between opening brace and designated array initializers used to have an excessive penalty (like breaking between an expression and the subscript operator), leading to unexpected wrapping:
Christof Douma [Mon, 19 Jun 2017 12:05:58 +0000 (12:05 +0000)]
[NFC] Refactor DiagnosticRenderer to use FullSourceLoc
Move the DiagnosticRenderer and its dependents to using FullSourceLocs
instead of a SourceLocation and SourceManager pointer. The changeset is
rather large but entirely mechanical.
This is step one to allow DiagnosticRenderer to take either
llvm::SMLocs or clang::SourceLocations.
Alex Lorenz [Mon, 19 Jun 2017 10:57:27 +0000 (10:57 +0000)]
[driver][macOS] Pick the system version for the deployment target
if the SDK is newer than the system
This commit improves the driver by making sure that it picks the system version
for the deployment target when the version of the macOS SDK is newer than the
system version.
Daniel Jasper [Mon, 19 Jun 2017 07:40:49 +0000 (07:40 +0000)]
clang-format: Handle "if constexpr".
c++1z adds the following constructions to the language:
if constexpr (cond)
statement1;
else if constexpr (cond)
statement2;
else if constexpr (cond)
statement3;
else
statement4;
A first version of this was proposed in reviews.llvm.org/D26953 by
Francis Visoiu Mistrih, but never commited. This patch additionally
fixes the behavior when allowing short if statements on a single line
and was authored by Jacob Bandes-Storch. Thank you to both authors.
Daniel Jasper [Mon, 19 Jun 2017 07:30:04 +0000 (07:30 +0000)]
clang-format: Add capability to format the diff on save in vim.
With this patch, one can configure a BufWrite hook that will make the
clang-format integration compute a diff of the current buffer with the file
that's on disk and format all changed lines. This should create a
zero-overhead auto-format solution that doesn't require the file to
already be clang-format clean to avoid spurious diffs.
CodeGen: make the type match the comment for a libcall
Fix the type for a (runtime) library call to match both the comment and
the runtime implementation. As it happens, the type being used matched,
this just makes it more precise.
Lang Hames [Sat, 17 Jun 2017 00:12:38 +0000 (00:12 +0000)]
Call setMustBuildLookupTable on TagDecls in ExternalASTMerger
Summary:
setMustBuildLookupTable should be called on imported TagDecls otherwise we may fail
to import their member decls (if they have any).
Not calling the setMustBuildLookupTable method results in a failure in the attached test
case when lookup for the 'x' member fails on struct S, which hasn't had its decls imported
elsewhere. (By contrast the member-in-struct testcase hasn't run into this issue
because the import of its decls is triggered when the struct instance is defined, and the
member access follows this).
Petr Hosek [Fri, 16 Jun 2017 22:40:18 +0000 (22:40 +0000)]
[Driver] Do a PATH lookup if needed when using -no-canonical-prefixes
When -no-canonical-prefixes option is used and argv0 contains only
a program name, we need to do a PATH lookup to get an executable path,
otherwise the return value won't be a valid path and any subsequent
uses of it (e.g. when invoking -cc1) will fail with an error.
Alex Lorenz [Fri, 16 Jun 2017 20:13:39 +0000 (20:13 +0000)]
[PR33394] Avoid lexing editor placeholders when Clang is used only
for preprocessing
r300667 added support for editor placeholder to Clang. That commit didn’t take
into account that users who use Clang for preprocessing only (-E) will get the
"editor placeholder in source file" error when preprocessing their source
(PR33394). This commit ensures that Clang doesn't lex editor placeholders when
running a preprocessor only action.
[XRay][clang] Support capturing the implicit `this` argument to C++ class member functions
Summary:
Before this change, we couldn't capture the `this` pointer that's
implicitly the first argument of class member functions. There are some
interesting things we can do with capturing even just this single
argument for zero-argument member functions.
Richard Trieu [Fri, 16 Jun 2017 02:44:29 +0000 (02:44 +0000)]
[ODRHash] Hash VarDecl members.
These VarDecl's are static data members of classes. Since the initializers are
also hashed, this also provides checking for default arguments to methods.
Alex Lorenz [Thu, 15 Jun 2017 21:40:54 +0000 (21:40 +0000)]
[Completion] Code complete the members for a dependent type after a '::'
This commit is a follow up to r302797 which added support for dependent
completions after the '.' and '->' operators. This commit adds support for
dependent completions after the '::' operator.
Alex Lorenz [Thu, 15 Jun 2017 20:50:43 +0000 (20:50 +0000)]
[index] Index static_assert declarations
static_assert declarations have to be visited while indexing so that we can
gather the references to declarations that are present in their assert
expression.
Apply summary-based dead stripping to regular LTO modules with summaries.
If a regular LTO module has a summary index, then instead of linking
it into the combined regular LTO module right away, add it to the
combined summary index and associate it with a special module that
represents the combined regular LTO module.
Any such modules are linked during LTO::run(), at which time we use
the results of summary-based dead stripping to control whether to
link prevailing symbols.
Dominic Chen [Thu, 15 Jun 2017 17:05:07 +0000 (17:05 +0000)]
[analyzer]: Improve test handling with multiple constraint managers
Summary: Modify the test infrastructure to properly handle tests that require z3, and merge together the output of all tests on success. This is required for D28954.
Daniel Jasper [Thu, 15 Jun 2017 09:17:12 +0000 (09:17 +0000)]
Revert "Define _GNU_SOURCE for rtems c++"
This reverts commit r305399.
This breaks a build in libcxx:
libcxx/src/system_error.cpp:90:16: error: assigning to 'int' from incompatible type 'char *'
if ((ret = ::strerror_r(ev, buffer, strerror_buff_size)) != 0) {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
Which makes sense according to:
https://linux.die.net/man/3/strerror_r
Erich Keane [Wed, 14 Jun 2017 23:09:01 +0000 (23:09 +0000)]
[Preprocessor]Correct Macro-Arg allocation of StringifiedArguments,
correct getNumArguments
StringifiedArguments is allocated (resized) based on the size the
getNumArguments function. However, this function ACTUALLY currently
returns the amount of total UnexpArgTokens which is minimum the same as
the new implementation of getNumMacroArguments, since empty/omitted arguments
result in 1 UnexpArgToken, and included ones at minimum include 2
(1 for the arg itself, 1 for eof).
This patch renames the otherwise unused getNumArguments to be more clear
that it is the number of arguments that the Macro expects, and thus the maximum
number that can be stringified. This patch also replaces the explicit memset
(which results in value instantiation of the new tokens, PLUS clearing the
memory) with brace initialization.
Serge Pavlov [Wed, 14 Jun 2017 10:07:02 +0000 (10:07 +0000)]
Function with unparsed body is a definition
While a function body is being parsed, the function declaration is not considered
as a definition because it does not have a body yet. In some cases it leads to
incorrect interpretation, the case is presented in
https://bugs.llvm.org/show_bug.cgi?id=14785:
```
template<typename T> struct Somewhat {
void internal() const {}
friend void operator+(int const &, Somewhat<T> const &) {}
};
void operator+(int const &, Somewhat<char> const &x) { x.internal(); }
```
When statement `x.internal()` in the body of global `operator+` is parsed, the type
of `x` must be completed, so the instantiation of `Somewhat<char>` is started. It
instantiates the declaration of `operator+` defined inline, and makes a check for
redefinition. The check does not detect another definition because the declaration
of `operator+` is still not defining as does not have a body yet.
To solves this problem the function `isThisDeclarationADefinition` considers
a function declaration as a definition if it has flag `WillHaveBody` set.
Eric Fiselier [Wed, 14 Jun 2017 03:24:55 +0000 (03:24 +0000)]
[coroutines] Fix co_await for range statement
Summary:
Currently we build the co_await expressions on the wrong implicit statements of the implicit ranged for; Specifically we build the co_await expression wrapping the range declaration, but it should wrap the begin expression.
Florian Hahn [Tue, 13 Jun 2017 18:06:15 +0000 (18:06 +0000)]
Align definition of DW_OP_plus with DWARF spec [2/3]
Summary:
This patch is part of 3 patches that together form a single patch, but must be introduced in stages in order not to break things.
Â
The way that LLVM interprets DW_OP_plus in DIExpression nodes is basically that of the DW_OP_plus_uconst operator since LLVM expects an unsigned constant operand. This unnecessarily restricts the DW_OP_plus operator, preventing it from being used to describe the evaluation of runtime values on the expression stack. These patches try to align the semantics of DW_OP_plus and DW_OP_minus with that of the DWARF definition, which pops two elements off the expression stack, performs the operation and pushes the result back on the stack.
Â
This is done in three stages:
• The first patch (LLVM) adds support for DW_OP_plus_uconst and changes all uses (and tests) of DW_OP_plus to use DW_OP_plus_uconst.
Â
• The second patch (Clang) contains changes to use DW_OP_plus_uconst instead of DW_OP_plus.
Â
• The third patch (LLVM) changes the semantics of DW_OP_plus to be in line with it’s DWARF meaning. It also does this for DW_OP_minus.
Francois Ferrand [Tue, 13 Jun 2017 07:02:43 +0000 (07:02 +0000)]
clang-format: add option to merge empty function body
Summary:
This option supplements the AllowShortFunctionsOnASingleLine flag, to
merge empty function body at the beginning of the line: e.g. when the
function is not short-enough and breaking braces after function.
Reid Kleckner [Mon, 12 Jun 2017 19:57:56 +0000 (19:57 +0000)]
Correct debug info bit offset calculation for big-endian targets
Summary:
The change "[CodeView] Implement support for bit fields in
Clang" (r274201, https://reviews.llvm.org/rL274201) broke the
calculation of bit offsets for the debug info describing bitfields on
big-endian targets.
Prior to commit r274201 the debug info for bitfields got their offsets
from the ASTRecordLayout in CGDebugInfo::CollectRecordFields(), the
current field offset was then passed on to
CGDebugInfo::CollectRecordNormalField() and used directly in the
DIDerivedType.
Since commit r274201, the bit offset ending up in the DIDerivedType no
longer comes directly from the ASTRecordLayout. Instead
CGDebugInfo::CollectRecordNormalField() calls the new method
CGDebugInfo::createBitFieldType(), which in turn calls
CodeGenTypes::getCGRecordLayout().getBitFieldInfo() to fetch a
CGBitFieldInfo describing the field. The 'Offset' member of
CGBitFieldInfo is then used to calculate the bit offset of the
DIDerivedType. Unfortunately the previous and current method of
calculating the bit offset are only equivalent for little endian
targets, as CGRecordLowering::setBitFieldInfo() reverses the bit
offsets for big endian targets as the last thing it does.
A simple reproducer for this error is the following module:
struct fields {
unsigned a : 4;
unsigned b : 4;
} flags = {0x0f, 0x1};
Compiled for Mips, with commit r274200 both the DIDerivedType bit
offsets on the IR-level and the DWARF information on the ELF-level
will have the expected values: the offsets of 'a' and 'b' are 0 and 4
respectively. With r274201 the offsets are switched to 4 and 0. By
noting that the static initialization of 'flags' in both cases is the
same, we can eliminate a change in record layout as the cause of the
change in the debug info. Also compiling this example with gcc,
produces the same record layout and debug info as commit r274200.
In order to restore the previous function we extend
CGDebugInfo::createBitFieldType() to compensate for the reversal done
in CGRecordLowering::setBitFieldInfo().
Vedant Kumar [Mon, 12 Jun 2017 18:42:51 +0000 (18:42 +0000)]
[ubsan] Detect invalid unsigned pointer index expression (clang)
Adding an unsigned offset to a base pointer has undefined behavior if
the result of the expression would precede the base. An example from
@regehr:
int foo(char *p, unsigned offset) {
return p + offset >= p; // This may be optimized to '1'.
}
foo(p, -1); // UB.
This patch extends the pointer overflow check in ubsan to detect invalid
unsigned pointer index expressions. It changes the instrumentation to
only permit non-negative offsets in pointer index expressions when all
of the GEP indices are unsigned.
Testing: check-llvm, check-clang run on a stage2, ubsan-instrumented
build.
Artem Dergachev [Mon, 12 Jun 2017 17:59:50 +0000 (17:59 +0000)]
[analyzer] Fix a crash when an ObjC object is constructed in AllocaRegion.
Memory region allocated by alloca() carries no implicit type information.
Don't crash when resolving the init message for an Objective-C object
that is being constructed in such region.
These options control the behaviour of the compression of debug info
sections on ELF targets. Our behaviour slightly diverges from the
behaviour of GCC. `-gz` maps to the `-compress-debug-sections` rather
than `-compress-debug-sections=zlib` or
`-compress-debug-sections=zlib-gnu`. This small divergence allows us to
be compatible across versions of binutils (=zlib support was introduced
in 2.26, while earlier versions only support =zlib-gnu). This also
allows users to not have to worry about the version of the assembler
they may be using if they are not using the IAS. Previously, users
would have had to go through the internal option
`-compress-debug-sectionss` and pass that through to the assembler,
which is no longer needed.
Driver: pass along [-]-[no]compress-debug-sections unfiltered
Rather than validating the flags, pass them through without any
validation. Arguments passed via -Wa or -Xassembler are passed directly
to the assembler without validation. The validation was previously
required since we did not provide proper driver level support for
controlling the debug compression on ELF targets. A subsequent change
will add support for the `-gz` and `-gz=` flags which provide proper
driver level control of the ELF compressed debug sections.
Erich Keane [Fri, 9 Jun 2017 22:50:02 +0000 (22:50 +0000)]
Support operator keywords used in Windows SDK(fix ubsan)
UBSan found an issue with a nullptr being assigned to a reference.
This was because a following function went back and checked the
identifier in the CPPOperatorName case. This patch corrects that
location with the original logic as well.
Vassil Vassilev [Fri, 9 Jun 2017 21:36:28 +0000 (21:36 +0000)]
[modules] Fix that global delete operator get's assigned to a submodule.
n the current local-submodule-visibility mode, as soon as we discover a virtual
destructor, we declare on demand a global delete operator. However, this causes
that this delete operator is owned by the submodule which contains said virtual
destructor. This means that other modules no longer can see the global delete
operator which is hidden inside another submodule and fail to compile.
This patch unhides those global allocation function once they're created to
prevent this issue.
Richard Smith [Fri, 9 Jun 2017 21:24:02 +0000 (21:24 +0000)]
Add -frewrite-imports flag.
If specified, when preprocessing, the contents of imported .pcm files will be
included in preprocessed output. The resulting preprocessed file can then be
compiled standalone without the module sources or .pcm files.
Richard Smith [Fri, 9 Jun 2017 19:22:32 +0000 (19:22 +0000)]
Add #pragma clang module build/endbuild pragmas for performing a module build
as part of a compilation.
This is intended for two purposes:
1) Writing self-contained test cases for modules: we can now write a single
source file test that builds some number of module files on the side and
imports them.
2) Debugging / test case reduction. A single-source testcase is much more
amenable to reduction, compared to a VFS tarball or .pcm files.
Vassil Vassilev [Fri, 9 Jun 2017 16:42:26 +0000 (16:42 +0000)]
Repair 2010-05-31-palignr.c test
This test was silently failing since a long time because it failed to include
stdlib.h (as it's running in a freestanding environment). However, because we
used just not clang_cc1 instead of the verify mode, this regression was never
noticed and the test was just always passing.
This adds -ffreestanding to the invocation, so that tmmintrin.h doesn't
indirectly include mm_malloc.h, which in turns includes the unavailable stdlib.h.
We also run now in the -verify mode to prevent that we silently regress again.
I've also updated the test to no longer check the return value of _mm_alignr_epi8
as this is also causing it to fail (and it's not really the job of this test to
test this).