Commit Graph

12108 Commits

Author SHA1 Message Date
Eli Friedman 8a78a58188 Improve the diagnostic in ARC mode when a conditional with an Objective-C type and void* is used. <rdar://problem/10486347>.
llvm-svn: 151416
2012-02-25 00:23:44 +00:00
Douglas Gregor 6073dcab38 Implement C++11 [over.match.copy]p1b2, which allows the use of
explicit conversion functions to initialize the argument to a
copy/move constructor that itself is the subject of direct
initialization. Since we don't have that much context in overload
resolution, we end up threading more flags :(.

Fixes <rdar://problem/10903741> / PR10456. 

llvm-svn: 151409
2012-02-24 23:56:31 +00:00
Richard Smith 324df5564e Back out __decltype warning from r151377: we should either warn on all the GNU
__keywords or none of them.

llvm-svn: 151401
2012-02-24 22:30:04 +00:00
Richard Smith fd3da9358f __decltype is a GNU extension, not a C++11 extension.
llvm-svn: 151377
2012-02-24 18:10:23 +00:00
Douglas Gregor 3a08c1cd3b Two minor, related fixes for template instantiation with blocks:
- Make sure that the block expression is instantiation-dependent if the
    block is in a dependent context
  - Make sure that the C++ 'this' expression gets captured even if we
  don't rebuild the AST node during template instantiation. This would
  also have manifested as a bug for lambdas.

Fixes <rdar://problem/10832617>.

llvm-svn: 151372
2012-02-24 17:41:38 +00:00
Douglas Gregor 29c42f2a25 Implement a new type trait __is_trivially_constructible(T, Args...)
that provides the behavior of the C++11 library trait
std::is_trivially_constructible<T, Args...>, which can't be
implemented purely as a library.

Since __is_trivially_constructible can have zero or more arguments, I
needed to add Yet Another Type Trait Expression Class, this one
handling arbitrary arguments. The next step will be to migrate
UnaryTypeTrait and BinaryTypeTrait over to this new, more general
TypeTrait class.

Fixes the Clang side of <rdar://problem/10895483> / PR12038.

llvm-svn: 151352
2012-02-24 07:38:34 +00:00
Ted Kremenek 60a7820ffe Reapply r151317, but when computing the PathDiagnostic profile and size keep into account the nested structure. Also fix a problem with how
inlining impacted Plist diagnostics, and adjust some ranges in the Plist output due to richer information.

llvm-svn: 151346
2012-02-24 06:00:00 +00:00
Chad Rosier c0ea158a2b Revert r151317 - Rework PathDiagnostics creation.. - to appease buildbots.
llvm-svn: 151338
2012-02-24 02:06:33 +00:00
Ted Kremenek f2131e7d95 Rework PathDiagnostic creation so that call stacks are captured by a nested PathDiagnosticCallPiece.
llvm-svn: 151317
2012-02-24 00:38:56 +00:00
Eli Friedman ec52f92db3 Handle "#pragma GCC visibility" in a few more places. Switch over "#pragma pack" to use the same handling that gcc does. Fixes <rdar://problem/10871094> and <rdar://problem/10893316>.
(Hopefully, common usage of these pragmas isn't irregular enough to break our current handling.  Doug has ideas for a more crazy approach if necessary.)

llvm-svn: 151307
2012-02-23 23:47:16 +00:00
Fariborz Jahanian 86f8266b9f objective-c++: Type of an objc string literal is NSString, not 'id'.
// rdar://10907410

llvm-svn: 151296
2012-02-23 22:51:36 +00:00
Douglas Gregor 2d5aea0f25 Pull the OpaqueValueExpr's source expression into its constructor, so
that we can correctly compute value-dependence of the OVE.

llvm-svn: 151291
2012-02-23 22:17:26 +00:00
Anna Zaks df901a4419 [analyzer] Malloc: unique leak reports by allocation site.
When we find two leak reports with the same allocation site, report only
one of them.

Provide a helper method to BugReporter to facilitate this.

llvm-svn: 151287
2012-02-23 21:38:21 +00:00
Argyrios Kyrtzidis 2e85c5f297 [libclang] Make sure that all top-level decls in a @implementation are
marked as such.

Previously we missed tag declarations; fixes rdar://10902015

llvm-svn: 151283
2012-02-23 21:11:20 +00:00
Douglas Gregor 1be329d838 Provide the __is_trivially_assignable type trait, which provides
compiler support for the std::is_trivially_assignable library type
trait.

llvm-svn: 151240
2012-02-23 07:33:15 +00:00
Rafael Espindola 8093fdfab1 Two fixes to how we compute visibility:
* Handle some situations where we should never make a decl more visible,
  even when merging in an explicit visibility.

* Handle attributes in members of classes that are explicitly specialized.

Thanks Nico for the report and testing, Eric for the initial review, and dgregor
for the awesome test27 :-)

llvm-svn: 151236
2012-02-23 04:17:32 +00:00
Richard Smith 1e3b0f0614 Update parser's disambiguation to cope with braced function-style casts in
C++11, and with braced-init-list initializers in conditions. This exposed an
ambiguity with enum underlying types versus bitfields, which we resolve by
treating 'enum E : T {' as always defining an enumeration (even if it would
only successfully parse as a bitfield). This appears to be g++ compatible.

llvm-svn: 151227
2012-02-23 01:36:12 +00:00
Chad Rosier 14f9cd8739 Add new driver warning from r151174 to a warning group. Please let me know if this isn't the appropriate grouping.
llvm-svn: 151177
2012-02-22 18:18:48 +00:00
Chad Rosier ce975d9997 [driver] Add a warning for when -mcpu= is specified without an argument. There
are likely many other OPT_xxxx_EQ options that could/should be added here.
rdar://10704648

llvm-svn: 151174
2012-02-22 17:55:22 +00:00
Sebastian Redl eef474ce1b Fix parsing and processing initializer lists in return statements and as direct member initializers.
llvm-svn: 151155
2012-02-22 10:50:08 +00:00
Hans Wennborg c9dd946852 Warn about non-standard format strings (pr12017)
This adds the -Wformat-non-standard flag (off by default,
enabled by -pedantic), which warns about non-standard
things in format strings (such as the 'q' length modifier,
the 'S' conversion specifier, etc.)

llvm-svn: 151154
2012-02-22 10:17:01 +00:00
Bill Wendling 8eb771d4ca More ArrayRef-ification of methods.
llvm-svn: 151152
2012-02-22 09:51:33 +00:00
Bill Wendling 8ac06afa9b ArrayRef-icize the function arguments.
llvm-svn: 151151
2012-02-22 09:38:11 +00:00
Richard Smith 2a15b74605 Accept braced-init-lists in conditions, and, in passing, dramatically improve
the diagnostic for using a parenthesized direct-initializer in a condition.

llvm-svn: 151137
2012-02-22 06:49:09 +00:00
Douglas Gregor ed90df3800 Generate an AST for the conversion from a lambda closure type to a
block pointer that returns a block literal which captures (by copy)
the lambda closure itself. Some aspects of the block literal are left
unspecified, namely the capture variable (which doesn't actually
exist) and the body (which will be filled in by IRgen because it can't
be written as an AST).

Because we're switching to this model, this patch also eliminates
tracking the copy-initialization expression for the block capture of
the conversion function, since that information is now embedded in the
synthesized block literal. -1 side tables FTW.

llvm-svn: 151131
2012-02-22 05:02:47 +00:00
Richard Smith fd555f6b1f Implement C++11 [expr.call]p11: If the operand to a decltype-specifier is a
function call (or a comma expression with a function call on its right-hand
side), possibly parenthesized, then the return type is not required to be
complete and a temporary is not bound. Other subexpressions inside a decltype
expression do not get this treatment.

This is implemented by deferring the relevant checks for all calls immediately
within a decltype expression, then, when the expression is fully-parsed,
checking the relevant constraints and stripping off any top-level temporary
binding.

Deferring the completion of the return type exposed a bug in overload
resolution where completion of the argument types was not attempted, which
is also fixed by this change.

llvm-svn: 151117
2012-02-22 02:04:18 +00:00
Kaelyn Uhrain 0178200062 Fix typo correction of template arguments to once again allow type names.
llvm-svn: 151112
2012-02-22 01:03:07 +00:00
Chad Rosier 877c0a27f8 Provide a way to disable auto-generation of preprocessed files during clang
crash.  This can speedup the process of generating a delta reduced test case.
rdar://10905465

llvm-svn: 151109
2012-02-22 00:30:39 +00:00
Argyrios Kyrtzidis cd90e3d37b Make sure Stmt::dump() is included in libclang.
llvm-svn: 151102
2012-02-21 23:41:58 +00:00
Douglas Gregor 680e9e018d Improve our handling of lambda expressions that occur within default
arguments. There are two aspects to this:

  - Make sure that when marking the declarations referenced in a
  default argument, we don't try to mark local variables, both because
  it's a waste of time and because the semantics are wrong: we're not
  in a place where we could capture these variables again even if it
  did make sense.
  - When a lambda expression occurs in a default argument of a
  function template, make sure that the corresponding closure type is
  considered dependent, so that it will get properly instantiated. The
  second bit is a bit of a hack; to fix it properly, we may have to
  rearchitect our handling of default arguments, parsing them only
  after creating the function definition. However, I'd like to
  separate that work from the lambdas work.

llvm-svn: 151076
2012-02-21 19:11:17 +00:00
Argyrios Kyrtzidis 90c2e86b63 Also mark Type's dump() as 'used' to make it available in libclang.
llvm-svn: 151037
2012-02-21 06:12:38 +00:00
Argyrios Kyrtzidis 8f931c56f9 Mark a few 'dump' methods as 'used' to make sure they are included in libclang
and useable while debugging.

llvm-svn: 151033
2012-02-21 05:04:44 +00:00
Douglas Gregor 926410d2db Implement name mangling for lambda expressions that occur within the
initializers of data members (both static and non-static).

llvm-svn: 151017
2012-02-21 02:22:07 +00:00
Douglas Gregor 7fcbd902b4 Implement name mangling for lambda expressions that occur within the
default arguments of function parameters. This simple-sounding task is
complicated greatly by two issues:

  (1) Default arguments aren't actually a real context, so we need to
  maintain extra state within lambda expressions to track when a
  lambda was actually in a default argument.
  (2) At the time that we parse a default argument, the FunctionDecl
  doesn't exist yet, so lambda closure types end up in the enclosing
  context. It's not clear that we ever want to change that, so instead
  we introduce the notion of the "effective" context of a declaration
  for the purposes of name mangling.

llvm-svn: 151011
2012-02-21 00:37:24 +00:00
Argyrios Kyrtzidis 969fdfddd2 [PCH] Recover gracefully if the ASTReader detects that a file is different
from the one stored in the PCH/AST, while trying to load a SLocEntry.

We verify that all files of the PCH did not change before loading it but this is not enough because:

- The AST may have been 1) kept around, 2) to do queries on it.
- We may have 1) verified the PCH and 2) started parsing.

Between 1) and 2) files may change and we are going to have crashes because the rest of clang
cannot deal with the ASTReader failing to read a SLocEntry.

Handle this by recovering gracefully in such a case, by initializing the SLocEntry
with the info from the PCH/AST as well as reporting failure by the ASTReader.

rdar://10888929

llvm-svn: 151004
2012-02-20 23:58:07 +00:00
Argyrios Kyrtzidis 5e5927eb0b Make PreprocessorOptions::DetailedRecordIncludesNestedMacroExpansions false by default.
Recording nested macro expansions is not useful, plus it fixes rdar://10893630

llvm-svn: 150995
2012-02-20 22:54:39 +00:00
Fariborz Jahanian a7765fea90 modern objc translator. Finish off first cut of the
modern meta-data translation by commenting out private ivar
declarations in user source. Also, added several tests.

llvm-svn: 150985
2012-02-20 20:09:20 +00:00
Douglas Gregor 6379854457 Basic support for name mangling of C++11 lambda expressions. Because
name mangling in the Itanium C++ ABI for lambda expressions is so
dependent on context, we encode the number used to encode each lambda
as part of the lambda closure type, and maintain this value within
Sema.

Note that there are a several pieces still missing:
  - We still get the linkage of lambda expressions wrong
  - We aren't properly numbering or mangling lambda expressions that
  occur in default function arguments or in data member initializers.
  - We aren't (de-)serializing the lambda numbering tables

llvm-svn: 150982
2012-02-20 19:44:39 +00:00
Dylan Noblesmith c95d81924d Basic: import IntrusiveRefCntPtr<> into clang namespace
The class name is long enough without the llvm:: added.
Also bring in RefCountedBase and RefCountedBaseVPTR.

llvm-svn: 150958
2012-02-20 14:00:23 +00:00
Rafael Espindola 1af7c219c7 Implement a -gcc-toolchain command line option that does the same as
configure's --with-gcc-toolchain. The configure option is now just a default
value for the command line one.

llvm-svn: 150898
2012-02-19 01:38:32 +00:00
Richard Smith 66c9699ac3 Implement constant expression support for __real__ and __imag__ on lvalue
complex numbers. Treat complex numbers as arrays of the corresponding component
type, in order to make std::complex behave properly if implemented in terms of
_Complex T.

Apparently libstdc++'s std::complex is implemented this way, and we were
rejecting a member like this:

  constexpr double real() { return __real__ val; }

because it was marked constexpr but unable to produce a constant expression.

llvm-svn: 150895
2012-02-18 22:04:06 +00:00
Ted Kremenek e98d63a823 Adopt ExprEngine and checkers to ObjC property refactoring. Everything was working, but now diagnostics are aware of message expressions implied by uses of properties. Fixes <rdar://problem/9241180>.
llvm-svn: 150888
2012-02-18 20:53:30 +00:00
David Chisnall 0867d9cfbc Implement #pragma redefine_extname.
This fixes PR5172 and allows clang to compile C++ programs on Solaris using the system headers.

llvm-svn: 150881
2012-02-18 16:12:34 +00:00
Douglas Gregor fdf598eaf3 Rewrite variable capture within lambda expressions and blocks,
eliminating a bunch of redundant code and properly modeling how the
captures of outside blocks/lambdas affect the types seen by inner
captures.

This new scheme makes two passes over the capturing scope stack. The
first pass goes up the stack (from innermost to outermost), assessing
whether the capture looks feasible and stopping when it either hits
the scope where the variable is declared or when it finds an existing
capture. The second pass then walks down the stack (from outermost to
innermost), capturing the variable at each step and updating the
captured type and the type that an expression referring to that
captured variable would see. It also checks type-specific
restrictions, such as the inability to capture an array within a
block. Note that only the first odr-use of each
variable needs to do the full walk; subsequent uses will find the
capture immediately, so multiple walks need not occur.

The same routine that builds the captures can also compute the type of
the captures without signaling errors and without actually performing
the capture. This functionality is used to determine the type of
declaration references as well as implementing the weird decltype((x))
rule within lambda expressions.

The capture code now explicitly takes sides in the debate over C++
core issue 1249, which concerns the type of captures within nested
lambdas. We opt to use the more permissive, more useful definition
implemented by GCC rather than the one implemented by EDG.

llvm-svn: 150875
2012-02-18 09:37:24 +00:00
Douglas Gregor 812d8f6387 Unify our computation of the type of a captured reference to a
variable; it was previously duplicated, and one of the copies failed
to account for outer non-mutable lambda captures.

llvm-svn: 150872
2012-02-18 05:51:20 +00:00
Ted Kremenek 084e1b48a1 Change wording of warning about using __bridge casts in non-ARC.
llvm-svn: 150868
2012-02-18 04:42:38 +00:00
Richard Smith eec915d686 Diagnose uses of deleted destructors and inaccessible defaulted destructors.
We had two separate issues here: firstly, varions functions were assuming that
they did not need to perform semantic checks on trivial destructors (this is
not true in C++11, where a trivial destructor can nonetheless be private or
deleted), and a bunch of DiagnoseUseOfDecl calls were missing for uses of
destructors.

llvm-svn: 150866
2012-02-18 04:13:32 +00:00
Richard Smith d951a1d9c8 Initial refactoring of 'ShouldDeleteSpecialMember', in preparation for providing
decent diagnostics. Finish the work of combining all the 'ShouldDelete'
functions into one. In unifying the code, fix a minor bug where an anonymous
union with a deleted default constructor as a member of a union wasn't being
considered as making the outer union's default constructor deleted.

llvm-svn: 150862
2012-02-18 02:02:13 +00:00
Ted Kremenek d519cae8aa Have conjured symbols depend on LocationContext, to add context sensitivity for functions called more than once.
llvm-svn: 150849
2012-02-17 23:13:45 +00:00
Sebastian Redl c83ed8248e Basic code generation support for std::initializer_list.
We now generate temporary arrays to back std::initializer_list objects
initialized with braces. The initializer_list is then made to point at
the array. We support both ptr+size and start+end forms, although
the latter is untested.

Array lifetime is correct for temporary std::initializer_lists (e.g.
call arguments) and local variables. It is untested for new expressions
and member initializers.

Things left to do:
Massively increase the amount of testing. I need to write tests for
start+end init lists, temporary objects created as a side effect of
initializing init list objects, new expressions, member initialization,
creation of temporary objects (e.g. std::vector) for initializer lists,
and probably more.
Get lifetime "right" for member initializers and new expressions. Not
that either are very useful.
Implement list-initialization of array new expressions.

llvm-svn: 150803
2012-02-17 08:42:25 +00:00
Douglas Gregor a80cae11f6 Disambiguate between C++11 lambda expressions and C99 array
designators in the parser. In the worst case, this disambiguation
requires tentative parsing just past the closing ']', but for most
cases we'll be able to tell by looking ahead just one token (without
going into the heavyweight tentative parsing machinery).

llvm-svn: 150790
2012-02-17 03:49:44 +00:00
John McCall c833deaa09 Block expressions always have a prototyped function type; expose this
in the AST accessor and micro-optimize it very slightly.

llvm-svn: 150787
2012-02-17 03:32:35 +00:00
John McCall 1e25a97ae2 Add a castAs<U> accessor to CanQual<T>.
llvm-svn: 150786
2012-02-17 03:32:17 +00:00
Douglas Gregor 355efbb2e0 Rework the Sema/AST/IRgen dance for the lambda closure type's
conversion to function pointer. Rather than having IRgen synthesize
the body of this function, we instead introduce a static member
function "__invoke" with the same signature as the lambda's
operator() in the AST. Sema then generates a body for the conversion
to function pointer which simply returns the address of __invoke. This
approach makes it easier to evaluate a call to the conversion function
as a constant, makes the linkage of the __invoke function follow the
normal rules for member functions, and may make life easier down the
road if we ever want to constexpr'ify some of lambdas.

Note that IR generation is responsible for filling in the body of
__invoke (Sema just adds a dummy body), because the body can't
generally be expressed in C++.

Eli, please review!

llvm-svn: 150783
2012-02-17 03:02:34 +00:00
Richard Smith 1002d10aaa Reject continue/break statements within members of local functions nested within
loop and switch statements, by teaching Scope that a function scope never has
a continue/break parent for the purposes of control flow. Remove the hack in
block and lambda expressions which worked around this by pretending that such
expressions were continue/break scopes.

Remove Scope::ControlParent, since it's unused.

In passing, teach default statements to recover properly from a missing ';', and
add a fixit for same to both default and case labels (the latter already
recovered correctly).

llvm-svn: 150776
2012-02-17 01:35:32 +00:00
Douglas Gregor 6746c5d487 Improve recovery for lambda expressions that have 'mutable' or a
trailing return type but not a '()'. Recover by inserting the
parentheses. Thanks to Xeo on IRC for the example.

llvm-svn: 150727
2012-02-16 21:53:36 +00:00
Ted Kremenek 35e55fe49f Revert "Move ExplodedNode reclaimation out of ExprEngine and into CoreEngine. Also have it based on adding predecessors/successors, not node allocation. No measurable performance change."
llvm-svn: 150722
2012-02-16 20:48:04 +00:00
Richard Smith 4297375561 C++11 allows unions to have static data members. Remove the corresponding
restriction and add some tests.

llvm-svn: 150721
2012-02-16 20:41:22 +00:00
Ted Kremenek ea8dbdeefd Move ExplodedNode reclaimation out of ExprEngine and into CoreEngine. Also have it based on adding predecessors/successors, not node allocation. No measurable performance change.
llvm-svn: 150720
2012-02-16 20:19:30 +00:00
Ted Kremenek a2aa929e74 Minor cleanup to node data structures in ExplodedGraph. No functionality change.
llvm-svn: 150719
2012-02-16 20:19:25 +00:00
Hans Wennborg 63cf65f85d Tweak the comment on the 'q' length modifier again.
llvm-svn: 150716
2012-02-16 18:58:32 +00:00
Hans Wennborg b328fe3710 Update comment as per Joerg's comment on r150697.
llvm-svn: 150711
2012-02-16 18:19:51 +00:00
DeLesley Hutchins 3fc6e4a7cd Allow thread safety attributes on function definitions.
For compatibility with gcc, clang will now parse gcc attributes on
function definitions, but issue a warning if the attribute is not a
thread safety attribute.  Warning controlled by -Wgcc-compat.

llvm-svn: 150698
2012-02-16 16:50:43 +00:00
Hans Wennborg 9bc9bcc247 Format string analysis: give 'q' its own enumerator.
This is in preparation for being able to warn about 'q' and other
non-standard format string features.

It also allows us to print its name correctly.

llvm-svn: 150697
2012-02-16 16:34:54 +00:00
Sebastian Redl 6047f07e81 Revert "Revert "Make CXXNewExpr contain only a single initialier, and not hold the used constructor itself.""
This reintroduces commit r150682 with a fix for the Bullet benchmark crash.

llvm-svn: 150685
2012-02-16 12:22:20 +00:00
Sebastian Redl c3a3c60040 Revert "Make CXXNewExpr contain only a single initialier, and not hold the used constructor itself."
It leads to a compiler crash in the Bullet benchmark.

This reverts commit r12014.

llvm-svn: 150684
2012-02-16 11:35:52 +00:00
Sebastian Redl 86fab844bb Make CXXNewExpr contain only a single initialier, and not hold the used constructor itself.
Holding the constructor directly makes no sense when list-initialized arrays come into play. The constructor is now held in a CXXConstructExpr, if construction is what is done. The new design can also distinguish properly between list-initialization and direct-initialization, as well as implicit default-initialization constructors and explicit value-initialization constructors. Finally, doing it this way removes redundance from the AST because CXXNewExpr doesn't try to handle both the allocation and the initialization responsibilities.

This breaks the static analysis of new expressions. I've filed PR12014 to track this.

llvm-svn: 150682
2012-02-16 10:58:10 +00:00
Richard Smith 17100bad0a constexpr tidyups:
* Fix bug when determining whether && / || are potential constant expressions
  * Try harder when determining whether ?: is a potential constant expression
  * Produce a diagnostic on sizeof(VLA) to provide a better source location

llvm-svn: 150657
2012-02-16 02:46:34 +00:00
Argyrios Kyrtzidis 85620ad239 Fix the RecursiveASTVisitor to not traverse C++ default parameters twice.
llvm-svn: 150651
2012-02-16 02:02:14 +00:00
Douglas Gregor d3b672c385 Implicitly define a lambda's conversion functions (to function
pointers and block pointers). We use dummy definitions to keep the
invariant that an implicit, used definition has a body; IR generation
will substitute the actual contents, since they can't be represented
as C++. 

For the block pointer case, compute the copy-initialization needed to
capture the lambda object in the block, which IR generation will need
later.

llvm-svn: 150645
2012-02-16 01:06:16 +00:00
Richard Smith 90e7c12961 Mark the parenthesized array member initialization diagnostic as DefaultError,
and move it out of -Wgnu so that -Wno-gnu leaves it enabled. As requested by
Eli.

llvm-svn: 150643
2012-02-16 00:54:02 +00:00
Richard Smith ebeed41587 Support GCC's bug^Wextension allowing class array members to be initalized by a
parenthesized braced-init-list in the base/member initialization list.

llvm-svn: 150625
2012-02-15 22:38:09 +00:00
David Blaikie af90ec11e1 Provide common include for all diagnostic headers.
Reviewed by Ted Kremenek.

llvm-svn: 150616
2012-02-15 21:58:34 +00:00
David Blaikie 040a3a28f1 Remove the unuseful -fdiagnostics-show-name
This option was added in r129614 and doesn't have any use case that I'm aware
of. It's possible that external tools are using these names - and if that's
the case we can certainly reassess the functionality, but for now it lets us
shave out a few unneeded bits from clang.

Move the "StaticDiagNameIndex" table into the only remaining consumer, diagtool.
This removes the actual diagnostic name strings from clang entirely.

Reviewed by Chris Lattner & Ted Kremenek.

llvm-svn: 150612
2012-02-15 19:45:34 +00:00
Douglas Gregor 74f7d50f6a When overload resolution picks an implicitly-deleted special member
function, provide a specialized diagnostic that indicates the kind of
special member function (default constructor, copy assignment
operator, etc.) and that it was implicitly deleted. Add a hook where
we can provide more detailed information later.

llvm-svn: 150611
2012-02-15 19:33:52 +00:00
Nico Weber a92c1eed0f Tweak comment above DiagGroup<"all">.
llvm-svn: 150600
2012-02-15 18:18:51 +00:00
Douglas Gregor 02267a8e48 A little more lambda capture initialization diagnostics cleanup
llvm-svn: 150589
2012-02-15 17:05:32 +00:00
Douglas Gregor 19666fb1aa Introduce a new initialization entity for lambda captures, and
specialize location information and diagnostics for this entity.

llvm-svn: 150588
2012-02-15 16:57:26 +00:00
Douglas Gregor cf11eb76ed Specialize noreturn diagnostics for lambda expressions.
llvm-svn: 150586
2012-02-15 16:20:15 +00:00
Douglas Gregor b9e38f19f7 Specialize the diagnostic complaining about conflicting types of
return statements within a lambda; this diagnostic previously referred
to blocks.

llvm-svn: 150584
2012-02-15 15:57:22 +00:00
Douglas Gregor d8c61785ed Implement code completion support for lambda capture lists.
llvm-svn: 150583
2012-02-15 15:34:24 +00:00
Hans Wennborg d99d688358 Make -Wformat fix-its preserve original conversion specifiers.
This commit makes PrintfSpecifier::fixType() and ScanfSpecifier::fixType()
only fix a conversion specification enough that Clang wouldn't warn about it,
as opposed to always changing it to use the "canonical" conversion specifier.
(PR11975)

This preserves the user's choice of conversion specifier in cases like:

printf("%a", (long double)1);
where we previously suggested "%Lf", we now suggest "%La"

printf("%x", (long)1);
where we previously suggested "%ld", we now suggest "%lx".

llvm-svn: 150578
2012-02-15 09:59:46 +00:00
Richard Smith b228a86fcf Implement DR1454. This allows all intermediate results in constant expressions
to be core constant expressions (including pointers and references to
temporaries), and makes constexpr calculations Turing-complete. A Turing machine
simulator is included as a testcase.

This opens up the possibilty of removing CCValue entirely, and removing some
copies from the constant evaluator in the process, but that cleanup is not part
of this change.

llvm-svn: 150557
2012-02-15 02:18:13 +00:00
John McCall c62bb39142 Split reinterpret_casts of member pointers out from CK_BitCast; this
is general goodness because representations of member pointers are
not always equivalent across member pointer types on all ABIs
(even though this isn't really standard-endorsed).

Take advantage of the new information to teach IR-generation how
to do these reinterprets in constant initializers.  Make sure this
works when intermingled with hierarchy conversions (although
this is not part of our motivating use case).  Doing this in the
constant-evaluator would probably have been better, but that would
require a *lot* of extra structure in the representation of
constant member pointers:  you'd really have to track an arbitrary
chain of hierarchy conversions and reinterpretations in order to
get this right.  Ultimately, this seems less complex.  I also
wasn't quite sure how to extend the constant evaluator to handle
foldings that we don't actually want to treat as extended
constant expressions.

llvm-svn: 150551
2012-02-15 01:22:51 +00:00
Douglas Gregor 3009383b9f Implement indexing support for lambdas in libclang (both kinds), as
well as improving the RecursiveASTVisitor's walk of lambda
expressions.

llvm-svn: 150549
2012-02-15 00:54:55 +00:00
Douglas Gregor adb376ec33 Implement C++ core issue 974, which permits default arguments for
lambda expressions. Because these issue was pulled back from Ready
status at the Kona meeting, we still emit an ExtWarn when using
default arguments for lambda expressions.

llvm-svn: 150519
2012-02-14 22:28:59 +00:00
Argyrios Kyrtzidis 7e747957cd [libclang] Indexing: only index implicit template instantiations via an opt-in indexing option.
llvm-svn: 150517
2012-02-14 22:23:11 +00:00
Dmitri Gribenko 800ddf3dda Generalize -Wempty-body: warn when statement body is empty (closes: PR11329)
* if, switch, range-based for: warn if semicolon is on the same line.
* for, while: warn if semicolon is on the same line and either next
statement is compound statement or next statement has more
indentation.

Replacing the semicolon with {} or moving the semicolon to the next
line will always silence the warning.

Tests from SemaCXX/if-empty-body.cpp merged into SemaCXX/warn-empty-body.cpp.

llvm-svn: 150515
2012-02-14 22:14:32 +00:00
Anna Zaks 3d34834bb0 [analyzer] Make Malloc Checker optimistic in presence of inlining.
(In response of Ted's review of r150112.)

This moves the logic which checked if a symbol escapes through a
parameter to invalidateRegionCallback (instead of post CallExpr visit.)

To accommodate the change, added a CallOrObjCMessage parameter to
checkRegionChanges callback.

llvm-svn: 150513
2012-02-14 21:55:24 +00:00
Richard Smith 98a0a49fbf Pending clear answer from WG21 on whether core issue 903 is intended to apply to
C++11 or just C++17, restrict the set of null pointer constants in C++11 mode
back to those which were considered null in C++98.

llvm-svn: 150510
2012-02-14 21:38:30 +00:00
Douglas Gregor 621003e7b9 Check the return type of lambda expressions.
llvm-svn: 150503
2012-02-14 21:20:44 +00:00
John McCall 5ed3caf2e3 Warn about non-int main() results in GNU C mode instead of erroring.
Based on a patch by Vasiliy Korchagin!

llvm-svn: 150500
2012-02-14 19:50:52 +00:00
Douglas Gregor 3e308b1fba Implement support for lambda capture pack expansions, e.g.,
[&values...] { print(values...); }

llvm-svn: 150497
2012-02-14 19:27:52 +00:00
Kaelyn Uhrain 0a16a8e531 Use several weighted factors to determine typo candidate viablity.
Replace the simple Levenshtein edit distance for typo correction
candidates--and the hacky way adding namespace qualifiers would affect
the edit distance--with a synthetic "edit distance" comprised of several
factors and their relative weights. This also allows the typo correction
callback object to convey more information about the viability of a
correction candidate than simply viable or not viable.

llvm-svn: 150495
2012-02-14 18:56:48 +00:00
Douglas Gregor 99ae806aff Implement AST (de-)serialization for lambda expressions.
llvm-svn: 150491
2012-02-14 17:54:36 +00:00
Ted Kremenek 0964cca5d5 Refactor DiagnosticRenderer and SDiagsRenderer to have some functionality
pulled into DiagnosticNoteRenderer, and common DiagnosticRenderer that
assumes that all custom diagnostic messages are notes.  Also extend
DiagnosticRenderer to work with StoredDiagnostics in preparation for
subsequent changes.

llvm-svn: 150455
2012-02-14 02:46:00 +00:00
Ted Kremenek 3efa357fee Add helper methods to StoredDiagnostic.
llvm-svn: 150454
2012-02-14 02:43:12 +00:00
Eli Friedman 6ae6302ddf Refactor out new function EmitInitializerForField from EmitMemberInitializer. The new function will be used to initialize the fields of lambda expressions.
llvm-svn: 150451
2012-02-14 02:15:49 +00:00
Matt Beaumont-Gay 4809fc1d9d Add a subgroup of -Wreturn-type, -Wreturn-type-c-linkage.
llvm-svn: 150418
2012-02-13 22:04:08 +00:00
Douglas Gregor 0c46b2b7ce Introduce support for template instantiation of lambda
expressions. This is mostly a simple refact, splitting the main "start
a lambda expression" function into smaller chunks that are driven
either from the parser (Sema::ActOnLambdaExpr) or during AST
transformation (TreeTransform::TransformLambdaExpr). A few minor
interesting points:

  - Added new entry points for TreeTransform, so that we can
  explicitly establish the link between the lambda closure type in the
  template and the lambda closure type in the instantiation.
  - Added a bit into LambdaExpr specifying whether it had an explicit
  result type or not. We should have had this anyway.

This code is 'lightly' tested.

llvm-svn: 150417
2012-02-13 22:00:16 +00:00
Dmitri Gribenko c233a545e8 Remove unused diagnostics from include/clang/Basic/Diagnostic*.td files.
llvm-svn: 150409
2012-02-13 20:13:24 +00:00
Anna Zaks d56c8794d3 [analyzer] Malloc checker: rework realloc handling:
1) Support the case when realloc fails to reduce False Positives. (We
essentially need to restore the state of the pointer being reallocated.)

2) Realloc behaves differently under special conditions (from pointer is
null, size is 0). When detecting these cases, we should consider
under-constrained states (size might or might not be 0). The
old version handled this in a very hacky way. The code did not
differentiate between definite and possible (no consideration for
under-constrained states). Further, after processing each special case,
the realloc processing function did not return but chained to the next
special case processing. So you could end up in an execution in which
you first see the states in which size is 0 and realloc ~ free(),
followed by the states corresponding to size is not 0 followed by the
evaluation of the regular realloc behavior.

llvm-svn: 150402
2012-02-13 18:05:39 +00:00
Douglas Gregor e556163a66 Split the storage of lambda information between the LambdaExpr and the
CXXRecordDecl in a way that actually makes some sense:
  - LambdaExpr contains all of the information for initializing the
  lambda object, including the capture initializers and associated
  array index variables.
  - CXXRecordDecl's LambdaDefinitionData contains the captures, which
  are needed to understand the captured variable references in the
  body of the lambda.

llvm-svn: 150401
2012-02-13 17:20:40 +00:00
Douglas Gregor 54fcea6e16 Keep track of the set of array index variables we use when we
synthesize a by-copy captured array in a lambda. This information will
be needed by IR generation.

llvm-svn: 150396
2012-02-13 16:35:30 +00:00
Douglas Gregor c8a734938b Move the storage of lambda captures and capture initializers from
LambdaExpr over to the CXXRecordDecl. This allows us to eliminate the
back-link from the closure type to the LambdaExpr, which will simplify
and lazify AST deserialization.

llvm-svn: 150393
2012-02-13 15:44:47 +00:00
Dylan Noblesmith 043fdf091d StaticAnalyzer/Core: fix MSVC build
Fix build breakage from r150378: MSVC only allows taking the
address of a member function using the &ClassName::Function
syntax.# It was giving

llvm-svn: 150387
2012-02-13 14:22:35 +00:00
Hans Wennborg f81b9d172a Fix typo in PrintfConversionSpecifier::isDoubleArg()
This makes the printf diagnostics issue warnigns for %a, %A, %e, etc.
when used with the wrong argument.

llvm-svn: 150370
2012-02-13 10:32:27 +00:00
Richard Smith 3607ffee5c Update constexpr implementation to match CWG's chosen approach for core issues
1358, 1360, 1452 and 1453.
 - Instantiations of constexpr functions are always constexpr. This removes the
   need for separate declaration/definition checking, which is now gone.
 - This makes it possible for a constexpr function to be virtual, if they are
   only dependently virtual. Virtual calls to such functions are not constant
   expressions.
 - Likewise, it's now possible for a literal type to have virtual base classes.
   A constexpr constructor for such a type cannot actually produce a constant
   expression, though, so add a special-case diagnostic for a constructor call
   to such a type rather than trying to evaluate it.
 - Classes with trivial default constructors (for which value initialization can
   produce a fully-initialized value) are considered literal types.
 - Classes with volatile members are not literal types.
 - constexpr constructors can be members of non-literal types. We do not yet use
   static initialization for global objects constructed in this way.

llvm-svn: 150359
2012-02-13 03:54:03 +00:00
David Blaikie 23b478d3e8 Move -Wdangling-else under -Wparentheses to be backwards compatibile with GCC.
llvm-svn: 150349
2012-02-12 19:51:50 +00:00
Douglas Gregor 81495f341d Within the body of a lambda expression, decltype((x)) for an
id-expression 'x' will compute the type based on the assumption that
'x' will be captured, even if it isn't captured, per C++11
[expr.prim.lambda]p18. There are two related refactors that go into
implementing this:

  1) Split out the check that determines whether we should capture a
  particular variable reference, along with the computation of the
  type of the field, from the actual act of capturing the
  variable. 
  2) Always compute the result of decltype() within Sema, rather than
  AST, because the decltype() computation is now context-sensitive.

llvm-svn: 150347
2012-02-12 18:42:33 +00:00
Sebastian Redl d74dd49065 Proper initializer list support for new expressions and type construct expressions. Array new still missing.
llvm-svn: 150346
2012-02-12 18:41:05 +00:00
Sebastian Redl 0501c63609 Change the way we store initialization kinds so that all direct inits can distinguish between list and parens form. This allows us to correctly diagnose the last test cases from litb.
llvm-svn: 150343
2012-02-12 16:37:36 +00:00
Sebastian Redl 5a41f68fe2 Employ DirectList initialized entities to properly sort through some initialization edge cases.
llvm-svn: 150342
2012-02-12 16:37:24 +00:00
Sebastian Redl a935179ab7 Represent C++ direct initializers as ParenListExprs before semantic analysis
instead of having a special-purpose function.

- ActOnCXXDirectInitializer, which was mostly duplication of
  AddInitializerToDecl (leading e.g. to PR10620, which Eli fixed a few days
  ago), is dropped completely.
- MultiInitializer, which was an ugly hack I added, is dropped again.
- We now have the infrastructure in place to distinguish between
  int x = {1};
  int x({1});
  int x{1};
-- VarDecl now has getInitStyle(), which indicates which of the above was used.
-- CXXConstructExpr now has a flag to indicate that it represents list-
   initialization, although this is not yet used.
- InstantiateInitializer was renamed to SubstInitializer and simplified.
- ActOnParenOrParenListExpr has been replaced by ActOnParenListExpr, which
  always produces a ParenListExpr. Placed that so far failed to convert that
  back to a ParenExpr containing comma operators have been fixed. I'm pretty
  sure I could have made a crashing test case before this.

The end result is a (I hope) considerably cleaner design of initializers.
More importantly, the fact that I can now distinguish between the various
initialization kinds means that I can get the tricky generalized initializer
test cases Johannes Schaub supplied to work. (This is not yet done.)

This commit passed self-host, with the resulting compiler passing the tests. I
hope it doesn't break more complicated code. It's a pretty big change, but one
that I feel is necessary.

llvm-svn: 150318
2012-02-11 23:51:47 +00:00
Sebastian Redl 46afb55177 Drive-by fix of incorrect diagnostic, and a test case for said diagnostic. The double error is unfortunate, but I really don't see an alternative whose effort is worth it.
llvm-svn: 150317
2012-02-11 23:51:21 +00:00
Eli Friedman 9436352a82 Implement warning for non-wide string literals with an unexpected encoding. Downgrade error for non-wide character literals with an unexpected encoding to a warning for compatibility with gcc and older versions of clang. <rdar://problem/10837678>.
llvm-svn: 150295
2012-02-11 05:08:10 +00:00
Eli Friedman c9751069f5 Make sure Sema creates a field for 'this' captures. (Doug, please double-check that this is correct.)
llvm-svn: 150292
2012-02-11 02:51:16 +00:00
Eli Friedman 7e7da2d285 const-qualify CXXRecordDecl::getCaptureFields.
llvm-svn: 150284
2012-02-11 00:18:00 +00:00
Douglas Gregor f0d495100c Implement C++11 [expr.lambda.prim]p13, which prohibits lambdas in
default arguments if in fact those lambdas capture any entity.

llvm-svn: 150282
2012-02-10 23:30:22 +00:00
Jim Grosbach 576452b830 Have the driver pass CPU and target feature information to cc1as.
When creating the MCSubtargetInfo, the assembler driver uses the CPU and
feature string to construct a more accurate model of what instructions
are and are not legal.

rdar://10840476

llvm-svn: 150273
2012-02-10 20:37:10 +00:00
Argyrios Kyrtzidis e5dc5b31f2 [libclang] Indexing API: Fully index implict template instantiations.
llvm-svn: 150267
2012-02-10 20:10:44 +00:00
Argyrios Kyrtzidis 926227811b Update MultiplexASTMutationListener with the missing methods from ASTMutationListener.
llvm-svn: 150265
2012-02-10 20:10:36 +00:00
Douglas Gregor a1bffa26ca Allow implicit capture of 'this' in a lambda even when the capture
default is '=', and reword the warning about explicitly capturing
'this' in such lambdas to indicate that only explicit capture is
banned. 

Introduce Fix-Its for this and other "save the programmer from
themself" rules regarding what can be explicitly captured and what
must be implicitly captured.

llvm-svn: 150256
2012-02-10 17:46:20 +00:00
Richard Smith 63168c7533 PR11684, core issue 1417:
o Correct the handling of the restrictions on usage of cv-qualified and
  ref-qualified function types.
o Fix a bug where such types were rejected in template type parameter default
  arguments, due to such arguments not being treated as a template type arg
  context.
o Remove the ExtWarn for usage of such types as template arguments; that was
  a standard defect, not a GCC extension.
o Improve the wording and unify the code for diagnosing cv-qualifiers with the
  code for diagnosing ref-qualifiers.

llvm-svn: 150244
2012-02-10 11:05:11 +00:00
Richard Smith 5e580292ac Track whether a function type has a trailing return type as type sugar. Use this
to pretty-print such function types better, and to fix a case where we were not
instantiating templates in lexical order. In passing, move the Variadic bit from
Type's bitfields to FunctionProtoType to get the Type bitfields down to 32 bits.
Also ensure that we always substitute the return type of a function when
substituting explicitly-specified arguments, since that can cause us to bail
out with a SFINAE error before we hit a hard error in parameter substitution.

llvm-svn: 150241
2012-02-10 09:58:53 +00:00
Douglas Gregor 9c702207e5 Extend CXXRecordDecl with a function that determines the mapping from
the variables captured by a lambda to the fields that store the
captured values. To be used in IRgen.

llvm-svn: 150235
2012-02-10 07:45:31 +00:00
Richard Smith 0cd4ab194b Update to new resolution for DR1458. When taking the address of an object of
incomplete class type which has an overloaded operator&, it's now just
unspecified whether the overloaded operator or the builtin is used.

llvm-svn: 150234
2012-02-10 07:41:06 +00:00
David Blaikie 54f5d859ad Move -Wswitch from -Wmost to -Wall, consitent with GCC.
This is a relatively noisy warning for a codebase not explicitly designed for
it (effectively enforcing a stylistic constraint about the use of defaults
in switches over enums) & there's nothing Clang does to clean up the noise
when compared to GCC's implementation so the same decision seems suitable.

llvm-svn: 150230
2012-02-10 05:15:16 +00:00
Ted Kremenek 6eb25628c5 Revert r145999. This turned out to be a bad idea. Unfortunately, 'id' is used so profusely
in many APIs and large codebases that this made the deprecated warning trigger happy to
the point of not being useful.

llvm-svn: 150223
2012-02-10 02:45:47 +00:00
Fariborz Jahanian 29082a5f1d objc: If a method is not implemented in the category implementation but
has been declared in its primary class, superclass,
or in one of their protocols, no need to issue unimplemented method. 
// rdar://10823023

llvm-svn: 150206
2012-02-09 21:30:24 +00:00
Benjamin Kramer 3edb3b4ac5 Kill the brief and full explanation fields from StaticDiagInfoRec. They were unused and wasted space for nothing.
- per PR11952.

llvm-svn: 150199
2012-02-09 19:38:26 +00:00
Douglas Gregor 940a550f0d Don't allow deduction of a lambda result type from an initializer
list; it is not an expression.

llvm-svn: 150194
2012-02-09 18:40:39 +00:00
Douglas Gregor 7345626a5b Implement return type deduction for lambdas per C++11
[expr.prim.lambda]p4, including the current suggested resolution of
core isue 975, which allows multiple return statements so long as the
types match. ExtWarn when user code is actually making use of this
extension.

llvm-svn: 150168
2012-02-09 10:18:50 +00:00
Douglas Gregor 656bc62a73 Remove the "unsupported" error for lambda expressions. It's annoying,
and rapidly becoming untrue.

llvm-svn: 150165
2012-02-09 08:26:42 +00:00
Douglas Gregor 8962549164 Implement C++ [expr.prim.lambda]p2, which bans lambda expressions in
unevaluated operands. Be certain that we're marking everything
referenced within a capture initializer as odr-used.

llvm-svn: 150163
2012-02-09 08:14:43 +00:00
Argyrios Kyrtzidis 5605de7c8b Fix ASTReader::FinishedDeserializing().
We were passing a decl to the consumer after all pending deserializations were finished
but this was not enough; due to processing by the consumer we may end up into yet another
deserialization process but the way FinishedDeserializing() was setup we would not ensure
that everything was fully deserialized before returning to the consumer.

Separate ASTReader::FinishedDeserializing() into two semantic actions.
The first is ensuring that a deserialization process ends up will fully deserialized decls/types even
if the process is started by the consumer.
The second is pushing "interesting" decls to the consumer; we make sure that we don't re-enter this
section recursively be checking a variable.

llvm-svn: 150160
2012-02-09 07:31:52 +00:00
Richard Smith 5a294e6a2c CWG issue 1405: mutable members are allowed in literal types, but can't undergo
lvalue-to-rvalue conversions in constant expressions.

llvm-svn: 150145
2012-02-09 03:29:58 +00:00
Eli Friedman faea56944c Fix a typo in the LambdaExpr class.
llvm-svn: 150139
2012-02-09 02:55:22 +00:00
Argyrios Kyrtzidis 6f40eb7e56 [PCH] Avoid using Decl::setAttrs() and Decl::setLexicalDeclContext() from the ASTReaderDecl
directly; they internally call Decl::getASTContext() which may crash if a declaration context
parent is still deserializing.

llvm-svn: 150137
2012-02-09 02:44:08 +00:00
Aaron Ballman c2a9493a26 Adding support for warning when a non-C compatible user-defined type is returned from an extern "C" function.
Fixes bug 6143

llvm-svn: 150128
2012-02-09 01:21:34 +00:00
Douglas Gregor 8c50e7c5e3 Various interrelated cleanups for lambdas:
- Complete the lambda class when we finish the lambda expression
    (previously, it was left in the "being completed" state)
  - Actually return the LambdaExpr object and bind to the resulting
  temporary when needed.
  - Detect when cleanups are needed while capturing a variable into a
  lambda (e.g., due to default arguments in the copy constructor), and
  make sure those cleanups apply for the whole of the lambda
  expression.
    

llvm-svn: 150123
2012-02-09 00:47:04 +00:00
Douglas Gregor 21f4692c62 When completing a lambda expression, make sure to check and attach the
body of the lambda to the function call operator.

llvm-svn: 150087
2012-02-08 20:17:14 +00:00
Richard Smith 90cacbbf3e Implement DR1458: Taking the address of an object of incomplete class type is
not a constant expression, because we can't tell whether the complete class type
will have an overloaded operator&.

llvm-svn: 150066
2012-02-08 08:11:33 +00:00
Craig Topper e5ea3b0239 Remove vperm2f* and vperm2i builtins. Same effect can be achieved with builtin_shufflevector.
llvm-svn: 150064
2012-02-08 07:33:36 +00:00
Richard Smith da7c4ba1af Implement the agreed resolution to DR1457: a signed left shift of a 1 bit into
the sign bit doesn't have undefined behavior, but a signed left shift of a 1 bit
out of the sign bit still does. As promised to Howard :)

The suppression of the potential constant expression checking in system headers
is also removed, since the problem it was working around is gone.

llvm-svn: 150059
2012-02-08 06:14:53 +00:00
Craig Topper fec9f8edb7 Remove vpermilp* builtins. Same effect can be achieved with builtin_shufflevector.
llvm-svn: 150056
2012-02-08 05:16:54 +00:00
Ted Kremenek 8d968ad5c0 Move -Wcovered-switch-default out of -Wswitch (and -Wall), and make it an opt-in warning.
This is a great warning, but it was observed that a ton of real world code violates
it all the time for (semi-)legitimate reasons.  This warnings is fairly pedantic, which is good,
but not for everyone.  For example, there is a fair amount of idiomatic code out there
that does "default: abort()", and similar idioms.

Addresses <rdar://problem/10814651>.

llvm-svn: 150055
2012-02-08 05:08:58 +00:00
Ted Kremenek afa6e249cb Change PathDiagnosticPieces to be reference counted (simplifying their management), and introduce 'PathPieces' as a common container for PathDiagnosticPieces.
llvm-svn: 150054
2012-02-08 04:32:34 +00:00
Ted Kremenek 3116c4e5cd Refactor pieces of PathDiagnostic into its own data structure. No functionality change.
llvm-svn: 150053
2012-02-08 04:32:27 +00:00
Argyrios Kyrtzidis a2a299e586 [libclang] For CXXOperatorCallExprs, give a valid source location to the DeclRefExpr
that is referencing the member function, so we can index the referenced function.

Fixes rdar://10762375&10324915 & http://llvm.org/PR11192

llvm-svn: 150033
2012-02-08 01:21:13 +00:00
John McCall 18ce25e1ec Revise the SplitQualType interface to make it its own thing instead of
a typedef of std::pair.  This slightly improves type-safety, but mostly
makes code using it clearer to read as well as making it possible to add
methods to the type.

Add such a method for efficiently single-step desugaring a split type.
Add a method to single-step desugaring a locally-unqualified type.
Implement both the SplitQualType and QualType methods in terms of that.

Also, fix a typo ("ObjCGLifetime").

llvm-svn: 150028
2012-02-08 00:46:36 +00:00
Benjamin Kramer 7ec12c928a Revert my patches which removed Diagnostic.h includes by moving some operator overloads out of line.
This seems to negatively affect compile time onsome ObjC tests
(which use a lot of partial diagnostics I assume). I have to come
up with a way to keep them inline without including Diagnostic.h
everywhere. Now adding a new diagnostic requires a full rebuild
of e.g. the static analyzer which doesn't even use those diagnostics.

This reverts commit 6496bd10dc3a6d5e3266348f08b6e35f8184bc99.
This reverts commit 7af19b817ba964ac560b50c1ed6183235f699789.
This reverts commit fdd15602a42bbe26185978ef1e17019f6d969aa7.
This reverts commit 00bd44d5677783527d7517c1ffe45e4d75a0f56f.
This reverts commit ef9b60ffed980864a8db26ad30344be429e58ff5.

llvm-svn: 150006
2012-02-07 22:29:24 +00:00
Chad Rosier 4c17fa7620 In r149662, setDiagnosticMapping was modified to not allow warnings mapped to
MAP_ERROR to be remapped to MAP_WARNING.  These new APIs are being added to 
allow the diagnostic mapping's "no Werror" bit to be set, and potentially 
downgrade anything already mapped to be a warning.

llvm-svn: 150001
2012-02-07 19:55:45 +00:00
Fariborz Jahanian 1167190344 objc rewriter: start supporting modern objective-c abi
in objective-c rewriter. wip.

llvm-svn: 149989
2012-02-07 17:11:38 +00:00
Argyrios Kyrtzidis b6c6a58366 Make parsing of objc @implementations more robust.
Parsing of @implementations was based on modifying global state from
the parser; the logic for late parsing of methods was spread in multiple places
making it difficult to have a robust error recovery.

  -it was difficult to ensure that we don't neglect parsing the lexed methods.
  -it was difficult to setup the original objc container context for parsing the lexed methods
   after completing ParseObjCAtImplementationDeclaration and returning to top level context.

Enhance parsing of @implementations by centralizing it in Parser::ParseObjCAtImplementationDeclaration().
ParseObjCAtImplementationDeclaration now returns only after an @implementation is fully parsed;
all the data and logic for late parsing of methods is now in one place.

This allows us to provide code-completion for late parsed methods with mis-matched braces.
rdar://10775381

llvm-svn: 149987
2012-02-07 16:50:53 +00:00
Aaron Ballman b97a5addd5 Hex literals without a significand no longer crash the lexer. Fixes bug 7910
Patch by Eitan Adler

llvm-svn: 149984
2012-02-07 13:46:03 +00:00
Benjamin Kramer 2f56992964 Switch the ObjC*Decl raw_stream overloads to take a reference, for consistency with NamedDecls.
llvm-svn: 149981
2012-02-07 11:57:45 +00:00
Douglas Gregor e31e606ff3 Introduce basic ASTs for lambda expressions. This covers:
- Capturing variables by-reference and by-copy within a lambda
  - The representation of lambda captures
  - The creation of the non-static data members in the lambda class
  that store the captured variables
  - The initialization of the non-static data members from the
  captured variables
  - Pretty-printing lambda expressions

There are a number of FIXMEs, both explicit and implied, including:
  - Creating a field for a capture of 'this'
  - Improved diagnostics for initialization failures when capturing
  variables by copy
  - Dealing with temporaries created during said initialization
  - Template instantiation
  - AST (de-)serialization
  - Binding and returning the lambda expression; turning it into a
  proper temporary
  - Lots and lots of semantic constraints
  - Parameter pack captures

llvm-svn: 149977
2012-02-07 10:09:13 +00:00
Ted Kremenek 0298834e46 Create PathDiagnosticCallEnter and PathDiagnosticCallExit, to remark calls in PathDiagnostics from other events. This will
have potential uses later.

llvm-svn: 149960
2012-02-07 02:27:37 +00:00
Anna Zaks e0c7c27473 [analyzer] Allow each CString check to be enabled/disabled
separately.

llvm-svn: 149947
2012-02-07 00:56:14 +00:00
Chris Lattner 8573dc7e1f tidy up code, make the common case (1-byte strings) come first
llvm-svn: 149942
2012-02-07 00:39:21 +00:00
Ted Kremenek a2bbac3ffc Add basic BugReporter support for CallEnter/CallExit. WIP.
llvm-svn: 149939
2012-02-07 00:24:33 +00:00
Eli Friedman dd053f6fba Misc improvements to the diagnostic when a variable is odr-used in a context that is not allowed to capture variables.
Fixes PR11883.

llvm-svn: 149937
2012-02-07 00:15:00 +00:00
Eli Friedman 433aae6927 Minor comment clarification.
llvm-svn: 149931
2012-02-06 23:34:35 +00:00
Abramo Bagnara e0a70b2656 Added source location for the template keyword in DependentTemplateSpecializationTypeLoc nodes (DTSTLoc).
The new info is propagated to TSTLoc on template instantiation, getting rid of 3 FIXMEs in TreeTransform.h and another one Parser.cpp.

Simplified code in TypeSpecLocFiller visitor methods for DTSTLoc and DependentNameTypeLoc by removing what now seems to be dead code (adding corresponding assertions). 

llvm-svn: 149923
2012-02-06 22:45:07 +00:00
Abramo Bagnara 9033e2b358 Removed redundant location info from ElaboratedTypeLoc / DependentNameLoc / DependentTSTLoc. Uniformed names referencing elaborated keyword. No intended functionality changes.
llvm-svn: 149889
2012-02-06 19:09:27 +00:00
Abramo Bagnara 48c05be124 Added location for template keyword in TemplateSpecializationTypeLoc. In the process removed some naming ambiguities.
llvm-svn: 149870
2012-02-06 14:41:24 +00:00
Abramo Bagnara 65f7c3dba2 Fixed instantiation of DependentScopeDeclRefExpr.
llvm-svn: 149868
2012-02-06 14:31:00 +00:00
Benjamin Kramer 2c0dd81b73 Move operator overload out of line. Calling operator<< on a forward declared type doesn't seem to work on MSVC.
llvm-svn: 149819
2012-02-05 09:46:30 +00:00
Aaron Ballman 0e95d90acc Fixing a warning in MSVC (this is also a test commit)
llvm-svn: 149806
2012-02-05 03:08:16 +00:00
Richard Smith 2de5a939e2 constexpr: Implement DR1358: An instantiation of a constexpr function which
can't produce a constant expression is not ill-formed (so long as some
instantiation of that function can produce a constant expression).

llvm-svn: 149802
2012-02-05 02:30:54 +00:00
Dylan Noblesmith 2c1dd2716a Basic: import SmallString<> into clang namespace
(I was going to fix the TODO about DenseMap too, but
that would break self-host right now. See PR11922.)

llvm-svn: 149799
2012-02-05 02:13:05 +00:00
Dylan Noblesmith e27789991d Basic: import OwningPtr<> into clang namespace
llvm-svn: 149798
2012-02-05 02:12:40 +00:00
NAKAMURA Takumi 9ef84dde49 Try to fix Benjamin's r149781 on MSVC.
MSVC has complained the definition of "inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, CanQualType T)" in clang/AST/CanonicalType.h.

llvm-svn: 149797
2012-02-05 02:00:07 +00:00
Sebastian Redl 860eb7cf12 A useful approximation of initializer list constructors.
llvm-svn: 149792
2012-02-04 21:27:47 +00:00
Sebastian Redl f2089a409e Remove an unused and unimplemented function prototype.
llvm-svn: 149789
2012-02-04 21:27:28 +00:00
Benjamin Kramer 6bc0952b0f Some compilers do require Diagnostic.h to be present here.
llvm-svn: 149785
2012-02-04 14:13:11 +00:00
Benjamin Kramer 1edced6810 Don't include Diagnostics.h twice when it's required zero times.
llvm-svn: 149784
2012-02-04 14:09:30 +00:00
Benjamin Kramer 4903802fbf Move a method from IdentifierTable.h out of line and remove the SmallString include.
Fix all the transitive include users.

llvm-svn: 149783
2012-02-04 13:45:25 +00:00
Benjamin Kramer 02c746de10 Remove Diagnostic.h include from Preprocessor.h.
- Move the offending methods out of line and fix transitive includers.
- This required changing an enum in the PPCallback API into an unsigned.

llvm-svn: 149782
2012-02-04 13:02:15 +00:00
Benjamin Kramer 3307c508c9 Move various diagnostic operator<< overloads out of line and remove includes of Diagnostic.h.
Fix all the files that depended on transitive includes of Diagnostic.h.
With this patch in place changing a diagnostic no longer requires a full rebuild of the StaticAnalyzer.

llvm-svn: 149781
2012-02-04 12:31:12 +00:00
Benjamin Kramer 728ed3f386 Move Storage and StorageAllocator out of the PartialDiagnostic class so we can forward declare them.
Let ASTContext allocate the storage in its BumpPtrAllocator.
This will help us remove ASTContext's depedency on PartialDiagnostic.h soon.

llvm-svn: 149780
2012-02-04 12:30:46 +00:00
Benjamin Kramer 3f85fb2277 StaticAnalyzer: Remove FixIts from PathDiagnosticPieces.
They were unused and pulled in Diagnostic.h for no reason.

llvm-svn: 149779
2012-02-04 12:30:37 +00:00
Richard Smith f4c51d9d76 In C++11 mode, when an integral constant expression is desired and we have a
value of class type, look for a unique conversion operator converting to
integral or unscoped enumeration type and use that. Implements [expr.const]p5.

Sema::VerifyIntegerConstantExpression now performs the conversion and returns
the converted result. Some important callers of Expr::isIntegralConstantExpr
have been switched over to using it (including all of those required for C++11
conformance); this switch brings a side-benefit of improved diagnostics and, in
several cases, simpler code. However, some language extensions and attributes
have not been moved across and will not perform implicit conversions on
constant expressions of literal class type where an ICE is required.

In passing, fix static_assert to perform a contextual conversion to bool on its
argument.

llvm-svn: 149776
2012-02-04 09:53:13 +00:00
Richard Smith 8dd3425077 Don't allow a value of a scoped enumeration to be used as the first bound for an
array new expression. This lays some groundwork for the implicit conversion to
integral or unscoped enumeration which C++11 ICEs undergo.

llvm-svn: 149772
2012-02-04 07:07:42 +00:00
Richard Smith 3f333f2edf Disallow constexpr main.
llvm-svn: 149770
2012-02-04 06:10:17 +00:00
Richard Smith bcc9bcb65f Fix a rejects-valid in C++11: array new of a negative size, or overflowing array
new, is well-formed with defined semantics of throwing (a type which can be
caught by a handler for) std::bad_array_new_length, unlike in C++98 where it is
somewhere nebulous between undefined behavior and ill-formed.

If the array size is an integral constant expression and satisfies one of these
criteria, we would previous the array new expression, but now in C++11 mode, we
merely issue a warning (the code is still rejected in C++98 mode, naturally).

We don't yet implement new C++11 semantics correctly (see PR11644), but we do
implement the overflow checking, and (for the default operator new) convert such
expressions to an exception, so accepting such code now does not seem especially
unsafe.

llvm-svn: 149767
2012-02-04 05:35:53 +00:00
Argyrios Kyrtzidis 275a671b2a ArrayRef goodness in MultiplexConsumer, no functionality change.
llvm-svn: 149764
2012-02-04 05:23:00 +00:00
Argyrios Kyrtzidis 3bd71be4af Remove unused field from FixItRecompile.
llvm-svn: 149762
2012-02-04 04:53:03 +00:00
Dylan Noblesmith 35952f82bd autoconf: update config header
Sync with the change in r149652.

Also fix the comment to sync with LLVM's config.h header.

llvm-svn: 149748
2012-02-04 02:38:34 +00:00
Argyrios Kyrtzidis 3d97a9beb9 Use variable in place of multiple CI.getFrontendOpts() calls and use a bit
of ArrayRef goodness. No functionality change.

llvm-svn: 149739
2012-02-04 01:36:04 +00:00
Sean Callanan 1ce3a6b650 Clang has existing support for debuggers that
want to provide "po"-like functionality which
treats the result of an expression implicitly as
"id" (if it is not otherwise known) and prints
it as an Objective-C object.

This has in the past been gated by the
"DebuggerSupport" language option, but that is
too general.  Debuggers also provide other commands
like "print" that do not make any assumptions
about whether the object is an Objective-C object.

This patch makes the assumption conditional on a
new language option: DebuggerCastResultToId.  I
have also made corresponding modifications to the
testsuite.

llvm-svn: 149735
2012-02-04 01:29:37 +00:00
Eli Friedman a023e0c619 Make explicit captures which cause implicit captures work correctly.
llvm-svn: 149719
2012-02-03 23:06:43 +00:00
Eli Friedman 24af850470 Implement implicit capture for lambda expressions.
Still left: explicit captures in lambdas need to cause implicit capture, and I need to take a look at the diagnostics for some cases.

llvm-svn: 149718
2012-02-03 22:47:37 +00:00
Douglas Gregor 1f79ca839c When a pack expansion occurs in the template argument list of an alias
template without a corresponding parameter pack, don't immediately
substitute the alias template. This is under discussion in the C++
committee, and may become ill-formed, but for now we match GCC.

llvm-svn: 149697
2012-02-03 17:16:23 +00:00
Hans Wennborg b64a1fa65c Don't warn about anonymous struct/union in C11.
Also, in C, call this a C11 extension rather than a GNU extension.

llvm-svn: 149695
2012-02-03 15:47:04 +00:00
Bob Wilson 14adb360a7 Fix -ftrap-function fallout from llvm r145714. <rdar://problem/10799325>
That llvm change removed the -trap-func backend option, so that using
-ftrap-function with clang would cause the backend to complain.  Fix it
by adding the trap function name to the CodeGenOptions and passing it through
to the TargetOptions.

llvm-svn: 149679
2012-02-03 06:27:22 +00:00
Argyrios Kyrtzidis 0d9e24b1db Change Lexer::makeFileCharRange() to have it accept a CharSourceRange
instead of a SourceRange, and handle the case where the range is
a char (not token) range.

llvm-svn: 149677
2012-02-03 05:58:29 +00:00
Argyrios Kyrtzidis de044e5bb8 Change the fixed array of FixitHints to a SmallVector to lift off
the limit on the number of fixits.

llvm-svn: 149676
2012-02-03 05:58:22 +00:00
Argyrios Kyrtzidis 2e809ce7b4 Move isSentinelNullExpr() from Sema to ASTContext to make it more widely
available.

llvm-svn: 149675
2012-02-03 05:58:16 +00:00