Commit Graph

642 Commits

Author SHA1 Message Date
Richard Smith 0f4e2c4d0f [modules] Defer setting up the lookup table for a DeclContext until we can
determine the primary context, rather than sometimes registering the lookup
table on the wrong context.

This exposed a couple of bugs:
 * the odr violation check didn't deal properly with mergeable declarations
   if the declaration retained by name lookup wasn't in the canonical
   definition of the class
 * the (broken) RewriteDecl mechanism would emit two name lookup tables for
   the same DeclContext into the same module file (one as part of the
   rewritten declaration and one as a visible update for the old declaration)
These are both fixed too.

llvm-svn: 244192
2015-08-06 04:23:48 +00:00
Argyrios Kyrtzidis 403cbcb84d Make sure the 2 method calls are sequenced.
llvm-svn: 243727
2015-07-31 01:39:23 +00:00
Argyrios Kyrtzidis c56419ed00 [modules] Fix issue where building a module from a relative path when -working-directory option is set, results in error.
The error was "module '<name>' was built in directory '<path>' but now resides in directory '<path>'
rdar://21330027

llvm-svn: 243718
2015-07-31 00:58:32 +00:00
Richard Smith f02662dec0 [modules] Remove redundant information written into DeclContext name lookup tables. We don't need to store the data length twice.
llvm-svn: 243612
2015-07-30 03:17:16 +00:00
Richard Smith 9b88a4cdf4 [modules] Add an assert for redeclarations that we never added to their redecl
chain and fix the cases where it fires.

 * Handle the __va_list_tag as a predefined decl. Previously we failed to merge
   sometimes it because it's not visible to name lookup. (In passing, remove
   redundant __va_list_tag typedefs that we were creating for some ABIs. These
   didn't affect the mangling or representation of the type.)

 * For Decls derived from Redeclarable that are not in fact redeclarable
   (implicit params, function params, ObjC type parameters), remove them from
   the list of expected redeclarable decls.

llvm-svn: 243259
2015-07-27 05:40:23 +00:00
Richard Smith 33e0f7ef94 [modules] Stop performing PCM lookups for all identifiers when building with C++ modules. Instead, serialize a list of interesting identifiers and mark those ones out of date on module import. Avoiding the identifier lookups here gives a 20-30% speedup in builds with large numbers of modules. No functionality change intended.
llvm-svn: 242868
2015-07-22 02:08:40 +00:00
Richard Smith a534a31c5e [modules] In C++, stop serializing and deserializing a list of declarations in
the identifier table. This is redundant, since the TU-scope lookups are also
serialized as part of the TU DeclContext, and wasteful in a number of ways. We
still emit the decls for PCH / preamble builds, since for those we want
identical results, not merely semantically equivalent ones.

llvm-svn: 242855
2015-07-21 23:54:07 +00:00
Richard Smith 9c25418424 [modules] Don't save uninteresting identifiers, and don't consider identifiers
to be interesting just because they are the name of a builtin. Reduces the size
of an empty module by over 80% (~100KB).

llvm-svn: 242650
2015-07-19 21:41:12 +00:00
Richard Smith cab8980229 Stop treating extension keywords as 'interesting'; we don't allow the extension
flag to change between serialization and deserialization, so it does not
require the identifier to be serialized.

llvm-svn: 242567
2015-07-17 20:19:56 +00:00
Richard Smith e2f8ce91e7 [modules] Switch to the normal reverse postorder visitation algorithm when computing redeclaration chains.
llvm-svn: 242253
2015-07-15 00:02:40 +00:00
Richard Smith 5fc18a9a1f [modules] Improve performance when there is a local declaration of an entity
before the first imported declaration.

We don't need to track all formerly-canonical declarations of an entity; it's sufficient to track those ones for which no other formerly-canonical declaration was imported into the same module. We call those ones "key declarations", and use them as our starting points for collecting redeclarations and performing namespace lookups.

llvm-svn: 241999
2015-07-12 23:43:21 +00:00
Douglas Gregor ab209d83be Implement the Objective-C __kindof type qualifier.
The __kindof type qualifier can be applied to Objective-C object
(pointer) types to indicate id-like behavior, which includes implicit
"downcasting" of __kindof types to subclasses and id-like message-send
behavior. __kindof types provide better type bounds for substitutions
into unspecified generic types, which preserves more type information.

llvm-svn: 241548
2015-07-07 03:58:42 +00:00
Douglas Gregor e83b95641f Substitute type arguments into uses of Objective-C interface members.
When messaging a method that was defined in an Objective-C class (or
category or extension thereof) that has type parameters, substitute
the type arguments for those type parameters. Similarly, substitute
into property accesses, instance variables, and other references.

This includes general infrastructure for substituting the type
arguments associated with an ObjCObject(Pointer)Type into a type
referenced within a particular context, handling all of the
substitutions required to deal with (e.g.) inheritance involving
parameterized classes. In cases where no type arguments are available
(e.g., because we're messaging via some unspecialized type, id, etc.),
we substitute in the type bounds for the type parameters instead.

Example:

  @interface NSSet<T : id<NSCopying>> : NSObject <NSCopying>
  - (T)firstObject;
  @end

  void f(NSSet<NSString *> *stringSet, NSSet *anySet) {
    [stringSet firstObject]; // produces NSString*
    [anySet firstObject]; // produces id<NSCopying> (the bound)
  }

When substituting for the type parameters given an unspecialized
context (i.e., no specific type arguments were given), substituting
the type bounds unconditionally produces type signatures that are too
strong compared to the pre-generics signatures. Instead, use the
following rule:

  - In covariant positions, such as method return types, replace type
    parameters with “id” or “Class” (the latter only when the type
    parameter bound is “Class” or qualified class, e.g,
    “Class<NSCopying>”)
  - In other positions (e.g., parameter types), replace type
    parameters with their type bounds.
  - When a specialized Objective-C object or object pointer type
    contains a type parameter in its type arguments (e.g.,
    NSArray<T>*, but not NSArray<NSString *> *), replace the entire
    object/object pointer type with its unspecialized version (e.g.,
    NSArray *).

llvm-svn: 241543
2015-07-07 03:57:53 +00:00
Douglas Gregor e9d95f1ecc Handle Objective-C type arguments.
Objective-C type arguments can be provided in angle brackets following
an Objective-C interface type. Syntactically, this is the same
position as one would provide protocol qualifiers (e.g.,
id<NSCopying>), so parse both together and let Sema sort out the
ambiguous cases. This applies both when parsing types and when parsing
the superclass of an Objective-C class, which can now be a specialized
type (e.g., NSMutableArray<T> inherits from NSArray<T>).

Check Objective-C type arguments against the type parameters of the
corresponding class. Verify the length of the type argument list and
that each type argument satisfies the corresponding bound.

Specializations of parameterized Objective-C classes are represented
in the type system as distinct types. Both specialized types (e.g.,
NSArray<NSString *> *) and unspecialized types (NSArray *) are
represented, separately.

llvm-svn: 241542
2015-07-07 03:57:35 +00:00
Alex Denisov fde64956f9 [ObjC] Add NSValue support for objc_boxed_expressions
Patch extends ObjCBoxedExpr to accept records (structs and unions):

typedef struct __attribute__((objc_boxable)) _Color {
  int r, g, b;
} Color;

Color color;
NSValue *boxedColor = @(color); // [NSValue valueWithBytes:&color objCType:@encode(Color)];

llvm-svn: 240761
2015-06-26 05:28:36 +00:00
Ben Langmuir d4a667a4c0 Use AddString/ReadString instead of doing it manually NFC
llvm-svn: 240434
2015-06-23 18:20:23 +00:00
Ben Langmuir cd98cb7312 [Modules] Consider -fmodule-feature in module hash and when loading
Any extra features from -fmodule-feature are part of the module hash and
need to get validated on load.  Also print them with -module-file-info.

llvm-svn: 240433
2015-06-23 18:20:18 +00:00
Alexander Kornienko ab9db51042 Revert r240270 ("Fixed/added namespace ending comments using clang-tidy").
llvm-svn: 240353
2015-06-22 23:07:51 +00:00
Alexander Kornienko 3d9d929e42 Fixed/added namespace ending comments using clang-tidy. NFC
The patch is generated using this command:

  $ tools/extra/clang-tidy/tool/run-clang-tidy.py -fix \
      -checks=-*,llvm-namespace-comment -header-filter='llvm/.*|clang/.*' \
      work/llvm/tools/clang

To reduce churn, not touching namespaces spanning less than 10 lines.

llvm-svn: 240270
2015-06-22 09:47:44 +00:00
Richard Smith f2b1eb9eb2 [modules] Better support for redefinitions of an entity from the same module.
Support this across module save/reload and extend the 'missing import'
diagnostics with a list of providing modules.

llvm-svn: 239750
2015-06-15 20:15:48 +00:00
Yunzhong Gao cb77930d6b Implementing C99 partial re-initialization behavior (DR-253)
Based on previous discussion on the mailing list, clang currently lacks support
for C99 partial re-initialization behavior:
Reference: http://lists.cs.uiuc.edu/pipermail/cfe-dev/2013-April/029188.html
Reference: http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_253.htm

This patch attempts to fix this problem.

Given the following code snippet,

struct P1 { char x[6]; };
struct LP1 { struct P1 p1; };

struct LP1 l = { .p1 = { "foo" }, .p1.x[2] = 'x' };
// this example is adapted from the example for "struct fred x[]" in DR-253;
// currently clang produces in l: { "\0\0x" },
//   whereas gcc 4.8 produces { "fox" };
// with this fix, clang will also produce: { "fox" };


Differential Review: http://reviews.llvm.org/D5789

llvm-svn: 239446
2015-06-10 00:27:52 +00:00
Daniel Marjamaki e4770da766 Refactor MacroInfo so macro arguments can be iterated with range-based for loops.
No functional change intended.

Patch by Sebastian Edman!

llvm-svn: 238547
2015-05-29 09:15:24 +00:00
Reid Kleckner 012665e16b Rename a helper template function to 'bytes' to avoid a C++17 STL conflict
MSVC 2015 includes the std::data() template function added to C++17. ADL
causes both cl.exe and clang-cl to prefer std::data over our static
helper here, and we get errors about converting int64_t* to StringRef.
Renaming it to bytes avoids the ambiguity.

llvm-svn: 237863
2015-05-21 00:13:09 +00:00
Ismail Pazarbasi e5768d1717 Detect uses of mismatching forms of 'new' and 'delete'
Emit warning when operand to `delete` is allocated with `new[]` or
operand to `delete[]` is allocated with `new`.

rev 2 update:
`getNewExprFromInitListOrExpr` should return `dyn_cast_or_null`
instead of `dyn_cast`, since `E` might be null.

Reviewers: rtrieu, jordan_rose, rsmith

Subscribers: majnemer, cfe-commits

Differential Revision: http://reviews.llvm.org/D4661

llvm-svn: 237608
2015-05-18 19:59:11 +00:00
Richard Smith 2b63d15f49 [modules] Retain the name as written for umbrella headers and directories, rather than converting to an absolute path. No observable change expected, but this allows us to correctly compute the module for an umbrella header, which later changes will require.
llvm-svn: 237508
2015-05-16 02:28:53 +00:00
Richard Smith 4241314164 [modules] Add local submodule visibility support for declarations.
With this change, enabling -fmodules-local-submodule-visibility results in name
visibility rules being applied to submodules of the current module in addition
to imported modules (that is, names no longer "leak" between submodules of the
same top-level module). This also makes it much safer to textually include a
non-modular library into a module: each submodule that textually includes that
library will get its own "copy" of that library, and so the library becomes
visible no matter which including submodule you import.

llvm-svn: 237473
2015-05-15 20:05:43 +00:00
Richard Smith 4caa449ade Refactor: when exposing a definition in some module, provide listeners with the
module rather than requiring them to work it out themselves.

llvm-svn: 237416
2015-05-15 02:34:32 +00:00
Diego Novillo c324b92c35 Revert "Detect uses of mismatching forms of 'new' and 'delete'"
This reverts commit 742dc9b6c9686ab52860b7da39c3a126d8a97fbc.

This is generating multiple segfaults in our internal builds.
Test case coming up shortly.

llvm-svn: 237391
2015-05-14 20:57:48 +00:00
Ismail Pazarbasi 538ef53c13 Detect uses of mismatching forms of 'new' and 'delete'
Emit warning when operand to `delete` is allocated with `new[]` or
operand to `delete[]` is allocated with `new`.

Reviewers: rtrieu, jordan_rose, rsmith

Subscribers: majnemer, cfe-commits

Differential Revision: http://reviews.llvm.org/D4661

llvm-svn: 237368
2015-05-14 16:14:57 +00:00
Richard Smith 23d8d0338e [modules] Fix a #include cycle when building a module for our builtin headers.
xmmintrin.h includes emmintrin.h and vice versa if SSE2 is enabled. We break
this cycle for a modules build, and instead make the xmmintrin.h module
re-export the immintrin.h module. Also included is a fix for an assert in the
serialization code if a module exports another module that was declared later
in the same module map.

llvm-svn: 237321
2015-05-14 00:45:20 +00:00
Richard Smith 66a8186ed4 Rename MacroDefinition -> MacroDefinitionRecord, Preprocessor::MacroDefinition -> MacroDefinition.
clang::MacroDefinition now models the currently-defined value of a macro. The
previous MacroDefinition type, which represented a record of a macro definition
directive for a detailed preprocessing record, is now called MacroDefinitionRecord.

llvm-svn: 236400
2015-05-04 02:25:31 +00:00
Richard Smith 10434f307c [modules] Remove dead code from Module for tracking macro import locations.
llvm-svn: 236376
2015-05-02 02:08:26 +00:00
Richard Smith ee977933f7 [modules] Add -fmodules-local-submodule-visibility flag.
This flag specifies that the normal visibility rules should be used even for
local submodules (submodules of the currently-being-built module). Thus names
will only be visible if a header / module that declares them has actually been
included / imported, and not merely because a submodule that happened to be
built earlier declared those names. This also removes the need to modularize
bottom-up: textually-included headers will be included into every submodule
that includes them, since their include guards will not leak between modules.

So far, this only governs visibility of macros, not of declarations, so is not
ready for real use yet.

llvm-svn: 236350
2015-05-01 21:22:17 +00:00
Richard Smith a7e2cc684f [modules] Start moving the module visibility information off the Module itself.
It has no place there; it's not a property of the Module, and it makes
restoring the visibility set when we leave a submodule more difficult.

llvm-svn: 236300
2015-05-01 01:53:09 +00:00
Richard Smith 3981b17709 Remove dead code: a MacroDirective can't be imported or ambiguous any more.
llvm-svn: 236197
2015-04-30 02:16:23 +00:00
Richard Smith 20e883e59b [modules] Stop trying to fake up a linear MacroDirective history.
Modules builds fundamentally have a non-linear macro history. In the interest
of better source fidelity, represent the macro definition information
faithfully: we have a linear macro directive history within each module, and at
any point we have a unique "latest" local macro directive and a collection of
visible imported directives. This also removes the attendent complexity of
attempting to create a correct MacroDirective history (which we got wrong
in the general case).

No functionality change intended.

llvm-svn: 236176
2015-04-29 23:20:19 +00:00
Richard Smith 713369b057 [modules] Store a ModuleMacro* on an imported macro directive rather than duplicating the info within it.
llvm-svn: 235644
2015-04-23 20:40:50 +00:00
Richard Smith b8b2ed6529 [modules] Determine the set of macros exported by a submodule at the end of that submodule.
Previously we'd defer this determination until writing the AST, which doesn't
allow us to use this information when building other submodules of the same
module. This change also allows us to use a uniform mechanism for writing
module macro records, independent of whether they are local or imported.

llvm-svn: 235614
2015-04-23 18:18:26 +00:00
Richard Smith d732939592 [modules] Move list of exported module macros from IdentifierInfo lookup table to separate storage, adjacent to the macro directive history.
This is substantially simpler, provides better space usage accounting in bcanalyzer,
and gives a more compact representation. No functionality change intended.

llvm-svn: 235420
2015-04-21 21:46:32 +00:00
Richard Smith 9eb309371b Try to work around failure to convert this lambda to a function pointer in some versions of GCC.
llvm-svn: 235264
2015-04-19 01:47:53 +00:00
Richard Smith cf97cf6693 [modules] Refactor macro emission. No functionality change.
llvm-svn: 235263
2015-04-19 01:34:23 +00:00
Richard Smith 13090a2304 [modules] Remove unused MACRO_TABLE record.
llvm-svn: 234555
2015-04-10 02:02:24 +00:00
Chandler Carruth 12c8f65408 [Modules] Make Sema's map of referenced selectors have a deterministic
order based on order of insertion.

This should cause both our warnings about these and the modules
serialization to be deterministic as a consequence.

Found by inspection.

llvm-svn: 233343
2015-03-27 00:55:05 +00:00
Chandler Carruth acbbeb9782 [Modules] Make our on-disk hash table of selector IDs be built in
a deterministic order.

This uses a MapVector to track the insertion order of selectors.

Found by inspection.

llvm-svn: 233342
2015-03-27 00:47:43 +00:00
Chandler Carruth b306d73a2d [Modules] Sort the file IDs prior to building the flattened array of
DeclIDs so that in addition to be grouped by file, the order of these
groups is stable.

Found by inspection, no test case. Not sure this can be observed without
a randomized seed for the hash table, but we shouldn't be relying on the
hash table layout under any circumstances.

llvm-svn: 233339
2015-03-27 00:31:20 +00:00
Chandler Carruth 8440c98642 [Modules] Make the AST serialization always use lexicographic order when
traversing the identifier table.

No easy test case as this table is somewhere between hard and impossible
to observe as non-deterministically ordered. The table is a hash table
but we hash the string contents and never remove entries from the table
so the growth pattern, etc, is all completely fixed. However, relying on
the hash function being deterministic is specifically against the
long-term direction of LLVM's hashing datastructures, which are intended
to provide *no* ordering guarantees. As such, this defends against these
things by sorting the identifiers. Sorting identifiers right before we
emit them to a serialized form seems a low cost for predictability here.

llvm-svn: 233332
2015-03-26 23:54:15 +00:00
Chandler Carruth 7bcfdd516c [Modules] Delete stale, pointless code. All tests still pass with this
logic removed.

This logic was both inserting all builtins into the identifier table and
ensuring they would get serialized. The first happens unconditionally
now, and we always write out the entire identifier table. This code can
simply go away.

llvm-svn: 233331
2015-03-26 23:45:40 +00:00
Chandler Carruth ffbf705cc3 [Modules] Fix a sneaky bug in r233249 where we would look for implicit
constructors in the current lexical context even though name lookup
found them via some other context merged into the redecl chain.

This can only happen for implicit constructors which can only have the
name of the type of the current context, so we can fix this by simply
*always* merging those names first. This also has the advantage of
removing the walk of the current lexical context from the common case
when this is the only constructor name we need to deal with (implicit or
otherwise).

I've enhanced the tests to cover this case (and uncovered an unrelated
bug which I fixed in r233325).

llvm-svn: 233327
2015-03-26 22:27:09 +00:00
Chandler Carruth 52cee4dad2 [Modules] Preserve source order for the map of late parsed templates.
Clang was inserting these into a dense map. While it never iterated the
dense map during normal compilation, it did when emitting a module. Fix
this by using a standard MapVector to preserve the order in which we
encounter the late parsed templates.

I suspect this still isn't ideal, as we don't seem to remove things from
this map even when we mark the templates as no longer late parsed. But
I don't know enough about this particular extension to craft a nice,
subtle test case covering this. I've managed to get the stress test to
at least do some late parsing and demonstrate the core problem here.
This patch fixes the test and provides deterministic behavior which is
a strict improvement over the prior state.

I've cleaned up some of the code here as well to be explicit about
inserting when that is what is actually going on.

llvm-svn: 233264
2015-03-26 09:08:15 +00:00
Chandler Carruth f85d98285e [Modules] Make "#pragma weak" undeclared identifiers be tracked
deterministically.

This fixes a latent issue where even Clang's Sema (and diagnostics) were
non-deterministic in the face of this pragma. The fix is super simple --
just use a MapVector so we track the order in which these are parsed (or
imported). Especially considering how rare they are, this seems like the
perfect tradeoff. I've also simplified the client code with judicious
use of auto and range based for loops.

I've added some pretty hilarious code to my stress test which now
survives the binary diff without issue.

llvm-svn: 233261
2015-03-26 08:32:49 +00:00