Commit Graph

42930 Commits

Author SHA1 Message Date
Douglas Gregor 250ee63515 Document the redeclaration and overriding restrictions on the
availability attribute.

llvm-svn: 172587
2013-01-16 01:12:31 +00:00
Douglas Gregor 43dc0c7d60 One can have an unavailable method overridden by an available method,
but not vice-versa. Fix bug introduced in r172567 and noticed by
Jordan, thanks!

llvm-svn: 172586
2013-01-16 00:54:48 +00:00
Douglas Gregor effe2a1e75 Apply adjustment to function- and array-typed non-type template
parameters (per C++ [temp.param]p8) when computing the type of a
reference to a non-type template parameter. Fixes <rdar://problem/13000548>.

llvm-svn: 172585
2013-01-16 00:52:15 +00:00
David Greene 464d219576 Fix signed/unsigned Compare
Do some casting to avoid a signed/unsigned compare.

llvm-svn: 172571
2013-01-15 23:13:49 +00:00
David Greene c5ff624222 Avoid unsigned Compare to int
Cast arithmetic results to avoid comparison of an unsigned to an int.

llvm-svn: 172570
2013-01-15 23:13:47 +00:00
Douglas Gregor 66a8ca0f7f When checking availability attributes for consistency between an
overriding and overridden method, allow the overridden method to have
a narrower contract (introduced earlier, deprecated/obsoleted later)
than the overriding method. Fixes <rdar://problem/12992023>.

llvm-svn: 172567
2013-01-15 22:43:08 +00:00
David Greene e6c9fe035d Fix Casting
Use const_cast<> to avoid a cast-away-const error.

llvm-svn: 172565
2013-01-15 22:09:51 +00:00
David Greene 02b002ac37 Fix Casting
Use const_cast<> to avoid a cast-away-const error.

llvm-svn: 172564
2013-01-15 22:09:49 +00:00
David Greene 4320e5e114 Fix Casting
Use const_cast<> to avoid a cast-away-const error.

llvm-svn: 172563
2013-01-15 22:09:48 +00:00
David Greene 0516ba604b Fix Casting
Use const_cast<> to avoid a cast-away-const error.

llvm-svn: 172562
2013-01-15 22:09:46 +00:00
David Greene 0d5a34bcad Fix Cast
Properly use const_cast to fix a cast-away-const error.

llvm-svn: 172561
2013-01-15 22:09:45 +00:00
David Greene bae0e356b6 Fix Casting
Make the const_cast explicit to silence a compiler warning.

llvm-svn: 172560
2013-01-15 22:09:43 +00:00
David Greene 0a528db95d Fix Const Cast
Do proper casting to avoid a cast-away-const error.

llvm-svn: 172559
2013-01-15 22:09:41 +00:00
David Greene 9431926064 Fix Cast
Avoid a cast-away-const error by properly using const_cast<>.

llvm-svn: 172558
2013-01-15 22:09:40 +00:00
David Greene a6394d0440 Fix Cast Code
Eliminate a cast and resulting cast-qual warning by using a temporary
as the target of memcpy.

llvm-svn: 172557
2013-01-15 22:09:39 +00:00
Aaron Ballman 5cb24115c2 Typo correction; no functional change.
llvm-svn: 172555
2013-01-15 21:59:46 +00:00
Daniel Dunbar b2543043e6 [driver/Darwin] Adjust SDKROOT handling code to not generate "-isysroot /".
llvm-svn: 172548
2013-01-15 20:33:56 +00:00
Dmitri Gribenko 29360247c5 Add a test for -Wsemicolon-before-method-body fixit
llvm-svn: 172545
2013-01-15 18:29:04 +00:00
Manuel Klimek a31e58b2df Do not traverse the break-state when we know we cannot break anyway.
This is an optimization that djasper spottet. For now, we do not format
anything after the first token that belongs to such an implicit string
literal. All our state is not made for handling that anyway, so we'll
revisit this if we find a problem.

llvm-svn: 172537
2013-01-15 16:41:02 +00:00
Manuel Klimek 99c7baa3cf Fix formatting of preprocessor directives (incluces, warnings & errors).
Treat tokens inside <> for includes and everything from the second token
of a warning / error on as an implicit string literal, e.g. do not
change its whitespace at all.

Now correctly formats:
 #include < path with space >
 #error Leave     all         white!!!!! space* alone!

Note that for #error and #warning we still format the space up to the
first token of the text, so:
   #  error   Text
will become
 #error Text

llvm-svn: 172536
2013-01-15 15:50:27 +00:00
Daniel Jasper 7194527d9f Improve operator kind detection in presence of comments.
We used to incorrectly identify some operators (*, &, +, -, etc.) if
there were comments around them.

Example:
Before: int a = /**/ - 1;
After:  int a = /**/ -1;

llvm-svn: 172533
2013-01-15 14:27:39 +00:00
Manuel Klimek e01bab587c Fixes various bugs around the keywords class, struct and union.
This switches to parsing record definitions only if we can clearly
identify them. We're specifically allowing common patterns for
visibility control through macros and attributes, but we cannot
currently fix all instances. This fixes all known bugs we have though.

Before:
static class A f() {
  return g();
} int x;

After:
static class A f() {
  return g();
}
int x;

llvm-svn: 172530
2013-01-15 13:38:33 +00:00
Alexander Kornienko 00911f1d55 Resolved merge error with r172323 (llvm::X -> X)
llvm-svn: 172528
2013-01-15 12:20:21 +00:00
Richard Smith 03d9393b4a Don't crash when binding a reference to a temporary pointer created from
resolving an overloaded function reference within an initializer list.
Previously we would try to resolve the overloaded function reference without
first stripping off the InitListExpr wrapper.

llvm-svn: 172517
2013-01-15 07:58:29 +00:00
Richard Smith 550de45861 PR14950: Fix out-of-bounds function parameter access in literal operator lookup.
llvm-svn: 172514
2013-01-15 07:12:59 +00:00
Richard Smith da1f933e12 PR14918: Don't confuse braced-init-lists after template variable declarations
with function definitions.

We really should remove Parser::isDeclarationAfterDeclarator entirely, since
it's meaningless in C++11 (an open brace could be either a function definition
or an initializer, which is what it's trying to differentiate between). The
other caller of it happens to be correct right now...

llvm-svn: 172510
2013-01-15 06:49:38 +00:00
Douglas Gregor 1517128912 Add -fopenmp -cc1 option and wire it up to define _OPENMP, from Alexey Bataev!
llvm-svn: 172509
2013-01-15 06:45:29 +00:00
Richard Smith 0faa2b1ae4 Fix behavior of [[gnu::]] function attributes. Per g++'s behavior, these
attributes appertain to a declaration, even though they would be much more
naturally modelled as appertaining to a function type. Previously, we would
try to distribute them from the declarator to the function type, then
reject them for being at an incorrect location. Now, we just distribute them
as far as the declarator; the existing attribute handling code can actually
apply them there just fine.

llvm-svn: 172504
2013-01-15 02:48:13 +00:00
Chad Rosier 5f15a35114 [driver] Warnings for warning options are handled by the frontend. The driver needs to process the
warning options to setup diagnostic state, but should not be emitting warnings as these would be
rudndant with what the frontend emits.
rdar://13001556

llvm-svn: 172497
2013-01-15 01:21:53 +00:00
Dmitri Gribenko fdfc739277 Document that we should recognize attributes supported by gcc with C++11
[[gnu::...]] syntax

Pointed out by Richard Smith on the mailing list.

llvm-svn: 172487
2013-01-14 22:44:07 +00:00
Richard Smith 945f8d32fd Refactor to call ActOnFinishFullExpr on every full expression. Teach
ActOnFinishFullExpr that some of its checks only apply to discarded-value
expressions. This adds missing checks for unexpanded variadic template
parameter packs to a handful of constructs.

llvm-svn: 172485
2013-01-14 22:39:08 +00:00
Michael Gottesman a2b5c4ba6a Multiprecision subtraction builtins.
We lower these into 2x chained usub.with.overflow intrinsics.

llvm-svn: 172476
2013-01-14 21:44:30 +00:00
Douglas Gregor bc25ff4661 Topologically sort the link options generated for modules based on
module-import dependencies, so we'll get the link order correct for
those silly linkers that need it.

llvm-svn: 172459
2013-01-14 20:53:57 +00:00
Douglas Gregor 1715a2f9d5 When forming the link options for an imported module, also include the
link options for the modules it imports.

llvm-svn: 172448
2013-01-14 19:00:05 +00:00
Jordan Rose 269894ca23 [analyzer] Add ProgramStatePartialTrait<const void *>.
This should fix cast-away-const warnings reported by David Greene.

llvm-svn: 172446
2013-01-14 18:58:42 +00:00
Jordan Rose d540aed61b [analyzer] Fix cast-away-const warning by using const_cast.
Patch by David Greene, modified by me.

llvm-svn: 172445
2013-01-14 18:58:38 +00:00
Jordan Rose cb6a721920 [analyzer] -drain is not an alias for -release.
This was previously added to support -[NSAutoreleasePool drain], which
behaves like -release under non-GC and "please collect" under GC. We're
not currently modeling the autorelease pool stack, though, so we can
just take this out entirely.

Fixes PR14927.

llvm-svn: 172444
2013-01-14 18:58:33 +00:00
Douglas Gregor ea02f26536 Switch autolinking metadata format over to actual linker options, e.g.,
!0 = metadata !{metadata !"-lautolink"}
  !1 = metadata !{metadata !"-framework", metadata !"autolink_framework"}

referenced from llvm.module.linkoptions, e.g.,

  !llvm.module.linkoptions = !{!0, !1, !2, !3}

This conceptually moves the logic for figuring out the syntax the
linker will accept from LLVM into Clang. Moreover, it makes it easier
to support MSVC's

  #pragma comment(linker, "some option")

in the future, should anyone care to do so.

llvm-svn: 172441
2013-01-14 18:28:43 +00:00
Douglas Gregor 11dfe6fe3d Infer "link" lines for top-level frameworks. Essentially, a framework
will have a shared library with the same name as its framework (and no
suffix!) within its .framework directory. Detect this both when
inferring the whole top-level framework and when parsing a module map.

llvm-svn: 172439
2013-01-14 17:57:51 +00:00
Bill Schmidt 924c478827 This patch addresses varargs processing for small complex types under
the 64-bit PowerPC ELF ABI.

The ABI requires that the real and imaginary parts of a complex argument
each occupy their own doubleword.  Arguments smaller than 8 bytes are
right-adjusted within the doubleword.

Clang expects EmitVAARG() to return a pointer to a structure in which
the real and imaginary parts are packed adjacently in memory.  To accomplish
this, we generate code to load the code appropriately from the varargs
location and pack the values into a temporary variable in the form Clang
expects, returning a pointer to that structure.

The test case demonstrates correct code generation for all "small" complex
types on PPC64:  int, short, char, and float.

llvm-svn: 172438
2013-01-14 17:45:36 +00:00
Douglas Gregor 6ddfca91e0 Implement parsing, AST, (de-)serialization, and placeholder global
metadata for linking against the libraries/frameworks for imported
modules.

The module map language is extended with a new "link" directive that
specifies what library or framework to link against when a module is
imported, e.g.,

  link "clangAST"

or

  link framework "MyFramework"

Importing the corresponding module (or any of its submodules) will
eventually link against the named library/framework.

For now, I've added some placeholder global metadata that encodes the
imported libraries/frameworks, so that we can test that this
information gets through to the IR. The format of the data is still
under discussion.

llvm-svn: 172437
2013-01-14 17:21:00 +00:00
Manuel Klimek a54d1a99a2 Fixes formatting of nested brace initializers.
We now format this correctly:
Status::Rep Status::global_reps[3] = {
  { kGlobalRef, OK_CODE, NULL, NULL, NULL },
  { kGlobalRef, CANCELLED_CODE, NULL, NULL, NULL },
  { kGlobalRef, UNKNOWN_CODE, NULL, NULL, NULL }
};

- fixed a bug where BreakBeforeClosingBrace would be set on the wrong
  state
- added penalties for breaking between = and {, and between { and any
  other non-{ token

llvm-svn: 172433
2013-01-14 16:41:43 +00:00
Daniel Jasper 1b750edda1 Make single-line if statements optional.
Now, "if (a) return;" is only allowed, if this option is set.

Also add a Chromium style which is currently identical to Google style
except for this option.

llvm-svn: 172431
2013-01-14 16:24:39 +00:00
Daniel Jasper 3e9218e50a Fix a bug in the line merging.
If the first line of a merge would exactly fit into the column limit,
an unsigned overflow made us not break.

llvm-svn: 172426
2013-01-14 16:02:06 +00:00
Daniel Jasper 2ab0d01a8e Fix bug that would lead to joining preprocessor directives.
Before: #include "a.h" #include "b.h"
After:  #include "a.h"
        #include "b.h"
llvm-svn: 172424
2013-01-14 15:52:06 +00:00
Daniel Jasper 39825eaff5 Put simple preprocessor directives on a single line.
Before: #define A  \
          A
After:  #define A A
llvm-svn: 172423
2013-01-14 15:40:57 +00:00
Benjamin Kramer e2e6e6a3d5 Turns out there is a simpler way of getting a set difference in bash than parsing diff output.
llvm-svn: 172420
2013-01-14 15:00:48 +00:00
Daniel Jasper 25837aa666 Put short if statements on a single line.
Before: if (a)
          return;
After:  if (a) return;

Not yet sure, whether this is always desired, but we can add options and
make this a style parameter as we go along.

llvm-svn: 172413
2013-01-14 14:14:23 +00:00
Alexander Kornienko ebc17b5b87 Dump comments in -ast-dump.
http://llvm-reviews.chandlerc.com/D269

"Added dumping of declaration comments in ASTDumper. This required moving the
comment dumping code from CommentDumper so that the indentation is correct."

Patch by Philip Craig!

llvm-svn: 172409
2013-01-14 14:07:11 +00:00
NAKAMURA Takumi 18c7689698 clang/test/SemaCXX/cxx11-gnu-attrs.cpp: Add explicit -triple x86_64-unknown-unknown, or it doesn't work for targetting win32.
llvm-svn: 172404
2013-01-14 13:16:02 +00:00
Daniel Jasper f1e4b7d750 Refactor datastructure used in clang-format.
Main difference, add an AnnotatedLine class to hold information about a
line while formatting. At the same time degrade the UnwrappedLine class
to a class solely used for communicating between the UnwrappedLineParser
and the Formatter.

No functional changes intended.

llvm-svn: 172403
2013-01-14 13:08:07 +00:00
Daniel Jasper 13f23e17c7 Improve understanding post increment and decrement.
Before: (a->f()) ++;
        a[42] ++;
After:  (a->f())++;
        a[42]++;
llvm-svn: 172400
2013-01-14 12:18:19 +00:00
Alexander Kornienko 116ba68220 Custom DiagnosticConsumer parameter of reformat() + silence diagnostics in unit tests.
Summary:
Added tests for clang-format diagnostics. Added DiagnosticConsumer
argument to clang::format::reformat().

Reviewers: klimek, djasper

Reviewed By: djasper

CC: cfe-commits, thakis, rafael.espindola

Differential Revision: http://llvm-reviews.chandlerc.com/D290

llvm-svn: 172399
2013-01-14 11:34:14 +00:00
Manuel Klimek 557811fe6c Adds some more tests for * and &.
While reviewing r172303 I noticed that I wasn't sure whether we still
format those correctly and didn't see any tests.

llvm-svn: 172396
2013-01-14 10:58:01 +00:00
Richard Smith b5b5320bff Add extra tests for [[gnu::...]] attributes, missed from r172382.
llvm-svn: 172391
2013-01-14 08:57:42 +00:00
Richard Smith 59b8e701d3 Fix regression in r172376. Don't try to detect missing 'constexpr' specifiers
on redeclarations, since that makes us pick wrong prior declarations under
some circumstances.

llvm-svn: 172384
2013-01-14 08:00:39 +00:00
Richard Smith 368ca52cd9 Accept [[gnu::*]] for all __attribute__((*))s which are:
1) Supported by Clang, and
 2) Supported by GCC, and
 3) Documented in GCC's manual.

g++ allows its C++11-style attributes to appertain only to the entity being
declared, and never to a type (even for a type attribute), so we do the same.

llvm-svn: 172382
2013-01-14 07:53:01 +00:00
Nico Weber 7769a9044e Formatter: Add a test for bitfields.
They work fine, but this fifth use of colons (after labels, in ?:,
in initalizer lists in constructors, in objc method expressions, and in
bitfields) wasn't covered by tests yet.

llvm-svn: 172377
2013-01-14 05:49:49 +00:00
Richard Smith 574f4f6a1d PR12008: defer adding the implicit 'const' to a constexpr member function until
we know whether it is static.

llvm-svn: 172376
2013-01-14 05:37:29 +00:00
Richard Smith 01141a95a5 *this is const in a trailing-return-type for a constexpr member function.
llvm-svn: 172375
2013-01-14 01:55:13 +00:00
Dmitri Gribenko 9c256e379e libclang: remove a few const_casts
llvm-svn: 172373
2013-01-14 00:46:27 +00:00
Dmitri Gribenko 049a4ffcb8 Constify argument of Preprocessor::getMacroInfoHistory and propagate to
callers, removing unneeded const_cast

llvm-svn: 172372
2013-01-14 00:36:42 +00:00
Dmitri Gribenko aaf7f2978c Remove an unneeded const_cast
llvm-svn: 172370
2013-01-14 00:25:25 +00:00
Dmitri Gribenko 765396f2f0 ArrayRef'ize Sema APIs related to format string checking
llvm-svn: 172367
2013-01-13 20:46:02 +00:00
Dmitri Gribenko dc81f51d37 Document behavior of -Wformat-nonliteral, it is different from GCC
llvm-svn: 172362
2013-01-13 16:37:18 +00:00
Daniel Jasper 942ee72aff Stronger respect the input codes line breaks wrt. comments.
clang-format should not change whether or not there is a line break
before a line comment as this strongly influences the percieved binding.

User input: void f(int a,
                   // b is awesome
		   int b);
            void g(int a, // a is awesome
		   int b);
Before:     void f(int a, // b is awesome
                   int b);
            void g(int a, // a is awesome
		   int b);
After:      <unchanged from input>

llvm-svn: 172361
2013-01-13 16:10:20 +00:00
Michael J. Spencer 7d1b7c4c38 Fix LLP64 build.
llvm-svn: 172357
2013-01-13 16:00:51 +00:00
Daniel Jasper 22cf462234 Format unions like structs and classes.
Note that I don't know whether we should put {} on a single line in this
case, but it is probably a theoretical issue as in practice such
structs, classes or unions won't be empty.

Before: union A {}
        a;
After:  union A {} a;
llvm-svn: 172355
2013-01-13 14:39:04 +00:00
Chandler Carruth 953fb087e5 Refactor the x86 CPU name logic in the driver and pass -march and -mcpu
flag information down from the Clang driver into the Gold linker plugin
for LTO. This allows specifying -march on the linker commandline and
should hopefully have it pass all the way through to the LTO optimizer.

Fixes PR14697.

llvm-svn: 172354
2013-01-13 11:46:33 +00:00
NAKAMURA Takumi 7ab4fbf5c2 CGBuiltin.cpp: Fix abuse of ArrayRef in EmitOverflowIntrinsic().
In ArrayRef<T>(X), X should not be temporary value. It could be rewritten more redundantly;

  llvm::Type *XTy = X->getType();
  ArrayRef<llvm::Type *> Ty(XTy);
  llvm::Value *Callee = CGF.CGM.getIntrinsic(IntrinsicID, Ty);

Since it is safe if both XTy and Ty are temporary value in one statement, it could be shorten;

  llvm::Value *Callee = CGF.CGM.getIntrinsic(IntrinsicID, ArrayRef<llvm::Type*>(X->getType()));

ArrayRef<T> has an implicit constructor to create uni-entry of T;

  llvm::Value *Callee = CGF.CGM.getIntrinsic(IntrinsicID, X->getType());

MSVC-generated clang.exe crashed.

llvm-svn: 172352
2013-01-13 11:26:44 +00:00
Daniel Jasper 48cb3b97c7 Always put a space after ",".
I am not aware of a case where that would be wrong. The specific case I
am fixing are function parameters wrapped in parenthesis (e.g. in
macros).

Before: function(a,(b));
After:  function(a, (b));
llvm-svn: 172351
2013-01-13 08:19:51 +00:00
Daniel Jasper 5ef433fc0c Don't put spaces around hyphens in include paths.
Before: #include <a - a>
After:  #include <a-a>
llvm-svn: 172350
2013-01-13 08:12:18 +00:00
Daniel Jasper ef906a9c67 Improve identification of c-style casts.
A ")" before any of "=", "{" or ";" won't be a cast. This fixes issues
with the formatting of unnamed parameters.

Before: void f(int *){}
After:  void f(int *) {}
llvm-svn: 172349
2013-01-13 08:01:36 +00:00
Michael Gottesman c5cc9f154d Updated documentation to reflect new multiprecision builtin functions.
llvm-svn: 172345
2013-01-13 04:35:31 +00:00
NAKAMURA Takumi 4b7d1ce9c1 clang/test/CodeGen/builtins-multiprecision.c: Enhance for each test to run on theree targets, i686, amd64, win64.
llvm-svn: 172344
2013-01-13 03:55:21 +00:00
Michael Gottesman 987226696e Fixed spelling of test name: builtins-multipercision.c => builtins-multiprecision.c.
llvm-svn: 172343
2013-01-13 03:44:31 +00:00
Michael Gottesman 0cd8b78916 Added a triple to the test builtins-multiprecision.c.
llvm-svn: 172342
2013-01-13 03:40:23 +00:00
Michael Gottesman 54398015bf Added builtins for multiprecision adds.
We lower all of these intrinsics into a 2x chained usage of
uadd.with.overflow.

llvm-svn: 172341
2013-01-13 02:22:39 +00:00
Richard Smith 1f5a4323e9 Remove some duplication in the handling of __attribute__((ext_vector_size(N))).
llvm-svn: 172340
2013-01-13 02:11:23 +00:00
Nico Weber 2827a7ec6b Formatter: Don't insert a space before unary operators after selector names.
Before:
  [color getRed: &r green: &g blue: &b alpha: &a];

Now:
  [color getRed:&r green:&g blue:&b alpha:&a];

llvm-svn: 172337
2013-01-12 23:48:49 +00:00
Nico Weber 5c8709bc5e Formatter: Add a test for @selector in an ObjC method expression, which happens to work already.
llvm-svn: 172335
2013-01-12 23:41:33 +00:00
Nico Weber 92c0539135 Formatter: Remove debugging junk I accidentally landed in r172333.
llvm-svn: 172334
2013-01-12 22:51:13 +00:00
Nico Weber c9d7361173 Formatter: Prefer breaking before ObjC selector names over breaking at their ':'
Before:
  if ((self = [super initWithContentRect:contentRect styleMask:
                  styleMask backing:NSBackingStoreBuffered defer:YES])) {

Now:
  if ((self = [super initWithContentRect:contentRect styleMask:styleMask
                  backing:NSBackingStoreBuffered defer:YES])) {

llvm-svn: 172333
2013-01-12 22:48:47 +00:00
Dmitri Gribenko 813985b073 Add a comment to test to clarify the intention here
Comment is taken from the commit message of r151080, by Jean-Daniel Dupas

llvm-svn: 172332
2013-01-12 22:39:30 +00:00
Dmitri Gribenko 4b84153da2 Prune an unused diagnostic, detected after improving the script in r172330
llvm-svn: 172331
2013-01-12 21:58:21 +00:00
Benjamin Kramer 6590abb384 Speed up find-unused-diagnostics. Now runs in less than a second instead of more than a minute.
llvm-svn: 172330
2013-01-12 21:39:06 +00:00
Dmitri Gribenko e392a9f2b0 Remove unused diagnostics
llvm-svn: 172326
2013-01-12 20:32:43 +00:00
Dmitri Gribenko f857950d39 Remove useless 'llvm::' qualifier from names like StringRef and others that are
brought into 'clang' namespace by clang/Basic/LLVM.h

llvm-svn: 172323
2013-01-12 19:30:44 +00:00
Arnaud A. de Grandmaison 3128a11ee8 Fix spurious output in JSONCompilationDatabase
llvm-svn: 172321
2013-01-12 18:37:52 +00:00
Dmitri Gribenko 1737bd3a92 Add missing includes and forward declarations so that headers don't depend on
other headers included before them.

llvm-svn: 172320
2013-01-12 16:54:37 +00:00
Rafael Espindola 6239e05adc comment
llvm-svn: 172317
2013-01-12 15:27:44 +00:00
Rafael Espindola c48f7341cc bar
llvm-svn: 172316
2013-01-12 15:27:43 +00:00
Rafael Espindola 8f1187a11b Remove unused private field.
llvm-svn: 172314
2013-01-12 14:22:42 +00:00
Daniel Jasper 7b7877ad7d Fix incorrect comparison operator causing loooong formatting times.
llvm-svn: 172308
2013-01-12 07:36:22 +00:00
Nico Weber cb465dcb1d Formatter: Remove an always-false condition.
canBreakBefore() does not allow breaking after ':' for LT_ObjCMethodDecl lines,
so if Newline is true in addTokenToState() for ':' then LT_ObjCMethodDecl
cannot be set. No functionality change.

llvm-svn: 172307
2013-01-12 07:05:25 +00:00
Nico Weber c7a56342bd Formatter: Remove a redundant CurrentLineType check.
The containing if checks for this already. No functionality change.

llvm-svn: 172306
2013-01-12 07:00:16 +00:00
Rafael Espindola 19de5613ea Disable caching of visibility.
The testcase in pr14929 shows that this is extremely hard to do. If we choose
to apply the attribute, that causes the visibility of some decls to change and
that can happen really late (during codegen).

Current gcc warns and ignores the attribute in this testcase with a warning.
This suggest that the correct solution is to find a point in the compilation
where we can compute the visibility and
* assert it was never computed before
* reject any attempts to compute it again in the future (with warnings).

llvm-svn: 172305
2013-01-12 06:42:30 +00:00
Nico Weber a7252d836a Formatter: Initial support for formatting Objective-C method expressions.
This follows the approach suggested by djasper in PR14911: When a '[' is         
seen that's at the start of a line, follows a binary operator, or follows one    
of : [ ( return throw, that '[' and its closing ']' are marked as
TT_ObjCMethodExpr and every ':' in that range that isn't part of a ternary
?: is marked as TT_ObjCMethodExpr as well.

Update the layout routines to not output spaces around ':' tokens that are
marked TT_ObjCMethodExpr, and only allow breaking after such tokens, not
before.

Before:
    [self adjustButton : closeButton_ ofKind : NSWindowCloseButton];

Now:
    [self adjustButton:closeButton_ ofKind:NSWindowCloseButton];

llvm-svn: 172304
2013-01-12 06:18:40 +00:00
Nico Weber eee7b81a16 Formatter: * and & are binary operators before ( and [.
llvm-svn: 172303
2013-01-12 05:50:48 +00:00
Nico Weber 5dafd4a7ae Formatter: * and & are binary operators after ) and ].
llvm-svn: 172302
2013-01-12 05:47:16 +00:00
Nico Weber 63a54eb766 Formatter: + and - after { are unary operators.
llvm-svn: 172301
2013-01-12 05:41:23 +00:00
NAKAMURA Takumi e73d2a9fff clang/unittests: Fixup corresponding to r172290.
llvm-svn: 172295
2013-01-12 02:16:29 +00:00
Rafael Espindola 7cf35ef8f6 Fix a regression from 171193: main cannot be overloaded.
Thanks Eli Friedman for noticing it.

llvm-svn: 172292
2013-01-12 01:47:40 +00:00
Douglas Gregor c147b0bc31 Provide Decl::getOwningModule(), which determines the (sub)module in
which a particular declaration resides. Use this information to
customize the "definition of 'blah' must be imported from another
module" diagnostic with the module the user actually has to
import. Additionally, recover by importing that module, so we don't
complain about other names in that module.

Still TODO: coming up with decent Fix-Its for these cases, and expand
this recovery approach for other name lookup failures.

llvm-svn: 172290
2013-01-12 01:29:50 +00:00
Nico Weber 4a5030c72f Formatter: add a test for :? in []
llvm-svn: 172289
2013-01-12 01:28:06 +00:00
Richard Smith a7edaad3b6 Only produce one -Wc++98-compat warning when initializing a reference from an init list with multiple elements.
llvm-svn: 172285
2013-01-12 01:05:20 +00:00
Rafael Espindola d60589ad39 Add a test from pr14898.
llvm-svn: 172283
2013-01-12 01:01:06 +00:00
Matt Beaumont-Gay b1e71a7d0c Fix -Wunused-comparison for comparisons in arguments to function-like macros.
Previously, -Wunused-comparison ignored comparisons in both macro bodies and
macro arguments, but we would still emit a -Wunused-value warning for either.
Now we correctly emit -Wunused-comparison for expressions in macro arguments.

Also, add isMacroBodyExpansion to SourceManager, to go along with
isMacroArgExpansion.

llvm-svn: 172279
2013-01-12 00:54:16 +00:00
Fariborz Jahanian 37494a176c comment parsing: when property accessors don't have comment
of their own (or are syntheszed), use prperty's comment.
for them. // rdar://12791315

llvm-svn: 172278
2013-01-12 00:28:34 +00:00
Ted Kremenek 4e9a2dbde5 Refine analyzer's handling of unary '!' and floating types to not assert.
Fixes PR 14634 and <rdar://problem/12903080>.

llvm-svn: 172274
2013-01-11 23:36:25 +00:00
Sean Callanan 19dfc93912 Fixed a bug that caused the AST importer to erroneously
import incomplete definitions for RecordDecls and then
mark the resulting definition as complete.

llvm-svn: 172273
2013-01-11 23:17:47 +00:00
Dmitri Gribenko 037f9d18ae libclang: use C++ casts in CXString.cpp
llvm-svn: 172272
2013-01-11 23:13:36 +00:00
Dmitri Gribenko ec3a16fc8c libclang: constness for CXString
llvm-svn: 172270
2013-01-11 23:08:18 +00:00
Ted Kremenek 039fac0347 Correctly propagate uninitialized values within logical expressions.
Fixes assertion failure reported in PR 14635 and
<rdar://problem/12902945> respectively.

llvm-svn: 172263
2013-01-11 22:35:39 +00:00
Argyrios Kyrtzidis c57e503c48 [PCH] Make the const_cast explicit to silence a compiler warning.
Patch by David Greene.

llvm-svn: 172262
2013-01-11 22:29:49 +00:00
Argyrios Kyrtzidis 49d9d02947 [libclang] Add some constness in CXSourceLocation and CXSourceRange.
llvm-svn: 172261
2013-01-11 22:29:47 +00:00
Argyrios Kyrtzidis 928e1fdecc [libclang] In ASTUnit::getMainFileName() Invocation may be null because the ASTUnit
came from loading a PCH/module.

llvm-svn: 172259
2013-01-11 22:11:14 +00:00
Ted Kremenek 632af24eb8 Set process return code of 1 in set-xcode-analyzer when Xcode needs to be quit. Fixes <rdar://problem/12983031>.
llvm-svn: 172256
2013-01-11 21:49:36 +00:00
Nico Weber a21aaae7b3 Formatter: Format ObjC static and instance methods consistently, add a test for that.
llvm-svn: 172254
2013-01-11 21:14:08 +00:00
Dmitri Gribenko 7a7284d881 libclang: remove unneeded casts
llvm-svn: 172253
2013-01-11 21:06:06 +00:00
Dmitri Gribenko ba2f746fea libclang: change CXCursor to store 'const void *' pointers for
const-correctness, and update all users

llvm-svn: 172252
2013-01-11 21:01:49 +00:00
Dmitri Gribenko bdc80de74c Constify parameter of clang::getCursorKindForDecl
llvm-svn: 172249
2013-01-11 20:32:41 +00:00
Rafael Espindola 46afb35181 Reject incompatible redeclarations of extern C symbols.
Before we were only checking if the new declaration itself was marked extern
C. Fixes prpr14766.

llvm-svn: 172243
2013-01-11 19:34:23 +00:00
Fariborz Jahanian 70ae634f87 Improve diagnostic per Richard's suggestion
(which may yet change if we move the diagnostic
 outside case value).

llvm-svn: 172242
2013-01-11 19:33:54 +00:00
Dmitri Gribenko 2c173b4806 libclang: use getCursorTU and getCursorASTUnit instead of explicit casts
llvm-svn: 172241
2013-01-11 19:28:44 +00:00
Manuel Klimek 9fa8d5578d Fix crashes in UnwrappedLineParser on missing parens.
llvm-svn: 172239
2013-01-11 19:23:05 +00:00
Manuel Klimek 2acb7b7bb1 Fix single-line optimization for ObjC.
Puts blocks always into multiple lines when they start with an ObjC
keyword or minus.

llvm-svn: 172238
2013-01-11 19:17:44 +00:00
Manuel Klimek adededff26 Fix crash on invalid.
if { foo; }
would previously crash clang-format.

llvm-svn: 172232
2013-01-11 18:28:36 +00:00
Manuel Klimek d5e5f8f2a4 Fix parsing of initializer lists with elaborated type specifier.
Now we correctly parse and format:
verifyFormat("struct foo a = { bar };
int n;

llvm-svn: 172229
2013-01-11 18:13:04 +00:00
Manuel Klimek f4ab9ef34c Implements pulling simple blocks into a single line.
void f() { return 42; }

The final change that implements the feature.

llvm-svn: 172225
2013-01-11 17:54:10 +00:00
Fariborz Jahanian 1e8a3c8ebd Add -std=c++98 to the test and minor improvment in addition.
llvm-svn: 172221
2013-01-11 17:33:57 +00:00
Edwin Vane 5038ac0fb8 Allow RefactoringTool to write to memory instead of always to disk
RefactoringTool::run() always writes the result of rewrites to disk.
Instead, make this optional and provide a method for getting the
refactoring results in a memory buffer instead.

Also made ClangTool polymorphic so RefactoringTool could inherit from it
to properly express the IS-A relationship. This change also provides
access to ClangTool's public interface, e.g. mapVirtualFile() which is
important once refactored buffers start living in memory instead of on
disk.

Reviewers: klimek
llvm-svn: 172219
2013-01-11 17:04:55 +00:00
Daniel Jasper d6a947f75f Correct spacing around new and delete.
This fixes llvm.org/PR14913.

Before:  A *a = new(placement) A;
After:   A *a = new (placement) A;
llvm-svn: 172212
2013-01-11 16:09:04 +00:00
Alexander Kornienko 2cc2d60451 clang-format: a bit nicer error message.
llvm-svn: 172211
2013-01-11 16:03:45 +00:00
David Chisnall 2ec1b10d8e Enable the new (more C++-like, less broken) EH model when targeting the GNUstep
Objective-C runtime 1.7 or greater.

llvm-svn: 172207
2013-01-11 15:33:01 +00:00
Enea Zaffanella 29e1c4b03e Fixed an assertion failure triggered by invalid code.
Set invalid type of declarator after emitting error diagnostics,
so that it won't be later considered when instantiating the template.
Added test5_inst in test/SemaCXX/condition.cpp for non-regression.

llvm-svn: 172201
2013-01-11 14:34:39 +00:00
Daniel Jasper fd8c4b1321 Improve handling of trailing declaration annotations.
Before:
void aaaaaaaaaaaa(int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) GUARDED_BY(
    aaaaaaaaaaaaa);

After:
void aaaaaaaaaaaa(int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)
    GUARDED_BY(aaaaaaaaaaaaa);

Also did some formatting cleanups with clang-format on the way.

llvm-svn: 172200
2013-01-11 14:23:32 +00:00
Daniel Jasper 2408a8c755 Improved formatting of constructor initializers
Added option to put each constructor initializer on its own line
if not all initializers fit on a single line. Enabling this for
Google style now as the style guide (arguable) suggests it. Not
sure whether we also want it for LLVM.

llvm-svn: 172196
2013-01-11 11:37:55 +00:00
Enea Zaffanella 392291f7dc Test commit.
llvm-svn: 172195
2013-01-11 11:37:08 +00:00
Daniel Jasper 337816e48a Refactor IndentState into two classes.
As we keep adding more stuff to it, this structure is easier to
maintain. At one point we might think about making it an actual
class with specific accessors, etc.

llvm-svn: 172188
2013-01-11 10:22:12 +00:00
Nikola Smiljanic c531dcc837 Pass false instead of 0 since isStar parameter of getArray has type bool. No functionality change.
llvm-svn: 172185
2013-01-11 08:33:05 +00:00
Nikola Smiljanic 9d22fb11ba Fix spelling error and remove the part about CMake having experimental Ninja support since 2.8.9 has been released some time ago.
llvm-svn: 172182
2013-01-11 07:23:53 +00:00
Nikola Smiljanic 7835e3d1fe Revert the line ending mess I made.
llvm-svn: 172179
2013-01-11 07:14:58 +00:00
Nikola Smiljanic f1bb07f1d8 Fix spelling error and remove the part about CMake having experimental Ninja support since 2.8.9 has been released some time ago.
llvm-svn: 172177
2013-01-11 07:09:00 +00:00
Anna Zaks 39a7692091 [analyzer] Rename the warning: state the issue before the hint of how it
can be fixed

llvm-svn: 172170
2013-01-11 03:52:44 +00:00
Anna Zaks ca49e535ae [analyzer]Recognize ivar invalidation protocol even if it was redeclared
This will get rid of some false positives as well as false negatives.

llvm-svn: 172169
2013-01-11 03:52:40 +00:00
Anna Zaks 2975cf27e4 [analyzer] Ivar invalidation: track ivars declared in categories.
llvm-svn: 172168
2013-01-11 03:52:37 +00:00
Jordan Rose 78dd388afb Revert "tg-fixits.td: fixup for Linux"
It's better to show no caret/ranges/fixits than to show them misaligned.
(It scares me a bit that Clang is going to show them misaligned on
systems without a proper llvm::sys::locale::columnWidth.) See PR14910.

This reverts commit a03cc72bedd015b7eb76e9ac650992f58a48549d.

llvm-svn: 172163
2013-01-11 02:37:47 +00:00
Dmitri Gribenko 5ca49f71fd Replace more usages of __func__ with LLVM_FUNCTION_NAME
llvm-svn: 172161
2013-01-11 02:23:13 +00:00
Dmitri Gribenko 9f08be0272 libclang logging: fixup for MSVC, which does not have __func__
llvm-svn: 172158
2013-01-11 01:15:02 +00:00
Fariborz Jahanian 00ccbdce21 Improve on my last test for patch for // rdar://12897704
llvm-svn: 172154
2013-01-11 00:55:44 +00:00
Dmitri Gribenko a237126fc6 tg-fixits.td: fixup for Linux, which does not have a correct implementation of
llvm::sys::locale::columnWidth()

llvm-svn: 172152
2013-01-11 00:37:33 +00:00
Richard Smith 78165b53bf Truth in advertising: LocallyScopedExternalDecls actually only contains
external declarations with C language linkage.

llvm-svn: 172150
2013-01-10 23:43:47 +00:00
Anna Zaks a96a9ef716 [analyzer] Allow IvarInvalidation checker to suppress warnings via
assertions.

To ensure that custom assertions/conditional would also be supported,
just check if the ivar that needs to be invalidated or set to nil is
compared against 0.

Unfortunately, this will not work for code containing 'assert(IvarName)'

llvm-svn: 172147
2013-01-10 23:34:16 +00:00
Fariborz Jahanian cc7f008b85 c++ IRGen. In trivial cases that object is going into static
storage and thus is implicitly zero-initialized, no need to
do C++11 memory model. This patch unconditionally detects
such condition and zeroinitializer's the variable.
Patch has been commented on and OKed by Doug off-line.
// rdar://12897704

llvm-svn: 172144
2013-01-10 23:28:43 +00:00
Nico Weber 71f95e05ec Formatter: Remove a fixme, Jordy says @synthesize is good as is.
llvm-svn: 172141
2013-01-10 23:12:29 +00:00
Nico Weber 9efe291fa8 Formatter: Put spaces in ObjC method decls in the right place for Google style.
Objective-C method declarations look like this:

- (returntype)name:(type)argname anothername:(type)arg2name;

In google style, there's no space after the leading '-' but one after
"(returntype)" instead (but none after the argument types), see
http://google-styleguide.googlecode.com/svn/trunk/objcguide.xml#Method_Declarations_and_Definitions

Not inserting the space after '-' is easy, but to insert the space after the
return type, the formatter needs to know that a closing parenthesis ends the
return type. To do this, I tweaked the code in parse() to check for this, which
in turn required moving detection of TT_ObjCMethodSpecifier from annotate() to
parse(), because parse() runs before annotate().

(To keep things interesting, the return type is optional, but it's almost
always there in practice.)

http://llvm-reviews.chandlerc.com/D280

llvm-svn: 172140
2013-01-10 23:11:41 +00:00
Anna Zaks 640123de5e [analyzer] Fix non-determinizm introduced in r172104.
In some cases, we just pick any ivar that needs invalidation and attach
the warning to it. Picking the first from DenseMap of pointer keys was
triggering non-deterministic output.

llvm-svn: 172134
2013-01-10 22:44:16 +00:00
Will Dietz a38608b43f ToolChains: Minor touchup to use correct type, avoid truncation.
Truncation happens regularly when find_first_not_of returns npos,
strings long enough to trigger bug here are implausible.

No functionality change intended (ignoring absurd string lengths).

llvm-svn: 172127
2013-01-10 22:20:02 +00:00
Fariborz Jahanian 54c3907484 Declare +new instead of -new in test.
llvm-svn: 172126
2013-01-10 22:17:49 +00:00
Chad Rosier 97b5895029 [ms-inline asm] Add test case for r172121.
Part of rdar://12991541

llvm-svn: 172122
2013-01-10 22:11:28 +00:00
Chad Rosier 8a11f77cf3 [ms-inline asm] Extend the inline asm Sema lookup interface to determine if the
Decl is a VarDecl.
Part of rdar://12991541

llvm-svn: 172120
2013-01-10 22:10:16 +00:00
Nico Weber a2a8495e19 Formatter: No spaces around '=' in @property lines.
Before:
@property(assign, getter = isEditable) BOOL editable;

Now:
@property(assign, getter=isEditable) BOOL editable;

It'd be nice if some Apple person could let me know if spaces are preferred
around '=' in @synthesize lines (see FIXME in the test).

llvm-svn: 172110
2013-01-10 21:30:42 +00:00
Anna Zaks 0aeb60d79d [analyzer] Add more checks to the ObjC Ivar Invalidation checker.
Restructured the checker so that it could easily find two new classes of
issues:
 - when a class contains an invalidatable ivar, but no declaration of an
invalidation method
 - when a class contains an invalidatable ivar, but no definition of an
invalidation method in the @implementation.

The second case might trigger some false positives, for example, when
the method is defined in a category.

llvm-svn: 172104
2013-01-10 20:59:51 +00:00
Fariborz Jahanian 9409e46714 In my last patch use InGroup<Switch> (per Dmitri's comment).
llvm-svn: 172103
2013-01-10 20:47:57 +00:00
Fariborz Jahanian 941827931e Provide a better warning when case value overflows.
// rdar://11577384

llvm-svn: 172102
2013-01-10 20:26:42 +00:00
Nico Weber 35496eea98 Formatter: Land header change I forgot to land in r172099.
llvm-svn: 172101
2013-01-10 20:19:27 +00:00
Nico Weber d6f962f151 Formatter: Add test for template and protocol parameters in ObjC method declarations.
llvm-svn: 172100
2013-01-10 20:18:33 +00:00
Nico Weber a608775ba2 Formatting: In @implementation etc lines, put a space before protocol lists.
Don't do this in Google style though:
http://google-styleguide.googlecode.com/svn/trunk/objcguide.xml#Protocols

Most other places (function declarations, variable declarations) still get
this wrong, and since this looks very similiar to template instantiations to
the lexer (`id <MyProtocol> a = ...`), it's going to be hard to fix in some
places.

llvm-svn: 172099
2013-01-10 20:12:55 +00:00
Manuel Klimek 51bd6ec142 Refactoring the outermost structure of the formatter.
This is the last step of pure shuffling stuff around, the next step will
be the actual feature.

llvm-svn: 172098
2013-01-10 19:49:59 +00:00
Argyrios Kyrtzidis 1489ed2b68 [libclang] Address some coding style issues pointed out by Dmitri.
llvm-svn: 172096
2013-01-10 19:43:44 +00:00
Nico Weber a1a5abd5b1 Formatter: Don't put a space in ObjC number literals like @+50
Before:
@ -4.5

Now:
@-4.5

llvm-svn: 172095
2013-01-10 19:36:35 +00:00
Ted Kremenek 4a800f876a ccc-analyzer: Forward -msse* options to the compiler.
llvm-svn: 172094
2013-01-10 19:29:31 +00:00
Nico Weber 2bb0074232 Formatter: Add space before '(' in @implemenation, @interface, @protocol lines
The first token in @implementation, @interface, and @protocol lines is now
marked TT_ObjCDecl, and lines starting with a TT_ObjCDecl token are now marked
LT_ObjCMethodDecl.

llvm-svn: 172093
2013-01-10 19:19:14 +00:00
Manuel Klimek b2c6dbec52 Pull calculation whether a line fits one level up.
This is the next step towards being able to configure multiple unwrapped
lines into one.

llvm-svn: 172092
2013-01-10 19:17:33 +00:00
Fariborz Jahanian 1eab052a7f objectiveC++: When throwing c++ exception of
an objectiveC object, use objc_exception_throw
to raise the exception. // rdar://12605907

llvm-svn: 172091
2013-01-10 19:02:56 +00:00
Argyrios Kyrtzidis f036f1a630 [libclang] Add missing header file
llvm-svn: 172090
2013-01-10 18:58:44 +00:00
Argyrios Kyrtzidis ea47435861 [libclang] Enhance logging capabilities of libclang.
-provide a "raw_ostream'ish" class to make it convenient to output logging info.
-use macros to automate a bit the logging functionality inside libclang functions
-when logging, print a stack trace if "LIBCLANG_LOGGING=2" environment is set.
-add logging to more functions.

llvm-svn: 172089
2013-01-10 18:54:52 +00:00
Jordan Rose d12618f6db Diagnostics: name all implicit groups used more than once.
This will be a new style requirement going forwards: a diagnostic can only
use the implicit InGroup<DiagGroup<"foo">> syntax if "foo" is not used by
any other diagnostics; as soon as it is, it needs an explicit group.

This also brings some stray "conversion" diagnostics into the
"Value Conversion Issue" category, instead of the more generic
"Semantic Issue" category. I consider this an improvement!
- warn_impcast_complex_scalar
- warn_impcast_float_integer
- warn_impcast_float_precision
- warn_impcast_integer_precision
- warn_impcast_vector_scalar

llvm-svn: 172088
2013-01-10 18:50:51 +00:00
Jordan Rose c3b23aa848 Error if an anonymous DiagGroup is referenced multiple times.
Not only is this inefficient for TableGen, it's annoying for maintenance
when renaming warning flags (unusual) or adding those flags to a group
(more likely).

This uses the new fix-it infrastructure for LLVM's SourceMgr/SMDiagnostic,
as well as a few changes to TableGen to track more source information.

llvm-svn: 172087
2013-01-10 18:50:46 +00:00
Manuel Klimek 0b689fd68d Pulling formatFirstToken one level up.
This prepares the code for single line optimizations and changes the
dependencies between single-line-formats to the indent of the first
token.

Conceptually, the first token is "between" the lines anyway, as the
whitespace for the first token includes the previous end-of-line, which
needs to be escaped when inside a preprocessor directive.

llvm-svn: 172083
2013-01-10 18:45:26 +00:00
Manuel Klimek 0ddd57a17b Fixes layout of right braces.
We now decide whether a newline should go before the closing brace
depending on whether a newline was inserted after the opening brace.

For example, we now insert a newline before '};' in:
static SomeClass WithALoooooooooooooooooooongName = {
  100000000, \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"
};
... while not inserting a newline here:
static SomeClass = { a, b, c, d, e, f, g, h, i, j,
                     looooooooooooooooooooooooooooooooooongname,
                     looooooooooooooooooooooooooooooong };

Also fixes the formating of (column limit 25):
int x = {
  avariable,
  b(alongervariable)
};

llvm-svn: 172076
2013-01-10 15:58:26 +00:00
Alexander Kornienko 5b7157ac8d Basic support for diagnostics.
Summary: Uses DiagnosticsEngine to output diagnostics.

Reviewers: djasper, klimek

Reviewed By: djasper

CC: cfe-commits

Differential Revision: http://llvm-reviews.chandlerc.com/D278

llvm-svn: 172071
2013-01-10 15:05:09 +00:00
Manuel Klimek 73a2fdf232 Fixes formatting of function calls etc inside an initializer list.
We're now formatting (column limit 25):
int x = {
  avariable,
  b(alongervariable) };

This also fixes:
Aaa({
  int i;
}, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
                                    ccccccccccccccccc));
... where we would previously break after the '},'.

Putting the closing curly into an extra line when there's a break
directly after the first curly will be done in a subsequent patch.

Paired with djasper.

llvm-svn: 172070
2013-01-10 14:36:46 +00:00
Manuel Klimek e7d10a1f50 Do not add newline in empty blocks.
void f() {}
now gets formatted in one line.

llvm-svn: 172067
2013-01-10 13:24:24 +00:00
Daniel Jasper c1fa281325 Improvements to function type and ObjC block formatting.
Before: int (^myBlock) (int) = ^(int num) {}
        A<void ()>;
	int (*b)(int);

After:  int (^myBlock)(int) = ^(int num) {}
        A<void()>;
	int(*b)(int);

For function types and function pointer types, this patch only makes
the behavior consistent (for types that are keywords and other types).
For the latter function pointer type declarations, we'll probably
want to add a space after "int".

Also added LangOpts.Bool = 1, so we handle "A<bool()>" appropriately
Moved the LangOpts-settings to a public place for use by tests
and clang-format binary.

llvm-svn: 172065
2013-01-10 13:08:12 +00:00
Simon Atanasyan 81c423cc97 [Mips] Pass a combination of +soft-float and -mips16-hard-float flags to
the backend if hard float ABI is selected under -mips16 mode.

llvm-svn: 172062
2013-01-10 12:36:19 +00:00
Manuel Klimek 8e07a1b64b Fix layout of blocks inside statements.
Previously, we would not indent:
SOME_MACRO({
  int i;
});
correctly. This is fixed by adding the trailing }); to the unwrapped
line starting with SOME_MACRO({, so the formatter can correctly match
the braces and indent accordingly.

Also fixes incorrect parsing of initializer lists, like:
int a[] = { 1 };

llvm-svn: 172058
2013-01-10 11:52:21 +00:00
Daniel Jasper 7194e1818e Improve clang-format's understanding of casts.
This fixes llvm.org/PR14684.

Before: int *pa = (int *) & a;
After:  int *pa = (int *)&a;

We still don't understand all kinds of casts. I added a FIXME to
address that.

llvm-svn: 172056
2013-01-10 11:14:08 +00:00
David Tweed c38f11de40 r172047 lacked a test (due to incomplete OpenCL support in clang). Use a modified
version of a test by Joey Gouly to use attributes to materialise the unsupported
types and test vector shifts.

llvm-svn: 172053
2013-01-10 10:42:08 +00:00
Guy Benyei 03e61960c8 Enable intel_ocl_bicc for x86_64 target only. Remove fix from 171969 that enabled this extension for multiple targets.
llvm-svn: 172052
2013-01-10 10:41:05 +00:00
Manuel Klimek fba4bb114b Introduce a define to switch on debug output.
After re-writing the same loop multiple times, we deicided it's time to
add this as an optional debugging help.

llvm-svn: 172050
2013-01-10 10:05:08 +00:00
Daniel Jasper 83a54d23d3 Do more error checking for '{}'.
This fixes llvm.org/PR14883, where clang-format would run into an
assertion on:

void f() { return } 42

llvm-svn: 172049
2013-01-10 09:26:47 +00:00
David Tweed 9fb566c076 Testing with a full OpenCL compiler (based on clang) reveals r71734 missed
difference between type widths of a vector and the width of one of its elements
in the case of vector shifts. Use correct witdth in the vector case.

llvm-svn: 172047
2013-01-10 09:11:33 +00:00
NAKAMURA Takumi eacd667238 clang-c/Index.h: Clarify empty argument with (void) for C89.
llvm-svn: 172037
2013-01-10 02:12:38 +00:00
Douglas Gregor 0f2b4635be Be more careful about updating the failed-modules set
llvm-svn: 172035
2013-01-10 02:04:18 +00:00
Nick Lewycky 230203c949 Don't assert in codegen on static data members which have NoLinkage. Fixes
PR14825!

llvm-svn: 172031
2013-01-10 01:46:29 +00:00
Douglas Gregor 4ddf2221b4 Rework the realpath nonsense for framework lookups to deal more
uniformly with symlinks between top-level and embedded frameworks.

llvm-svn: 172030
2013-01-10 01:43:00 +00:00
Nico Weber bbe28b3d80 Formatter: Remove unused @-formatting code.
@optional @property is put on two different unwrapped lines now, so this is no
longer necessary.

llvm-svn: 172024
2013-01-10 00:42:07 +00:00
Nico Weber 51306d232e Formatter: @optional and @required go on their own line.
Previously:
@protocol myProtocol
- (void)mandatoryWithInt:(int)i;
@optional - (void) optional;
@required - (void) required;
@end

Now:
@protocol myProtocol
- (void)mandatoryWithInt:(int)i;
@optional
- (void)optional;
@required
- (void)required;
@end

llvm-svn: 172023
2013-01-10 00:25:19 +00:00
Nico Weber 2ce0ac5a8c Formatter: Add support for @implementation.
Just reuse the @interface code for this. It accepts slightly more than
necessary (@implementation cannot have protocol lists), but that's ok.

llvm-svn: 172019
2013-01-09 23:25:37 +00:00
Argyrios Kyrtzidis eb994f4064 [PreprocessingRecord] A macro expansion can be reported out-of-order in cases when
there are macro expansions inside macro arguments where the arguments are
not expanded in the same order as listed; don't assert that all macro expansions
are in source order.

rdar://12397063

llvm-svn: 172018
2013-01-09 23:22:20 +00:00
Argyrios Kyrtzidis 9f89bffc25 [utils/ClangDataFormat.py] Don't use lldb.frame directly, get the frame from the value.
Some lldb changes made lldb.frame not set until a script is invoked, which made the
formatters not working after a restart.

llvm-svn: 172017
2013-01-09 23:22:08 +00:00
Fariborz Jahanian 8b115b7872 Issue warning when case value is too large to fit
in case condition type. // rdar://11577384.
Test is conditionalized on x86_64-apple triple as
I am not sure if the INT_MAX/LONG_MAX values in the test
will pass this test for other hosts.

llvm-svn: 172016
2013-01-09 23:04:56 +00:00
Dmitri Gribenko dd7d8a0f35 ClangTools.rst: spelling and formatting
llvm-svn: 172008
2013-01-09 22:22:51 +00:00
Dmitri Gribenko cb9ede9437 ClangFormat.rst: improve formatting
llvm-svn: 172007
2013-01-09 22:18:55 +00:00
Hal Finkel 6134a6e7b8 Remove the unused Parser::ParseTranslationUnit function
Parser::ParseTranslationUnit is now dead because the loop over
ParseTopLevelDecl is in ParseAST.

llvm-svn: 172005
2013-01-09 21:49:51 +00:00
Daniel Jasper 85a77c1609 Add documentation for clang-format.
This adds documentation for both LibFormat as well as the standalone
tools and integrations built on top of it. It slightly restructures
the ClangTools documentation.

llvm-svn: 172004
2013-01-09 21:49:28 +00:00
Nico Weber d8ffe75ad1 Formatter: Make parseObjCUntilAtEnd() actually work.
llvm-svn: 172003
2013-01-09 21:42:32 +00:00
Nico Weber 8696a8d9e3 Formatting: Add support for @protocol.
Pull pieces of the @interface code into reusable methods.

llvm-svn: 172001
2013-01-09 21:15:03 +00:00
Nico Weber 4d03055e70 Fix test after r171995.
I wasn't aware libFormat is used elsewhere already. Let me know if rebasing
is not the right thing to do here.

llvm-svn: 171996
2013-01-09 20:36:10 +00:00
Nico Weber 7eecf4b6e3 Formatter: Add support for @interface.
Previously:
@interface Foo + (id)init; @end

Now:
@interface Foo
+ (id)init;
@end

Some tweaking remains, but this is a good first step.

llvm-svn: 171995
2013-01-09 20:25:35 +00:00
Benjamin Kramer 696651429d unwind.h: Add include guards and don't mess with visibility if HIDE_EXPORTS is specified.
For GCC compatibility.

llvm-svn: 171991
2013-01-09 19:54:57 +00:00
Ted Kremenek 2f2edd3fb1 Do not model loads from complex types, since we don't accurately model the imaginary and real parts yet.
Fixes false positive reported in <rdar://problem/12964481>.

llvm-svn: 171987
2013-01-09 18:46:17 +00:00
David Blaikie 5a6a020d9b Suppress GCC -Wreturn warning.
Modified from a patch by David Greene.

llvm-svn: 171982
2013-01-09 17:48:41 +00:00
Rafael Espindola 3bd836a58e Handle static functions being redeclared in function scope.
Fixes pr14861.

llvm-svn: 171978
2013-01-09 16:34:58 +00:00
Manuel Klimek 52b1515405 Enables layouting unwrapped lines around preprocessor directives.
Previously, we'd always start at indent level 0 after a preprocessor
directive, now we layout the following snippet (column limit 69) as
follows:

functionCallTo(someOtherFunction(
    withSomeParameters, whichInSequence,
    areLongerThanALine(andAnotherCall,
  B
                       withMoreParamters,
                       whichStronglyInfluenceTheLayout),
    andMoreParameters),
               trailing);

Note that the different jumping indent is a different issue that will be
addressed separately.

This is the first step towards handling #ifdef->#else->#endif chains
correctly.

llvm-svn: 171974
2013-01-09 15:25:02 +00:00
Guy Benyei 6313f780e1 Enable intel_ocl_bicc for x86_64 target. This was missed in r171056.
llvm-svn: 171969
2013-01-09 12:21:44 +00:00
Daniel Jasper bcab430fee Only align after assignments on the top level.
This fixes llvm.org/PR14870 and we no longer mess up:
template <typename T1, typename T2 = char, typename T3 = char,
          typename T4 = char>
void f();

It removes the nice aligment for assignments inside other expressions,
but I am not sure those are actually practically relevant. If so, we can
fix those later.

llvm-svn: 171966
2013-01-09 10:40:23 +00:00
Daniel Jasper 2df93311da Don't simply give up when exceeding 80cols, choose an "ok" option.
This addresses llvm.org/PR14847.

We can now format something like:
int aaaaaaaaaaaaaaaaaaaaaaaaaaa =
    // aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaiaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
    + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;

clang-format unavoidably exceeds the column limit, but does not just
flush everything into a single line. Moreover, it tries to minimize the
number of characters beyond the column limit.

llvm-svn: 171964
2013-01-09 10:16:05 +00:00
Daniel Jasper 890589414b Correctly format wrapped function call parameters in templated functions.
This fixes llvm.org/PR14846.

Before:
template <typename T>
void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
        int aaaaaaaaaaaaaaaaa);

After:
template <typename T>
void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
    int aaaaaaaaaaaaaaaaa);

llvm-svn: 171963
2013-01-09 09:50:48 +00:00
Manuel Klimek cdd5c2397a Fixes dump_ast_matchers to parse all matcher macros and updates the
docs.

llvm-svn: 171962
2013-01-09 09:38:21 +00:00
Daniel Jasper d8bb2db242 Allow comments in the middle of statements to be on their own line.
This fixes llvm.org/PR14860.

Before, we messed up the format of:
if (DeclaratorInfo.isFunctionDeclarator() &&
    //getDeclSpecContextFromDeclaratorContext(Context) == DSC_top_level &&
    Tok.is(tok::semi) && NextToken().is(tok::l_brace)) {
}

llvm-svn: 171961
2013-01-09 09:33:39 +00:00
Daniel Jasper fb3f2482e5 Fix ObjC block declarations.
Before: int ( ^ Block1) (int, int) = ^ (int i, int j)
After:  int (^Block1) (int, int) = ^(int i, int j)
llvm-svn: 171959
2013-01-09 08:36:49 +00:00
Daniel Jasper 399d24bc7d Improve formatting of conditional operators.
This addresses llvm.org/PR14864.

We used to completely mess this up and now format as:
Diag(NewFD->getLocation(),
     getLangOpts().MicrosoftExt ? diag::ext_function_specialization_in_class :
         diag::err_function_specialization_in_class)
    << NewFD->getDeclName();

llvm-svn: 171957
2013-01-09 07:06:56 +00:00
Nico Weber 69dce49c76 Don't mention -fno-diagnostics-print-source-range-info in manual.
Clang doesn't understand it.

If someone wants to teach clang about that flag instead, please also add
support for -fno-diagnostics-parseable-fixits for consistency.

Until then, let the documentation match the current behavior.

llvm-svn: 171952
2013-01-09 05:06:41 +00:00
Will Dietz 450f1a1f45 [ubsan] Make static check data non-const so it can be used for deduplication.
llvm-svn: 171947
2013-01-09 03:39:41 +00:00
Eli Friedman c52435b4a2 Make sure clang puts tokens from different files on separate lines in "-E -P" mode. <rdar://problem/12774044>
llvm-svn: 171944
2013-01-09 03:16:42 +00:00
Eli Friedman ec94b61745 Make __has_include a bit more resilient in the presence of macros. <rdar://problem/12748859>.
llvm-svn: 171939
2013-01-09 02:20:00 +00:00
Douglas Gregor 3552dabfe1 When name lookup for a redeclaration finds declarations that are known
(because they are part of some module) but have not been made visible
(because they are in a submodule that wasn't imported), filter out
those declarations unless both the old declaration and the new
declaration have external linkage. When one or both has internal
linkage, there should be no conflict unless both are imported.

llvm-svn: 171925
2013-01-09 00:47:56 +00:00
Fariborz Jahanian 14da440018 put back diagnostics when flexible members are captured
in lambdas.

llvm-svn: 171921
2013-01-09 00:09:15 +00:00
Michael Gottesman 675444d5de Removed extra "`" from ARC documentation.
llvm-svn: 171920
2013-01-08 23:55:10 +00:00
Chad Rosier d35ae732ac [ms-inline asm] Add a test case for the offset operator where the operand is a
global variable.

llvm-svn: 171919
2013-01-08 23:51:48 +00:00
Fariborz Jahanian 5eae4adf23 Fix typo (again).
llvm-svn: 171917
2013-01-08 23:48:48 +00:00
Fariborz Jahanian 7a83f04094 Remove lambda from my last patch.
llvm-svn: 171915
2013-01-08 23:40:08 +00:00
Fariborz Jahanian b68f7b2a77 Fixes typo in comment.
llvm-svn: 171913
2013-01-08 23:21:22 +00:00
Fariborz Jahanian a716a34527 objectiveC blocks: It is impractical to capture
struct variables with flexiable array members in
blocks (and lambdas). Issue error instead of
crashing in IRGen. // rdar://12655829

llvm-svn: 171912
2013-01-08 23:17:51 +00:00
Richard Smith 5f044ad5f0 PR14855: don't silently swallow a nested-name-specifier after a type name.
llvm-svn: 171908
2013-01-08 22:43:49 +00:00
Rafael Espindola b68dd4717e Clear LV cache when dropping availability attributes.
llvm-svn: 171906
2013-01-08 22:31:36 +00:00
Rafael Espindola a3aea433f8 Tighten types a bit. No functionality change.
llvm-svn: 171902
2013-01-08 22:04:34 +00:00
Rafael Espindola c231fab756 Don't crash when trying to apply the availability attribute to a block.
llvm-svn: 171899
2013-01-08 21:30:32 +00:00
Rafael Espindola c2453dd8f5 Tighten types a bit. No functionality change.
llvm-svn: 171895
2013-01-08 21:00:12 +00:00
Rafael Espindola 0a67e2fc8b Tighten types a bit. No functionality change.
llvm-svn: 171894
2013-01-08 20:44:06 +00:00
David Blaikie 9360953135 Remove on-by-default warning from -Wmost.
-Wint-to-pointer-cast, added to match GCC's warning by the same name, doesn't
need to be in any other groups (as it isn't in any groups in GCC either).

Found in post-commit review by Ted Kremenek.

llvm-svn: 171893
2013-01-08 20:28:13 +00:00
Nico Weber 4cc9874ff9 Formatter: More tests for already-passing ObjC bits.
llvm-svn: 171892
2013-01-08 20:16:23 +00:00
Anna Zaks efe76bc821 [analyzer] Bump down the max size of functions being analyzed.
With the new setting, we are not going to inline any functions that are
more than 50 basic blocks. (The analyzer is 20% faster on several
especially bad benchmarks with the new default.)

llvm-svn: 171891
2013-01-08 20:09:00 +00:00
Daniel Jasper 66dcb1ca86 Don't break after unary operators.
Before:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaa, *
                                                 aaaaaaaaaaaaaaaaaaaaaaaaaaaaa);

After:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
    aaaaaaaaaaaaaaaaaaaaaaaaaaaa, *aaaaaaaaaaaaaaaaaaaaaaaaaaaaa);

llvm-svn: 171890
2013-01-08 20:03:18 +00:00
Rafael Espindola f26d5391ab Move loop variable update.
Thanks to Dmitri Gribenko for the suggestion.

llvm-svn: 171889
2013-01-08 19:58:34 +00:00
Rafael Espindola 820fa707b1 Mark all subsequent decls used.
In the source

  static void f();
  static void f();
  template<typename T>
  static void g() {
    f();
  }
  static void f() {
  }
  void h() {
    g<int>();
  }

the call to f refers to the second decl, but it is only marked used at the end
of the translation unit during instantiation, after the third f decl has been
linked in.

With this patch we mark all subsequent decls used, so that it is easy to check
if a symbol is used or not.

llvm-svn: 171888
2013-01-08 19:43:34 +00:00
Nico Weber 77aa25090a Formatter: Format @ literals better. Array and dictionary literals need more work.
llvm-svn: 171887
2013-01-08 19:40:21 +00:00