Support GNU style rule to put a space before opening parenthesis.
Summary:
The rule from the GNU style states:
"We find it easier to read a program when it has spaces before the open-parentheses and after the commas."
This patch makes clang-format adds an option to put spaces before almost all open parentheses, except the cases, where different behavior is dictated by the style rules or language syntax:
* preprocessor:
** function-like macro definitions can't have a space between the macro name and the parenthesis;
** `#if defined(...)` can have a space, but it seems, that it's more frequently used without a space in GCC, for example;
* never add spaces after unary operators;
* adding spaces between two opening parentheses is controlled with the `SpacesInParentheses` option;
* never add spaces between `[` and `(` (there's no option yet).
Richard Smith [Tue, 10 Dec 2013 08:25:00 +0000 (08:25 +0000)]
Implement DR1460: fix handling of default initializers in unions; don't allow
more than one such initializer in a union, make mem-initializers override
default initializers for other union members, handle anonymous unions with
anonymous struct members better. Fix a couple of semi-related bugs exposed by
the tests for same.
Warren Hunt [Tue, 10 Dec 2013 01:44:39 +0000 (01:44 +0000)]
[ms-abi] 64-bit fixes for r196549
In order to address latent bugs that were easier to expose in 64-bit
mode, we move the application of __declspec(align) to before the layout
of vbases rather than after.
Output destructors and constructors in a more natural order.
With this patch we output the in the order
C2
C1
D2
D1
D0
Which means that a destructor or constructor that call another is output after
the callee. This is a bit easier to read IHMO and a tiny bit more efficient
as we don't put a decl in DeferredDeclsToEmit.
Daniel Jasper [Mon, 9 Dec 2013 14:40:19 +0000 (14:40 +0000)]
clang-format: Be more conservative about braced list column layout.
Specifically disable it for nested braced lists as it commonly can look
really weird. Eventually, we'll want to become smarter and format some of
the nested lists better.
Alp Toker [Mon, 9 Dec 2013 12:41:02 +0000 (12:41 +0000)]
Make the -Wkeyword-compat diag message more accurate
Changed from:
keyword '__is_empty' will be treated as an identifier for the remainder of the translation unit
To:
keyword '__is_empty' will be made available as an identifier for the remainder of the translation unit
This is a more accurate description of clang's keyword compatibility feature,
given that some of the keywords are turned into context-sensitive keywords
(e.g. REVERTIBLE_TYPE_TRAIT) rather than being fully disabled.
David Majnemer [Mon, 9 Dec 2013 10:44:32 +0000 (10:44 +0000)]
[-cxx-abi microsoft] Mangle large integral constants correctly
Testing has revealed that large integral constants (i.e. > INT64_MAX)
are always mangled as-if they are negative, even in places where it
would not make sense for them to be negative (like non-type template
parameters of type unsigned long long).
To address this, we change the way we model number mangling: always
mangle as-if our number is an int64_t. This should result in correct
results when we have large unsigned numbers.
N.B. Bizarrely, things that are 32-bit displacements like vbptr offsets
are mangled as-if they are unsigned 32-bit numbers. This is a pretty
egregious waste of space, it would be a 4x savings if we could mangle it
like a signed 32-bit number. Instead, we explicitly cast these
displacements to uint32_t and let the mangler proceed.
Richard Smith [Mon, 9 Dec 2013 07:03:59 +0000 (07:03 +0000)]
Update compatibility page to list some GCC language extensions that Clang does
not support as a possible reason for choosing GCC instead of Clang (and vice
versa). Weaken some of the claimed advantages of Clang in light of GCC
improvements.
Before this patch GetOrCreateLLVMFunction would add a decl to
DeferredDeclsToEmit even when it was being called by the function trying to
emit that decl.
David Majnemer [Mon, 9 Dec 2013 04:28:34 +0000 (04:28 +0000)]
[-cxx-abi microsoft] Properly mangle enums
While testing our ability to mangle large constants (PR18175), I
incidentally discovered that we did not properly mangle enums correctly.
Previously, we would append the width of the enum in bytes after the
type-tag differentiator.
This would mean "enum : short" would be mangled as 'W2' while "enum :
char" would be mangled as 'W1'. Upon testing this with several versions
of MSVC, I found that this did not match their behavior: they always use
'W4'.
N.B. Quick testing uncovered that undname allows different numbers to
follow the 'W' in the following way:
Faisal Vali [Sun, 8 Dec 2013 15:00:29 +0000 (15:00 +0000)]
Fix an assertion introduced by my previous refactoring.
Add back the test that was triggering the assertion (which I removed mistakenly thinking it was triggering just a warning and not an assertion). My error was brought to my attention by Rafael (Thanks!).
Clang outputs LLVM one top level decl at a time. This combined with the
visibility computation code looking for the newest NamespaceDecl would cause
it to produce different results for nested namespaces.
The two options for producing consistent results are
* Delay codegen of anything inside a namespace until the end of the file.
* Don't look for the newest NamespaceDecl.
This patch implements the second option.
This matches the gcc behavior too.
Faisal Vali [Sat, 7 Dec 2013 20:22:44 +0000 (20:22 +0000)]
[REFACTOR] Refactored some of the generic-lambda capturing code.
Employed the following refactorings:
- Renamed some functions
- Introduced explaining variables
- Cleaned up & added comments
- Used Optional<unsigned> for return value instead of an out parameter
- Added assertions
- Constified a few member functions
Benjamin Kramer [Sat, 7 Dec 2013 16:12:52 +0000 (16:12 +0000)]
CodeGen: Don't emit linkage on thunks that aren't emitted because they're vararg.
This can happen when we're trying to emit a thunk with available_externally
linkage with optimization enabled but bail because it doesn't make sense
for vararg functions.
Alp Toker [Sat, 7 Dec 2013 07:20:22 +0000 (07:20 +0000)]
Type traits: No need for switch to handle __builtin_types_compatible_p
__builtin_types_compatible_p() isn't a C++ type trait at all, rather a GNU C
special-case, so it's fine to use BoolTy the default return type for binary
type traits.
This brings BTT in line with other arities that already default to BoolTy.
Richard Smith [Sat, 7 Dec 2013 05:09:50 +0000 (05:09 +0000)]
Give a more appropriate diagnostic when a template specialization or
instantiation appears in a non-enclosing namespace (the previous diagnostic
talked about the C++98 rule even in C++11 mode).
ObjectiveC. Continuing implementation of objc_bridge_related
attribute in sema and issuing a variety of diagnostics lazily
for misuse of this attribute (and what to do) when converting
from CF types to ObjectiveC types (and vice versa).
// rdar://15499111
Ana Pazos [Fri, 6 Dec 2013 22:43:17 +0000 (22:43 +0000)]
Added support for mcpu krait
- krait processor currently modeled with the same features as A9.
- Krait processor additionally has VFP4 (fused multiply add/sub)
and hardware division features enabled.
- krait has currently the same Schedule model as A9
- krait cpu flag is not recognized by the GNU assembler yet,
it is replaced with march=armv7-a to avoid a lower march
from being used.
David Peixotto [Fri, 6 Dec 2013 20:27:33 +0000 (20:27 +0000)]
Add option to use temporary file for assembling with clang
This commit adds the flag '-via-file-asm' to the clang driver. The
purpose of this flag is to have a way to test that clang can consume
the assembly code that it outputs. When passed this flag, clang will
generate a temporary file that contains the assembly output from the
compile step. This assembly file will then be consumed by either the
integrated assembler or the external assembler. To test that the
integrated assembler can consume its own output compile with:
$ clang -integrated-assembler -via-file-asm
Without the '-via-file-asm' flag, clang would directly create the
object file when using the integrated assembler. With the flag it
will first create the temporary assembly file and then read that
file and assemble it with the integrated assembler.
The flow is similar to -save-temps, except that it only effects
the assembly input and the temporary file is not saved.
Warren Hunt [Fri, 6 Dec 2013 20:16:49 +0000 (20:16 +0000)]
[MS-ABI] adds padding before all vbases after a bitfield
MS-ABI adds padding before *every* vbase if the last field in a record
is a bit-field. This changes clangs behavior to match. I also fix some
windows-style line endings in the test file.
Warren Hunt [Fri, 6 Dec 2013 19:54:25 +0000 (19:54 +0000)]
[MS-ABI] Fix alias-avoidance padding between bases
Adds padding between bases or virtual bases in an attempt to avoid
aliasing of zero-sized sub-objects. The approach used by the ABI adds
two more bits of state. Detailed comments are in the code. Test cases
included.
Anna Zaks [Fri, 6 Dec 2013 19:28:16 +0000 (19:28 +0000)]
Fixup to r196593.
This is another regression fixed by reverting r189090.
In this case, the problem is not live variables but the approach that was taken in r189090. This regression was caused by explicitly binding "true" to the condition when we take the true branch. Normally that's okay, but in this case we're planning to reuse that condition as the value of the expression.
The original patch introduced regressions (see the added live-variables.* tests). The patch depends on the correctness of live variable analyses, which are not computed correctly. I've opened PR18159 to track the proper resolution to this problem.
The patch was a stepping block to r189746. This is why part of the patch reverts temporary destructor tests that started crashing. The temporary destructors feature is disabled by default.
Aaron Ballman [Fri, 6 Dec 2013 18:56:03 +0000 (18:56 +0000)]
Turning the __w64 attribute into an ignored attribute to match other Microsoft extensions we do not currently support. Note that __w64 has been deprecated in MSVC since 2008.
Roman Divacky [Fri, 6 Dec 2013 18:32:18 +0000 (18:32 +0000)]
Move the body of GCCInstallationDetector ctor into an init() function
and call it from its only user. The linux toolchain. This saves quite
a lot of directory searching on other platforms.
Aaron Ballman [Fri, 6 Dec 2013 15:58:47 +0000 (15:58 +0000)]
Reverting changes from r196415; this patch exposed a different, but unrelated bug regarding the __has_attribute implementation. Reverting to unblock the Chrome tsan builds.
Daniel Jasper [Fri, 6 Dec 2013 09:25:54 +0000 (09:25 +0000)]
Allow string literals as module names.
In order to make the migration to modules easier, it seems to be helpful
to allow a 1:1 mapping between target names of a current build system
and the corresponding C++ modules. As such targets commonly contain
characters like "-". ":" and "/", allowing arbitrary quote-escaped
strings seems to be a straightforward option.
After several offline discussions, the precise mechanisms for C++
module names especially regarding submodules and import statements has
yet to be determined. Thus, this patch only enables string literals as
names inside the module map files which can be used by automatic module
import (through #include).
Also improve the error message on missing use-declarations.
Warren Hunt [Fri, 6 Dec 2013 00:01:17 +0000 (00:01 +0000)]
Support MS-ABI's concept of "Required Alignment" imposed by
__declspec(align())
This patch implements required alignment in a way that makes
__declspec(align()) and #pragma pack play correctly together. In the
MS-ABI, __declspec(align()) is a hard rule and cannot be overridden by
#pragma pack. This cases each record to have two interesting alignments
"preferred alignment" (which matches Itanium's concept of alignment) and
"required alignment" which is an alignment that must never be violated,
even in the case of #pragma pack. This patch introduces the concept of
Required Alignment to the record builder and tracks/uses it
appropriately. Test cases are included.
Dmitri Gribenko [Thu, 5 Dec 2013 23:06:53 +0000 (23:06 +0000)]
-Wassign-enum: compare unqualified types
This commit changes -Wassign-enum to compare unqualified types. One could
think that this does not matter much, because who wants a value of enum type
that is const-qualified? But this breaks the intended pattern to silence this
warning with an explicit cast:
static const enum Foo z = (enum Foo) 42;
In this case, source type is 'enum Foo', and destination type is 'const enum
Foo', and if we compare qualified types, they don't match, so we used warn.
Dmitri Gribenko [Thu, 5 Dec 2013 22:52:07 +0000 (22:52 +0000)]
Allow the warning 'case value not in enumerated type' to be silenced with
the following pattern.
If 'case' expression refers to a static const variable of the correct enum
type, then we count this as a sufficient declaration of intent by the user,
so we silence the warning.
ObjectiveC: Don't warn when method implemented in
category is declared in category's primary
class's super class. Because the super class is
expected to implemented the method. // rdar://15580969
Bob Wilson [Thu, 5 Dec 2013 19:38:42 +0000 (19:38 +0000)]
Fix assertion failure left over from changes to move away from "darwin" triples.
I happened to notice this while trying to write a test for an iOS simulator
target. I suspect we just missed this when we added separate "macosx" and "ios"
triples instead of the generic "darwin" OS.
Hans Wennborg [Thu, 5 Dec 2013 17:49:58 +0000 (17:49 +0000)]
clang-format vsix cmake build: use ${LLVM_TOOLS_BINARY_DIR}/${CMAKE_CFG_INTDIR}
as the location for grabbing clang-format.exe, and also output the .vsix here.
This allows us to find clang-format.exe when building from a MSVC Solution.
Richard Smith [Thu, 5 Dec 2013 08:30:59 +0000 (08:30 +0000)]
PR17983: Fix crasher bug in C++1y mode when performing a non-global array
delete on a class which has no array cookie and has no class-specific operator
new.