Commit Graph

3716 Commits

Author SHA1 Message Date
David Blaikie 876657b9c8 Correcting grammar.
llvm-svn: 143894
2011-11-06 22:28:03 +00:00
Benjamin Kramer 867e40135a Make format string 64 bit safe.
llvm-svn: 143870
2011-11-06 09:34:11 +00:00
John McCall fe96e0b6be Change the AST representation of operations on Objective-C
property references to use a new PseudoObjectExpr
expression which pairs a syntactic form of the expression
with a set of semantic expressions implementing it.
This should significantly reduce the complexity required
elsewhere in the compiler to deal with these kinds of
expressions (e.g. IR generation's special l-value kind,
the static analyzer's Message abstraction), at the lower
cost of specifically dealing with the odd AST structure
of these expressions.  It should also greatly simplify
efforts to implement similar language features in the
future, most notably Managed C++'s properties and indexed
properties.

Most of the effort here is in dealing with the various
clients of the AST.  I've gone ahead and simplified the
ObjC rewriter's use of properties;  other clients, like
IR-gen and the static analyzer, have all the old
complexity *and* all the new complexity, at least
temporarily.  Many thanks to Ted for writing and advising
on the necessary changes to the static analyzer.

I've xfailed a small diagnostics regression in the static
analyzer at Ted's request.

llvm-svn: 143867
2011-11-06 09:01:30 +00:00
Benjamin Kramer 96ad717226 Now that we have a portable 64 bit format string use it to make this simple again.
llvm-svn: 143800
2011-11-05 09:02:52 +00:00
Eli Friedman 5b08d9adf5 Fix incorrect format string in debug output.
llvm-svn: 143768
2011-11-05 00:38:30 +00:00
Benjamin Kramer 62144477eb Remove unused variables.
llvm-svn: 143696
2011-11-04 15:05:51 +00:00
Richard Smith ed5165ff52 Constant expression evaluation: refactor to start the groundwork for coping with
initializations which refer indirectly to elements of the object being
initialized.

llvm-svn: 143680
2011-11-04 05:33:44 +00:00
Richard Smith 96e0c101fe Constant expression evaluation: track the manner in which an lvalue was written,
to allow us to implement the C++11 rule that a non-active union member can't be
read, and use it to implement subobject access for string literals.

llvm-svn: 143677
2011-11-04 02:25:55 +00:00
Richard Smith e9e20dd302 Constant expression evaluation: although we don't know whether a literal will
be at the same address as another object, we do know it won't alias a null
pointer.

llvm-svn: 143674
2011-11-04 01:10:57 +00:00
Richard Trieu 364ee42ee8 In the AST dump, add a space between the type and value for CharacterLiteral.
llvm-svn: 143667
2011-11-03 23:56:23 +00:00
Douglas Gregor 3c2404b31b Teach the ASTImporter to import DefinitionData bits.
llvm-svn: 143631
2011-11-03 18:07:07 +00:00
Douglas Gregor 2e10cf9620 Add a printing policy flag to suppress printing "<anonymous>::" prior
to types. Enable this flag for code completion, where knowing whether
something is in an anonymous or inline namespace is actually not
useful, since you don't have to type it anyway. Fixes
<rdar://problem/10208818>.

llvm-svn: 143599
2011-11-03 00:16:13 +00:00
Douglas Gregor 07216d174e Fix various minor issues find via unreachable code warnings, from
Ahmed Charles!

llvm-svn: 143569
2011-11-02 20:52:01 +00:00
Douglas Gregor 9d0eb8f929 Use StringLiteral::getBytes(), not StringLiteral::getString(), when profiling the expression, so that it works for non-UTF8 strings.
llvm-svn: 143550
2011-11-02 17:26:05 +00:00
Richard Smith cecf184e64 When constant-folding, don't look at the initializer of a global const variable
if it's marked as weak: that definition may not end up being used.

llvm-svn: 143496
2011-11-01 21:06:14 +00:00
Richard Smith 1f1f2d8ca3 Temporarily disable lvalue-to-rvalue conversions on const pointers while an
apparent miscompile triggered by this is investigated. This is essentially a
revert of r143298.

llvm-svn: 143491
2011-11-01 20:38:59 +00:00
Argyrios Kyrtzidis b9689bb46f [libclang] For a class extension, give it a unique USR but for any property or ivar
it contains give it a USR based on its semantic context, which is the interface.

This follows what we already did for objc methods. rdar://10371669

llvm-svn: 143464
2011-11-01 17:14:12 +00:00
Richard Smith fec0992aca Implement C++11 'constexpr calls must return constant expressions' rule, and
perform the code simplifications this rule allows.

llvm-svn: 143463
2011-11-01 16:57:24 +00:00
Eli Friedman fcec630a57 Fix the representation of wide strings in the AST and IR so that it uses the native representation of integers for the elements. This fixes a bunch of nastiness involving
treating wide strings as a series of bytes.

Patch by Seth Cantrell.

llvm-svn: 143417
2011-11-01 02:23:42 +00:00
Douglas Gregor d73f3ddb44 Rework the AST for the initializer of a delegating constructor, so
that it retains source location information for the type. Aside from
general goodness (being able to walk the types described in that
information), we now have a proper representation for dependent
delegating constructors. Fixes PR10457 (for real).

llvm-svn: 143410
2011-11-01 01:16:03 +00:00
Eli Friedman 42fbd62d92 Some minor comment changes in constant-folding comparisons.
llvm-svn: 143391
2011-10-31 22:54:30 +00:00
Eli Friedman c6be94b3de Don't try to fold comparisons between the address of an object and an arbitrary integer constant. Fixes regression from r143334.
llvm-svn: 143374
2011-10-31 22:28:05 +00:00
Richard Smith dd78544d44 Refactoring and test for r143360. Support for array rvalue to pointer decay is
needed for C++11, and will follow later.

llvm-svn: 143363
2011-10-31 20:57:44 +00:00
Richard Smith fdc6a5956a Temporary fix for assert while evaluating array-to-pointer decay on array
rvalue. Test and better fix to follow.

llvm-svn: 143360
2011-10-31 20:20:33 +00:00
Richard Smith 4e4c78ffff C++11 generalized constant expression handling: evaluation support for
materialized temporaries.

llvm-svn: 143335
2011-10-31 05:52:43 +00:00
Richard Smith 83c682115b C++11 generalized constant expressions: evaluate equality comparisons between
arbitrary pointers, if those pointers don't point to weak objects or literals.

llvm-svn: 143334
2011-10-31 05:11:32 +00:00
Richard Smith 8b3497ee54 C++11 generalized constant expressions: support pointer comparisons where the
result is not unspecified.

llvm-svn: 143329
2011-10-31 01:37:14 +00:00
Richard Smith 390cd49906 Fix assert on constant expression evaluation of floating point increment.
llvm-svn: 143320
2011-10-30 23:17:09 +00:00
Jim Goodnow II 921b9f52f4 Fixed CXX struct and class initialization printing to support 'move'
type constructors.

llvm-svn: 143309
2011-10-30 11:17:39 +00:00
Richard Smith 9c8d1c5c64 Don't crash if a GCC binary conditional is used in a constant expression on an
integer-cast pointer value.

llvm-svn: 143299
2011-10-29 22:55:55 +00:00
Richard Smith 35a1f85466 constexpr evaluation: allow lvalue-to-rvalue conversion on any literal type, not
just integers and floating point types. Since we don't support evaluating class
types or performing lvalue-to-rvalue conversions on array elements yet, this
just means pointer types right now.

llvm-svn: 143298
2011-10-29 21:53:17 +00:00
Richard Smith 0b0a0b6174 constexpr function substitution:
Track the function invocation where an lvalue referring to a constexpr function
parameter originated from, and use it to substitute the correct argument and to
determine whether such an argument's lifetime has ended.

llvm-svn: 143296
2011-10-29 20:57:55 +00:00
Richard Smith 7b553f1b19 Rename Expr::Evaluate to Expr::EvaluateAsRValue to make it clear that it will
implicitly perform an lvalue-to-rvalue conversion if used on an lvalue
expression. Also improve the documentation of Expr::Evaluate* to indicate which
of them will accept expressions with side-effects.

llvm-svn: 143263
2011-10-29 00:50:52 +00:00
Richard Smith 472d495372 Fix assertion in constant expression evaluation. The LHS of a floating-point
binary operator isn't an rvalue if it's an assignment operator.

llvm-svn: 143250
2011-10-28 23:26:52 +00:00
Richard Smith 254a73d636 Initial support for C++11 constexpr function invocation substitution. Using
constexpr function arguments outside of their function (passing or returning
them by reference) does not work correctly yet.

Calling constexpr function templates does not work yet, since the bodies are not
instantiated until the end of the translation unit.

llvm-svn: 143234
2011-10-28 22:34:42 +00:00
Richard Smith 11562c5e10 Reinstate r142844 (reverted in r142872) now that lvalue-to-rvalue conversions
are present in all the necessary places:

In constant expression evaluation, evaluate lvalues as lvalues and rvalues as
rvalues. Remove special case for caching reference initialization and fix a
cyclic initialization crash in the process.

llvm-svn: 143204
2011-10-28 17:51:58 +00:00
Hans Wennborg 27541dbe1a Teach format string analysis that "%zu" means size_t.
The code had it backwards, thinking size_t was signed, and using that for "%zd".

Also let the analysis get the types for (u)intmax_t while we are at it.

llvm-svn: 143099
2011-10-27 08:29:09 +00:00
Eli Friedman 3f37c1ce4c Correctly perform integral promotions on wchar_t/char16_t/char32_t in C++. <rdar://problem/10309088>.
llvm-svn: 143019
2011-10-26 07:22:48 +00:00
John McCall 526ab47a55 Restore r142914 and r142915, now with missing file and apparent
GCC compiler workaround.

llvm-svn: 142931
2011-10-25 17:37:35 +00:00
NAKAMURA Takumi 9a8f13961c Revert r142914 and r142915, due to possibly missing file.
r142914: "Introduce a placeholder type for "pseudo object""
r142915: "Pull the pseudo-object stuff into its own file."
llvm-svn: 142921
2011-10-25 14:32:25 +00:00
John McCall c4a2d3259f Introduce a placeholder type for "pseudo object"
expressions: expressions which refer to a logical rather
than a physical l-value, where the logical object is
actually accessed via custom getter/setter code.
A subsequent patch will generalize the AST for these
so that arbitrary "implementing" sub-expressions can
be provided.

Right now the only client is ObjC properties, but
this should be generalizable to similar language
features, e.g. Managed C++'s __property methods.

llvm-svn: 142914
2011-10-25 07:27:56 +00:00
Ted Kremenek 7b2fbc61de Relax restriction of assigning to 'self' in ARC when a method is attributed with ns_consumes_self. Fixes <rdar://problem/10274056>.
llvm-svn: 142909
2011-10-25 04:52:20 +00:00
Douglas Gregor deb4a2be67 Implement support for dependent Microsoft __if_exists/__if_not_exists
statements. As noted in the documentation for the AST node, the
semantics of __if_exists/__if_not_exists are somewhat different from
the way Visual C++ implements them, because our parsed-template
representation can't accommodate VC++ semantics without serious
contortions. Hopefully this implementation is "good enough".

llvm-svn: 142901
2011-10-25 01:33:02 +00:00
Richard Smith 2d7bb04788 Clean up, as suggested by John.
llvm-svn: 142884
2011-10-25 00:21:54 +00:00
Richard Smith 733237db23 Revert r142844, it broke selfhost. The problem appears to be a missing
lvalue-to-rvalue conversion on the LHS operand of '->'.

llvm-svn: 142872
2011-10-24 23:14:33 +00:00
Richard Smith 62f6595122 Add explanatory comments for ICE checking in C99 mode.
llvm-svn: 142866
2011-10-24 22:35:48 +00:00
Richard Smith cbb407268e Constant expression evaluation: evaluate lvalues as lvalues, and rvalues as
rvalues, as C++11 constant evaluation semantics require. DeclRefs referring to
references can now use the normal initialization-caching codepath, which
incidentally fixes a crash in cyclic initialization of references.

llvm-svn: 142844
2011-10-24 21:07:08 +00:00
Richard Smith 4a6781215e Constant expression evaluation: factor out handling of ignored values.
llvm-svn: 142835
2011-10-24 18:44:57 +00:00
Richard Smith c3e31e7bb2 In accordance with the C89, C99 and C++98 standards, ICEs can only contain
floating-point literals if they are the immediate operands of casts.
ImplicitCastExpr is not a cast in the language-standards sense.

llvm-svn: 142832
2011-10-24 18:26:35 +00:00
Richard Smith 2790870de0 Constant expression evaluation: factor out VarDecl initializer evaluation and
caching.

llvm-svn: 142812
2011-10-24 17:54:18 +00:00
Richard Smith 2d4063412c Refactor vector constant expression evaluation to return bool like all the other
const expression evaluation subclasses, and remove some APValue copying and
malloc traffic in the process.

llvm-svn: 142733
2011-10-22 21:10:00 +00:00
Argyrios Kyrtzidis d4590a5d5f Don't try to set the "array filler" in a InitListExpr twice.
llvm-svn: 142695
2011-10-21 23:02:22 +00:00
Eli Friedman 43114f9084 More ASTRecordLayout changes for MS ABI; based on patch by r4start.
llvm-svn: 142694
2011-10-21 22:49:56 +00:00
Sean Callanan 95e74be193 I added a new function to DeclContext called
addDeclInternal().  This function suppresses any
calls to FindExternalVisibleDeclsByName() while
a Decl is added to a DeclContext.  This behavior
is required for the ASTImporter, because in the
case of the LLDB client the ASTImporter would be
called recursively to import the visible decls,
which leads to assertions because the recursive
call is seeing partially-formed types.

I also modified the ASTImporter to use
addDeclInternal() in all places where it would
otherwise use addDecl().  This fix should not
affect the rest of Clang, passes Clang's
testsuite, and fixes several serious LLDB bugs.

llvm-svn: 142634
2011-10-21 02:57:43 +00:00
Argyrios Kyrtzidis 4e8b13613b Don't forget to complete the objc interface before asking for information,
otherwise lldb will suffer.

llvm-svn: 142471
2011-10-19 02:25:16 +00:00
John McCall e314e27c58 Macro metaprogramming for builtin types.
llvm-svn: 142420
2011-10-18 21:02:43 +00:00
Richard Smith aed32b4d8c Simplify RecordDeclCXX::setBases slightly. No functional change.
Add test that a variadic base list which expands to 0 bases doesn't make the
class a non-aggregate. This test passed before the change, too.

llvm-svn: 142411
2011-10-18 20:08:55 +00:00
Eli Friedman 66005df1f1 Revert accidental commit.
llvm-svn: 142326
2011-10-18 01:18:41 +00:00
Eli Friedman 5e9534b0ae Rewrite parts of MS ABI C++ layout. Based on work by r4start; I ended up doing this while I was trying to review his patch.
llvm-svn: 142325
2011-10-18 00:55:28 +00:00
Eli Friedman a4c2602b71 Initial implementation of __atomic_is_lock_free. The input is the size of an atomic type rather than an atomic type itself just to save some implementation pain; I can change that if it seems worthwhile.
I think this is the last hook needed for <atomic> besides defines for ATOMIC_CHAR_LOCK_FREE and friends.

llvm-svn: 142281
2011-10-17 21:44:23 +00:00
Argyrios Kyrtzidis bd8b150dfc Introduce ASTConsumer::HandleTopLevelDeclInObjCContainer which accepts
top-level declarations that occurred inside an ObjC container.

This is useful to keep track of such decls otherwise when e.g. a function
is declared inside an objc interface, it is not passed to HandleTopLevelDecl
and it is not inside the DeclContext of the interface that is returned.

llvm-svn: 142232
2011-10-17 19:48:13 +00:00
Argyrios Kyrtzidis 690dccd9d4 Have ObjCMethodDecl::getCanonicalDecl take into account redeclared methods.
llvm-svn: 142231
2011-10-17 19:48:09 +00:00
Argyrios Kyrtzidis 1f4bee5601 Keep track when a ObjC interface/protocol was initially created as a forward reference.
llvm-svn: 142230
2011-10-17 19:48:06 +00:00
John McCall 8a6b59ad97 Add a new placeholder type to represent "unbridged"
casts in ARC.

No semantic analysis yet.

llvm-svn: 142208
2011-10-17 18:09:15 +00:00
Richard Smith 725810a2bb Split apart the state accumulated during constant expression evaluation and the
end result. Use this split to propagate state information and diagnostics
through more of constant expression evaluation.

llvm-svn: 142159
2011-10-16 21:26:27 +00:00
Douglas Gregor 9e0a5b3900 Teach the ASTImporter to perform DeclContext lookups in a way that
avoids loading data from an external source, since those lookups were
causing some "interesting" recursion in LLDB.

This code is not efficient. I plan to remedy this inefficiency in a
follow-up commit.

llvm-svn: 142023
2011-10-15 00:10:27 +00:00
Anton Korobeynikov f0c267e6e0 Provide half floating point support as a storage only type.
Lack of half FP was a regression compared to llvm-gcc.

llvm-svn: 142016
2011-10-14 23:23:15 +00:00
Eli Friedman 8d3e43ff4a Add template instantiation support for AtomicExpr.
llvm-svn: 142012
2011-10-14 22:48:56 +00:00
Douglas Gregor 03d1ed304b Teach the ASTImporter not to import redundant fields.
llvm-svn: 142009
2011-10-14 21:54:42 +00:00
Eli Friedman 4b72fddd99 Misc fixes for atomics. Biggest fix is doing alignment correctly for _Atomic types.
llvm-svn: 142002
2011-10-14 20:59:01 +00:00
Benjamin Kramer b89514a9b8 Change operator<< for raw_ostream and NamedDecl to take a reference instead of a pointer.
Passing a pointer was a bad idea as it collides with the overload for void*.

llvm-svn: 141971
2011-10-14 18:45:37 +00:00
Argyrios Kyrtzidis db21596473 [PCH] Serialize info about redeclared objc methods.
llvm-svn: 141964
2011-10-14 17:41:52 +00:00
Argyrios Kyrtzidis dcaaa21fbe Really protect from infinite loop when there are objc method redeclarations.
Serialization part will come later.

llvm-svn: 141950
2011-10-14 08:02:31 +00:00
Argyrios Kyrtzidis c5e829cad2 Keep track of objc method redeclarations in the same interface.
Avoid possible infinite loop when iterating over an ObjCMethod's redeclarations.

llvm-svn: 141946
2011-10-14 06:48:06 +00:00
Rafael Espindola 2d21ab024e Add returns_twice to functions that are known to return twice. This implements
the same behavior of gcc by keeping the attribute out of the function type.

llvm-svn: 141803
2011-10-12 19:51:18 +00:00
Richard Smith fd53aaf7e7 constexpr: don't consider class types with mutable members to be literal types.
The standard doesn't allow this, but mutable constexpr variables break the
semantics so badly that we can't reasonably accept them.

llvm-svn: 141768
2011-10-12 05:08:15 +00:00
Eli Friedman 94ab9308d7 PR11062: Make C99 inlining work properly for names with associated builtin libcalls.
llvm-svn: 141723
2011-10-11 22:09:24 +00:00
Richard Smith 4ce706afc4 Constant expression evaluation: refactor value initialization and scalar list initialization into base class.
llvm-svn: 141717
2011-10-11 21:43:33 +00:00
Eli Friedman c2025567f5 Silence some -Wuninitialized false positives with gcc.
llvm-svn: 141701
2011-10-11 20:00:47 +00:00
Eli Friedman df14b3a837 Initial implementation of __atomic_* (everything except __atomic_is_lock_free).
llvm-svn: 141632
2011-10-11 02:20:01 +00:00
Eli Friedman ce3e02a343 Extend lvalue evaluation in ExprConstant.cpp to handle CK_LValueBitCast (which is completely trivial). PR8836.
llvm-svn: 141604
2011-10-11 00:13:24 +00:00
Richard Smith caf3390d44 Constant expression evaluation refactoring:
- Remodel Expr::EvaluateAsInt to behave like the other EvaluateAs* functions,
   and add Expr::EvaluateKnownConstInt to capture the current fold-or-assert
   behaviour.
 - Factor out evaluation of bitfield bit widths.
 - Fix a few places which would evaluate an expression twice: once to determine
   whether it is a constant expression, then again to get the value.

llvm-svn: 141561
2011-10-10 18:28:20 +00:00
Douglas Gregor 556e5860f9 Per C++ [class.bit]p2, unnamed bit-fields are not members. Fixes PR10289.
llvm-svn: 141549
2011-10-10 17:22:13 +00:00
Benjamin Kramer 138ef9ca4a Another case of HadMultipleCandidates being used uninitialized.
llvm-svn: 141532
2011-10-10 12:54:05 +00:00
Argyrios Kyrtzidis 094da739e0 In DeclContext::LoadLexicalDeclsFromExternalStorage don't clear out
the fields if they are already loaded, just ignore them when we are building
the chain in BuildDeclChain.

This fixes an lldb issue where fields were removed and not getting re-added
because lldb is based on ASTImporter adding decls to DeclContext and fields
were already added before by the ASTImporter.

We should really simplify the interaction between DeclContext <-> lldb
going forward..

rdar://10246067

llvm-svn: 141418
2011-10-07 21:55:43 +00:00
John McCall f937c023bf Rename TagDecl::isDefinition -> isCompleteDefinition
for better self-documenting code, since the semantics
are subtly different from getDefinition().

llvm-svn: 141355
2011-10-07 06:10:15 +00:00
John McCall 0710e551ef Record layout requires not just a definition, but a complete
definition.  Assert this.  Change IR generation to not try to
aggressively emit the IR translation of a record during its
own definition.  Fixes PR10912.

llvm-svn: 141350
2011-10-07 02:39:22 +00:00
Eli Friedman 0dfb889575 Support for C1x _Atomic specifier (see testcase). This is primarily being committed at the moment to help support C++0x <atomic>, but it should be a solid base for implementing the full specification of C1x _Atomic.
Thanks to Jeffrey Yasskin for the thorough review!

llvm-svn: 141330
2011-10-06 23:00:33 +00:00
Ted Kremenek 540017e54e Use a sidetable in ASTContext for ParmVarDecls whose index exceeds the 8 bits reserved for that value in VarDecl. Fixes PR 10538.
llvm-svn: 141273
2011-10-06 05:00:56 +00:00
Argyrios Kyrtzidis a7324ede34 Fix crash when using archaic protocol, rdar://10238337
llvm-svn: 141215
2011-10-05 21:28:06 +00:00
Daniel Dunbar 096ed290a1 Driver & AST: Implement support for -fpack-struct and -fpack-struct= command
line options.
 - <rdar://problem/10120602>, PR9631

llvm-svn: 141211
2011-10-05 21:04:55 +00:00
Eli Friedman 533920650b Use APFloat::toString to print APFloats more precisely in the AST printer. Patch by Olaf Krzikalla.
llvm-svn: 141208
2011-10-05 20:32:03 +00:00
Abramo Bagnara 635ed24e1d Added a flag to identify resolved overloaded function references.
llvm-svn: 141171
2011-10-05 07:56:41 +00:00
Eric Christopher 8a39a01a10 Fix doxygen comment.
llvm-svn: 141165
2011-10-05 06:00:51 +00:00
Fariborz Jahanian 48c69106e4 c: assignment/init of a function pointer whose function(s)
return to one which does not return (has noreturn attribute) 
should warn as it is an unsafe assignment. // rdar://10095762
c++ already handles this. This is the c version.

llvm-svn: 141141
2011-10-05 00:05:34 +00:00
Argyrios Kyrtzidis 52f53fb303 Improve location fidelity of objc decls.
-Add the location of the class name to all objc container decls, not just ObjCInterfaceDecl.
-Make objc decls consistent with the rest of the NamedDecls and have getLocation() point to the
 class name, not the location of '@'.

llvm-svn: 141061
2011-10-04 04:48:02 +00:00
Abramo Bagnara fd3a455ac7 Fixed source range for template implicit instantiations.
llvm-svn: 141018
2011-10-03 20:34:03 +00:00
Argyrios Kyrtzidis b8c3aaf479 Allow getting all source locations of selector identifiers in a ObjCMethodDecl.
Instead of always storing all source locations for the selector identifiers
we check whether all the identifiers are in a "standard" position; "standard" position is

  -Immediately before the arguments: -(id)first:(int)x second:(int)y;
  -With a space between the arguments: -(id)first: (int)x second: (int)y;
  -For nullary selectors, immediately before ';': -(void)release;

In such cases we infer the locations instead of storing them.

llvm-svn: 140989
2011-10-03 06:37:04 +00:00
Argyrios Kyrtzidis b98e3714f2 Move field in ObjCMessageExpr to avoid padding.
llvm-svn: 140988
2011-10-03 06:36:55 +00:00
Argyrios Kyrtzidis a6011e25a1 Allow getting all source locations of selector identifiers in a ObjCMessageExpr.
Instead of always storing all source locations for the selector identifiers
we check whether all the identifiers are in a "standard" position; "standard" position is

  -Immediately before the arguments: [foo first:1 second:2]
  -With a space between the arguments: [foo first: 1 second: 2]
  -For nullary selectors, immediately before ']': [foo release]

In such cases we infer the locations instead of storing them.

llvm-svn: 140987
2011-10-03 06:36:51 +00:00
Argyrios Kyrtzidis 59ad1e3f57 ArrayRef'ize ObjCMessageExpr
llvm-svn: 140986
2011-10-03 06:36:45 +00:00
Argyrios Kyrtzidis dc1244386f Add an assertion that we don't overflow the bitfield ObjCMessageExpr::NumArgs.
llvm-svn: 140985
2011-10-03 06:36:40 +00:00
Argyrios Kyrtzidis dfd6570643 Pass from the parser the locations of selector identifiers when creating
objc method decls.

They are not stored in the AST yet.

llvm-svn: 140984
2011-10-03 06:36:36 +00:00
Argyrios Kyrtzidis 3849394b81 Don't keep NumSelectorArgs in the ObjCMethodDecl, the number can be derived from the selector.
llvm-svn: 140983
2011-10-03 06:36:29 +00:00
Argyrios Kyrtzidis f934ec8b7b Pass all the locations of the selector identifiers for a message expression from the parser.
They are not kept in the AST yet.

llvm-svn: 140982
2011-10-03 06:36:17 +00:00
Richard Smith eb3c10c248 constexpr: semantic checking for constexpr functions and constructors. Based in
part on patches by Peter Collingbourne.

We diverge from the C++11 standard in a few areas, mostly related to checking
constexpr function declarations, and not just definitions. See WG21 paper
N3308=11-0078 for details.

Function invocation substitution is not available in this patch; constexpr
functions cannot yet be used from within constant expressions.

llvm-svn: 140926
2011-10-01 02:31:28 +00:00
Richard Smith befa6f0caa Fix typo.
llvm-svn: 140829
2011-09-30 00:35:43 +00:00
Eli Friedman 76d4e43063 PR11040: CheckICE should not allow an lvalue bitcast as part of an integer constant expression.
llvm-svn: 140812
2011-09-29 21:49:34 +00:00
Peter Collingbourne 2f3cf4b158 Add support for alignment-specifiers in C1X and C++11, remove
support for the C++0x draft [[align]] attribute and add the C1X
standard header file stdalign.h

llvm-svn: 140796
2011-09-29 18:04:28 +00:00
Fariborz Jahanian 97676979a7 objc arc: Diagnose block pointer type mismatch when
some arguments types are ns_consumed and some otherwise
matching types are not. This is objc side of
// rdar://10187884

llvm-svn: 140729
2011-09-28 21:52:05 +00:00
Argyrios Kyrtzidis 0ce4c9ab55 Introduce Decl::getParentFunctionOrMethod which if the decl is defined inside
a function/method/block it returns the corresponding DeclContext, otherwise it returns null.

llvm-svn: 140672
2011-09-28 02:45:33 +00:00
Douglas Gregor 75acd925d0 Only print _Bool as 'bool' when 'bool' is defined as an object-like
macro whose only replacement token is '_Bool'.

llvm-svn: 140656
2011-09-27 23:30:47 +00:00
Douglas Gregor c0b07286cf When 'bool' is not a built-in type but is defined as a macro, print
'bool' rather than '_Bool' within types, to make things a bit more
readable. Fixes <rdar://problem/10063263>.

llvm-svn: 140650
2011-09-27 22:38:19 +00:00
Eli Friedman 84d2d3a90e Some changes to improve compatibility for MSVC-style C++ struct layout. Patch from r4start at gmail.com (with some minor modifications by me).
llvm-svn: 140623
2011-09-27 19:12:27 +00:00
Peter Collingbourne fec95198aa Constant evaluation for pointer CXXScalarValueInitExpr
llvm-svn: 140613
2011-09-27 17:33:05 +00:00
Argyrios Kyrtzidis 81c0b5c200 Fix assertion hit when @encoding C++ classes. rdar://10172840 & http://llvm.org/PR10990
llvm-svn: 140542
2011-09-26 18:14:24 +00:00
Douglas Gregor 488c231183 Re-arrange and bitfieldify data members of CXXConstructExpr to save a
little storage.

llvm-svn: 140529
2011-09-26 14:47:03 +00:00
Peter Collingbourne cfd2356180 Move VTable builder to AST
llvm-svn: 140510
2011-09-26 01:57:12 +00:00
Peter Collingbourne 2d2595235d Move VTT builder to AST
llvm-svn: 140501
2011-09-26 01:56:24 +00:00
David Blaikie 9c902b5502 Rename Diagnostic to DiagnosticsEngine as per issue 5397
llvm-svn: 140478
2011-09-25 23:23:43 +00:00
Sebastian Redl 12757ab4cb Treat list-initialization of scalars as a first-class citizen in C++11.
Allow empty initializer lists for scalars, which mean value-initialization.
Constant evaluation for single-element and empty initializer lists for scalars.
Codegen for empty initializer lists for scalars.
Test case comes in next commit.

llvm-svn: 140459
2011-09-24 17:48:14 +00:00
David Blaikie aa347f9392 Removing a bunch of dead returns/breaks after llvm_unreachables.
llvm-svn: 140407
2011-09-23 20:26:49 +00:00
Fariborz Jahanian c367b8f8cc objc-gc: Fix a corner case where clang fails to generate GC
write barrier with captured pointer to object. // rdar://10150823

llvm-svn: 140399
2011-09-23 18:57:30 +00:00
David Blaikie 76bd3c80d4 Fix missing includes for llvm_unreachable
llvm-svn: 140368
2011-09-23 05:35:21 +00:00
David Blaikie 83d382b1ca Switch assert(0/false) llvm_unreachable.
llvm-svn: 140367
2011-09-23 05:06:16 +00:00
Argyrios Kyrtzidis e9a24435c6 Don't use TemplateArgumentListInfo inside AST nodes because it may leak.
Use ASTTemplateArgumentListInfo instead.

llvm-svn: 140331
2011-09-22 20:07:09 +00:00
Argyrios Kyrtzidis de6aa08013 Rename ExplicitTemplateArgumentList -> ASTTemplateArgumentListInfo, no functionality change.
llvm-svn: 140330
2011-09-22 20:07:03 +00:00
Douglas Gregor da9740061b Fix the ASTImporter's lookup for anonymous structs/unions that get a
linkage name via typedef. Patch from/fixes PR10958.

llvm-svn: 140317
2011-09-22 17:51:56 +00:00
David Blaikie 9c70e04bec ArrayRef-ifying Function/BlockDecl's setParams
llvm-svn: 140268
2011-09-21 18:16:56 +00:00
Peter Collingbourne 9a8f1534d9 Remove redundant break statements, and replace asserts with llvm_unreachable
Per John's review comments for r140068.

llvm-svn: 140142
2011-09-20 12:40:26 +00:00
Peter Collingbourne 2dbb708b8a OpenCL: introduce support for function scope __local variables
llvm-svn: 140068
2011-09-19 21:14:35 +00:00
Argyrios Kyrtzidis e6e67deeed Rename SourceLocation::getFileLocWithOffset -> getLocWithOffset.
It already works (and is useful with) macro locs as well.

llvm-svn: 140057
2011-09-19 20:40:19 +00:00
Matt Beaumont-Gay dcaacaa190 Fix a QoI bug with overloaded operators inside macros.
We were failing to set source locations and ranges in isUnusedResultAWarning
for CXXOperatorCallExprs, leading to an "expression result unused" warning
with absolutely no context if the expression was inside a macro.

llvm-svn: 140036
2011-09-19 18:51:20 +00:00
John McCall e3ca8eb049 In general, don't look through explicit casts when trying
to find the called declaration.  Explicit casts can radically
change the semantics of a call, and it's no longer really a
builtin call any more than it would be a builtin call if you stored
the function pointer into a variable and called that.

llvm-svn: 139659
2011-09-13 23:08:34 +00:00
Argyrios Kyrtzidis a98e861939 [PCH] Fix a regression that r139441 introduced (decls were getting passed
to the consumer without being fully deserialized).

The regression was on compiling boost.python and it was too difficult to get a reduced
test case unfortunately.

Also modify the logic of how objc methods are getting passed to the consumer;
codegen depended on receiving objc methods before the implementation decl.
Since the interesting objc methods are ones with a body and such methods only
exist inside an ObjCImplDecl, deserialize and pass to consumer all the methods
of ObCImplDecl when we see one.

Fixes http://llvm.org/PR10922 & rdar://10117105.

llvm-svn: 139644
2011-09-13 21:35:00 +00:00
Douglas Gregor 79a91418bd Switch LangOptions over to a .def file that describes header of the
language options. Use that .def file to declare the LangOptions class
and initialize all of its members, eliminating a source of annoying
initialization bugs.

AST serialization changes are next up.

llvm-svn: 139605
2011-09-13 17:21:33 +00:00
John McCall 2d637d2e79 Rename the ARC cast kinds to start with "ARC".
llvm-svn: 139466
2011-09-10 06:18:15 +00:00
Richard Trieu 7fde916498 Fix a broken assert in AST/DeclCXX.cpp.
llvm-svn: 139461
2011-09-10 02:16:48 +00:00
John McCall cd78e805e9 When converting a block pointer to an Objective-C pointer type, extend
the lifetime of the block by copying it to the heap, or else we'll get
a dangling reference because the code working with the non-block-typed
object will not know it needs to copy.

There is some danger here, e.g. with assigning a block literal to an
unsafe variable, but, well, it's an unsafe variable.

llvm-svn: 139451
2011-09-10 01:16:55 +00:00
Douglas Gregor 87d8124b0e Clean up our handling of Objective-C definitions in AST files. Rather
than having CodeGen check whether a declaration comes from an AST file
(which it shouldn't know or care about), make sure that the AST writer and
reader pass along "interesting" declarations that CodeGen needs to
know about.

llvm-svn: 139441
2011-09-10 00:22:34 +00:00
Chandler Carruth a626d645d5 Extend the Stmt AST to make it easier to look through label, default,
and case statements. Use this to make the logic in the CFG builder more
robust at finding the actual statements within a compound statement,
even when there are many layers of labels obscuring it.

Also extend the test cases for a large chunk of PR10063. Still more work
to do here though.

llvm-svn: 139437
2011-09-10 00:02:34 +00:00
Argyrios Kyrtzidis 94d3f9dcd0 Use ArrayRef in ExternalASTSource::SetExternalVisibleDeclsForName.
llvm-svn: 139357
2011-09-09 06:44:14 +00:00
John McCall 9320b87cff Give conversions of block pointers to ObjC pointers a different cast kind
than conversions of C pointers to ObjC pointers.  In order to ensure that
we've caught every case, add asserts to CastExpr that strictly determine
which cast kind is used for which kind of bit cast.

llvm-svn: 139352
2011-09-09 05:25:32 +00:00
Douglas Gregor 26701a4371 Modules: introduce the __module_private__ declaration specifier, which
indicates that a declaration is only visible within the module it is
declared in.

llvm-svn: 139348
2011-09-09 02:06:17 +00:00
Douglas Gregor 6a40b088e9 Look through SubstNonTypeTemplateParmExpr nodes in the various
Expr::Ignore* methods that also look through implicit casts.

llvm-svn: 139303
2011-09-08 17:56:33 +00:00
Caitlin Sadowski 990d571226 Thread safety: added support for function scopes in attribute arguments.
This patch was written by DeLesley Hutchins.

llvm-svn: 139302
2011-09-08 17:42:31 +00:00
Douglas Gregor 8b7d403684 Allow C++0x enumerations with a fixed underlying type in
Objective-C. The @encode'ing of such an enumeration type is the same
as its underlying type. <rdar://problem/5276348>.

llvm-svn: 139297
2011-09-08 17:18:35 +00:00
Douglas Gregor bab8a96f2f Implement the Objective-C 'instancetype' type, which is an alias of
'id' that can be used (only!) via a contextual keyword as the result
type of an Objective-C message send. 'instancetype' then gives the
method a related result type, which we have already been inferring for
a variety of methods (new, alloc, init, self, retain). Addresses
<rdar://problem/9267640>.

llvm-svn: 139275
2011-09-08 01:46:34 +00:00
Douglas Gregor e0e9630e07 When extracting the callee declaration from a call expression, be sure
to look through SubstNonTypeTemplateParmExprs. Then, update the IR
generation of CallExprs to actually use CallExpr::getCalleeDecl()
rather than attempting to mimick its behavior (badly).

Fixes <rdar://problem/10063539>.

llvm-svn: 139185
2011-09-06 21:41:04 +00:00
Ted Kremenek fed48af3de Don't emit -Wpadded warnings without a valid SourceLocation. This can happen when RecordLayoutBuilder is used by Codegen, not Sema.
llvm-svn: 139162
2011-09-06 19:40:45 +00:00
Richard Smith a528507418 Implement the suggested resolution of WG21 N3307 issue 19: When determining whether a class is an aggregate in C++0x, treat all functions which are neither deleted nor defaulted as user-provided, not just special member functions. The wording of the standard only defines the term "user-provided" for special member functions, but the intent seems to be that any function can be user-provided.
llvm-svn: 139111
2011-09-05 02:13:09 +00:00
Eli Friedman 29538899ef Make StmtDumper::VisitCXXFunctionalCastExpr dump the attached cast kind. Fix the cast kind for a cast from floating-point to enum type. (The difference isn't actually visible, but that's just because IRGen is overly forgiving.) Per report by Enea Zaffanella on cfe-dev.
llvm-svn: 139011
2011-09-02 17:38:59 +00:00
Douglas Gregor e8bbc12152 Extend the ASTContext constructor to delay the initialization of
builtin types (When requested). This is another step toward making
ASTUnit build the ASTContext as needed when loading an AST file,
rather than doing so after the fact. No actual functionality change (yet).

llvm-svn: 138985
2011-09-02 00:18:52 +00:00
Douglas Gregor 7018d5bcfb Teach ASTContext and Preprocessor to hold on to references to the same
LangOptions, rather than making distinct copies of
LangOptions. Granted, LangOptions doesn't actually get modified, but
this will eventually make it easier to construct ASTContext and
Preprocessor before we know all of the LangOptions.

llvm-svn: 138959
2011-09-01 20:23:19 +00:00
Argyrios Kyrtzidis 7d847c9fd8 Support importing of ObjC categories from modules.
The initial incentive was to fix a crash when PCH chaining categories
to an interface, but the fix was done in the "modules way" that I hear
is popular with the kids these days.

Each module stores the local chain of categories and we combine them
when the interface is loaded. We also warn if non-dependent modules
introduce duplicate named categories.

llvm-svn: 138926
2011-09-01 00:58:55 +00:00
Chandler Carruth c841b6e598 Improve the diagnostic text for -Wmissing-noreturn to include the name
of the function in question when applicable (that is, not for blocks).
Patch by Joerg Sonnenberger with some stylistic tweaks by me.

When discussing this weth Joerg, streaming the decl directly into the
diagnostic didn't work because we have a pointer-to-const, and the
overload doesn't accept such. In order to make my style tweaks to the
patch, I first changed the overload to accept a pointer-to-const, and
then changed the diagnostic printing layer to also use
a pointer-to-const, cleaning up a gross line of code along the way.

llvm-svn: 138854
2011-08-31 09:01:53 +00:00
Sebastian Redl 22653bac1a Declare and define implicit move constructor and assignment operator.
This makes the code duplication of implicit special member handling even worse,
but the cleanup will have to come later. For now, this works.
Follow-up with tests for explicit defaulting and enabling the __has_feature
flag to come.

llvm-svn: 138821
2011-08-30 19:58:05 +00:00
Argyrios Kyrtzidis 3a5094b18c Remove a few mutating ObjCCategoryDecl methods.
Remove
  -setClassInterface
  -setNextClassCategory
  -insertNextClassCategory

and combine them in the Create function.

llvm-svn: 138817
2011-08-30 19:43:26 +00:00
Nico Weber 1fb82667dd Warn on missing [super finalize] calls.
This matches gcc's logic. Second half of PR10661.

llvm-svn: 138730
2011-08-28 22:35:17 +00:00
Fariborz Jahanian 3a039e339f objective-c: Treat top-level objective-c declarations
, such as list of forward @class decls, in a DeclGroup
node. Deal with its consequence throught clang. This
is in preparation for more Sema work ahead. // rdar://8843851.
Feel free to reverse if it breaks something important
and I am unavailable.

llvm-svn: 138709
2011-08-27 20:50:59 +00:00
Douglas Gregor f337ae9477 When we're deserializing declarations lexically stored in a RecordDecl
after having already deserialized the fields, clear out the fields
first. This makes sure that we keep all of the declarations in the
lexical context (including those implicitly added by later
type-checking) within the same list. A test case for this behavior is
coming as part of another commit; testing for this problem in
isolation is a nightmare.

llvm-svn: 138661
2011-08-26 21:23:06 +00:00
Axel Naumann cb2c52f7ac From Vassil Vassilev: unnamed decls cannot be removed from the lookup map.
llvm-svn: 138631
2011-08-26 14:06:12 +00:00
Douglas Gregor 754ff8b622 Remove long-dead FIXME
llvm-svn: 138498
2011-08-24 22:09:40 +00:00
Douglas Gregor a3e59b49e7 Don't force the complete deserialization of the visible-declarations
table when serializing an AST file. This was a holdover from the days
before chained PCH, and is a complete waste of time and storage
now. It's a good thing it's useless, because I have no idea how I
would have implemented MaterializeVisibleDecls efficiently in the
presence of modules.

llvm-svn: 138496
2011-08-24 21:56:08 +00:00
Fariborz Jahanian 73952fc263 objc - fix up the builtin type for objc_assign_ivar.
// rdar://9362887.

llvm-svn: 138412
2011-08-23 23:33:09 +00:00
Chandler Carruth 41c6dcc734 Fix a crash-on-valid that has been here for a very long time:
const int &x = x;

This crashed by inifinetly recursing within the lvalue evaluation
routine. I've added a (somewhat) braindead way of preventing this
recursion. If folks have better suggestions for how to avoid it I'm all
ears.

That said, we have some work to do. This doesn't trigger a single
warning for uninitialized, self-initialized or otherwise completely
wrong code. In some senses, the crash was almost better.

llvm-svn: 138239
2011-08-22 17:24:56 +00:00
Argyrios Kyrtzidis c7e50c5cbd Fix a bug in objc @encoding of C++ classes.
llvm-svn: 138235
2011-08-22 16:03:14 +00:00
Chad Rosier 6fdf38bfbd Fix else style. No functionality change intended.
llvm-svn: 137896
2011-08-17 23:08:45 +00:00
Ted Kremenek 897af91e1a Fix incorrect code indentation and silence dead store warning due to idiomatic code.
llvm-svn: 137870
2011-08-17 21:09:35 +00:00
Argyrios Kyrtzidis 004df6e053 Mark objc methods that are implicitly declared for properties (not user-declared) as implicit.
This results in libclang ignoring such methods.

llvm-svn: 137852
2011-08-17 19:25:08 +00:00
Chandler Carruth 463394752b Whitelist operator== and operator!= as valid for unused value warnings,
even when overloaded and user-defined. These operators are both more
valuable to warn on (due to likely typos) and extremely unlikely to be
reasonable for use to trigger side-effects.

llvm-svn: 137823
2011-08-17 09:49:44 +00:00
Francois Pichet 09af8c36d1 Add serialization support for ClassScopeFunctionSpecializationDecl.
llvm-svn: 137799
2011-08-17 01:06:54 +00:00
Richard Smith a77a0a6bf2 Track in the AST whether a function is constexpr.
llvm-svn: 137653
2011-08-15 21:04:07 +00:00
Francois Pichet 5792825fb2 Fix typo.
llvm-svn: 137585
2011-08-14 14:28:49 +00:00
Francois Pichet 00c7e6ceb1 Implement function template specialization at class scope extension in Microsoft mode. A new AST node is introduced: ClassScopeFunctionSpecialization. This node holds a FunctionDecl that is not yet specialized; then during the class template instantiation the ClassScopeFunctionSpecialization will spawn the actual function specialization.
Example:
template <class T>
class A {
public:
  template <class U> void f(U p) {  }
  template <> void f(int p) {  } // <== class scope specialization
};

This extension is necessary to parse MSVC standard C++ headers, MFC and ATL code.
BTW, with this feature in, clang can parse (-fsyntax-only) all the MSVC 2010 standard header files without any error.

llvm-svn: 137573
2011-08-14 03:52:19 +00:00
Fariborz Jahanian 70a315c363 metadata generated by the compiler does not include the weak
attribute of a property. patch by Remy Demarest fixes it.

llvm-svn: 137509
2011-08-12 20:47:08 +00:00
Douglas Gregor 801c99d22d Switch the __int128_t and __uint128_t types over to predefined types
in the AST format, which are built lazily by the ASTContext when
requested.

llvm-svn: 137437
2011-08-12 06:49:56 +00:00
Douglas Gregor 52e02808c5 Switch the Objective-C 'SEL' type over to a predefined type in the
AST file format, lazily generating the actual declaration in
ASTContext as needed.

llvm-svn: 137434
2011-08-12 06:17:30 +00:00
Douglas Gregor 0a58618a09 Switch the Objective-C 'Class' type over to a predefined type in the
AST file format, lazily generating the actual declaration in
ASTContext as needed.

llvm-svn: 137431
2011-08-12 05:59:41 +00:00
Douglas Gregor 3ea7269b54 Move the creation of the predefined typedef for Objective-C's 'id'
type over into the AST context, then make that declaration a
predefined declaration in the AST format. This ensures that different
AST files will at least agree on the (global) declaration ID for 'id',
and eliminates one of the "special" types in the AST file format.

llvm-svn: 137429
2011-08-12 05:46:01 +00:00
Douglas Gregor 9767347b11 Encapsulate the Objective-C id/Class/SEL "redefinition" types in
ASTContext with accessors/mutators. The only functional change is that
the AST writer won't bother writing the id/Class/SEL redefinition type
if it hasn't been explicitly set; previously, it ended up being
written as a synonym for the built-in id/Class/SEL.

llvm-svn: 137349
2011-08-11 20:58:55 +00:00
Sean Callanan da6df8a186 Extended the AST importer to support ParenTypes.
This is necessary to support importing certain
function pointer types.

llvm-svn: 137311
2011-08-11 16:56:07 +00:00
Richard Smith 111af8ddb9 Renamings to consistently use 'Constexpr' not 'ConstExpr' when referring to the C++0x 'constexpr' keyword.
llvm-svn: 137230
2011-08-10 18:11:37 +00:00
Douglas Gregor 636e200675 Move the creation of the record type for the state of Objective-C fast
enumerations from the ASTContext into CodeGen, so that we don't need
to serialize it to AST files. This appears to be the last of the
low-hanging fruit for SpecialTypes.

llvm-svn: 137124
2011-08-09 17:23:49 +00:00
Douglas Gregor 7874310ba1 Don't serialize the block descriptor or block extended descriptor
types to AST files; they're only used by debug info generation anyway,
and shouldn't ever exist in the AST anyway.

llvm-svn: 137122
2011-08-09 16:24:26 +00:00
Douglas Gregor abf4e0dfcd Move the construction of the RecordDecl representing the runtime
layout of a constant NSString from the ASTContext over to CodeGen,
since this is solely CodeGen's responsibility. Eliminates one of the
unnecessary "special" types that we serialize.

llvm-svn: 137121
2011-08-09 15:54:21 +00:00
Chad Rosier e1a6a0e05c Add support for using anonymous bitfields (e.g., int : 0) to enforce alignment.
This fixes cases where the anonymous bitfield is followed by a bitfield member.
E.g.,
struct t4
{
 char foo;
 long : 0;
 char bar : 1;
};

rdar://9859156

llvm-svn: 136991
2011-08-05 22:38:04 +00:00
Abramo Bagnara ff371acaa4 Fixed FieldDecl source range.
llvm-svn: 136963
2011-08-05 08:02:55 +00:00
Chad Rosier f01a7ddcd6 More whitespace and naming fixup. No functionality change.
llvm-svn: 136944
2011-08-04 23:34:15 +00:00
Chad Rosier b43c21a1e2 Whitespace.
llvm-svn: 136929
2011-08-04 21:50:29 +00:00
Chad Rosier 64b18eebc6 Fix style and remove obviously redundant code.
llvm-svn: 136907
2011-08-04 19:25:14 +00:00
Chad Rosier a336c6f380 Additional comments and whitespace.
llvm-svn: 136892
2011-08-04 17:52:43 +00:00
Kaelyn Uhrain 7d9bc633d2 Match type names and give more info for out-of-line function definition errors.
Having a function declaration and definition with different types for a
parameter where the types have same (textual) name can occur when an unqualified
type name resolves to types in different namespaces in each location.

The error messages have been extended by adding notes that point to the first
parameter of the function definition that doesn't match the declaration, instead
of a generic "member declaration nearly matches". The generic message is still
used in cases where the mismatch is not in the paramenter list, such as
mismatched cv qualifiers on the member function itself.

llvm-svn: 136891
2011-08-04 17:40:00 +00:00
Chad Rosier 18903ee2d3 Add partial support for using anonymous bitfields (e.g., int : 0) to enforce
alignment.  This fixes cases where the anonymous bitfield is followed by a 
non-bitfield member.  E.g.,

struct t4
{
  int foo : 1;
  long : 0;
  char bar;
};

Part of rdar://9859156

llvm-svn: 136858
2011-08-04 01:21:14 +00:00
Argyrios Kyrtzidis 582ae9916a Not sure why we bother updating FunctionDecl's EndRangeLoc in FunctionDecl::setParams.
EndRangeLoc should always be set to at least the ending paren or brace.

llvm-svn: 136573
2011-07-30 17:23:28 +00:00
Argyrios Kyrtzidis 4c6efa62e0 [libclang] Annotation of parameters that got default args from a previous declarations was
broken because the end location of the parameter was the end location of the default arg,
resulting in a source range that could begin in one file and end in another.

llvm-svn: 136572
2011-07-30 17:23:26 +00:00
Douglas Gregor d451ea9ca9 Teach the ASTImporter to cope with cases where we have already
imported a forward declaration, but later the full definition of the
same entity becomes available. When this happens, import the definition.

llvm-svn: 136537
2011-07-29 23:31:30 +00:00
Richard Trieu 82398f9cd6 Add template instantiations to the output of -ast-dump.
llvm-svn: 136306
2011-07-28 00:19:05 +00:00
Eli Friedman b2f3695e9a Make CodeGen for array delete involving incomplete class work without crashing. Should fix regression on g++.dg/init/delete1.C.
llvm-svn: 136241
2011-07-27 18:54:57 +00:00
Ted Kremenek 7d39c9ae36 Change ASTContext::getSideTableAllocatedMemory() to use llvm::capacity_in_bytes().
llvm-svn: 136235
2011-07-27 18:41:12 +00:00
Douglas Gregor fb65e592e0 Add support for C++0x unicode string and character literals, from Craig Topper!
llvm-svn: 136210
2011-07-27 05:40:30 +00:00
Argyrios Kyrtzidis 9390747349 [arcmt] More automatic transformations and safety improvements; rdar://9615812 :
- Replace calling -zone with 'nil'. -zone is obsolete in ARC.
- Allow removing retain/release on a static global var.
- Fix assertion hit when scanning for name references outside a NSAutoreleasePool scope.
- Automatically add bridged casts for results of objc method calls and when calling CFRetain, for example:

NSString *s;
CFStringRef ref = [s string];   -> CFStringRef ref = (__bridge CFStringRef)([s string]);
ref = s.string;                 -> ref = (__bridge CFStringRef)(s.string);
ref = [NSString new];           -> ref = (__bridge_retained CFStringRef)([NSString new]);
ref = [s newString];            -> ref = (__bridge_retained CFStringRef)([s newString]);
ref = [[NSString alloc] init];  -> ref = (__bridge_retained CFStringRef)([[NSString alloc] init]);
ref = [[s string] retain];      -> ref = (__bridge_retained CFStringRef)([s string]);
ref = CFRetain(s);              -> ref = (__bridge_retained CFTypeRef)(s);
ref = [s retain];               -> ref = (__bridge_retained CFStringRef)(s);

- Emit migrator error when trying to cast to CF type the result of autorelease/release:
  for

CFStringRef f3() {
  return (CFStringRef)[[[NSString alloc] init] autorelease];
}

emits:

t.m:12:10: error: [rewriter] it is not safe to cast to 'CFStringRef' the result of 'autorelease' message; a __bridge cast may result in a pointer to a destroyed object and a __bridge_retained may leak the object
  return (CFStringRef)[[[NSString alloc] init] autorelease];
         ^            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
t.m:12:3: note: [rewriter] remove the cast and change return type of function to 'NSString *' to have the object automatically autoreleased
  return (CFStringRef)[[[NSString alloc] init] autorelease];
  ^

- Before changing attributes to weak/unsafe_unretained, check if the backing ivar
  is set to a +1 object, in which case use 'strong' instead.

llvm-svn: 136208
2011-07-27 05:28:18 +00:00
Chad Rosier 99ee7829ff After further discussion it has been determined that alignof should report
the preferred alignment.  Thus, revert r135934, r135935, and r135940.

llvm-svn: 136062
2011-07-26 07:03:04 +00:00
Chad Rosier b23ee96cd5 Allow target to specify about using minimum alignment vs preferred. Takes care of
FIXME: Override "preferred align" for double and long long for ARM apcs-gnu ABI. 
Also part of rdar://9802874

llvm-svn: 135940
2011-07-25 19:39:39 +00:00
NAKAMURA Takumi fb66d5cc9c lib/AST/CMakeLists.txt: Update LLVM_USED_LIBS, not to miss symbols with building shared lib. Thanks to Ryuta Suzuki.
llvm-svn: 135864
2011-07-23 23:29:47 +00:00
Chris Lattner 0e62c1cc0b remove unneeded llvm:: namespace qualifiers on some core types now that LLVM.h imports
them into the clang namespace.

llvm-svn: 135852
2011-07-23 10:55:15 +00:00
Sean Callanan 81d577c5c9 This patch (thanks to Doug Gregor) fixes a
problem where Clang was setting the
hasExternalVisibleDecls() bit for all
DeclContexts it imported.  This caused Clang
to make unnecessary calls to
findExternalVisibleDecls() when an external
AST source was installed.

In fact, Clang sometimes interpreted a failure
by one of these spurious calls to find a
Decl as meaning the Decl didn't exist, even
though findExternalLexicalDecls() did locate
that decl.  This produced amusing errors of
the form:

-
error: no member named 'b' in 'A'; did you
mean 'b'?
-

Now, if hasExternalVisibleDecls() or
hasExternalLexicalDecls() should be set, the
external AST source must do so itself.

llvm-svn: 135824
2011-07-22 23:46:03 +00:00
John McCall 0410e572b9 Move this ObjCImplementationDecl member function into libAST
where it belongs.

llvm-svn: 135746
2011-07-22 04:15:06 +00:00
Jordy Rose a91768e569 Add a const overload for ObjCInterfaceDecl::all_declared_ivar_begin.
This was previously not-const only because it has to lazily construct a chain
of ivars the first time it is called (and after the chain is invalidated).
In practice, all the clients were just const_casting their const Decls;
all those now-unnecessary const_casts have been removed.

llvm-svn: 135741
2011-07-22 02:08:32 +00:00
Sean Callanan 53a6bff7e1 This fix (thanks to Doug Gregor) corrects a bug
in ImportDefinition when replacing a previously
forward-declared CXXRecordDecl with its full
definition.  The forward-declared type's
DefinitionData had not been intialized for the
forward-declared type, so adding fields to the
Decl caused CXXRecordDecl::addedMember() to
crash when accessing the DefinitionData.

llvm-svn: 135530
2011-07-19 22:38:25 +00:00
Jeffrey Yasskin d2af962eee Define DiagnosticBuilder<<APValue so it's easy to include APValues in
diagnostics.

llvm-svn: 135398
2011-07-18 16:43:53 +00:00
Nick Lewycky ba4cc01a1f Don't crash when codegen'ing an empty redecl of a function in C99 mode, when
neither was inline. Fixes bug introduced in r135377.

llvm-svn: 135380
2011-07-18 07:11:55 +00:00
Nick Lewycky 26da4ddfa6 In C99, emit an inline function when encountering an extern redeclaration.
Fixes PR10233!

llvm-svn: 135377
2011-07-18 05:26:13 +00:00
Douglas Gregor 3d0adb3201 Augment the interface of ExternalASTSource::FindExternalLexicalDecls()
to allow clients to specify that they've already (correctly) loaded
declarations, and that no further action is needed. 

Also, make sure that we clear the "has external lexical declarations"
bit before calling FindExternalLexicalDecls(), to avoid infinite
recursion.

llvm-svn: 135306
2011-07-15 21:46:17 +00:00
Jeffrey Yasskin d0f079dad4 Use the new APFloat::convertToInt(APSInt) function to simplify uses of
convertToInt(integerParts*) and make them more reliable.

llvm-svn: 135279
2011-07-15 17:03:07 +00:00
John McCall 7c454bb8ce Create a new expression node, SubstNonTypeTemplateParmExpr,
to represent a fully-substituted non-type template parameter.
This should improve source fidelity, as well as being generically
useful for diagnostics and such.

llvm-svn: 135243
2011-07-15 05:09:51 +00:00
Chandler Carruth 2536641cd5 Switch comments and assert text in AST from 'instantiation' to
'expansion'.

llvm-svn: 135224
2011-07-15 00:04:35 +00:00
Eli Friedman 609ada27ce Silliness with commas, as reported at http://blog.regehr.org/archives/558 . As it turns out, this is my fault for not noticing this was an issue when I was looking at this a long time ago. :(
llvm-svn: 135026
2011-07-13 02:05:57 +00:00
Richard Smith 26935e60b6 Correctly set up the list of virtual base classes for a CXXRecordDecl. Previously we got the source range wrong for everything in the virtual bases list.
llvm-svn: 135011
2011-07-12 23:49:11 +00:00
Fariborz Jahanian c87c8799ec revert fix for // rdar://9740328
llvm-svn: 135010
2011-07-12 23:20:13 +00:00
Fariborz Jahanian c0f6af2103 objc++: Some level of covariance is allowed in ObjC properties.
Make it also available in ObjC++ propeties. // rdar://9740328

llvm-svn: 135001
2011-07-12 22:05:16 +00:00
Douglas Gregor 7e6bfb4a0d In ARC mode, consider Objective-C lifetime types (object pointers and
block pointers) that don't have any qualification to be POD types. We
were previously considering them to be non-POD types, because this was
convenient in C++ for is_pod-like traits. However, we now end up
inferring lifetime in such cases (template arguments infer __strong),
so it is not necessary.

Moreover, we want rvalues of object type (which have their lifetime
stripped) to be PODs to allow, e.g., va_arg(arglist, id) to function
properly. Fixes <rdar://problem/9758798>.

llvm-svn: 134993
2011-07-12 17:28:52 +00:00
Douglas Gregor 2207ec273a Improve name mangling for instantiation-dependent types that are not
dependent. This covers an odd class of types such as

  int (&)[sizeof(sizeof(T() + T()))];

which involve template parameters but, because of some trick typically
involving a form of expression that is never type-dependent, resolve
down to a non-dependent type. Such types need to be mangled
essentially as they were written in the source code (involving
template parameters), rather than via their canonical type.

In general, instantiation-dependent types should be mangled as
they were written in the source. However, since we can't do that now
without non-trivial refactoring of the AST (see the new FIXME), I've
gone for this partial solution: only use the as-written-in-the-source
mangling for these strange types that are instantiation-dependent but
not dependent. This provides better compatibility with previous
incarnations of Clang and with GCC. In the future, we'd like to get
this right.

Fixes <rdar://problem/9663282>.

llvm-svn: 134984
2011-07-12 15:18:55 +00:00
Douglas Gregor e5802234f9 Implement name mangling for sizeof...(function parameter pack).
llvm-svn: 134974
2011-07-12 07:03:48 +00:00
Douglas Gregor 4a80f9fd98 Fix the desugaring of dependent decltype and typeof(expr) nodes. The
isSugared() and desugar() routines previously provided were never
actually called, since the corresponding types
(DependentTypeOfExprType, DependentDecltypeType) don't have
corresponding type classes. Outside of the current (incomplete) patch
I'm working on, I haven't found a way to trigger this problem.

llvm-svn: 134973
2011-07-12 06:55:29 +00:00
Douglas Gregor 1cf9dd21dc Mangle dependent template names of unknown arity
llvm-svn: 134967
2011-07-12 05:06:05 +00:00
Douglas Gregor 6ef06cc48d Implement the Itanium C++ ABI's mangling rule for
non-instantiation-dependent sizeof and alignof expressions.

llvm-svn: 134963
2011-07-12 04:47:20 +00:00
Douglas Gregor 842806450c Centralize the getCanonicalType() calls in the Itanium C++ mangling
code so that they only occur in a single place. No functionality change.

llvm-svn: 134961
2011-07-12 04:42:08 +00:00
Douglas Gregor 2e12550e37 Allow us to compute linkage et al for instantiation-dependent types.
llvm-svn: 134932
2011-07-11 22:38:07 +00:00
Chandler Carruth d517395248 Apply patch from Richard Trieu to fix PR9548:
When two different types has the same text representation in the same
diagnostic message, print an a.k.a. after the type if the a.k.a. gives extra
information about the type.

class versa_string;

typedef versa_string string;

namespace std {template <typename T> class vector;}

using std::vector;

void f(vector<string> v);

namespace std {
class basic_string;
typedef basic_string string;
template <typename T> class vector {};
void g() {
  vector<string> v;
  f(v);
}
}

Old message:
----------------
test.cc:15:3: error: no matching function for call to 'f'
  f(&v);
  ^
test.cc:7:6: note: candidate function not viable: no known conversion from
      'vector<string>' to 'vector<string>' for 1st argument
void f(vector<string> v);
     ^
1 error generated.

New message:
---------------
test.cc:15:3: error: no matching function for call to 'f'
  f(v);
  ^
test.cc:7:6: note: candidate function not viable: no known conversion from
      'vector<string>' (aka 'std::vector<std::basic_string>') to
      'vector<string>' (aka 'std::vector<versa_string>') for 1st argument
void f(vector<string> v);
     ^
1 error generated.

llvm-svn: 134904
2011-07-11 17:49:21 +00:00
Douglas Gregor 6336f29669 Teach CXXUnresolvedConstructExpr when it should be an
lvalue/xvalue/rvalue, rather than just (incorrectly) assuming it's an
lvalue. Fixes PR10285 / <rdar://problem/9743926>.

llvm-svn: 134700
2011-07-08 15:50:43 +00:00
Cameron Zwarich be652e6a24 r134634 causes a failure on MultiSource/Benchmarks/Olden/bh with TEST=nightly,
so roll it out.

llvm-svn: 134638
2011-07-07 21:03:28 +00:00
Nick Lewycky d755e6ac48 A redeclaration of an inline method in C99 mode should trigger emission of that
function. Fixes PR10233!

llvm-svn: 134634
2011-07-07 20:25:10 +00:00
John McCall 4db5c3c83a In ARC, reclaim all return values of retainable type, not just those
where we have an immediate need of a retained value.

As an exception, don't do this when the call is made as the immediate
operand of a __bridge retain.  This is more in the way of a workaround
than an actual guarantee, so it's acceptable to be brittle here.

rdar://problem/9504800

llvm-svn: 134605
2011-07-07 06:58:02 +00:00
Eli Friedman a3c122db7e Zap a couple unnecessary loops.
llvm-svn: 134578
2011-07-07 01:54:01 +00:00
Fariborz Jahanian b7a773626f objc-arc: enforce performSelector rules in rejecting retaining selectors
passed to it, and unknown selectors causing potential leak.
// rdar://9659270

llvm-svn: 134449
2011-07-05 22:38:59 +00:00
Benjamin Kramer e87c38b229 Don't overread the buffer when an %x escape in inline asm ends prematurely.
Tested by valgrind & Sema/asm.c.

llvm-svn: 134404
2011-07-05 11:13:37 +00:00
Chandler Carruth bfb154ad3f Switch the Decl and Stmt stats printing to use llvm::errs() instead of
fprintf, and to be more consistent in formatting with the other stats
printing routines.

llvm-svn: 134374
2011-07-04 06:13:27 +00:00
Chandler Carruth 3c147a7731 Start switching the AST stats printing to use llvm::errs() instead of
fprintf. There is more cleanup to be done to the AST stats printing...

llvm-svn: 134373
2011-07-04 05:32:14 +00:00
Abramo Bagnara 9ae292d810 Rewritten fix in r134139 to conform evaluation result to original evaluation context.
llvm-svn: 134320
2011-07-02 13:13:53 +00:00
Argyrios Kyrtzidis 8e25253e14 -Fix mistake in ASTContext::getInnerObjCOwnership noticed by Doug
-Remove unnecessary 'return'.
-Remove unnecessary 'if' check (llvm_unreachable make sure attrStr will be non-null)
-Add a test of transferring ownership to a reference cast type.

llvm-svn: 134285
2011-07-01 23:01:46 +00:00
Argyrios Kyrtzidis 7451d1cd00 [ARC] When casting from a pointer to an objective-c object with known ownership, if the
cast type has no ownership specified, implicitly "transfer" the ownership of the cast'ed type
to the cast type:

id x;
static_cast<NSString**>(&x); // Casting as (__strong NSString**).

This currently only works for C++ named casts, C casts to follow.

llvm-svn: 134273
2011-07-01 22:22:50 +00:00
John McCall 2de1c33f77 Just mangle substituted template parameter types as unresolved types.
This is kindof questionable but seems to do more-or-less the right thing.
This is not a particularly friendly part of the ABI.

llvm-svn: 134227
2011-07-01 02:19:08 +00:00
Douglas Gregor 678d76c026 Introduce the notion of instantiation dependence into Clang's AST. A
type/expression/template argument/etc. is instantiation-dependent if
it somehow involves a template parameter, even if it doesn't meet the
requirements for the more common kinds of dependence (dependent type,
type-dependent expression, value-dependent expression).

When we see an instantiation-dependent type, we know we always need to
perform substitution into that instantiation-dependent type. This
keeps us from short-circuiting evaluation in places where we
shouldn't, and lets us properly implement C++0x [temp.type]p2.

In theory, this would also allow us to properly mangle
instantiation-dependent-but-not-dependent decltype types per the
Itanium C++ ABI, but we aren't quite there because we still mangle
based on the canonical type in cases like, e.g.,

  template<unsigned> struct A { };
  template<typename T>
    void f(A<sizeof(sizeof(decltype(T() + T())))>) { }
  template void f<int>(A<sizeof(sizeof(int))>);

and therefore get the wrong answer.

llvm-svn: 134225
2011-07-01 01:22:09 +00:00
John McCall 3a4a4c5228 Change the mangling of enclosing template template parameters
that serve as the base template name of an unresolved-name to
be mangled as a substitution.

llvm-svn: 134213
2011-07-01 00:04:39 +00:00
John McCall db49969b32 No, actually, we do need to be able to mangle substituted template names.
llvm-svn: 134195
2011-06-30 21:59:02 +00:00
Hans Wennborg 77d1abef07 Fix off-by-one error in StringLiteral::getLocationOfByte.
This fixes PR10223.

llvm-svn: 134183
2011-06-30 20:17:41 +00:00
Abramo Bagnara 2caedf449e Fixed enum constant evaluation assertions.
llvm-svn: 134139
2011-06-30 09:36:05 +00:00
John McCall d9dfe3a1f8 Preserve that a TemplateName was arrived at by substituting
for a template template parameter.

Uses to follow.

I've also made the uniquing of SubstTemplateTemplateParmPacks
use a ContextualFoldingSet as a minor space efficiency.

llvm-svn: 134137
2011-06-30 08:33:18 +00:00
John McCall 8bdae58c3a Document and check tighter assumptions about the TemplateName of a
TemplateSpecializationType.

llvm-svn: 134120
2011-06-30 00:42:27 +00:00