Commit Graph

450 Commits

Author SHA1 Message Date
Kaelyn Uhrain 272d718808 Add the PCH file name to the message about not being able to read the PCH.
Also add a couple of unit tests to check the invalid-PCH error messages
to satisfy PR4568 and for the assertion (introduced in r149918 and fixed
in r158769) that would cause clang to crash when given an empty PCH.

llvm-svn: 158772
2012-06-20 00:36:03 +00:00
Meador Inge 5d3fb22bac Explicitly build __builtin_va_list.
The target specific __builtin_va_list types are now explicitly built instead
of injecting strings into the preprocessor input.

llvm-svn: 158592
2012-06-16 03:34:49 +00:00
Richard Smith 2b013185f8 PR13064: Store whether an in-class initializer uses direct or copy
initialization, and use that information to produce the right kind of
initialization during template instantiation.

llvm-svn: 158288
2012-06-10 03:12:00 +00:00
Jordan Rose ccf43ca05c Add pedantic warning -Wempty-translation-unit (C11 6.9p1).
In standard C since C89, a 'translation-unit' is syntactically defined to have
at least one "external-declaration", which is either a decl or a function
definition. In Clang the latter gives us a declaration as well.

The tricky bit about this warning is that our predefines can contain external
declarations (__builtin_va_list and the 128-bit integer types). Therefore our
AST parser now makes sure we have at least one declaration that doesn't come
from the predefines buffer.

Also, remove bogus warning about empty source files. This doesn't catch source
files that only contain comments, and never fired anyway because of our
predefines.

PR12665 and <rdar://problem/9165548>

llvm-svn: 158085
2012-06-06 17:25:21 +00:00
David Blaikie 7555b6a4e5 Improve some of the conversion warnings to fire on conversion to bool.
Moves the bool bail-out down a little in SemaChecking - so now
-Wnull-conversion and -Wliteral-conversion can fire when the target type is
bool.

Also improve the wording/details in the -Wliteral-conversion warning to match
the -Wconstant-conversion.

llvm-svn: 156826
2012-05-15 16:56:36 +00:00
Argyrios Kyrtzidis 45f5118248 The Lexer constructor expects a source location at the start of the
file buffer, not at the start of lexing.

Fixes assertion hit in format diagnostics. rdar://11418366

llvm-svn: 156647
2012-05-11 21:39:18 +00:00
NAKAMURA Takumi dcb0e394a9 test/PCH/remap-file-from-pch.cpp: Fix expression for DOS pathsep.
llvm-svn: 156153
2012-05-04 03:42:28 +00:00
Argyrios Kyrtzidis 0f7d7ab968 [PCH] Really, pinky swear, fix for PR12689
rdar://11353109

llvm-svn: 156145
2012-05-04 01:49:36 +00:00
Argyrios Kyrtzidis 6eec06d0d4 [PCH] When validating that the files coming from PCH did not change, also
validate that we didn't override the contents of any of such files.

If this is detected, emit a diagnostic error and recover gracefully
by using the contents of the original file that the PCH was built from.

Part of rdar://11305263

llvm-svn: 156107
2012-05-03 21:50:39 +00:00
Argyrios Kyrtzidis 2a5deff59d [PCH] Clear switch case IDs when deserializing a objc method body.
Fixes rdar://11353109 & http://llvm.org/bugs/show_bug.cgi?id=12689

llvm-svn: 156056
2012-05-03 02:26:32 +00:00
Richard Smith e85e176600 PR12585: When processing a friend template inside a class template, don't
pretend there was no previous declaration -- that can lead us to injecting
a class template (with no access specifier) into a class scope. Instead,
just avoid the problematic checks.

llvm-svn: 155303
2012-04-22 02:13:50 +00:00
Richard Smith 8b987a9976 Fix serialization of uninstantiated exception specifications. Patch by Li Kan,
test by me.

llvm-svn: 155289
2012-04-21 17:47:47 +00:00
Nick Lewycky 2bd0ab2b11 Implement the all_lookups_iterator for PCH as a follow-up to r153970. This
includes a patch from Matthias Kleine with a regression testcase!

Adds a new iterator 'data_iterator' to OnDiskHashTable which doesn't try to
reconstruct the external_key from the internal_key, which is useful for traits
that don't store enough information to do that mapping in their key. Also
deletes the 'item_iterator' from OnDiskHashTable as dead code.

llvm-svn: 154784
2012-04-16 02:51:46 +00:00
Patrick Beard acfbe9e1f2 Added a new attribute, objc_root_class, which informs the compiler when a root class is intentionally declared.
The warning this inhibits, -Wobjc-root-class, is opt-in for now. However, all clang unit tests that would trigger
the warning have been updated to use -Wno-objc-root-class. <rdar://problem/7446698>

llvm-svn: 154187
2012-04-06 18:12:22 +00:00
David Blaikie 09ffc9b473 Enable warn_impcast_literal_float_to_integer by default.
This diagnostic seems to be production ready, it's just an oversight that it
wasn't turned on by default.

The test changes are a bit of a mixed bag. Some tests that seemed like they
clearly didn't need to use this behavior have been modified not to use it.
Others that I couldn't be sure about, I added the necessary expected-warnings
to.

It's possible the diagnostic message could be improved to make it clearer that
this warning can be suppressed by using a value that won't lose precision when
converted to the target type (but can still be a floating point literal, such
as "bool b = 1.0;").

llvm-svn: 154068
2012-04-05 00:16:44 +00:00
Douglas Gregor 6a37784a35 Eliminate obvious use-after-free. Fixes PR12433 / <rdar://problem/11168333>.
llvm-svn: 153982
2012-04-04 00:34:49 +00:00
Douglas Gregor 9f21889a7d Canonicalize the declaration we write to a PCH file for an
InjectedClassNameType; otherwise, it won't be properly wired to the
original (canonical) declaration when it is deserialized. Fixes
<rdar://problem/11112464>.

llvm-svn: 153442
2012-03-26 15:52:37 +00:00
Argyrios Kyrtzidis bf6c3395db [PCH] When we are replacing a decl in a chained PCH that is also a DeclContext,
make sure to fully load its external lexical and visible declarations before
re-writing it.

rdar://10914192

llvm-svn: 153254
2012-03-22 16:08:04 +00:00
Richard Smith 4b38ded66a Instantiating a class template should not instantiate the definition of any
scoped enumeration members. Later uses of an enumeration temploid as a nested
name specifier should cause its instantiation. Plus some groundwork for
explicit specialization of member enumerations of class templates.

llvm-svn: 152750
2012-03-14 23:13:10 +00:00
Richard Smith c67fdd4eb9 AST representation for user-defined literals, plus just enough of semantic
analysis to make the AST representation testable. They are represented by a
new UserDefinedLiteral AST node, which is a sugared CallExpr. All semantic
properties, including full CodeGen support, are achieved for free by this
representation.

UserDefinedLiterals can never be dependent, so no custom instantiation
behavior is required. They are mangled as if they were direct calls to the
underlying literal operator. This matches g++'s apparent behavior (but not its
actual mangling, which is broken for literal-operator-ids).

User-defined *string* literals are now fully-operational, but the semantic
analysis is quite hacky and needs more work. No other forms of user-defined
literal are created yet, but the AST support for them is present.

This patch committed after midnight because we had already hit the quota for
new kinds of literal yesterday.

llvm-svn: 152211
2012-03-07 08:35:16 +00:00
Ted Kremenek e65b086e07 Add clang support for new Objective-C literal syntax for NSDictionary, NSArray,
NSNumber, and boolean literals.  This includes both Sema and Codegen support.
Included is also support for new Objective-C container subscripting.

My apologies for the large patch.  It was very difficult to break apart.
The patch introduces changes to the driver as well to cause clang to link
in additional runtime support when needed to support the new language features.

Docs are forthcoming to document the implementation and behavior of these features.

llvm-svn: 152137
2012-03-06 20:05:56 +00:00
Argyrios Kyrtzidis 5cb4760aed [PCH] Include a darwin-only PCH test on Cocoa.h.
llvm-svn: 151668
2012-02-28 23:39:20 +00:00
Richard Smith 561fb15801 Teach CXXRecordDecl::hasIrrelevantDestructor to check the base classes and
data members for deleted or user-provided destructors.

Now it's computed in advance, serialize it, and in passing fix all the other
record DefinitionData flags whose serialization was missing.

llvm-svn: 151441
2012-02-25 07:33: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
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 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
Douglas Gregor caf4826e2e Deserialize the direct-initialization range of a "new" expression
properly. Previously, we deserialized it but failed to set the
corresponding member in CXXNewExpr. Fixes <rdar://problem/10893600>.

llvm-svn: 150963
2012-02-20 16:12: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
Douglas Gregor ae64101e49 Simplify and robustify lambda PCH test
llvm-svn: 150493
2012-02-14 18:47:12 +00:00
Douglas Gregor 99ae806aff Implement AST (de-)serialization for lambda expressions.
llvm-svn: 150491
2012-02-14 17:54:36 +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
Argyrios Kyrtzidis cee840fa92 [PCH] Add a PCH test.
llvm-svn: 150192
2012-02-09 18:31:19 +00:00
Sebastian Pop 422377cfd3 rename -ccc-host-triple into -target
llvm-svn: 148582
2012-01-20 22:01:23 +00:00
Eli Friedman d749c6bf2e Revert r148138; it's causing test failures.
llvm-svn: 148141
2012-01-13 21:33:06 +00:00
Sebastian Pop 9a8d528ddf rename -ccc-host-triple into -target
llvm-svn: 148138
2012-01-13 20:37:02 +00:00
Richard Smith ed2974f3cf C++ constant expression handling: eagerly instantiate static const integral data
members of class templates so that their values can be used in ICEs. This
required reverting r105465, to get such instantiated members to be included in
serialized ASTs.

llvm-svn: 147023
2011-12-21 00:25:33 +00:00
Fariborz Jahanian f9aca2089e objc-arc: bridge casts in non-arc mode are now
error. // rdar://10597832

llvm-svn: 146918
2011-12-19 22:52:53 +00:00
Richard Smith d0b4dd656d constexpr handling improvements. Produce detailed diagnostics when a 'constexpr'
variable is initialized by a non-constant expression, and pass in the variable
being declared so that earlier-initialized fields' values can be used.

Rearrange VarDecl init evaluation to make this possible, and in so doing fix a
long-standing issue in our C++ constant expression handling, where we would
mishandle cases like:

  extern const int a;
  const int n = a;
  const int a = 5;
  int arr[n];

Here, n is not initialized by a constant expression, so can't be used in an ICE,
even though the initialization expression would be an ICE if it appeared later
in the TU. This requires computing whether the initializer is an ICE eagerly,
and saving that information in PCH files.

llvm-svn: 146856
2011-12-19 06:19:21 +00:00
Douglas Gregor 05f10357a9 Completely re-implement (de-)serialization of declaration
chains. The previous implementation relied heavily on the declaration
chain being stored as a (circular) linked list on disk, as it is in
memory. However, when deserializing from multiple modules, the
different chains could get mixed up, leading to broken declaration chains.

The new solution keeps track of the first and last declarations in the
chain for each module file. When we load a declaration, we search all
of the module files for redeclarations of that declaration, then
splice together all of the lists into a coherent whole (along with any
redeclarations that were actually parsed). 

As a drive-by fix, (de-)serialize the redeclaration chains of
TypedefNameDecls, which had somehow gotten missed previously. Add a
test of this serialization.

This new scheme creates a redeclaration table that is fairly large in
the PCH file (on the order of 400k for Cocoa.h's 12MB PCH file). The
table is mmap'd in and searched via a binary search, but it's still
quite large. A future tweak will eliminate entries for declarations
that have no redeclarations anywhere, and should
drastically reduce the size of this table.

llvm-svn: 146841
2011-12-17 23:38:30 +00:00
Argyrios Kyrtzidis f76e13e9ea [PCH] Remove extraneous line in the test that was mistakenly copied.
No functionality change.

llvm-svn: 146825
2011-12-17 08:11:28 +00:00
Argyrios Kyrtzidis 2072fbd775 [PCH] Fix bug where we failed to update an identifier for a single token
macro expansion.

rdar://10588825

llvm-svn: 146818
2011-12-17 04:13:31 +00:00
Richard Trieu 553b2b2e5d Modify how the -verify flag works. Currently, the verification string and
diagnostic message are compared.  If either is a substring of the other, then
no error is given.  This gives rise to an unexpected case:

  // expect-error{{candidate function has different number of parameters}}

will match the following error messages from Clang:

  candidate function has different number of parameters (expected 1 but has 2)
  candidate function has different number of parameters

It will also match these other error messages:

  candidate function
  function has different number of parameters
  number of parameters

This patch will change so that the verification string must be a substring of
the diagnostic message before accepting.  Also, all the failing tests from this
change have been corrected.  Some stats from this cleanup:

87 - removed extra spaces around verification strings
70 - wording updates to diagnostics
40 - extra leading or trailing characters (typos, unmatched parens or quotes)
35 - diagnostic level was included (error:, warning:, or note:)
18 - flag name put in the warning (-Wprotocol)

llvm-svn: 146619
2011-12-15 00:38:15 +00:00
Argyrios Kyrtzidis b9e53ed4e2 [PCH] In ASTReader::FinishedDeserializing, after we do PassInterestingDeclsToConsumer
we may end up having added more pending stuff to do, so go in a loop until everything
is cleared out.

This fixes the error in rdar://10278815 which has a certain David Lynch-esque quality..

  error: unknown type name 'BOOL'; did you mean 'BOOL'?

llvm-svn: 145536
2011-11-30 23:18:26 +00:00
Argyrios Kyrtzidis 5938650b13 [PCH] When serializing an PseudoObjectExpr or AtomicExpr, the serialization code must be set
otherwise it will crash with asserts on or it will be written as null pointer.

llvm-svn: 144626
2011-11-15 06:20:27 +00:00
Argyrios Kyrtzidis 846e61a363 [PCH] Do not crash if a class extension in a chained PCH introduces/redeclares a property.
llvm-svn: 144520
2011-11-14 04:52:29 +00:00
Argyrios Kyrtzidis f9d0f4744e [PCH] Fix the test.
llvm-svn: 144467
2011-11-12 21:07:54 +00:00
Argyrios Kyrtzidis b97a4025ff [PCH] When completing an objc forward reference, do not serialize the chain of its categories because
it is going to be rewritten (and the chain will be serialized again), otherwise we may form a cycle in its
categories list when deserializing.

Also introduce ASTMutationListener::CompletedObjCForwardRef to notify that a forward reference
was completed; using Decl's isChangedSinceDeserialization/setChangedSinceDeserialization
is bug inducing and kinda gross, we should phase it out.

Fixes infinite loop in rdar://10418538.

llvm-svn: 144465
2011-11-12 21:07:46 +00:00
Chandler Carruth 996cb8ad84 This test was assuming that /usr/include was in the system header search
path. That assumption should never have been true, but it was until
I fixed it. Now that its fixed, add a triple here to get correct
behavior even on Windows.

llvm-svn: 143863
2011-11-06 06:59:15 +00:00
Chandler Carruth e3fcb6981f Switch these two tests to use the Clang driver instead of CC1. They want
to do "realistic" includes, and so need the header search logic now in
the driver. This in turn requires switching the CC1 options to the
actual driver options, and passing -Xclang where there is no analogy.

llvm-svn: 143805
2011-11-05 10:15:30 +00:00
Argyrios Kyrtzidis 6fb6003aad [PCH] Now that we store the location of a decl outside its record
make sure that we keep track of locations of replaced decls as well.

llvm-svn: 143341
2011-10-31 07:20:15 +00:00
Douglas Gregor 80ad289fb7 Disable on Windows, for real.
llvm-svn: 143027
2011-10-26 14:35:30 +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
Argyrios Kyrtzidis 6a59897d50 [PCH] When serializing Stmts, keep track of when sub statements are referenced again and
in such a case just write out a reference of a previously serialized Stmt, instead
of serializing it all over again.

This saves memory + space + [de]serializing time, and avoids blowing up memory
with pathological cases. rdar://10293911

llvm-svn: 142696
2011-10-21 23:02:28 +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
Richard Smith 9ca5c42582 Update all tests other than Driver/std.cpp to use -std=c++11 rather than
-std=c++0x. Patch by Ahmed Charles!

llvm-svn: 141900
2011-10-13 22:29:44 +00:00
Eli Friedman 73ddccf7d7 Add a simple PCH test for _Atomic.
llvm-svn: 141409
2011-10-07 20:08:35 +00:00
John McCall 9b0a7cea0f Make -fobjc-nonfragile-abi the -cc1 default, since it's the
increasingly prevailing case to the point that new features
like ARC don't even support the fragile ABI anymore.

This required a little bit of reshuffling with exceptions
because a check was assuming that ObjCNonFragileABI was
only being set in ObjC mode, and that's actually a bit
obnoxious to do.

Most, though, it involved a perl script to translate a ton
of test cases.

Mostly no functionality change for driver users, although
there are corner cases with disabling language-specific
exceptions that we should handle more correctly now.

llvm-svn: 140957
2011-10-02 01:16:38 +00:00
Argyrios Kyrtzidis 7c06d8666b [libclang] When getting a source location from a file:line:col triplet
check whether the requested location points inside the precompiled preamble,
in which case the returned source location will be a "loaded" one.

llvm-svn: 140060
2011-09-19 20:40:35 +00:00
Douglas Gregor af3ccaf22c Disable this test on win32. My "sleep 2" trick didn't seem to work
llvm-svn: 139729
2011-09-14 20:38:11 +00:00
John McCall 4319286337 Refactoring, mostly to give ObjCPropertyDecls stronger invariants for
their semantic attributes and then to take advantage of that.

llvm-svn: 139615
2011-09-13 18:31:23 +00:00
Douglas Gregor c2ae880070 Switch the serialization of LangOptions over to use the .def file. We
should no longer have the serialization of LangOptions out of sync
with the structure itself (yay).

llvm-svn: 139613
2011-09-13 18:26:39 +00:00
John McCall 7959fee258 Treat the weak export of block runtime symbols as a deployment-target
feature akin to the ARC runtime checks.  Removes a terrible hack where
IR gen needed to find the declarations of those symbols in the translation
unit.

llvm-svn: 139404
2011-09-09 20:41:01 +00:00
Argyrios Kyrtzidis 2169a75a0a Do a lookup for the blocks runtime globals to see if they were declared,
instead of codegen waiting to consume such a declaration, which won't
happen if that decls are coming from a PCH.

Fixes rdar://10028656.

llvm-svn: 139359
2011-09-09 06:44:21 +00:00
Douglas Gregor 8d9c56bb59 Add some delay between PCH creation and modifying one of the headers it depends on, which will---hopefully make this test predictably pass on Windows
llvm-svn: 139327
2011-09-08 22:32:33 +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 cd0d826001 Finish implementing (de-)serialization of the CXXDefinitionData bits
needed for implicit move constructors and move assignment
operators. Fixes PR10847.

llvm-svn: 139144
2011-09-06 16:38:46 +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
Douglas Gregor 05ef93158d When writing out the entries in a lookup table for a DeclContext, make
sure that all of the CXXConversionDecls go into the same
bucket. Otherwise, name lookup might not find them all. Fixes
<rdar://problem/10041960>.

llvm-svn: 138824
2011-08-30 20:49:19 +00:00
Douglas Gregor 2ed0ee1ace Eliminate the -chained-pch flag and all of the frontend and libclang options associated with it. Chained PCH is the only way to build a PCH file that includes another PCH file
llvm-svn: 138597
2011-08-25 22:54:01 +00:00
Douglas Gregor aa7cbfd259 Remove a bogus assertion from the AST reader, which assumed that
redeclarations of a particular entity would occur in source
order. Friend declarations that occur within class templates (or
member classes thereof) do not follow this, nor would modules. Big
thanks to Erik Verbruggen for reducing this problem from the Very
Large Qt preamble testcase he found.

llvm-svn: 138557
2011-08-25 15:28:26 +00:00
Francois Pichet 09af8c36d1 Add serialization support for ClassScopeFunctionSpecializationDecl.
llvm-svn: 137799
2011-08-17 01:06:54 +00:00
Douglas Gregor 3b65ed0a5c Change the hashing function for DeclContext lookup within an AST file
by eliminating the type ID from constructor, destructor, and
conversion function names. There are several reasons for this change:
  - A given type (say, int*) isn't guaranteed to have a single, unique
  type ID within a chain of PCH files. Hence, we could end up hashing
  based on the wrong type ID, causing name lookup to fail.

  - The mapping from types back to type IDs required one DenseMap
  entry for every type that was ever deserialized, which was an
  unacceptable cost to support just the name lookup of constructors,
  destructors, and conversion functions. Plus, this mapping could
  never actually work with chained or multiple PCH, based on the first
  bullet.

Once we have eliminated the type from the hash function, these
problems go away, as does my horrible "reverse type remap" hack, which
was doomed from the start (see bullet #1 above) and far too
complicated. 

However, note that removing the type from the hash function means that
all constructors, destructors, and conversion functions have the same
hash key, so I've updated the caller to double-check that the
declarations found have the appropriate name.

llvm-svn: 136708
2011-08-02 18:32:54 +00:00
Peter Collingbourne 3bc84ca376 Fix an inconsistency in Sema::ConvertArgumentsForCall in that
the callee note diagnostic was not emitted in the case where
there were too few arguments.

llvm-svn: 136437
2011-07-29 00:24:42 +00:00
Argyrios Kyrtzidis 4145732818 Fix diagnostic when loading a PCH which has different enabled/disabled state of -fobjc-arc. rdar://9818341
llvm-svn: 135707
2011-07-21 21:56:04 +00:00
Douglas Gregor 925296b4c2 Revamp the SourceManager to separate the representation of parsed
source locations from source locations loaded from an AST/PCH file.

Previously, loading an AST/PCH file involved carefully pre-allocating
space at the beginning of the source manager for the source locations
and FileIDs that correspond to the prefix, and then appending the
source locations/FileIDs used for parsing the remaining translation
unit. This design forced us into loading PCH files early, as a prefix,
whic has become a rather significant limitation.

This patch splits the SourceManager space into two parts: for source
location "addresses", the lower values (growing upward) are used to
describe parsed code, while upper values (growing downward) are used
for source locations loaded from AST/PCH files. Similarly, positive
FileIDs are used to describe parsed code while negative FileIDs are
used to file/macro locations loaded from AST/PCH files. As a result,
we can load PCH/AST files even during parsing, making various
improvemnts in the future possible, e.g., teaching #include <foo.h> to
look for and load <foo.h.gch> if it happens to be already available.

This patch was originally written by Sebastian Redl, then brought
forward to the modern age by Jonathan Turner, and finally
polished/finished by me to be committed.

llvm-svn: 135484
2011-07-19 16:10:42 +00:00
Argyrios Kyrtzidis 41fb2d95a3 Make the Preprocessor more memory efficient and improve macro instantiation diagnostics.
When a macro instantiation occurs, reserve a SLocEntry chunk with length the
full length of the macro definition source. Set the spelling location of this chunk
to point to the start of the macro definition and any tokens that are lexed directly
from the macro definition will get a location from this chunk with the appropriate offset.

For any tokens that come from argument expansion, '##' paste operator, etc. have their
instantiation location point at the appropriate place in the instantiated macro definition
(the argument identifier and the '##' token respectively).
This improves macro instantiation diagnostics:

Before:

t.c:5:9: error: invalid operands to binary expression ('struct S' and 'int')
int y = M(/);
        ^~~~
t.c:5:11: note: instantiated from:
int y = M(/);
          ^

After:

t.c:5:9: error: invalid operands to binary expression ('struct S' and 'int')
int y = M(/);
        ^~~~
t.c:3:20: note: instantiated from:
\#define M(op) (foo op 3);
                ~~~ ^  ~
t.c:5:11: note: instantiated from:
int y = M(/);
          ^

The memory savings for a candidate boost library that abuses the preprocessor are:

- 32% less SLocEntries (37M -> 25M)
- 30% reduction in PCH file size (900M -> 635M)
- 50% reduction in memory usage for the SLocEntry table (1.6G -> 800M)

llvm-svn: 134587
2011-07-07 03:40:34 +00:00
Douglas Gregor c2fa169d6c Add support for C++ namespace-aware typo correction, e.g., correcting
vector<int>

to

  std::vector<int>

Patch by Kaelyn Uhrain, with minor tweaks + PCH support from me. Fixes
PR5776/<rdar://problem/8652971>.

Thanks Kaelyn!

llvm-svn: 134007
2011-06-28 16:20:02 +00:00
John McCall 31168b077c Automatic Reference Counting.
Language-design credit goes to a lot of people, but I particularly want
to single out Blaine Garst and Patrick Beard for their contributions.

Compiler implementation credit goes to Argyrios, Doug, Fariborz, and myself,
in no particular order.

llvm-svn: 133103
2011-06-15 23:02:42 +00:00
Richard Smith 938f40b5aa Implement support for C++11 in-class initialization of non-static data members.
llvm-svn: 132878
2011-06-11 17:19:42 +00:00
Douglas Gregor 33823727c8 Implement Objective-C Related Result Type semantics.
Related result types apply Cocoa conventions to the type of message
sends and property accesses to Objective-C methods that are known to
always return objects whose type is the same as the type of the
receiving class (or a subclass thereof), such as +alloc and
-init. This tightens up static type safety for Objective-C, so that we
now diagnose mistakes like this:

t.m:4:10: warning: incompatible pointer types initializing 'NSSet *'
with an
      expression of type 'NSArray *' [-Wincompatible-pointer-types]
  NSSet *array = [[NSArray alloc] init];
         ^       ~~~~~~~~~~~~~~~~~~~~~~
/System/Library/Frameworks/Foundation.framework/Headers/NSObject.h:72:1:
note: 
      instance method 'init' is assumed to return an instance of its
      receiver
      type ('NSArray *')
- (id)init;
^

It also means that we get decent type inference when writing code in
Objective-C++0x:

  auto array = [[NSMutableArray alloc] initWithObjects:@"one",  @"two",nil];
  //    ^ now infers NSMutableArray* rather than id

llvm-svn: 132868
2011-06-11 01:09:30 +00:00
Eli Friedman 9ed3cde1fa Start fixing up clang tests to work on the clang-native-arm-cortex-a9 builder.
llvm-svn: 132691
2011-06-06 21:23:05 +00:00
Eli Friedman 4e2cefffd5 Revert r132426; this test passes more often than not, and we don't have a way to mark tests as intermittently failing at the moment.
llvm-svn: 132446
2011-06-02 00:42:47 +00:00
Argyrios Kyrtzidis 7e48d8ff0c XFAIL the test on windows.
llvm-svn: 132426
2011-06-01 21:52:17 +00:00
Argyrios Kyrtzidis 460132d35c [PCH] Be conservative and check all the files the PCH references to see if
a file was modified since the time the PCH was created.

The parser is not fit to deal with stale PCHs, too many invariants do not hold up. rdar://9530587.

llvm-svn: 132389
2011-06-01 05:43:53 +00:00
Alexis Hunt 119c10ef23 Update our diagnostics to properly account for move operations.
llvm-svn: 132096
2011-05-25 23:16:36 +00:00
Alexis Hunt 94f9cbf998 Implement a few basic tests for defaulted and deleted functions.
More comprehensive testing once copy {constructors,assignment operators}
can be defaulted.

llvm-svn: 131275
2011-05-13 01:01:05 +00:00
Richard Smith 3f1b5d077b Implement support for C++0x alias templates.
llvm-svn: 130953
2011-05-05 21:57:07 +00:00
Alexis Hunt 27a761d5bd there i fixed it
Increase robustness of the delegating constructor cycle detection
mechanism. No more infinite loops on invalid or logic errors leading to
false results. Ensure that this is maintained correctly accross
serialization.

llvm-svn: 130887
2011-05-04 23:29:54 +00:00
Argyrios Kyrtzidis 6f09245c33 Change test/PCH/cxx-static_assert.cpp so that it doesn't need a separate header.
llvm-svn: 130839
2011-05-04 14:58:28 +00:00
Alexis Hunt 6118d6642b Implement a better version of delegating constructor cycle detection.
This is more efficient as it's all done at once at the end of the TU.
This could still get expensive, so a flag is provided to disable it. As
an added bonus, the diagnostics will now print out a cycle.

The PCH test is XFAILed because we currently can't deal with a note
emitted in the header and I, being tired, see no other way to verify the
serialization of delegating constructors. We should probably address
this problem /somehow/ but no good solution comes to mind.

llvm-svn: 130836
2011-05-04 05:57:24 +00:00
Alexis Hunt 37a477f7eb Implement serialization of delegating constructors.
llvm-svn: 130822
2011-05-04 01:19:08 +00:00
Chad Rosier f897d3b88b Fixed test case asserts due to checkin of r130710.
llvm-svn: 130720
2011-05-02 20:39:21 +00:00
NAKAMURA Takumi c3a8529269 lib/Frontend/InitHeaderSearch.cpp: Tweak AddPath() to accept "/foo/bar" (not "X:\foo\bar") with -isysroot. test/PCH/reloc.c can pass.
FIXME: We should consider better isysroot scheme on Win32 hosts.
llvm-svn: 130683
2011-05-02 04:50:10 +00:00
Sebastian Redl 2ac2c725e0 Add a decl update when a static data member of a class template is instantiated in a different PCH than its containing class. Otherwise we get double definition errors. Fixes a Boost.MPL problem that affects Boost.Accumulators and probably a lot more of Boost.
llvm-svn: 130488
2011-04-29 08:19:30 +00:00
Sebastian Redl bc9a20949f Use -emit-llvm-only as suggested by Argyrios.
llvm-svn: 130486
2011-04-29 08:19:03 +00:00
Francois Pichet 4c3b68c366 Because of r130359 this test no longer fail on Windows.
llvm-svn: 130370
2011-04-28 02:01:57 +00:00
Matt Beaumont-Gay 7e92e57b0b Fix modified-header-crash.c for read-only source trees
llvm-svn: 130359
2011-04-28 00:23:49 +00:00
Argyrios Kyrtzidis 21362becdc Disable a test that fails on windows; for some reason we don't detect that the header has different timestamp.
llvm-svn: 130204
2011-04-26 16:49:25 +00:00
Argyrios Kyrtzidis daa41f59e4 Fix a crash when ASTReader emits diagnostic when another one is in flight. Fixes rdar//9334563.
llvm-svn: 130162
2011-04-25 22:23:56 +00:00
Sebastian Redl 010288f7c1 Set the correct anonymous namespace (must be last reopening), and behave correctly in the presence of the ever-annoying linkage specifications.
llvm-svn: 130105
2011-04-24 16:28:21 +00:00
Sebastian Redl fa1f370b7d Fix adding an anonymous namespace in a chained PCH to a namespace from a previous PCH.
Fix anonymous namespaces in PCH.

llvm-svn: 130104
2011-04-24 16:28:13 +00:00
Sebastian Redl ab238a7d18 Synthesizing the definition of an implicit member is an AST modification, so notify any mutation listeners of it. This fixes a crasher in chained PCH, where an implicit destructor in a PCH gets a definition in a chained PCH, which is then lost. However, any further use of the destructor would cause its definition to be regenerated in the final file, hiding the bug.
llvm-svn: 130103
2011-04-24 16:28:06 +00:00
Sebastian Redl f830df4e9d On reading DeclContexts from PCH, check for visible updates even if the context was empty in the original version. Also, if there are any, tell the context that it has external visible decls. This fixes the problem that a namespace that was empty in the initial PCH (could also happen if the initial PCH didn't include any std header but caused implicit creation of namespace std, e.g. due to implicit declaration of a virtual destructor) never found any declaration declared in *any* chained PCH. Very ugly when the chained PCH includes all that std stuff, as the errors were effectively the same as not including std headers.
llvm-svn: 130102
2011-04-24 16:27:54 +00:00
Sebastian Redl 14afaf0093 Store the full list of pending instantiations in a chained PCH. Previously we attempted to store only new pending instantiations, but our filter was incorrect, dropping implicit instantiations of class template members. It's just not worth coming up with a complex filter that is correct, when the only cost is PCH files that are a few hundred bytes (at most) larger.
llvm-svn: 130098
2011-04-24 16:27:30 +00:00
Peter Collingbourne 9114759641 C1X: implement generic selections
As an extension, generic selection support has been added for all
supported languages.  The syntax is the same as for C1X.

llvm-svn: 129554
2011-04-15 00:35:48 +00:00
Richard Smith 02e85f3bc5 Add support for C++0x's range-based for loops, as specified by the C++11 draft standard (N3291).
llvm-svn: 129541
2011-04-14 22:09:26 +00:00
Sebastian Redl 9ab988fe00 Chained PCH: Remember when additional specializations are added to a function template from a previous PCH. Fixes the only crasher when using massive chains on Clang's Sema component. We still have some incomplete codegen there.
llvm-svn: 129516
2011-04-14 14:07:59 +00:00
Richard Smith 0f538460d2 Fix AST serialization of reference-to-reference types. This previously caused
a crash when deserializing the AST for this:

  typedef char (&R);
    extern R &r;

llvm-svn: 129358
2011-04-12 10:38:03 +00:00
Chandler Carruth 24284afa2d Flip the default for showing include stacks on notes to false. This
required modifying a few tests that specifically use note include stacks
to check the source manager's view of include stacks. I've simply added
the flag to these tests for now, they may have to be more substantially
changed if we decide to remove support for note include stacks
altogether.

Also, add a test for include stacks on notes that was supposed to go in
with the previous commit.

llvm-svn: 128390
2011-03-27 20:00:08 +00:00
Chandler Carruth 33bf3e758d Diagnose uninitialized uses of a variable within its own initializer.
This is basically the same idea as the warning on uninitialized uses of
fields within an initializer list. As such, it is on by default and
under -Wuninitialized.

Original patch by Richard Trieu, with some massaging from me on the
wording and grouping of the diagnostics.

llvm-svn: 128376
2011-03-27 09:46:56 +00:00
John McCall 6a4fa52b37 The emission of an Objective-C++'s class .cxx_destruct method should be
conditioned on whether it has any destructible ivars, not on whether
it has any non-trivial class-object initializers.

llvm-svn: 128074
2011-03-22 07:05:39 +00:00
Peter Collingbourne e190dee7a5 Add support for the OpenCL vec_step operator, by generalising and
extending the existing support for sizeof and alignof.  Original
patch by Guy Benyei.

llvm-svn: 127475
2011-03-11 19:24:49 +00:00
Argyrios Kyrtzidis 35dcda7922 Introduce '-chain-include' option to specify headers that will be converted to chained PCHs in memory
without having to use multiple runs and intermediate files.

Intended for testing & debugging of chained PCH.

llvm-svn: 127339
2011-03-09 17:21:42 +00:00
Anders Carlsson 1f13bb5f00 When deserializing CXXBaseSpecifiers (and offsets), make sure to walk the chain in the correct order.
llvm-svn: 127315
2011-03-09 05:09:32 +00:00
Anders Carlsson a426705cc6 When writing file references in a pch, make sure to ask the file manager for the absolute path.
llvm-svn: 127248
2011-03-08 16:04:35 +00:00
NAKAMURA Takumi 3b78ef47fe test/PCH/headersearch.cpp: Tweak for Windows hosts especially cygming.
This test requires shell feature, to change working directory.
On Windows, current directory cannot be moved nor removed.

llvm-svn: 127130
2011-03-06 20:44:33 +00:00
Anders Carlsson 9bb83e85b8 Write CXX base specifier offsets for chained ASTs.
llvm-svn: 127126
2011-03-06 18:41:18 +00:00
Anders Carlsson 80756f6240 When serializing a DeclRefExpr, always store the number of explicit template
arguments at the same offset, since it's needed when creating the empty
DeclRefExpr when deserializing. Fixes a memory corruption issue that would lead
to random bugs and crashes.

llvm-svn: 127125
2011-03-06 18:19:42 +00:00
NAKAMURA Takumi fb7133249c test: Mark 3 tests as XFAIL:cygwin,mingw.
llvm-svn: 127077
2011-03-05 11:15:48 +00:00
NAKAMURA Takumi 7362afad29 test: Mark two tests as XFAIL:mingw.
llvm-svn: 127076
2011-03-05 11:15:38 +00:00
Douglas Gregor 250ffb1fcb When we're deserializing a template parameter declaration, temporarily
use the translation unit as its declaration context, then deserialize
the actual lexical and semantic DeclContexts after the template
parameter is complete. This avoids problems when the DeclContext
itself (e.g., a class template) is dependent on the template parameter
(e.g., for the injected-class-name).

llvm-svn: 127056
2011-03-05 01:35:54 +00:00
Anders Carlsson 6774b1f1c1 Add -fcxx-exceptions to all tests that use C++ exceptions.
llvm-svn: 126599
2011-02-28 00:40:07 +00:00
Anders Carlsson 3320e1575f Make clang -cc1 disable Objective-C exceptions by default, and add a -fobjc-exceptions flag to turn them on.
Update all tests accordingly.

llvm-svn: 126177
2011-02-22 01:52:06 +00:00
Anders Carlsson 479d6f51e3 Pass -fexceptions to all tests that use try/catch/throw.
llvm-svn: 126037
2011-02-19 19:23:03 +00:00
Francois Pichet b3e0886599 test/PCH/headersearch.cpp fails on Win32. Not trivial to fix.
llvm-svn: 125644
2011-02-16 02:29:43 +00:00
Peter Collingbourne 5df20e02af Serialization/deserialization support for floating point #pragma
options, enabled OpenCL extensions and default FP_CONTRACT setting.

llvm-svn: 125589
2011-02-15 19:46:30 +00:00
Argyrios Kyrtzidis 10b2368e9f Allow resolving headers from a PCH even after headers+PCH were moved to another path.
Store in PCH the directory that the PCH was originally created in.
If a header file is not found at the path that we expect it to be and the PCH file
was moved from its original location, try to resolve the file by assuming that
header+PCH were moved together and the header is in the same place relative to the PCH.

llvm-svn: 125576
2011-02-15 17:54:22 +00:00
Douglas Gregor 68051a74ec Implement AST/PCH chaining support for macro definitions. Previously,
we would deserialize all of the macro definitions we knew about while
serializing the macro definitions at the end of the AST/PCH file. Even
though we skipped most of them (since they were unchanged), it's still
a performance problem.

Now, we do the standard AST/PCH chaining trick: watch what identifiers
are deserialized as macro names, and consider only those identifiers
(along with macro definitions that have been deserialized/written in
the source) when serializing the preprocessor state.

llvm-svn: 125324
2011-02-11 00:26:14 +00:00
Douglas Gregor 2e5571d0fb When we're writing macro definitions to an AST/PCH File, sort the
macro definitions by macro name first. That way, we'll get a stable
ordering in the AST/PCH file.

llvm-svn: 125297
2011-02-10 18:20:09 +00:00
Peter Collingbourne 5eec5f0422 Parse: add support for parsing CUDA kernel calls
llvm-svn: 125219
2011-02-09 21:12:02 +00:00
Douglas Gregor 87866ceda7 Implement proper (de-)serialization for explicit template argument
lists with zero template arguments. Fixes some seriously scary
crashers in C++ PCH.

llvm-svn: 124862
2011-02-04 12:01:24 +00:00
Axel Naumann 6cff969eec Remove unnecessary RUN: directive.
llvm-svn: 124795
2011-02-03 14:05:55 +00:00
Matt Beaumont-Gay 06cebfd9a5 Use tempfiles for the .o outputs.
llvm-svn: 124697
2011-02-01 22:44:06 +00:00
Douglas Gregor 1732850158 Fix a thinko where I didn't update a consistency check for
PackExpansionType in the AST reader. We need more testing for variadic
templates + PCH, but this fixes PR9073.

llvm-svn: 124662
2011-02-01 15:24:58 +00:00
John McCall 4fff8f6cff Perform the bad-address-space conversions check as part of
CheckPointerTypesForAssignment.

llvm-svn: 124632
2011-02-01 00:10:29 +00:00
Axel Naumann 63fbaeda29 TextDiagnosticPrinter.cpp: Show diagnostics as far as possible even with invalid PresomedLoc, instead of just silencing it.
FileManager.cpp: Allow virtual files in nonexistent directories.
FileManager.cpp: Close FileDescriptor for virtual files that correspond to actual files.
FileManager.cpp: Enable virtual files to be created even for files that were flagged as NON_EXISTENT_FILE, e.g. by a prior (unsuccessful) addFile().

ASTReader.cpp: Read a PCH even if the original source files cannot be found.

Add a test for reading a PCH of a file that has been removed and diagnostics referencing that file.

llvm-svn: 124374
2011-01-27 10:55:51 +00:00
Argyrios Kyrtzidis 243aedb6ec Properly propagate #pragma diagnostic mappings from PCH but not command-line warning flags.
Addresses rdar://8435969&8852495

llvm-svn: 123462
2011-01-14 20:54:07 +00:00
Francois Pichet 9b45fdf060 Adding a line for XFAIL win32 broke the test.
Remove a line: this test is line position sensitive.

llvm-svn: 122231
2010-12-20 05:53:40 +00:00
Francois Pichet e919ba6516 test/PCH/reloc.c fails on Win32.
XFAIL for now, I'll investigate why later.

llvm-svn: 122229
2010-12-20 04:36:21 +00:00
Argyrios Kyrtzidis 452707c125 Read/write from/to PCH the diagnostic mappings that the user set so that e.g. #pragma clang diagnostic can be used in a PCH.
Fixes rdar://8435969.

llvm-svn: 118303
2010-11-05 22:10:18 +00:00
Douglas Gregor d4c5ed038c Make the deserialization of C++ base class specifiers lazy, improving
the performance of C++ PCH and reducing stack depth in the reader.

llvm-svn: 117732
2010-10-29 22:39:52 +00:00
Douglas Gregor f86c939bff When de-serializing a type that is supposed to be canonical, call
getCanonicalType() to make sure that the type we got back is actually
canonical. This is the case for most types, which always build a
canonical type when given canonical components. However, some types that
involve expressions in their canonicalization (e.g., array types with
dependent sizes) don't always build canonical types from canonical
components, because there is no such thing as a "canonical"
expression. Therefore, we do this extra mapping to ensure that the
canonical types we store are actually canonical.

llvm-svn: 117344
2010-10-26 00:51:02 +00:00
Argyrios Kyrtzidis d170d844c4 Start fleshing out ASTMutationListener; notify when a tag definition is completed.
In that case a chained PCH will record the updates to the DefinitionData pointer of forward references.
If a forward reference mutated into a definition re-write it into the chained PCH, this is too big of a change.

llvm-svn: 117239
2010-10-24 17:26:50 +00:00
Argyrios Kyrtzidis ad5f95cc4b Simplify and "robust-ify" the way that CXXRecord references point to the definition data when loaded from PCH.
Temporary disable 'test/PCH/chain-cxx.cpp' until a better way to fix it is in place.

llvm-svn: 117234
2010-10-24 17:26:31 +00:00
Argyrios Kyrtzidis a41f66064f Fix issue with chained PCH where forward references did not pick up later definition in the chained PCH.
llvm-svn: 116887
2010-10-20 00:11:15 +00:00
Andrew Trick ba266eec79 Putting back safe fixes 116836,116837,116838
llvm-svn: 116866
2010-10-19 21:54:32 +00:00
Andrew Trick b20ed574ab Reverting 116836,116837,116838 until we resolve the getLangStandardForKind failures.
llvm-svn: 116859
2010-10-19 21:14:46 +00:00
Argyrios Kyrtzidis 40338af47d Merge headers into test/PCH/chain-cxx.cpp for convenience.
llvm-svn: 116836
2010-10-19 18:06:43 +00:00
Argyrios Kyrtzidis 9beef8e53d Read/write declaration attributes from/to PCH properly. Embed them in the declaration block instead of trying to create another block.
The new block was messing with the assumption that after decls block comes the stmts block.
Fixes http://llvm.org/PR8406

llvm-svn: 116737
2010-10-18 19:20:11 +00:00