Commit Graph

1243 Commits

Author SHA1 Message Date
Adrian Prantl 5e30490644 Typo.
llvm-svn: 279491
2016-08-22 22:38:18 +00:00
Adrian Prantl 8ff4c08e34 Add the second half of the testcase I should have added in 279485.
llvm-svn: 279489
2016-08-22 22:30:34 +00:00
Richard Smith 2fbcbb7b38 Fix regression introduced by r279164: only pass definitions as the PatternDef
to DiagnoseUninstantiableTemplate, teach hasVisibleDefinition to correctly
determine whether a function definition is visible, and mark both the function
and the template as visible when merging function template definitions to
provide hasVisibleDefinition with the relevant information.

The change to always pass the right declaration as the PatternDef to
DiagnoseUninstantiableTemplate also caused those checks to happen before other
diagnostics in InstantiateFunctionDefinition, giving worse diagnostics for the
same situations, so I sunk the relevant diagnostics into
DiagnoseUninstantiableTemplate. Those parts of this patch are based on changes
in reviews.llvm.org/D23492 by Vassil Vassilev.

llvm-svn: 279486
2016-08-22 22:25:03 +00:00
Adrian Prantl a72972b985 Module debug info: Don't assert when encountering an incomplete definition
in isDefinedInClangModule() and assume that the incomplete definition
is not defined in the module.

This broke the -gmodules self host recently.
rdar://problem/27894367

llvm-svn: 279485
2016-08-22 22:23:58 +00:00
NAKAMURA Takumi cc980fc55f clang/test/Modules/prebuilt-module.m: Prune "-triple" to fix a configuration mismatch.
llvm-svn: 279207
2016-08-19 05:25:26 +00:00
Vassil Vassilev b21ee08e57 PR28794: Don't try to instantiate function templates which are not visible.
Reviewed by Richard Smith.

llvm-svn: 279164
2016-08-18 22:01:25 +00:00
Manman Ren 11f2a47772 Module: add -fprebuilt-module-path to support loading prebuilt modules.
In this mode, there is no need to load any module map and the programmer can
simply use "@import" syntax to load the module directly from a prebuilt
module path. When loading from prebuilt module path, we don't support
rebuilding of the module files and we ignore compatible configuration
mismatches.

rdar://27290316
Differential Revision: http://reviews.llvm.org/D23125

llvm-svn: 279096
2016-08-18 17:42:15 +00:00
Richard Smith ceaf5ad041 Remove debugging aids from this test and fix its expectations.
llvm-svn: 279034
2016-08-18 06:15:19 +00:00
Richard Smith 3dba7ebde4 PR28438: Update the information on an identifier with local definitions before
trying to write out its macro graph, in case we imported a module that added
another module macro between the most recent local definition and the end of
the module.

llvm-svn: 279024
2016-08-18 01:16:55 +00:00
Adrian Prantl 99e765b4f8 Print the module format in clang -module-file-info.
llvm-svn: 279005
2016-08-17 23:14:00 +00:00
Adrian Prantl 576b2dbec5 Support object-file-wrapped modules in clang -module-file-info.
rdar://problem/24504815

llvm-svn: 279004
2016-08-17 23:13:53 +00:00
Adrian Prantl 26cb1d2660 Module debug info: Fix a bug in handling record decls without fields.
The previous condition would erroneously mark all CXXRecordDecls
that didn't have any fields as being defined in a clang module.
This patch fixes the condition to only apply to explicit template
instantiations.

<rdar://problem/27771823>

llvm-svn: 278952
2016-08-17 18:27:24 +00:00
Bruno Cardoso Lopes b40d8ad225 [VFS] Add 'ignore-non-existent-contents' field to YAML files
Add 'ignore-non-existent-contents' to tell the VFS whether an invalid path
obtained via 'external-contents' should cause iteration on the VFS to stop.

If 'true', the VFS should ignore the entry and continue with the next. Allows
YAML files to be shared across multiple compiler invocations regardless of
prior existent paths in 'external-contents'. This global value is overridable
on a per-file basis.

This adds the parsing and write test part, but use by VFS comes next.

Differential Revision: https://reviews.llvm.org/D23422

rdar://problem/27531549

llvm-svn: 278456
2016-08-12 01:50:53 +00:00
Etienne Bergeron 74dc9b8388 [clang/test] Fix a flaky unittest on windows
Summary:
The append operator on a shell command for quick command-line is
causing trouble on windows. [NFC]
The easiest way to fix them is to avoid using them.

This patch is an attempt to fix this broken build bot:
  clang-x86-win2008-selfhost

http://lab.llvm.org:8011/builders/clang-x86-win2008-selfhost/builds/9523

Reviewers: rnk

Subscribers: cfe-commits, chrisha

Differential Revision: https://reviews.llvm.org/D23105

llvm-svn: 277576
2016-08-03 06:10:15 +00:00
Manman Ren 47a4445687 Modules: add command line option fmodules-disable-diagnostic-validation
With PCH+Module, sometimes compiler gives a hard error:
Module file ‘<some-file path>.pcm' is out of date and needs to be rebuilt

This happens when we have a pch importing a module and the module gets
overwritten by another compiler instance after we build the pch (one example is
that both compiler instances hash to the same pcm file but use different
diagnostic options). When we try to load the pch later on, the compiler notices
that the imported module is out of date (modification date, size do not match)
but it can't handle this out of date pcm (i.e it does not know how to rebuild
the pch).

This commit introduces a new command line option so for PCH + module, we can
turn on this option and if two compiler instances only differ in diagnostic
options, the latter instance will not invalidate the original pcm.

rdar://26675801
Differential Revision: http://reviews.llvm.org/D22773

llvm-svn: 276769
2016-07-26 17:12:17 +00:00
Vassil Vassilev 19765fb68c [modules] Teach the ASTWriter to ignore mutations coming from the ASTReader.
Processing update records (and loading a module, in general) might trigger
unexpected calls to the ASTWriter (being a mutation listener). Now we have a
mechanism to suppress those calls to the ASTWriter but notify other possible
mutation listeners.

Fixes https://llvm.org/bugs/show_bug.cgi?id=28332

Patch by Cristina Cristescu and me.

Reviewed by Richard Smith (D21800).

llvm-svn: 276473
2016-07-22 21:08:24 +00:00
Vassil Vassilev 462a5328dd Add regression test for PR27699.
llvm-svn: 276469
2016-07-22 20:49:31 +00:00
Reid Kleckner 07915f6cb0 Disable a flaky test on Windows that uses "echo >>"
llvm-svn: 276335
2016-07-21 21:07:47 +00:00
Adrian McCarthy ab1e786503 Reroll "Include unreferenced nested types in member list only for CodeView"
Another attempt at r276271, hopefully without breaking ModuleDebugInfo test.

llvm-svn: 276317
2016-07-21 18:43:20 +00:00
Adrian McCarthy a9a89ae77f Revert "Include unreferenced nested types in member list only for CodeView"
Patch broke ModuleDebugInfo test on the build bots (but not locally).  Again.

svn revision:  r276271

This reverts commit 9da8a1b05362bc96f2855fb32b5588b89407685d.

llvm-svn: 276279
2016-07-21 13:41:25 +00:00
Adrian McCarthy e89c62a102 Include unreferenced nested types in member list only for CodeView
Unreferenced nested structs and classes were omitted from the debug info.  In DWARF, this was intentional, to avoid bloat.  But for CodeView, we want this information to be consistent with what Microsoft tools would produce and expect.

llvm-svn: 276271
2016-07-21 13:16:14 +00:00
Richard Smith dc1f042171 [modules] Don't emit initializers for VarDecls within a module eagerly whenever
we first touch any part of that module. Instead, defer them until the first
time that module is (transitively) imported. The initializer step for a module
then recursively initializes modules that its own headers imported.

For example, this avoids running the <iostream> global initializer in programs
that don't actually use iostreams, but do use other parts of the standard
library.

llvm-svn: 276159
2016-07-20 19:10:16 +00:00
Richard Smith 13fb860c78 Revert r275481, r275490. This broke modules bootstrap.
llvm-svn: 275624
2016-07-15 21:33:46 +00:00
Richard Smith 3cbf3f1f59 Push alias-declarations and alias-template declarations into scope even if
they're redeclarations. This is necessary in order for name lookup to correctly
find the most recent declaration of the name (which affects default template
argument lookup and cross-module merging, among other things).

llvm-svn: 275612
2016-07-15 20:53:25 +00:00
Richard Smith 6b016c1575 Add test inputs missed by r275481.
llvm-svn: 275490
2016-07-14 22:15:06 +00:00
Richard Smith 6c35b2dea4 [modules] Don't pass interesting decls to the consumer for a module file that's
passed on the command line but never actually used. We consider a (top-level)
module to be used if any part of it is imported, either by the current
translation unit, or by any part of a top-level module that is itself used.

(Put another way, a module is used if an implicit modules build would have
loaded its .pcm file.)

llvm-svn: 275481
2016-07-14 21:50:09 +00:00
Rafael Espindola c9d336e549 Restructure the propagation of -fPIC/-fPIE.
The PIC and PIE levels are not independent. In fact, if PIE is defined
it is always the same as PIC.

This is clear in the driver where ParsePICArgs returns a PIC level and
a IsPIE boolean. Unfortunately that is currently lost and we pass two
redundant levels down the pipeline.

This patch keeps a bool and a PIC level all the way down to codegen.

llvm-svn: 273566
2016-06-23 15:07:32 +00:00
Vassil Vassilev cc218abe34 [modules] Allow emission of update records for predefined __va_list_tag.
Handles the cases where old __va_list_tag is coming from a module and the new
is not, needing an update record.

Fixes https://llvm.org/bugs/show_bug.cgi?id=27890

Patch by Cristina Cristescu, Richard Smith and me.

llvm-svn: 273159
2016-06-20 15:10:40 +00:00
Richard Trieu d5849279fc Redirect unused output in test to /dev/null
Discard unused output so when the test fails, it only prints information that
is helpful about the failure.  No functional change.

llvm-svn: 272325
2016-06-09 22:39:20 +00:00
Manman Ren 33d8029589 PCH + module: make sure we write out macros associated with builtin identifiers.
When we import a module that defines a builtin identifier from prefix header and
precompile the prefix header, the macro information related to the identifier
is lost.

If we don't precompile the prefix header, the source file can still see the
macro information. The reason is that we write out the identifier in the pch
but not the macro information since the macro is not defined locally.

This is related to r251565. In that commit, if we read a builtin identifier from
a module that wasn't "interesting" to that module, we will still write it out to
a PCH that imports that module.

The fix is to write exported module macros for PCH as well.

rdar://24666630

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

llvm-svn: 271310
2016-05-31 18:19:32 +00:00
Vassil Vassilev 8ffe3be8be [modules] Ask the canonical decl whether the constructor was defaulted.
In case of template instantiations query the template instantiation pattern,
which had actually '=default'.

Fixes https://llvm.org/bugs/show_bug.cgi?id=27739

Patch reviewed by Richard Smith.

llvm-svn: 270553
2016-05-24 12:10:36 +00:00
Richard Smith b648399f9f PR27754: CXXRecordDecl::data() needs to perform an update even if it's called
on a declaration that already knows the location of the DefinitionData object.

llvm-svn: 269858
2016-05-17 22:44:15 +00:00
Manman Ren e4a5d37d6b Modules: set SystemHeader to true if we are building a system module.
If we are processing a #include from a module build, we should treat it
as a system header if we're building a system module. Passing an optional
flag to HeaderSearch::LookupFile.

Before this, the testing case will crash when accessing a freed FileEntry.

rdar://26214027

llvm-svn: 269730
2016-05-17 02:15:12 +00:00
Bruno Cardoso Lopes b171a59bfd [Modules] Use vfs for (recursive) directory iteration
Clang performs directory walk while searching headers inside modules by
using the ::sys::fs instead of ::vfs. This prevents any code that uses
the VFS (e.g, reproducer scripts) to actually find such headers, since
the VFS will never be searched for those.

Change these places to use vfs::recursive_directory_iterator and
vfs::directory_iterator instead.

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

rdar://problem/25880368

llvm-svn: 269661
2016-05-16 16:46:01 +00:00
Bruno Cardoso Lopes b3a0fa4863 [ModuleMap][CrashReproducer] Collect headers from inner frameworks
(1) Collect headers under inner frameworks (frameworks inside other
other frameworks).
(2) Make sure we also collect the right header files inside them.

More info on (2):

Consider a dummy framework module B, with header Frameworks/B/B.h. Now
consider that another framework A, with header Frameworks/A/A.h, has a
layout with a inner framework Frameworks/A/Frameworks/B/B.h, where the
"B/B.h" part is a symlink for Frameworks/B/B.h. Also assume that
Frameworks/A/A.h includes <B/B.h>.

When parsing header Frameworks/A/A.h, framework module lookup is
performed in search for B, and it happens that
"Frameworks/A/Frameworks/B/B.h" path is registered in the module instead
of real "Frameworks/B/B.h". This occurs because
"Frameworks/A/Frameworks/B/B.h" is scanned first by the FileManager,
when looking for inner framework modules under Frameworks/A/Frameworks.
This makes Frameworks/A/Frameworks/B/B.h the default cached named inside
the FileManager for the B.h file UID.

This leads to modules being built without consistent paths to underlying
header files. This is usually not a problem in regular compilation flow,
but it's an issue when running the crash reproducer. The issue is that
clangs collect "Frameworks/A/Frameworks/B/B.h" but not
"Frameworks/B/B.h" into the VFS, leading to err_mmap_umbrella_clash. So
make sure we also collect the original header.

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

rdar://problem/25880368

llvm-svn: 269502
2016-05-13 22:21:51 +00:00
Bruno Cardoso Lopes 0df3e04460 [CrashReproducer] Always use realpath for destination
When running reproducer scripts we need that original symlinks from the
source filesystem are reproduced in the VFS so that different virtual
paths can map to the same file, allowing the FileManager to share the
same UID between these virtual entries. This avoids all sorts of module
redefinition errors when using frameworks.

llvm-svn: 268825
2016-05-06 23:58:58 +00:00
Richard Smith 6739a10cec [modules] Enforce the rules that an explicit or partial specialization must be
declared before it is used. Because we don't use normal name lookup to find
these, the normal code to filter out non-visible names from name lookup results
does not apply.

llvm-svn: 268585
2016-05-05 00:56:12 +00:00
Ben Langmuir 537c5b5b62 Fix CodeCompletion & TypoCorrection when combining a PCH with Modules
This commit fixes the IdentifierIterator to actually include identifiers
from a PCH or precompiled preamble when there is also a global module
index. This was causing code-completion (outside of C++) and
typo-correction to be missing global identifiers defined in the
PCH/preamble. Typo-correction has been broken since we first started
using the module index, whereas code-completion only started relying on
identifier iterator in r232793.

rdar://problem/25642879

llvm-svn: 268471
2016-05-04 00:53:13 +00:00
David Blaikie af09f4ac72 [modules][debuginfo] Only include imported modules when targeting LLDB
These constructs are only applicable to a debugger capable of loading a
Clang AST, so omit them for brevity when not doing so.

We could potentially propagate more of CodeGenOptions through the
ObjectFilePCGContainerOperations for consistency (so the next person who
adds some CodeGenOpts feature that tweaks debug info output doesn't get
caught by this), so I'm open to objections/alternatives there, but went
with this for now.

Tested just a couple of basic cases (one direct, one indirect (through
the ObjectFilePCHContainerOperations) & fixed up other cases to pass the
-debugger-tuning flag as appropriate.

llvm-svn: 268460
2016-05-03 23:06:40 +00:00
Douglas Yung d58d9fa573 Adding a test for a compiler crash that was fixed in r248069.
Differential Revision: http://reviews.llvm.org/D19048

llvm-svn: 268344
2016-05-03 00:29:56 +00:00
Manman Ren a0f31a01f3 Method Pool in modules: we make sure that if a module contains an entry for
a selector, the entry should be complete, containing everything introduced by
that module and all modules it imports.

Before writing out the method pool of a module, we sync up the out of date
selectors by pulling in methods for the selectors, from all modules it imports.

In ReadMethodPool, after pulling in the method pool entry for module A, this
lets us skip the modules that module A imports.

rdar://problem/25900131

llvm-svn: 268091
2016-04-29 19:04:05 +00:00
Vassil Vassilev 928c8254a9 Reland r267691 fixing PR27535.
llvm-svn: 267882
2016-04-28 14:13:28 +00:00
Richard Smith 4eb8393c63 [modules] When diagnosing a missing module import, suggest adding a #include if
the current language doesn't have an import syntax and we can figure out a
suitable file to include.

llvm-svn: 267802
2016-04-27 21:57:05 +00:00
Nico Weber 3a94763101 Revert r267691, it caused PR27535.
llvm-svn: 267744
2016-04-27 17:26:08 +00:00
Vassil Vassilev a4d7d783d0 [modules] Fix Decl's Used invariant.
The Decl::isUsed has a value for every decl. In non-module builds it is very
difficult (but possible) to break this invariant but when we walk up the redecl
chain we find the neccessary information.

When deserializing the decls from a module it is much more difficult to update
correctly this invariant. The patch centralizes the information whether a decl
is used in the canonical decl marking the entire entity as being used.

Fixes https://llvm.org/bugs/show_bug.cgi?id=27401

Patch by Cristina Cristescu and me.

Thanks to Richard Smith who helped to debug and understand the issue!

Reviewed by Richard Smith.

llvm-svn: 267691
2016-04-27 10:46:06 +00:00
Richard Smith d49941b726 PR27513: When determining which declaration to put into an exported lookup
table for a module / PCH, never map from a normal declaration of a class to an
injected-class-name declaration (or vice versa). Those declarations live in
distinct lookup tables and should not be confused.

We really shouldn't be using a CXXRecordDecl to represent an
injected-class-name in the first place; I've filed PR27532 so we don't forget.

llvm-svn: 267632
2016-04-26 23:40:43 +00:00
Adrian Prantl 0dabc2adba Module debugging: Also correctly handle typedef'd foward-declared members.
Thanks again to Richard Smith for pointing this out.

llvm-svn: 267630
2016-04-26 23:37:38 +00:00
Adrian Prantl 90931c4853 Module debugging: Add testcase for member classes of class template specializations.
llvm-svn: 267612
2016-04-26 21:58:23 +00:00
Adrian Prantl 88d7917970 Module debugging: Use the definition to determine module-defined types.
Follow-up to r267464. Thanks to Richard Smith for pointing this out!

llvm-svn: 267611
2016-04-26 21:58:18 +00:00
Adrian Prantl 05fefa4a85 Module Debugging: Fix the condition for determining whether a template
instantiation is in a module.

This patch fixes the condition for determining whether the debug info for a
template instantiation will exist in an imported clang module by:

- checking whether the ClassTemplateSpecializationDecl is complete and
- checking that the instantiation was in a module by looking at the first field.

I also added a negative check to make sure that a typedef to a forward-declared
template (with the definition outside of the module) is handled correctly.

http://reviews.llvm.org/D19443
rdar://problem/25553724

llvm-svn: 267464
2016-04-25 20:52:40 +00:00
Duncan P. N. Exon Smith 383f8413cf DebugInfo: Adapt to loss of DITypeRef in LLVM r267296
LLVM stopped using MDString-based type references, and DIBuilder no
longer fills 'retainedTypes:' with every DICompositeType that has an
'identifier:' field.   There are just minor changes to keep the same
behaviour in CFE.

Leaving 'retainedTypes:' unfilled has a dramatic impact on the output
order of the IR though.  There are a huge number of testcase changes,
which were unfortunately not really scriptable.

llvm-svn: 267297
2016-04-23 21:08:27 +00:00
Adrian Prantl 50fd1a87c4 Module Debugging: Emit the canonical debug info for Objective-C classes
in the compile unit that contains their implementation even if their
interface is declared in a module.

The private @implementation of an @interface may have additional
hidden ivars so we should not defer to the public version of the
type that is found in the module.

<rdar://problem/25541798>

llvm-svn: 266937
2016-04-20 23:59:32 +00:00
Duncan P. N. Exon Smith f9521b0bb7 DebugInfo: Make DICompositeTypes distinct most of the time
Since elements of most kinds of DICompositeType have back references,
most are involved in uniquing cycles.  Except via the ODR 'identifier:'
field, which doesn't care about the storage type (see r266549),
they have no hope of being uniqued.

Distinct nodes are far more efficient, so use them for most kinds of
DICompositeType definitions (i.e., when DIType::isForwardDecl is false).
The exceptions:

  - DW_TAG_array_type, since their elements never have back-references
    and they never have ODR 'identifier:' fields;

  - DW_TAG_enumeration_type when there is no ODR 'identifier:' field,
    since their elements usually don't have back-references.

This breaks the last major uniquing cycle I'm aware of in the debug info
graph.  The impact won't be enormous for C++ because references to
ODR-uniqued nodes still use string-based DITypeRefs; but this should
prevent a regression in C++ when we drop the string-based references.

This wouldn't have been reasonable until r266549, when composite types
stopped relying on being uniqued by structural equivalence to prevent
blow-ups at LTO time.

llvm-svn: 266556
2016-04-17 07:45:08 +00:00
Adrian Prantl e76bda544b Update to match LLVM changes for PR27284.
(Reverse the ownership between DICompileUnit and DISubprogram.)

http://reviews.llvm.org/D19034
<rdar://problem/25256815>

llvm-svn: 266445
2016-04-15 15:55:45 +00:00
Richard Smith 9c4fb0a833 Fix off-by-one error in worst-case number of offsets needed for an AST record.
llvm-svn: 266353
2016-04-14 18:32:54 +00:00
Bruno Cardoso Lopes 50688beb10 [CrashReproducer] Add test to run the reproducer script + modules
Now that we have basic support in place, make sure the reproducer script
works with modules for a simple testcase.

llvm-svn: 266235
2016-04-13 19:28:24 +00:00
Bruno Cardoso Lopes fc8644cd62 [CrashReproducer] Setup 'use-external-names' in YAML files.
Hide the real paths when rebuilding from VFS by setting up the crash
reproducer to use 'use-external-names' = false. This way we avoid
module redifinition errors and consistently use the same paths against
all modules.

With this change on Darwin we are able to simulate a crash for a simple
application using "Foundation/Foundation.h" (which relies on a bunch of
different frameworks and headers) and successfully rebuild all the
modules by relying solely at the VFS overlay.

llvm-svn: 266234
2016-04-13 19:28:21 +00:00
Richard Smith 6893570853 [modules] Extend r266113 to cope with submodules.
llvm-svn: 266116
2016-04-12 20:20:33 +00:00
Richard Smith 58df343b76 [modules] When an incompatible module file is explicitly provided for a module,
and we fall back to textual inclusion, don't require the module as a whole to
be marked available; it's OK if some other file in the same module is missing,
just as it would be if the header were explicitly marked textual.

llvm-svn: 266113
2016-04-12 19:58:30 +00:00
Richard Smith 1e8e91b379 PR25501: Delay loading visible updates for a declaration until after we've
processed update records. If an update record adds a definition, we need to
merge that with any pre-existing definition to determine which the canonical
definition is before we apply the visible update, otherwise we wouldn't know
where to apply it.

Thanks to Vassil Vassilev for help reducing this and tracking down the problem.

llvm-svn: 265848
2016-04-08 20:53:26 +00:00
Richard Smith fe1bc708b5 [modules] Handle merged fields in designated initializers.
llvm-svn: 265838
2016-04-08 19:57:40 +00:00
Richard Smith 6a6747d9dd [modules] Add a comment to explain why -E leaves some #includes in the preprocessed output.
llvm-svn: 265766
2016-04-08 01:23:59 +00:00
Richard Smith 466a15ef7f [modules] Don't write @import in -E output if the current language mode doesn't
support @import; use the form as written instead.

llvm-svn: 265756
2016-04-08 00:09:53 +00:00
Richard Smith 351241c83e Replace Sema-level implementation of -fassume-sane-operator-new with a
CodeGen-level implementation. Instead of adding an attribute to clang's
FunctionDecl, add the IR attribute directly. This means a module built with
this flag is now compatible with code built without it and vice versa.

This change also results in the 'noalias' attribute no longer being added to
calls to operator new in the IR; it's now only added to the declaration. It
also fixes a bug where we failed to add the attribute to the 'nothrow' versions
(because we didn't implicitly declare them, there was no good time to inject a
fake attribute).

llvm-svn: 265728
2016-04-07 21:46:12 +00:00
Richard Smith a1ddf5e744 [modules] Allow differences in flags that only affect preprocessor predefines
(and __has_feature checks) between explicitly-specified module files and the
current compilation.

llvm-svn: 265718
2016-04-07 20:47:37 +00:00
Bruno Cardoso Lopes 4c20bef1ef [CrashReproducer] Setup 'case-sensitive' in YAML files.
The crash reproducer was not setting up case sensitivity in the
VFS yaml files, which defaults to true. Make the crash reproducer
explicitly set that flag based on the case sensitivity of the .cache
path where vfs and modules are dumped.

llvm-svn: 265622
2016-04-07 00:00:57 +00:00
Manman Ren 8f42e69b18 Keep -fmodule-implementation-of as an alias of -fmodule-name.
This helps us transitioning to -fmodule-name. Once the transitioning is done,
we can remove this alias.

rdar://24800983

llvm-svn: 265616
2016-04-06 23:28:26 +00:00
Vassil Vassilev 59f6586da0 [modules] Add forgotten test case to r265597.
llvm-svn: 265599
2016-04-06 20:58:12 +00:00
Bruno Cardoso Lopes b810b02b85 [CrashReproducer] Pass -I, -F and -resource-dir to the reproducer script when using modules/vfs
The reproducer should use -I/-F/-resource-dir in the same way as the
original command. The VFS already collects the right headers but without
these flags the reproducer will fail to do the right thing.

llvm-svn: 265343
2016-04-04 20:26:57 +00:00
Bruno Cardoso Lopes f854b042e7 [CrashReproducer] Add -fmodule-cache-path to reproducer script
The cc1 invocation in the reproducer script should contain a valid path in
-fmodule-cache-path; for that reuse "<name>.cache/module" dir we already
use to dump the vfs and modules.

llvm-svn: 265162
2016-04-01 17:39:08 +00:00
Bruno Cardoso Lopes e62cfd7c17 [CrashReproducer] Add a module map callback for added headers
The current ModuleDependencyCollector has a AST listener to collect
header files present in loaded modules, but this isn't enough to collect
all headers needed in the crash reproducer. One of the reasons is that
the AST writer doesn't write symbolic link header paths in the pcm modules,
this makes the listeners on the reader only able to collect the real files.

Since the module maps could contain submodules that use headers which
are symbolic links, not collecting those forbid the reproducer scripts
to regen the modules.

For instance:

usr/include/module.map:
  ...
  module pthread {
    header "pthread.h"
    export *

    module impl {
      header "pthread_impl.h"
      export *
    }
  }
  ...

usr/include/pthread/pthread_impl.h
usr/include/pthread_impl.h -> pthread/pthread_impl.h

The AST dump for the module above:

  <SUBMODULE_HEADER abbrevid=6/> blob data = 'pthread_impl.h'
  <SUBMODULE_TOPHEADER abbrevid=7/> blob data = '/<path_to_sdk>/usr/include/pthread/pthread_impl.h'

Note that we don't have "usr/include/pthread_impl.h" which is requested
by the module.map in case we want to reconstruct the module in the
reproducer. The reason the original symbolic link path isn't used is
because the headers are kept by name and requested through the
FileManager, which unique files and returns the real path only.

To fix that, add a callback to be invoked everytime a header is added
while parsing module maps and hook that up to the module dependecy
collector. This callback is only registered when generating the
reproducer.

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

rdar://problem/24499339

llvm-svn: 264971
2016-03-30 23:54:25 +00:00
Bruno Cardoso Lopes d712b34167 [VFS] Handle empty entries in directory traversal
The VFS YAML files contain empty directory entries to describe that it's
returning from a subdirectory before describing new files in the parent.
In the future, we should properly sort and write YAML files avoiding
such empty dirs and mitigate the extra recurson cost. However, since
this is used by previous existing YAMLs, make the traversal work in
their presence.

rdar://problem/24499339

llvm-svn: 264970
2016-03-30 23:54:00 +00:00
Vassil Vassilev 85daf65c5a Add -emit-llvm-only to the regression test for PR21547.
llvm-svn: 264939
2016-03-30 22:22:50 +00:00
Vassil Vassilev bab6f96fff Canonicalize UnaryTransformType types when they don't have a known underlying type.
Fixes https://llvm.org/bugs/show_bug.cgi?id=26014

Reviewed by Richard Smith.

llvm-svn: 264937
2016-03-30 22:18:29 +00:00
Vassil Vassilev 262f41e91c [modules] Write out identifiers if the ID is local, too.
In some cases a slot for an identifier is requested but it gets written to
another module, causing an assertion.

At the point when we start serializing Rtypes, we have no imported IdentifierID
for float_round_style. We start serializing stuff and allocate an ID for it.
Then, during the serialization process, we pull in the identifier info for it
from TSchemaHelper. Finally, WriteIdentifierTable decides that the identifier
has not changed since it was deserialized, so doesn't emit it.

Fixes https://llvm.org/bugs/show_bug.cgi?id=27041

Discussed on IRC with Richard Smith. Agreed on post commit review if needed.

llvm-svn: 264913
2016-03-30 20:16:03 +00:00
Vassil Vassilev a3cbf2a738 [modules] Add a regression test for PR21547.
llvm-svn: 264908
2016-03-30 20:10:07 +00:00
Richard Smith 8a3e39ab67 [modules] If both a module file and a module map for the same module are
explicitly provided, and the module map lists a header that does not exist,
unmark the module as 'unavailable' when loading its .pcm file. (Use of the
module might still fail if the relevant headers aren't embedded, but this
behavior is now consistent with how we behave if the module map is not
provided, and with the desired behavior for embedding headers in modules.)

llvm-svn: 264664
2016-03-28 21:31:09 +00:00
Richard Smith 8d83d6db7c [modules] Don't invent a module cache path unless implicit module builds are enabled.
llvm-svn: 263970
2016-03-21 19:06:06 +00:00
Bruno Cardoso Lopes 936a054522 [VFS] Fix test to use more restrict set of headers
llvm-svn: 263912
2016-03-20 18:08:32 +00:00
Bruno Cardoso Lopes d878e28e67 Reapply [2] [VFS] Add 'overlay-relative' field to YAML files
This reapplies r261552 and r263748. Fixed testcase to reapply.

The VFS overlay mapping between virtual paths and real paths is done through
the 'external-contents' entries in YAML files, which contains hardcoded paths
to the real files.

When a module compilation crashes, headers are dumped into <name>.cache/vfs
directory and are mapped via the <name>.cache/vfs/vfs.yaml. The script
generated for reproduction uses -ivfsoverlay pointing to file to gather the
mapping between virtual paths and files inside <name>.cache/vfs. Currently, we
are only capable of reproducing such crashes in the same machine as they
happen, because of the hardcoded paths in 'external-contents'.

To be able to reproduce a crash in another machine, this patch introduces a new
option in the VFS yaml file called 'overlay-relative'. When it's equal to
'true' it means that the provided path to the YAML file through the
-ivfsoverlay option should also be used to prefix the final path for every
'external-contents'.

Example, given the invocation snippet "... -ivfsoverlay
<name>.cache/vfs/vfs.yaml" and the following entry in the yaml file:

"overlay-relative": "true",
"roots": [
...
  "type": "directory",
  "name": "/usr/include",
  "contents": [
    {
      "type": "file",
      "name": "stdio.h",
      "external-contents": "/usr/include/stdio.h"
    },
...

Here, a file manager request for virtual "/usr/include/stdio.h", that will map
into real path "/<absolute_path_to>/<name>.cache/vfs/usr/include/stdio.h.

This is a useful feature for debugging module crashes in machines other than
the one where the error happened.

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

rdar://problem/24499339

llvm-svn: 263893
2016-03-20 02:08:48 +00:00
Bruno Cardoso Lopes 9e2f9d818f Revert "Reapply [VFS] Add 'overlay-relative' field to YAML files"
Tests failing on
http://bb.pgr.jp/builders/cmake-clang-x86_64-linux/builds/46102

This reverts commit a1683cd6c9e07359c09f86e98a4db6b4e1bc51fc.

llvm-svn: 263750
2016-03-17 21:30:55 +00:00
Bruno Cardoso Lopes 016b2d0ddc Reapply [VFS] Add 'overlay-relative' field to YAML files
This reapplies r261552.

The VFS overlay mapping between virtual paths and real paths is done through
the 'external-contents' entries in YAML files, which contains hardcoded paths
to the real files.

When a module compilation crashes, headers are dumped into <name>.cache/vfs
directory and are mapped via the <name>.cache/vfs/vfs.yaml. The script
generated for reproduction uses -ivfsoverlay pointing to file to gather the
mapping between virtual paths and files inside <name>.cache/vfs. Currently, we
are only capable of reproducing such crashes in the same machine as they
happen, because of the hardcoded paths in 'external-contents'.

To be able to reproduce a crash in another machine, this patch introduces a new
option in the VFS yaml file called 'overlay-relative'. When it's equal to
'true' it means that the provided path to the YAML file through the
-ivfsoverlay option should also be used to prefix the final path for every
'external-contents'.

Example, given the invocation snippet "... -ivfsoverlay
<name>.cache/vfs/vfs.yaml" and the following entry in the yaml file:

"overlay-relative": "true",
"roots": [
...
  "type": "directory",
  "name": "/usr/include",
  "contents": [
    {
      "type": "file",
      "name": "stdio.h",
      "external-contents": "/usr/include/stdio.h"
    },
...

Here, a file manager request for virtual "/usr/include/stdio.h", that will map
into real path "/<absolute_path_to>/<name>.cache/vfs/usr/include/stdio.h.

This is a useful feature for debugging module crashes in machines other than
the one where the error happened.

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

rdar://problem/24499339

llvm-svn: 263748
2016-03-17 21:11:23 +00:00
Benjamin Kramer f8bff1c31c Use a simpler set of mock headers for the vfs+modules crash recovery tests.
The System/ mock is large and too complex for this test. It can cause
the tests to fail in mysterious ways as it depends on the resource dir
being present, which is not really supported for driver tests (using
%clang instead of %clang_cc1). Copy the tree and trim out all the
%unnecessary fat.

llvm-svn: 263718
2016-03-17 16:19:51 +00:00
Bruno Cardoso Lopes b76c027717 Reapply [2]: [VFS] Add support for handling path traversals
This was applied twice r261551 and 263617 and later reverted because:

(1) Windows bot failing on unittests. Change the current behavior to do
not handle path traversals on windows.

(2) Windows bot failed to include llvm/Config/config.h in order to use
HAVE_REALPATH. Use LLVM_ON_UNIX instead, as done in lib/Basic/FileManager.cpp.

Handle ".", ".." and "./" with trailing slashes while collecting files
to be dumped into the vfs overlay directory.

Include the support for symlinks into components. Given the path:

/install-dir/bin/../lib/clang/3.8.0/include/altivec.h, if "bin"
component is a symlink, it's not safe to use `path::remove_dots` here,
and `realpath` is used to get the right answer. Since `realpath`
is expensive, we only do it at collecting time (which only happens
during the crash reproducer) and cache the base directory for fast lookups.

Overall, this makes the input to the VFS YAML file to be canonicalized
to never contain traversal components.

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

rdar://problem/24499339

llvm-svn: 263686
2016-03-17 02:20:43 +00:00
NAKAMURA Takumi 9ed443ccca Revert r263617, "Reapply: [VFS] Add support for handling path traversals"
It broke standalone clang build.

llvm-svn: 263636
2016-03-16 12:15:29 +00:00
Vassil Vassilev 632eac3428 [modules] Fix adding a templated friend functions to a namespace from another module.
When clang adds argument dependent lookup candidates, it can perform template
instantiation. For example, it can instantiate a templated friend function and
register it in the enclosing namespace's lookup table.

Fixes https://llvm.org/bugs/show_bug.cgi?id=24954

Reviewed by Richard Smith.

llvm-svn: 263634
2016-03-16 11:17:04 +00:00
Bruno Cardoso Lopes c9daaaedb6 Reapply: [VFS] Add support for handling path traversals
This is originally r261551, reverted because of windows bots failing on
unittests. Change the current behavior to do not handle path traversals
on windows.

Handle ".", ".." and "./" with trailing slashes while collecting files
to be dumped into the vfs overlay directory.

Include the support for symlinks into components. Given the path:

/install-dir/bin/../lib/clang/3.8.0/include/altivec.h, if "bin"
component is a symlink, it's not safe to use `path::remove_dots` here,
and `realpath` is used to get the right answer. Since `realpath`
is expensive, we only do it at collecting time (which only happens
during the crash reproducer) and cache the base directory for fast lookups.

Overall, this makes the input to the VFS YAML file to be canonicalized
to never contain traversal components.

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

rdar://problem/24499339

llvm-svn: 263617
2016-03-16 04:39:38 +00:00
Richard Smith 8d4e90b319 [modules] Don't diagnose non-modular includes from modular files that are
implementation units of modules rather than interface units.

llvm-svn: 263449
2016-03-14 17:52:37 +00:00
Adrian Prantl 5a9a42778a Module Debugging: Fix a crash when emitting debug info for nested tag types
whose DeclContext is not yet complete by deferring their emission.

rdar://problem/24918680

llvm-svn: 262851
2016-03-07 20:58:52 +00:00
Davide Italiano 5d29dee003 [Modules] Don't swallow errors when parsing optional attributes.
Differential Revision:	http://reviews.llvm.org/D17787

llvm-svn: 262789
2016-03-06 04:20:05 +00:00
Vassil Vassilev 4d75e8d676 [modules] Prefer more complete array types.
If we import a module that has a complete array type and one that has an
incomplete array type, the declaration found by name lookup might be the one with
the incomplete type, possibly resulting in rejects-valid.

Now, the name lookup prefers decls with a complete array types. Also,
diagnose cases when the redecl chain has array bound, different from the merge
candidate.

Reviewed by Richard Smith.

llvm-svn: 262189
2016-02-28 19:08:24 +00:00
Bruno Cardoso Lopes be056b1667 Revert "[VFS] Add support for handling path traversals"
This reverts commit r261551 due to failing tests in windows bots:

http://lab.llvm.org:8011/builders/clang-x64-ninja-win7/builds/10054

Failing Tests (4):
    Clang-Unit :: Basic/BasicTests.exe/VFSFromYAMLTest.CaseInsensitive
    Clang-Unit :: Basic/BasicTests.exe/VFSFromYAMLTest.DirectoryIteration
    Clang-Unit :: Basic/BasicTests.exe/VFSFromYAMLTest.MappedFiles
    Clang-Unit :: Basic/BasicTests.exe/VFSFromYAMLTest.UseExternalName

llvm-svn: 261654
2016-02-23 17:06:50 +00:00
Bruno Cardoso Lopes b7eb8db023 Revert "[VFS] Add 'overlay-relative' field to YAML files" and "[VFS] Fix call to getVFSFromYAML in unittests"
This reverts commit r261552 and r261556 because of failing unittests on
windows:

Failing Tests (4):
    Clang-Unit :: Basic/BasicTests.exe/VFSFromYAMLTest.CaseInsensitive
    Clang-Unit :: Basic/BasicTests.exe/VFSFromYAMLTest.DirectoryIteration
    Clang-Unit :: Basic/BasicTests.exe/VFSFromYAMLTest.MappedFiles
    Clang-Unit :: Basic/BasicTests.exe/VFSFromYAMLTest.UseExternalName

llvm-svn: 261613
2016-02-23 07:06:12 +00:00
Bruno Cardoso Lopes 8c03c54200 [VFS] Add 'overlay-relative' field to YAML files
The VFS overlay mapping between virtual paths and real paths is done through
the 'external-contents' entries in YAML files, which contains hardcoded paths
to the real files.

When a module compilation crashes, headers are dumped into <name>.cache/vfs
directory and are mapped via the <name>.cache/vfs/vfs.yaml. The script
generated for reproduction uses -ivfsoverlay pointing to file to gather the
mapping between virtual paths and files inside <name>.cache/vfs. Currently, we
are only capable of reproducing such crashes in the same machine as they
happen, because of the hardcoded paths in 'external-contents'.

To be able to reproduce a crash in another machine, this patch introduces a new
option in the VFS yaml file called 'overlay-relative'. When it's equal to
'true' it means that the provided path to the YAML file through the
-ivfsoverlay option should also be used to prefix the final path for every
'external-contents'.

Example, given the invocation snippet "... -ivfsoverlay
<name>.cache/vfs/vfs.yaml" and the following entry in the yaml file:

"overlay-relative": "true",
"roots": [
...
  "type": "directory",
  "name": "/usr/include",
  "contents": [
    {
      "type": "file",
      "name": "stdio.h",
      "external-contents": "/usr/include/stdio.h"
    },
...

Here, a file manager request for virtual "/usr/include/stdio.h", that will map
into real path "/<absolute_path_to>/<name>.cache/vfs/usr/include/stdio.h.

This is a useful feature for debugging module crashes in machines other than
the one where the error happened.

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

rdar://problem/24499339

llvm-svn: 261552
2016-02-22 18:41:09 +00:00
Bruno Cardoso Lopes 956e6a0dc6 [VFS] Add support for handling path traversals
Handle ".", ".." and "./" with trailing slashes while collecting files
to be dumped into the vfs overlay directory.

Include the support for symlinks into components. Given the path:

/install-dir/bin/../lib/clang/3.8.0/include/altivec.h, if "bin"
component is a symlink, it's not safe to use `path::remove_dots` here,
and `realpath` is used to get the right answer. Since `realpath`
is expensive, we only do it at collecting time (which only happens
during the crash reproducer) and cache the base directory for fast lookups.

Overall, this makes the input to the VFS YAML file to be canonicalized
to never contain traversal components.

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

rdar://problem/24499339

llvm-svn: 261551
2016-02-22 18:41:01 +00:00
Richard Smith 7e82e019c6 [modules] Flatten -fmodule-name= and -fmodule-implementation-of= into a single
option. Previously these options could both be used to specify that you were
compiling the implementation file of a module, with a different set of minor
bugs in each case.

This change removes -fmodule-implementation-of, and instead tracks a flag to
determine whether we're currently building a module. -fmodule-name now behaves
the same way that -fmodule-implementation-of previously did.

llvm-svn: 261372
2016-02-19 22:25:36 +00:00
Ben Langmuir 9b1e442e67 [Modules] Early-exit if ReadOptionsBlock fails to avoid crashing
If we didn't tell ReadOptionsBlock to allow failures then we can't
assume that the stream is not in the middle of a block if it returns
out-of-date. This was causing a crash when we tried to continue reading.

Also, it's just generally a good idea to early-exit if we're doing
implicit module builds, since we will want to immediately rebuild this
module anyway and there's no reason to waste time continuing after
failure.

rdar://problem/24114938

llvm-svn: 260563
2016-02-11 18:54:02 +00:00
Justin Lebar af94c0f2b3 Remove some unnecessary CHECK-SAMEs in ModuleDebugInfo.{cpp,m}.
Suggested by Paul Robinson.

llvm-svn: 260346
2016-02-10 01:34:17 +00:00
Justin Lebar ae06ca0c7e Get rid of CHECK-SAME-NOT in tests.
Summary: This isn't a FileCheck directive; it does nothing.

Reviewers: jroelofs

Subscribers: cfe-commits, majnemer

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

llvm-svn: 260334
2016-02-10 00:38:15 +00:00
Richard Smith aada85c5f7 [modules] Compress files embedded into a .pcm file, to reduce the disk usage of -fembed-all-files mode.
llvm-svn: 259976
2016-02-06 02:06:43 +00:00
Richard Smith d79514e24b [modules] Separately track whether an identifier's preprocessor information and
name lookup information have changed since deserialization. For a C++ modules
build, we do not need to re-emit the identifier into the serialized identifier
table if only the name lookup information has changed (and in all cases, we
don't need to re-emit the macro information if only the name lookup information
has changed).

llvm-svn: 259901
2016-02-05 19:03:40 +00:00
Ben Langmuir e7d67575f2 Don't synthesize an ImportDecl for a module named in -fmodule-implementation-of
When building a PCH with modules enabled this import would assert in the
ASTWriter and (if assertions were disabled) sometimes crash the compiler
that loaded the resulting PCH when trying to lookup the submodule ID.

rdar://problem/24137448

llvm-svn: 259859
2016-02-05 01:10:05 +00:00
Ben Langmuir f5416740fc Fix predefine for __NSConstantString struct type
Per review feedback the name was wrong and it can be used outside
Objective-C.

Unfortunately, making the internal struct visible broke some ASTMatchers
tests that assumed that the first record decl would be from user code,
rather than a builtin type.  I'm worried that this will also affect
users' code.  So this patch adds a typedef to wrap the internal struct
and only makes the typedef visible to namelookup.  This is sufficient to
allow the ASTReader to merge the decls we need without making the struct
itself visible.

rdar://problem/24425801

llvm-svn: 259734
2016-02-04 00:55:24 +00:00
Quentin Colombet 043406b87f Reapply r259624, it is likely not the commit causing the bot failures.
Original message:
Make CF constant string decl visible to name lookup to fix module errors

The return type of the __builtin___*StringMakeConstantString functions
is a pointer to a struct, so we need that struct to be visible to name
lookup so that we will correctly merge multiple declarations of that
type if they come from different modules.

Incidentally, to make this visible to name lookup we need to rename the
type to __NSConstantString, since the real NSConstantString is an
Objective-C interface type.  This shouldn't affect anyone outside the
compiler since users of the constant string builtins cast the result
immediately to CFStringRef.

Since this struct type is otherwise implicitly created by the AST
context and cannot access namelookup, we make this a predefined type
and initialize it in Sema.

Note: this issue of builtins that refer to types not visible to name
lookup technically also affects other builtins (e.g. objc_msgSendSuper),
but in all other cases the builtin is a library builtin and the issue
goes away if you include the library that defines the types it uses,
unlike for these constant string builtins.

rdar://problem/24425801

llvm-svn: 259721
2016-02-03 22:41:00 +00:00
Quentin Colombet 0cdb86bd38 Revert r259624 - Make CF constant string decl visible to name lookup to fix module errors.
This breaks some internal bots in stage2: clang seg fault.
Looking with Ben to see what is going on.

llvm-svn: 259715
2016-02-03 22:14:53 +00:00
Ben Langmuir 6a34e10514 Make CF constant string decl visible to name lookup to fix module errors
The return type of the __builtin___*StringMakeConstantString functions
is a pointer to a struct, so we need that struct to be visible to name
lookup so that we will correctly merge multiple declarations of that
type if they come from different modules.

Incidentally, to make this visible to name lookup we need to rename the
type to __NSConstantString, since the real NSConstantString is an
Objective-C interface type.  This shouldn't affect anyone outside the
compiler since users of the constant string builtins cast the result
immediately to CFStringRef.

Since this struct type is otherwise implicitly created by the AST
context and cannot access namelookup, we make this a predefined type
and initialize it in Sema.

Note: this issue of builtins that refer to types not visible to name
lookup technically also affects other builtins (e.g. objc_msgSendSuper),
but in all other cases the builtin is a library builtin and the issue
goes away if you include the library that defines the types it uses,
unlike for these constant string builtins.

rdar://problem/24425801

llvm-svn: 259624
2016-02-03 03:26:19 +00:00
Adrian Prantl 3a2d4947a6 Module Debugging: Canonicalize the file names used as PCH module names
by stripping the path. Follow-up to r258555.

This is safe because only one PCH per CU is currently supported for
module debugging.

rdar://problem/24301262

llvm-svn: 258582
2016-01-22 23:30:56 +00:00
Adrian Prantl aa5d08d04b Module debugging: Create a parent DIModule with the PCH name for types
emitted into a precompiled header to mirror the debug info emitted for
object files importing the PCH.

rdar://problem/24290667

llvm-svn: 258555
2016-01-22 21:14:41 +00:00
Adrian Prantl d4e73e7412 Rephrase this test to help debug a buildbot issue
llvm-svn: 258526
2016-01-22 19:14:24 +00:00
Yaron Keren e94da64e65 Merge templated static member variables, fixes http://llvm.org/pr26179.
Patch by Vassil Vassilev!
Reviewed by Richard Smith.

llvm-svn: 258524
2016-01-22 19:03:27 +00:00
Adrian Prantl ae108c4704 Fix a typo in r258507 and change the PCH dwoid constant to ~1UL.
rdar://problem/24290667

llvm-svn: 258519
2016-01-22 18:46:45 +00:00
Adrian Prantl e1c2ad8aa7 Fix 80-column violations.
llvm-svn: 258518
2016-01-22 18:46:40 +00:00
Adrian Prantl c96da8faa6 Module Debugging: Use a nonzero DWO id for precompiled headers.
PCH files don't have a module signature and LLVM uses a nonzero DWO id as
an indicator for skeleton / module CUs. This change pins the DWO id for PCH
files to a known constant value.
The correct long-term solution here is to implement a module signature
that is an actual dterministic hash (at the moment module signatures are
just random nonzero numbers) and then enable this for PCH files as well.

<rdar://problem/24290667>

llvm-svn: 258507
2016-01-22 17:43:43 +00:00
Adrian Prantl 8f55b66a53 Module Debugging: Fine-tune the condition that determines whether a type
can be found in a module.

There are externally visible anonymous types that can be found:
  typedef struct { } s; // I can be found via the typedef.
There are anonymous internal types that can be found:
  namespace { struct s {}; } // I can be found by name.

rdar://problem/24199640

llvm-svn: 258272
2016-01-20 01:29:34 +00:00
Adrian Prantl 8c0e50519b Module Debugging: Add Objective-C testcases for anonymous tag decls. (NFC)
rdar://problem/24199640

llvm-svn: 258252
2016-01-19 23:42:56 +00:00
Adrian Prantl 43e0081740 Module Debugging: Don't emit external type references to anonymous types.
Even if they exist in the module, they can't be matched with the forward
declaration in the object file.
<rdar://problem/24199640>

llvm-svn: 258251
2016-01-19 23:42:53 +00:00
Adrian Prantl cd975018fe Module Debugging: Make sure that anonymous tag decls that define global
variables are visited.

This shouldn't encourage anyone to put global variables into clang modules.
rdar://problem/24199640

llvm-svn: 258250
2016-01-19 23:42:44 +00:00
Adrian Prantl e5238d2a82 Module Debugging: Defer the emission of anonymous tag decls
until we are visiting their declcontext.

This fixes a regression introduced in r256962:
When building debug info for a typdef'd anonymous tag type, we would be
visiting the inner anonymous type first thus creating a "typedef changes
linkage of anonymous type, but linkage was already computed" error.

rdar://problem/24199640

llvm-svn: 258152
2016-01-19 18:02:47 +00:00
Richard Smith 2de44e658d [modules] Don't diagnose a conflict between two using-declarations that name equivalent internal linkage entities.
llvm-svn: 257512
2016-01-12 20:34:32 +00:00
Richard Smith 38c202e97e When a tag is declared in prototype scope in C, if we've decided that it
redeclares an existing tag but are creating a new declaration anyway (because
it has attributes or changes the visibility of the name), don't warn that it
won't be visible outside the current scope. That's not true.

Also narrow down the set of cases where we create these extra declarations when
building modules; previously, all tag declarations but the first in a module
header would get this treatment if -fmodules-local-submodule-visibility. (This
isn't a functional change, but we try to avoid creating these extra
declarations whenever we can.)

llvm-svn: 257403
2016-01-11 22:41:53 +00:00
Richard Smith e123cd2f40 [modules] If we're treating an elaborated-type-specifier as if it introduces a
tag (because the previous declaration was found in a different module), inject
the tag into the appropriate scope (that is, the enclosing scope if we're in a
function prototype scope in C++).

llvm-svn: 257251
2016-01-09 06:58:48 +00:00
Adrian Prantl 35e765baff Module debugging: Add a testcase for standalone forward declarations.
llvm-svn: 257241
2016-01-09 01:11:35 +00:00
Richard Smith f7aeda1f07 [modules] Make sure we always include the contents of private headers when
building a module. Prior to this change, the private header's content would
only be included if the header were included by another header in the same
module. If not (if the private header is only used by the .cc files of the
module, or is included from outside the module via -Wno-private-header),
a #include of that file would be silently ignored.

llvm-svn: 257222
2016-01-08 22:36:45 +00:00
Adrian Prantl b2a8b35349 Fix a typo.
llvm-svn: 256963
2016-01-06 19:22:23 +00:00
Adrian Prantl b3b821f1df Module debugging: Defer emitting tag types until their definition
was visited and all decls have been merged.

We only get a single chance to emit the types for virtual classes because
CGDebugInfo::completeRequiredType() categorically doesn't complete them.

llvm-svn: 256962
2016-01-06 19:22:19 +00:00
Richard Smith 26dfbace82 [modules] When a tag type that was imported from a module is referenced via an
elaborated-type-specifier, create a declaration of it to track that the current
module makes it visible too.

llvm-svn: 256907
2016-01-06 03:52:10 +00:00
Adrian Prantl aac97c93ac Fix a typo in testcase and increase its coverage!
llvm-svn: 256874
2016-01-05 23:54:01 +00:00
Richard Smith 82b8d4e6fd [modules] Don't try to use the definition of a class if
RequireCompleteType(..., 0) says we're not permitted to do so. The definition
might not be visible, even though we know what it is.

llvm-svn: 256045
2015-12-18 22:19:11 +00:00
Richard Smith 84824edd0b Allow non-defining declarations of class template partial specializations to
have a nested name specifier. Strictly speaking, forward declarations of class
template partial specializations are not permitted at all, but that seems like
an obvious wording defect, and if we allow them without a nested name specifier
we should also allow them with a nested name specifier.

llvm-svn: 255383
2015-12-11 22:39:52 +00:00
Ben Langmuir 237ccb165e Reapply "[Modules] Fix regression when an elaborated-type-specifier mentions a hidden tag"
Now not trying to use a C++ lookup mechanism in C (d'oh).  Unqualified
lookup is actually fine for this case in C.

llvm-svn: 255377
2015-12-11 22:05:13 +00:00
Ben Langmuir 38f2bfbbe4 Revert "[Modules] Fix regression when an elaborated-type-specifier mentions a hidden tag"
This is causing assertion failures; reverting until I can fix.

This reverts commit r255267

llvm-svn: 255324
2015-12-11 01:44:43 +00:00
Ben Langmuir c589462beb [Modules] Fix regression when an elaborated-type-specifier mentions a hidden tag
This makes non-C++ languages find the same decl as C++ does to
workaround a regression introduced in r252960.

rdar://problem/23784203

llvm-svn: 255267
2015-12-10 17:28:51 +00:00
Richard Smith 64daf7b1a5 [modules] Don't reject multiple modules providing contents for the same embedded file.
llvm-svn: 254365
2015-12-01 03:32:49 +00:00
Richard Smith 919ce23566 [modules] Add -cc1 flag -fmodules-embed-all-files.
This flag causes all files that were read by the compilation to be embedded
into a produced module file. This is useful for distributed build systems that
use an include scanning system to determine which files are "needed" by a
compilation, and only provide those files to remote compilation workers. Since
using a module can require any file that is part of that module (or anything it
transitively includes), files that are not found by an include scanner can be
required in a regular build using explicit modules. With this flag, only files
that are actually referenced by transitively-#included files are required to be
present on the build machine.

llvm-svn: 253950
2015-11-24 04:22:21 +00:00
Pete Cooper 3b39e88ae0 Revert "Change memcpy/memset/memmove to have dest and source alignments."
This reverts commit r253512.

This likely broke the bots in:
http://lab.llvm.org:8011/builders/clang-ppc64-elf-linux2/builds/20202
http://bb.pgr.jp/builders/clang-3stage-i686-linux/builds/3787

llvm-svn: 253542
2015-11-19 05:55:59 +00:00
Pete Cooper 7bfd5cb7be Change memcpy/memset/memmove to have dest and source alignments.
This is a follow on from a similar LLVM commit: r253511.

Note, this was reviewed (and more details are in) http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20151109/312083.html

These intrinsics currently have an explicit alignment argument which is
required to be a constant integer.  It represents the alignment of the
source and dest, and so must be the minimum of those.

This change allows source and dest to each have their own alignments
by using the alignment attribute on their arguments.  The alignment
argument itself is removed.

The only code change to clang is hidden in CGBuilder.h which now passes
both dest and source alignment to IRBuilder, instead of taking the minimum of
dest and source alignments.

Reviewed by Hal Finkel.

llvm-svn: 253512
2015-11-18 22:18:45 +00:00
Richard Smith 752ada870d [modules] When a #include is mapped to a module import and appears somewhere
other than the top level, we issue an error. This breaks a fair amount of C++
code wrapping C libraries, where the C library is #included within a namespace
/ extern "C" combination, because the C library (probably) includes C++
standard library headers which may be within modules.

Without modules, this setup is harmless if (and *only* if) the corresponding
standard library module was already included outside the namespace, so
downgrade the error to a default-error extension in that case, so that it can
be selectively disabled for such misbehaving libraries.

llvm-svn: 253398
2015-11-17 23:32:01 +00:00
Richard Smith 10568d8c1c [modules] Fix some more cases where we used to reject a conflict between two
declarations that are not simultaneously visible, and where at least one of
them has internal/no linkage.

llvm-svn: 253283
2015-11-17 03:02:41 +00:00
Ben Langmuir 90717ad731 [modules] Allow "redefinition" of typedef of anon tag from unimported submodule
r233345 started being stricter about typedef names for linkage purposes
in non-visible modules, but broke languages without the ODR.

rdar://23527954

llvm-svn: 253123
2015-11-14 03:26:14 +00:00
Juergen Ributzka 8aaae5a911 Fix auto-link for text-based dynamic library SDKs.
When linking against text-based dynamic library SDKs the library name of a
framework has now more than one possible filename extensions. This fix tests for
both possible extensions (none, and .tbd).

This fixes rdar://problem/20609975

llvm-svn: 253060
2015-11-13 19:08:07 +00:00
Richard Smith 6e132bef6f [modules] When a declaration has non-trivial visibility, check whether it's
actually hidden before we check its linkage. This avoids computing the linkage
"too early" for an anonymous struct with a typedef name for linkage.

llvm-svn: 253012
2015-11-13 05:14:45 +00:00
Richard Smith 26210db67f [modules] Follow the C++ standard's rule for linkage of enumerators: they have
the linkage of the enumeration. For enumerators of unnamed enumerations, extend
the -Wmodules-ambiguous-internal-linkage extension to allow selecting an
arbitrary enumerator (but only if they all have the same value, otherwise it's
ambiguous).

llvm-svn: 253010
2015-11-13 03:52:13 +00:00
Richard Smith 4b213d73d8 Avoid duplicated diagnostic when lookup for a nested-name-specifier fails due to ambiguity.
llvm-svn: 252967
2015-11-12 22:40:09 +00:00
Richard Smith 97135cc94a [modules] Simplify and generalize the existing rule for finding hidden
declarations in redeclaration lookup. A declaration is now visible to
lookup if:

 * It is visible (not in a module, or in an imported module), or
 * We're doing redeclaration lookup and it's externally-visible, or
 * We're doing typo correction and looking for unimported decls.

We now support multiple modules having different internal-linkage or no-linkage
definitions of the same name for all entities, not just for functions,
variables, and some typedefs. As previously, if multiple such entities are
visible, any attempt to use them will result in an ambiguity error.

This patch fixes the linkage calculation for a number of entities where we
previously didn't need to get it right (using-declarations, namespace aliases,
and so on).  It also classifies enumerators as always having no linkage, which
is a slight deviation from the C++ standard's definition, but not an observable
change outside modules (this change is being discussed on the -core reflector
currently).

This also removes the prior special case for tag lookup, which made some cases
of this work, but also led to bizarre, bogus "must use 'struct' to refer to type
'Foo' in this scope" diagnostics in C++.

llvm-svn: 252960
2015-11-12 22:19:45 +00:00
Richard Smith 5e3fb7616d Revert r240335.
This failed to solve the problem it was aimed at, and introduced just as many
issues as it resolved. Realistically, we need to deal with the possibility that
multiple modules might define different internal linkage symbols with the same
name, and this isn't a problem unless two such symbols are simultaneously
visible.

The case where two modules define equivalent internal linkage symbols is
handled by r252063: if lookup finds multiple sufficiently-similar entities from
different modules, we just pick one of them as an extension (but we keep them
separate).

llvm-svn: 252957
2015-11-12 21:55:58 +00:00
Manuel Klimek e8bd0db698 Allow use of private headers in different sub-modules.
llvm-svn: 252170
2015-11-05 15:24:47 +00:00
Richard Smith edcc92a4c1 [modules] Don't merge an anonymous enum definition into a named enum definition.
llvm-svn: 252125
2015-11-05 01:30:19 +00:00
Richard Smith 8a308ec24d [modules] If we're given a module file, via -fmodule-file=, for a module, but
we can't load that file due to a configuration mismatch, and implicit module
building is disabled, and the user turns off the error-by-default warning for
that situation, then fall back to textual inclusion for the module rather than
giving an error if any of its headers are included.

llvm-svn: 252114
2015-11-05 00:54:55 +00:00
Richard Smith 2dbe4043e8 [modules] Generalize the workaround for multiple ambiguous definitions of
internal linkage entities in different modules from r250884 to apply to all
names, not just function names.

This is really awkward: we don't want to merge internal-linkage symbols from
separate modules, because they might not actually be defining the same entity.
But we don't want to reject programs that use such an ambiguous symbol if those
internal-linkage symbols are in fact equivalent. For now, we're resolving the
ambiguity by picking one of the equivalent definitions as an extension.

llvm-svn: 252063
2015-11-04 19:26:32 +00:00
Douglas Gregor 6623e1f10f Introduce module file extensions to piggy-back data onto module files.
Introduce the notion of a module file extension, which introduces
additional information into a module file at the time it is built that
can then be queried when the module file is read. Module file
extensions are identified by a block name (which must be unique to the
extension) and can write any bitstream records into their own
extension block within the module file. When a module file is loaded,
any extension blocks are matched up with module file extension
readers, that are per-module-file and are given access to the input
bitstream.

Note that module file extensions can only be introduced by
programmatic clients that have access to the CompilerInvocation. There
is only one such extension at the moment, which is used for testing
the module file extension harness. As a future direction, one could
imagine allowing the plugin mechanism to introduce new module file
extensions.

llvm-svn: 251955
2015-11-03 18:33:07 +00:00
Richard Smith 5cd86f8cec [modules] Rationalize the behavior of Decl::declarationReplaces, and in
particular don't assume that two declarations of the same kind in the same
context are declaring the same entity. That's not true when the same name is
declared multiple times as internal-linkage symbols within a module.
(getCanonicalDecl is cheap now, so we can just use it here.)

llvm-svn: 251898
2015-11-03 03:13:11 +00:00
Douglas Gregor acf4fd3039 Stop back-patching 'readonly' Objective-C properties with 'readwrite' ones.
A 'readonly' Objective-C property declared in the primary class can
effectively be shadowed by a 'readwrite' property declared within an
extension of that class, so long as the types and attributes of the
two property declarations are compatible.

Previously, this functionality was implemented by back-patching the
original 'readonly' property to make it 'readwrite', destroying source
information and causing some hideously redundant, incorrect
code. Simplify the implementation to express how this should actually
be modeled: as a separate property declaration in the extension that
shadows (via the name lookup rules) the declaration in the primary
class. While here, correct some broken Fix-Its, eliminate a pile of
redundant code, clean up the ARC migrator's handling of properties
declared in extensions, and fix debug info's naming of methods that
come from categories.

A wonderous side effect of doing this write is that it eliminates the
"AddedObjCPropertyInClassExtension" method from the AST mutation
listener, which in turn eliminates the last place where we rewrite
entire declarations in a chained PCH file or a module file. This
change (which fixes rdar://problem/18475765) will allow us to
eliminate the rewritten-decls logic from the serialization library,
and fixes a crash (rdar://problem/23247794) illustrated by the
test/PCH/chain-categories.m example.

llvm-svn: 251874
2015-11-03 01:15:46 +00:00
Tim Northover 6f3ff22e73 Support watchOS and tvOS driver options
This patch should add support for almost all command-line options and
driver tinkering necessary to produce a correct "clang -cc1"
invocation for watchOS and tvOS.

llvm-svn: 251706
2015-10-30 16:30:27 +00:00
Ben Langmuir b9ad4e6063 Fix missing builtin identifier infos with PCH+modules
Use the *current* state of "is-moduleness" rather than the state at
serialization time so that if we read a builtin identifier from a module
that wasn't "interesting" to that module, we will still write it out to
a PCH that imports that module.

Otherwise, we would get mysterious "unknown builtin" errors when using
PCH+modules.

rdar://problem/23287656

llvm-svn: 251565
2015-10-28 22:25:37 +00:00
Adrian Prantl 28ba6fda48 Fixup this testcase after r251120.
I accidentally tested r251120 with assertions disabled.

llvm-svn: 251126
2015-10-23 17:25:17 +00:00
Adrian Prantl d43fe0bd39 Module Debugging: Emit module debug info for types inside of Objective-C
containers.

rdar://problem/23196170

llvm-svn: 251120
2015-10-23 17:02:22 +00:00
Richard Smith 896c66ecc6 [modules] libstdc++ defines some static inline functions in its internal
headers. If those headers end up being textually included twice into the same
module, we get ambiguity errors.

Work around this by downgrading the ambiguity error to a warning if multiple
identical internal-linkage functions appear in an overload set, and just pick
one of those functions as the lookup result.

llvm-svn: 250884
2015-10-21 07:13:52 +00:00
Richard Smith 95dc57a611 [modules] Allow the error when explicitly loading an incompatible module file
via -fmodule-file= to be turned off; in that case, just include the relevant
files textually. This allows module files to be unconditionally passed to all
compile actions via CXXFLAGS, and to be ignored for rules that specify custom
incompatible flags.

llvm-svn: 250577
2015-10-16 23:20:19 +00:00
Richard Smith e69bdd10ea [modules] Allow the error on importing a C++ module within an extern "C"
context (but otherwise at the top level) to be disabled, to support use of C++
standard library implementations that (legitimately) mark their <blah.h>
headers as being C++ headers from C libraries that wrap things in 'extern "C"'
a bit too enthusiastically.

llvm-svn: 250137
2015-10-13 00:39:40 +00:00
Richard Smith f983f7f627 [modules] Fix merging of __va_list_tag's implicit special member functions.
We model predefined declarations as not being from AST files, but in most ways
they act as if they come from some implicit prebuilt module file imported
before all others. Therefore, if we see an update to the predefined 'struct
__va_list_tag' declaration (and we've already loaded any modules), it needs a
corresponding update record, even though it didn't technically come from an AST
file.

llvm-svn: 250134
2015-10-13 00:23:25 +00:00
David Majnemer c10b8381f7 Update tests touched by r249656
These test updates almost exclusively around the change in behavior
around enum: enums without a definition are considered incomplete except
when targeting MSVC ABIs.  Since these tests are interested in the
'incomplete-enum' behavior, restrict them to %itanium_abi_triple.

llvm-svn: 249660
2015-10-08 06:31:22 +00:00
Douglas Katzman 3459ce2e5e Stop messing with the 'g' group of options in CompilerInvocation.
With this change, most 'g' options are rejected by CompilerInvocation.
They remain only as Driver options. The new way to request debug info
from cc1 is with "-debug-info-kind={line-tables-only|limited|standalone}"
and "-dwarf-version={2|3|4}". In the absence of a command-line option
to specify Dwarf version, the Toolchain decides it, rather than placing
Toolchain-specific logic in CompilerInvocation.

Also fix a bug in the Windows compatibility argument parsing
in which the "rightmost argument wins" principle failed.

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

llvm-svn: 249655
2015-10-08 04:24:12 +00:00
Adrian Prantl f0cd677b17 Module Debugging: Emit (ObjC) function declarations in the module scope
when building a module.

llvm-svn: 249282
2015-10-04 23:23:04 +00:00
Adrian Prantl 335f5c7e3e Module debugging: Don't emit forward declarations in module scopes.
A forward declaration inside a module header does not belong to the module.

llvm-svn: 249157
2015-10-02 17:36:14 +00:00
Adrian Prantl 992d820e30 Break long lines for readability.
llvm-svn: 249156
2015-10-02 17:36:10 +00:00
Adrian Prantl 42ce2d3ba3 Module debugging: Also emit Objective-C interfaces forward declarations
in their module scope when building a clang module.

llvm-svn: 249031
2015-10-01 16:57:02 +00:00
Adrian Prantl fd69611c8e Module debugging: Emit Objective-C interfaces in their module scope when
building a clang module.

llvm-svn: 248974
2015-10-01 00:48:51 +00:00
Adrian Prantl 835e6633ab Module Debugging: Emit submodules as nested DW_TAG_modules.
llvm-svn: 248511
2015-09-24 16:10:10 +00:00
Adrian Prantl a5206ce72a Module Debugging: Use the clang module signature as the module's dwo_id
when building a module. Clang already records the module signature when
building a skeleton CU to reference a clang module.

Matching the id in the skeleton with the one in the module allows a DWARF
consumer to verify that they found the correct version of the module
without them needing to know about the clang module format.

llvm-svn: 248345
2015-09-22 23:26:43 +00:00
Adrian Prantl 68448fe00c Add a belated testcase for the skeleton CU behavior in r248062.
llvm-svn: 248185
2015-09-21 17:48:42 +00:00
Adrian Prantl 85d938aadb Debug Info: When building a module, emit skeleton CUs for imported modules.
llvm-svn: 248184
2015-09-21 17:48:37 +00:00
NAKAMURA Takumi 2fbdb68073 clang/test/Modules/DebugInfoSubmodules.c REQUIRES asserts due to -debug-only.
llvm-svn: 248142
2015-09-21 06:57:36 +00:00
Adrian Prantl 9402cef0ae Module debugging: Support submodules in the PCM/PCH debug info.
llvm-svn: 248127
2015-09-20 16:51:35 +00:00
Serge Pavlov c4e04a2964 [Modules] More descriptive diagnostics for misplaced import directive
If an import directive was put into wrong context, the error message was obscure,
complaining on misbalanced braces. To get more descriptive messages, annotation
tokens related to modules are processed where they must not be seen.

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

llvm-svn: 248085
2015-09-19 05:32:57 +00:00
Richard Smith 938d701fad [modules] Fix a corner case in the macro override rules: properly handle overridden leaf module macros.
llvm-svn: 247765
2015-09-16 00:55:50 +00:00
Richard Smith ec4ad5ac9b [modules] Make sure we make hidden UsingShadowDecls visible to redeclaration
lookup for the UsingShadowDecls themselves.

llvm-svn: 247714
2015-09-15 18:51:56 +00:00
Richard Smith f091e129db [modules] A using-declaration doesn't introduce a new entity, just a new name
for an existing entity, and as such a using-declaration doesn't need to
conflict with a hidden entity (nor vice versa).

llvm-svn: 247654
2015-09-15 01:28:55 +00:00
Evgeniy Stepanov 6b2a61d3a5 Revert "Always_inline codegen rewrite" and 2 follow-ups.
Revert "Update cxx-irgen.cpp test to allow signext in alwaysinline functions."
Revert "[CodeGen] Remove wrapper-free always_inline functions from COMDATs"
Revert "Always_inline codegen rewrite."

Reason for revert: PR24793.

llvm-svn: 247620
2015-09-14 21:35:16 +00:00
Samuel Antao c23a8b2d39 Update cxx-irgen.cpp test to allow signext in alwaysinline functions.
This was causing an error in Power8 targets.

llvm-svn: 247584
2015-09-14 17:41:32 +00:00
Evgeniy Stepanov 93db40a147 Always_inline codegen rewrite.
Current implementation may end up emitting an undefined reference for
an "inline __attribute__((always_inline))" function by generating an
"available_externally alwaysinline" IR function for it and then failing to
inline all the calls. This happens when a call to such function is in dead
code. As the inliner is an SCC pass, it does not process dead code.

Libc++ relies on the compiler never emitting such undefined reference.

With this patch, we emit a pair of
1. internal alwaysinline definition (called F.alwaysinline)
2a. A stub F() { musttail call F.alwaysinline }
  -- or, depending on the linkage --
2b. A declaration of F.

The frontend ensures that F.inlinefunction is only used for direct
calls, and the stub is used for everything else (taking the address of
the function, really). Declaration (2b) is emitted in the case when
"inline" is meant for inlining only (like __gnu_inline__ and some
other cases).

This approach, among other nice properties, ensures that alwaysinline
functions are always internal, making it impossible for a direct call
to such function to produce an undefined symbol reference.

This patch is based on ideas by Chandler Carruth and Richard Smith.

llvm-svn: 247494
2015-09-12 01:07:37 +00:00
Evgeniy Stepanov 67037ee21e Revert "Specify target triple in alwaysinline tests."
Revert "Always_inline codegen rewrite."

Breaks gdb & lldb tests.
Breaks on Fedora 22 x86_64.

llvm-svn: 247491
2015-09-11 23:48:37 +00:00
Richard Smith c8a7eb5939 Add new test file missing from r247486.
llvm-svn: 247488
2015-09-11 22:54:01 +00:00
Richard Smith 535ff80354 [modules] When picking one of two template declarations as a lookup result,
it's not sufficient to prefer the declaration with more default arguments, or
the one that's visible; they might both be visible, but one of them might have
a visible default argument where the other has a hidden default argument.

llvm-svn: 247486
2015-09-11 22:39:35 +00:00
Evgeniy Stepanov 072e83500e Always_inline codegen rewrite.
Current implementation may end up emitting an undefined reference for
an "inline __attribute__((always_inline))" function by generating an
"available_externally alwaysinline" IR function for it and then failing to
inline all the calls. This happens when a call to such function is in dead
code. As the inliner is an SCC pass, it does not process dead code.

Libc++ relies on the compiler never emitting such undefined reference.

With this patch, we emit a pair of
1. internal alwaysinline definition (called F.alwaysinline)
2a. A stub F() { musttail call F.alwaysinline }
  -- or, depending on the linkage --
2b. A declaration of F.

The frontend ensures that F.inlinefunction is only used for direct
calls, and the stub is used for everything else (taking the address of
the function, really). Declaration (2b) is emitted in the case when
"inline" is meant for inlining only (like __gnu_inline__ and some
other cases).

This approach, among other nice properties, ensures that alwaysinline
functions are always internal, making it impossible for a direct call
to such function to produce an undefined symbol reference.

This patch is based on ideas by Chandler Carruth and Richard Smith.

llvm-svn: 247465
2015-09-11 20:29:07 +00:00
Adrian Prantl 660195a792 Fix a typo and make this test stricter.
llvm-svn: 247449
2015-09-11 18:54:34 +00:00
Reid Kleckner 854a2b7f76 Use Itanium C++ ABI triple for new modules+debug test
llvm-svn: 247438
2015-09-11 17:50:14 +00:00
Adrian Prantl 5c8bd88a4c Module Debugging: Emit forward declarations for types that are defined in
clang modules, if -dwarf-ext-refs (DebugTypesExtRefs) is specified.

This reimplements r247369 in about a third of the amount of code.
Thanks to David Blaikie pointing this out in post-commit review!

llvm-svn: 247432
2015-09-11 17:23:08 +00:00
Adrian Prantl ca8441810f Revert "Module Debugging: Emit forward declarations for types that are defined in"
This reverts commit r247369 to facilitate reviewing of the following patch.

llvm-svn: 247431
2015-09-11 17:23:03 +00:00
NAKAMURA Takumi 6d14f6aa4e clang/test/Modules/ExtDebugInfo.cpp: Use %itanium_abi_triple.
llvm-svn: 247397
2015-09-11 08:56:12 +00:00
NAKAMURA Takumi 5f901426e2 clang/test/Modules/ExtDebugInfo.cpp: Use [[@LINE]].
llvm-svn: 247396
2015-09-11 08:53:29 +00:00
Adrian Prantl 49553dd269 Module Debugging: Emit forward declarations for types that are defined in
clang modules, if -dwarf-ext-refs (DebugTypesExtRefs) is specified.

llvm-svn: 247369
2015-09-11 01:03:26 +00:00
Adrian Prantl 54a3457fe1 Debug Info: Remove an unnecessary debug type visitor.
Thanks to dblaikie for spotting this.

llvm-svn: 247303
2015-09-10 17:13:31 +00:00
NAKAMURA Takumi 0981f73473 clang/test/Modules/ModuleDebugInfo.cpp: Add -triple %itanium to appease ms-targeted builds.
I think DebugInfo tests may avoid MS stuff for now.

llvm-svn: 247093
2015-09-08 22:47:32 +00:00
Adrian Prantl 748a6cd1ac Module Debugging: Emit debug type information into clang ObjC modules.
When -fmodule-format is set to "obj", emit debug info for all types
declared in a module or referenced by a declaration into the module's
object file container.

This patch adds support for Objective-C types and methods.

llvm-svn: 247068
2015-09-08 20:41:52 +00:00
Adrian Prantl 4aa2b3a311 Module Debugging: Emit debug type information into clang modules.
When -fmodule-format is set to "obj", emit debug info for all types
declared in a module or referenced by a declaration into the module's
object file container.

This patch adds support for C and C++ types.

llvm-svn: 247049
2015-09-08 19:20:27 +00:00
Sean Silva 0df0391fb6 [modules] Tighten up this test a bit.
llvm-svn: 246702
2015-09-02 20:16:09 +00:00
Richard Smith d88a7f1a92 Re-commit r246497 (and dependent changes r246524 and r246521), reverted in
r246546, with a workaround for an MSVC 2013 miscompile and an MSVC 2015
rejects-valid.

Original commit message:

[modules] Rework serialized DeclContext lookup table management. Instead of
walking the loaded ModuleFiles looking for lookup tables for the context, store
them all in one place, and merge them together if we find we have too many
(currently, more than 4). If we do merge, include the merged form in our
serialized lookup table, so that downstream readers never need to look at our
imports' tables.

This gives a huge performance improvement to builds with very large numbers of
modules (in some cases, more than a 2x speedup was observed).

llvm-svn: 246582
2015-09-01 20:35:42 +00:00
Aaron Ballman 6a4a210126 Reverting r246497 (which requires also reverting r246524 and r246521 to avoid merge conflicts). It broke the build on MSVC 2015. It also broke an MSVC 2013 bot with testing issues.
llvm\tools\clang\lib\serialization\MultiOnDiskHashTable.h(117):
error C2065: 'Files': undeclared identifier

http://bb.pgr.jp/builders/ninja-clang-i686-msc18-R/builds/2917

llvm-svn: 246546
2015-09-01 13:24:39 +00:00
Richard Smith 7fa450c6ae [modules] Preserve DeclID order when merging lookup tables to give a more
predictable diagnostic experience. The hash-of-DeclID order we were using
before gave different results on Win32 due to a different predefined
declaration of __builtin_va_list.

llvm-svn: 246521
2015-09-01 01:37:34 +00:00
Richard Smith 9ce2b45936 [modules] Rework serialized DeclContext lookup table management. Instead of
walking the loaded ModuleFiles looking for lookup tables for the context, store
them all in one place, and merge them together if we find we have too many
(currently, more than 4). If we do merge, include the merged form in our
serialized lookup table, so that downstream readers never need to look at our
imports' tables.

This gives a huge performance improvement to builds with very large numbers of
modules (in some cases, more than a 2x speedup was observed).

llvm-svn: 246497
2015-08-31 22:17:11 +00:00
Richard Smith 79bf920552 [modules] Stop updating all identifiers when writing a module. This is
unnecessary in C++ modules (where we don't need the identifiers for their
Decls) and expensive.

llvm-svn: 245821
2015-08-24 03:33:22 +00:00
Richard Smith d8a83718f0 [modules] Rearrange how redeclaration chains are loaded, to remove a walk over
all modules and reduce the number of declarations we load when loading a
redeclaration chain.

The new approach is:
 * when loading the first declaration of an entity within a module file, we
   first load all declarations of the entity that were imported into that
   module file, and then load all the other declarations of that entity from
   that module file and build a suitable decl chain from them
 * when loading any other declaration of an entity, we first load the first
   declaration from the same module file

As before, we complete redecl chains through name lookup where necessary.

To make this work, I also had to change the way that template specializations
are stored -- it no longer suffices to track only canonical specializations; we
now emit all "first local" declarations when emitting a list of specializations
for a template.

On one testcase with several thousand imported module files, this reduces the
total runtime by 72%.

llvm-svn: 245779
2015-08-22 01:47:18 +00:00
Richard Smith 401cd25b23 [modules] Tests for r245390.
llvm-svn: 245391
2015-08-18 23:42:50 +00:00
Richard Smith 6dc8ae10aa [modules] When parsing the base specifiers of a parse-merged class, the current
context is the class itself but lookups should be performed starting with the
lookup parent of the class (class and base members don't shadow types from the
surrounding context because they have not been declared yet).

llvm-svn: 245236
2015-08-17 20:24:17 +00:00
Sean Silva 8b7c0398b6 [modules] PR20507: Avoid silent textual inclusion.
Summary:
If a module was unavailable (either a missing requirement on the module
being imported, or a missing file anywhere in the top-level module (and
not dominated by an unsatisfied `requires`)), we would silently treat
inclusions as textual. This would cause all manner of crazy and
confusing errors (and would also silently "work" sometimes, making the
problem difficult to track down).

I'm really not a fan of the `M->isAvailable(getLangOpts(), getTargetInfo(),
Requirement, MissingHeader)` function; it seems to do too many things at
once, but for now I've done things in a sort of awkward way.

The changes to test/Modules/Inputs/declare-use/module.map
were necessitated because the thing that was meant to be tested there
(introduced in r197805) was predicated on silently falling back to textual
inclusion, which we no longer do.

The changes to test/Modules/Inputs/macro-reexport/module.modulemap
are just an overlooked missing header that seems to have been missing since
this code was committed (r213922), which is now caught.

Reviewers: rsmith, benlangmuir, djasper

Subscribers: cfe-commits

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

llvm-svn: 245228
2015-08-17 16:39:30 +00:00
Richard Smith e75ee0f0c8 [modules] When explicitly building a module file, don't include timestamps in
the produced pcm file for stable file creation across distributed build
systems.

llvm-svn: 245199
2015-08-17 07:13:32 +00:00
Richard Smith 3938f0c728 [modules] Stop dropping 'module.timestamp' files into the current directory
when building with implicit modules disabled.

llvm-svn: 245136
2015-08-15 00:34:15 +00:00
Reid Kleckner 397a17bfeb Don't run explicit-modules-missing-files.cpp on Windows
It is flaky due to inability to remove files with open handles.  We
could paper over it with rm -f, but then the file would still be
present.

This is more evidence to me that we should roll our own 'rm'
implementation in LLVM.

llvm-svn: 245083
2015-08-14 19:03:02 +00:00
Richard Smith fb1e7f7d1a [modules] Add an experimental -cc1 feature to embed the contents of an input
file in the .pcm files. This allows a smaller set of files to be sent to a
remote build worker when building with explicit modules (for instance, module
map files need not be sent along with the corresponding precompiled modules).

This doesn't actually make the embedded files visible to header search, so
it's not useful as a packaging format for public header files.

llvm-svn: 245028
2015-08-14 05:02:58 +00:00
Richard Smith f7b41371d9 [modules] When writing a module file built with -fmodule-map-file-home-is-cwd,
via a module map found by -fmodule-map-file=, the home directory of the module
is the current working directory, even if that's a different directory on
reload.

llvm-svn: 244988
2015-08-13 23:47:44 +00:00
Richard Smith be9b6c75c3 [modules] For explicit module file dependencies, only list direct dependency module files.
llvm-svn: 244931
2015-08-13 18:30:25 +00:00
Richard Smith 1dbb95151b Fix wrong expected test output in r244923.
llvm-svn: 244927
2015-08-13 18:11:20 +00:00
Richard Smith 216a3bd70d [modules] Change the way we deal with .d output for explicitly-specified module
files: include the .pcm file itself in the .d output, rather than including its
own input files. Other forms of module file continue to be transparent for .d
output.

Arguably, the input files for the .pcm file are still inputs to the
compilation, but that's unnecessary for make-like build systems (where the
mtime of the .pcm file is sufficient) and harmful for smarter build systems
that know about module files and want to track only the local dependencies.

llvm-svn: 244923
2015-08-13 17:57:10 +00:00
Ben Langmuir 7ff29148ac [Modules] Add Darwin-specific compatibility module map parsing hacks
This preserves backwards compatibility for two hacks in the Darwin
system module map files:

1. The use of 'requires excluded' to make headers non-modular, which
should really be mapped to 'textual' now that we have this feature.

2. Silently removes a bogus cplusplus requirement from IOKit.avc.

Once we start diagnosing missing requirements and headers on
auto-imports these would have broken compatibility with existing Darwin
SDKs.

llvm-svn: 244912
2015-08-13 17:13:33 +00:00
Richard Smith dd55b95fb2 [modules] Fix thread safety analysis to cope with merging of FieldDecls across modules.
llvm-svn: 244714
2015-08-12 02:17:52 +00:00
Richard Smith 9c9173dcc8 [modules] When instantiating the contents of an imported CXXRecordDecl, we can
emit lexical contents for a declaration for another module. Track which module
those contents came from, and ensure that we only grab the lexical contents
from a single such instantiation.

llvm-svn: 244682
2015-08-11 22:00:24 +00:00
Richard Smith d61c1f8280 [modules] Don't suggest deleting the module cache on an error if there is no module cache for this build.
llvm-svn: 244547
2015-08-11 00:32:42 +00:00
Richard Smith a24ff5545b [modules] Properly diagnose errors in module files for which we have no
corresponding include location (those specified on the command line).

llvm-svn: 244538
2015-08-11 00:05:21 +00:00
NAKAMURA Takumi 4b81164810 clang/test/Modules: Satisfy win32 hosts due to dospath issue.
llvm-svn: 244427
2015-08-09 22:55:50 +00:00
Richard Smith 0f99d6a441 [modules] PR22534: Load files specified by -fmodule-file= eagerly. In particular, this avoids the need to re-parse module map files when using such a module.
llvm-svn: 244416
2015-08-09 08:48:41 +00:00
Richard Smith 38c1e6d355 Unrevert r244412 (reverted in r244414), and delete the bogus line left behind
in the unit test that was checking a file the test no longer creates.

llvm-svn: 244415
2015-08-09 06:03:55 +00:00
Justin Bogner b102d1a432 Revert "[modules] Don't leak -M flags for dependency file generation into the module"
This was failing tests on a bunch of bots:

http://lab.llvm.org:8011/builders/clang-hexagon-elf/builds/29919/steps/check-all
http://lab.llvm.org:8011/builders/clang-x86_64-debian-fast/builds/29627/steps/check-all
http://lab.llvm.org:8080/green/job/clang-stage1-configure-RA_check/9959/
http://lab.llvm.org:8080/green/job/clang-stage2-configure-Rlto_check/5591/

This reverts r244412

llvm-svn: 244414
2015-08-09 05:40:38 +00:00
Richard Smith 2a6edb30d9 [modules] When building a dependency file, include module maps parsed in the
current compilation, not just those from imported modules.

llvm-svn: 244413
2015-08-09 04:46:57 +00:00
Richard Smith 2d7fbbc7be [modules] Don't leak -M flags for dependency file generation into the module
build process when we implicitly build a module. Previously, we'd create the
specified .d file once for each implicitly-built module and then finally
overwrite it with the correct contents after the requested build completes.
(This fails if you use stdout as a dependency file, which is what the provided
testcase does, and is how I discovered this brokenness.)

llvm-svn: 244412
2015-08-09 02:44:20 +00:00
Richard Smith d9a0e64f66 Add file missed from r244409.
llvm-svn: 244410
2015-08-09 01:50:14 +00:00
Richard Smith 2bb3c34ed4 [modules] When loading a template specialization, re-canonicalize its template
arguments because the reloaded form might have become non-canonical across the
serialization/deserialization step (this particularly happens when the
canonical form of the type involves an expression).

llvm-svn: 244409
2015-08-09 01:05:31 +00:00
Ben Langmuir 587aeafe2c Make 'arm' cover both 32 and 64 bit architecutres
... and add aarch32 to specifically refer to the 32-bit ones.

Previously, 'arm' meant only 32-bit architectures and there was no way
for a module to build with both 32 and 64 bit ARM architectures.

Now a module that is intended to work on both architectures can specify
    requires arm
whereas a module only for 32-bit platforms can say
    requires aarch32
and just like before, 64-bit only can say
    requires aarch64

llvm-svn: 244306
2015-08-07 01:59:56 +00:00
Richard Smith 8cbd895947 [modules] Make IndirectFieldDecl mergeable to avoid lookup ambiguity when the same anonymous union is defined across multiple modules.
llvm-svn: 243940
2015-08-04 02:05:09 +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
Pete Cooper bfcf676737 Add fmodules-cache-path to 2 tests which were missing it.
These tests were creating a modules.idx file in my clang checkout, not
the build directory or temp.

All the other tests in this directory use -fmodules-cache-path=%t so
updated these to match.

llvm-svn: 243657
2015-07-30 16:44:07 +00:00
Sean Silva 5a45222745 Enable accidentally-disabled tests.
I think I was isolating the failure in the last RUN: line during
development, and forgot to re-enable the others.

llvm-svn: 243624
2015-07-30 07:23:17 +00:00
Sean Silva b963dedbe8 Avoid failure to canonicalize '..'.
Also fix completely broken and untested code which was hiding the
primary bug. The !LLVM_ON_UNIX branch of the ifdef was actually a no-op.

I ran into this in the wild. It was causing failures in our SDK build.

Ideally we'd have a perfect llvm::sys::fs::canonical, but at least this
is a step in the right direction, and fixes an obviously broken case.
In some sense the test case I've added here is an integration test. We
should have these routines thoroughly unit tested in llvm::sys::fs.

llvm-svn: 243597
2015-07-30 00:26:34 +00:00
Richard Smith 826711d456 [modules] When performing redeclaration lookup for a using declaration, prefer
UsingShadowDecls over other declarations of the same entity in the lookup
results. This ensures that we build correct redeclaration chains for the
UsingShadowDecls (otherwise we could see assertions and other misbehavior in
modules builds, when merging combines multiple redeclaration chains for the
same entity from the same module into one chain).

llvm-svn: 243592
2015-07-29 23:38:25 +00:00
Richard Smith a7c535b3c1 [modules] Change module manager visitation order to be a bit more stable when
more modules are added: visit modules depth-first rather than breadth-first.
The visitation is still (approximately) oldest-to-newest, and still guarantees
that a module is visited before anything it imports, so modules that are
imported by others sometimes need to jump to a later position in the visitation
order when more modules are loaded, but independent module trees don't
interfere with each other any more.

llvm-svn: 242863
2015-07-22 01:28:05 +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 d520a250b6 [modules] Produce an error if -cc1 wants to implicitly build a module and no
module cache has been provided, rather than creating one in the current
directory.

llvm-svn: 242819
2015-07-21 18:07:47 +00:00
Richard Smith 842d61f50c Attempt to fix greendragon buildbot failures; apparently wc sometimes inserts a leading space into its output. Just check for a matching number anywhere in the output.
llvm-svn: 242661
2015-07-20 08:40:51 +00:00
Richard Smith 4440d6eae0 [modules] Add (already passing) test for template default argument merging when the template is declared in a namespace.
llvm-svn: 242653
2015-07-19 23:44:27 +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
Adrian Prantl fb2398d0c4 Make the clang module container format selectable from the command line.
- introduces a new cc1 option -fmodule-format=[raw,obj]
  with 'raw' being the default
- supports arbitrary module container formats that libclang is agnostic to
- adds the format to the module hash to avoid collisions
- splits the old PCHContainerOperations into PCHContainerWriter and
  a PCHContainerReader.

Thanks to Richard Smith for reviewing this patch!

llvm-svn: 242499
2015-07-17 01:19:54 +00:00
David Majnemer 38a50c0a16 [Sema] Emit a better diagnostic when variable redeclarations disagree
We referred to all declaration in definitions in our diagnostic messages
which is can be inaccurate.  Instead, classify the declaration and emit
an appropriate diagnostic for the new declaration and an appropriate
note pointing to the old one.

This fixes PR24116.

llvm-svn: 242190
2015-07-14 20:08:49 +00:00
Richard Smith 8a53a0ddbd Add file missed from r242105.
llvm-svn: 242109
2015-07-14 02:40:33 +00:00
Richard Smith ae6df27ef4 [modules] When diagnosing errors in module map files found by 'extern module' declarations, show how we got to that module map file.
llvm-svn: 242105
2015-07-14 02:06:01 +00:00
Ben Langmuir 75a7e43581 [Modules] Allow missing header before a missing requirement
And make the module unavailable without breaking any parent modules.

If there's a missing requirement after we've already seen a missing
header, still update the IsMissingRequiement bit correctly.  Also,
diagnose missing requirements before missing headers, since the
existence of the header is moot if there are missing requirements.

llvm-svn: 242055
2015-07-13 19:48:52 +00:00
Richard Smith e70dadd67b [modules] When checking the include guard for a header, check whether it's
visible in the module we're considering entering. Previously we assumed that if
we knew the include guard for a modular header, we'd already parsed it, but
that need not be the case if a header is present in the current module and one
of its dependencies; the result of getting this wrong was that the current
module's submodule for the header would end up empty.

llvm-svn: 241953
2015-07-10 22:27:17 +00:00
Richard Smith 8692a4d199 [modules] Fix "prefer own module over others" rule when selecting a module for a header to work in the presence of module hierarchy.
llvm-svn: 241936
2015-07-10 20:09:49 +00:00
Richard Smith b1d8ea4635 [modules] Fix merging support for forward-declared enums with fixed underlying types. A visible declaration is enough to make the type complete, but not enough to make the definition visible.
llvm-svn: 241743
2015-07-08 21:49:31 +00:00
Richard Smith 696e812bb3 [modules] Fix crash when writing an update record for a redeclaration of an empty namespace.
llvm-svn: 241732
2015-07-08 21:15:32 +00:00
Richard Smith 7a591a4a46 [modules] When determining the visible module set during template
instantiation, use the set of modules visible from the template definition, not
from whichever declaration the specialization was instantiated from.

llvm-svn: 241662
2015-07-08 02:22:15 +00:00
Adrian Prantl bc068586ac Revert "Revert r241620 and follow-up commits" and move the initialization
of the llvm targets from clang/CodeGen into ClangCheck.cpp and CIndex.cpp.

llvm-svn: 241653
2015-07-08 01:00:30 +00:00
Adrian Prantl 142ec39739 Revert r241620 and follow-up commits while investigating linux buildbot failures.
llvm-svn: 241642
2015-07-07 23:19:46 +00:00
Adrian Prantl 726855a8da Update testcases that use precompiled headers to require a target after
r241620.

llvm-svn: 241623
2015-07-07 20:31:18 +00:00
Adrian Prantl e50371b948 Wrap clang modules and pch files in an object file container.
This patch adds ObjectFilePCHContainerOperations uses the LLVM backend
to put the contents of a PCH into a __clangast section inside a COFF, ELF,
or Mach-O object file container.

This is done to facilitate module debugging by makeing it possible to
store the debug info for the types defined by a module alongside the AST.

rdar://problem/20091852

llvm-svn: 241620
2015-07-07 20:11:29 +00:00
NAKAMURA Takumi 258c068008 Mark clang/test/Modules/signal.m as REQUIRES:crash-recovery.
llvm-svn: 241421
2015-07-05 23:00:44 +00:00
Ben Langmuir a525400d37 [Modules] Be consistent about finding a module for framework headers
We use findModuleForHeader() in several places, but in header search we
were not calling it when a framework module didn't show up with the
expected name, which would then lead to unexpected non-modular includes.
Now we will find the module unconditionally for frameworks.  For regular
frameworks, we use the spelling of the module name from the module map
file, and for inferred ones we use the canonical directory name.

In the future we might want to lock down framework modules sufficiently
that these name mismatches cannot happen.

rdar://problem/20465870

llvm-svn: 241258
2015-07-02 13:19:48 +00:00
Richard Smith da6c234c39 [modules] Merging support for specializations of a function template. This very
rarely matters, but can affect whether two dependent types are canonically
equivalent.

llvm-svn: 241207
2015-07-01 23:19:58 +00:00
Richard Smith 5327b89001 [modules] Don't make out-of-line member specializations of an instantiated
class template specialization visible just because the class template
specialization's definition is visible.

llvm-svn: 241182
2015-07-01 19:32:54 +00:00
Richard Smith 04c6c1f3a5 [modules] Skip trailing attributes when skipping a class definition during parse-merging.
llvm-svn: 241180
2015-07-01 18:56:50 +00:00
Richard Smith 7655381aa1 [modules] Don't require the 'inline' specifier when merging an inline function;
any source of the inline nature is sufficient.

llvm-svn: 241146
2015-07-01 07:24:18 +00:00
Richard Smith 2aedca340c [modules] Before checking whether the controlling macro of a header is defined,
update the identifier in case we've imported a definition of the macro (and
thus the contents of the header) from a module.

Also fold ExternalIdentifierLookup into ExternalPreprocessorSource; it no longer
makes sense to keep these separate now that the only user of the former also
needs the latter.

llvm-svn: 241137
2015-07-01 02:29:35 +00:00
Richard Smith 4df6093ca3 [modules] Make sure macros get made visible in the top-level file if we've got
local submodule visibility enabled; that top-level file might not actually be
the module includes buffer if use of prebuilt modules is disabled.

llvm-svn: 241120
2015-06-30 21:29:55 +00:00
Adrian Prantl 324c03fe83 Update testcases: DICompileUnits are now created distinct by DIBuilder.
llvm-svn: 241098
2015-06-30 18:32:50 +00:00
Adrian Prantl d9f09858a4 Relax this test so it also works on platforms that use characters other
than forward slashes as path separators.

llvm-svn: 241090
2015-06-30 18:05:46 +00:00
Adrian Prantl c4bb47e301 Debug Info: Emit debug info for @import declarations.
This allows a module-aware debugger such as LLDB to import the currently
visible modules before dropping into the expression evaluator.

rdar://problem/20965932

llvm-svn: 241084
2015-06-30 17:39:51 +00:00
NAKAMURA Takumi 886fbad410 Fix a couple of tests in clang/test to match "x86_thiscallcc" introduced in r240971.
llvm-svn: 241047
2015-06-30 08:02:26 +00:00
David Blaikie ea3e51d73f Account for calling convention specifiers in function definitions in IR test cases
Several tests wouldn't pass when executed on an armv7a_pc_linux triple
due to the non-default arm_aapcs calling convention produced on the
function definitions in the IR output. Account for this with the
application of a little regex.

Patch by Ying Yi.

llvm-svn: 240971
2015-06-29 17:29:50 +00:00
Ben Langmuir 51e3d7b2e0 [Modules] Test lock file removed on signal
For r240967.

rdar://problem/21512307

llvm-svn: 240968
2015-06-29 17:09:24 +00:00
Richard Smith 1e02a5aac8 [modules] Properly merge visibility of class definitions that got merged while
parsing then merged again when the module was loaded.

llvm-svn: 240700
2015-06-25 21:42:33 +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
Daniel Jasper 1758a9f1f7 Write output file to temp directory. The tests shouldn't assume that
they can write to the current working directory.

llvm-svn: 240388
2015-06-23 09:26:37 +00:00
NAKAMURA Takumi 4a8917be84 Tweak clang/test/Modules/modules-with-same-name.m to run with GnuWin32's find.exe on newer version of Windows.
It seems "*.pcm" would be expanded with current directory by NTOS 6.x's msvcrt. GnuWin32 utils are affected.
To avoid the issue, put an expression that msvcrt's glob won't match, like "*.pc[m]".

llvm-svn: 240387
2015-06-23 08:37:21 +00:00
Richard Smith 2f633e7c3c [modules] When building a module, if there are multiple matches for a header
file in the loaded module maps and one of them is from the current module,
that's the right match.

llvm-svn: 240350
2015-06-22 22:20:47 +00:00
Richard Smith 529ecb237a [modules] Add a flag to disable the feature that permits conflicting redefinitions of internal-linkage symbols that are not visible.
Such conflicts are an accident waiting to happen, and this feature conflicts
with the desire to include existing headers into multiple modules and merge the
results. (In an ideal world, it should not be possible to export internal
linkage symbols from a module, but sadly the glibc and libstdc++ headers
provide 'static inline' functions in a few cases.)

llvm-svn: 240335
2015-06-22 21:15:01 +00:00
Richard Smith beb44788b3 [modules] When determining whether a definition of a class is visible, check all modules even if we've already found a definition that's not visible.
llvm-svn: 240204
2015-06-20 01:05:19 +00:00
Richard Smith 86dfc1eafd [modules] Merging support for enums with a local definition prior to the first
imported definition.

llvm-svn: 240068
2015-06-18 22:07:00 +00:00
Richard Smith 75ea855fd7 [modules] Ensure that if we merge the definitions of two enumerations, that
making either of them visible makes the merged definition visible.

llvm-svn: 239969
2015-06-17 23:07:50 +00:00
Richard Smith afe800c456 [modules] Fix typo in default argument merging.
llvm-svn: 239954
2015-06-17 22:13:23 +00:00
Richard Smith 63e09bf70b [modules] If we merge a template, also track that its parameters are merged so
that we know when its default arguments should be visible.

llvm-svn: 239936
2015-06-17 20:39:41 +00:00
Richard Smith 35c1df5cb6 [modules] Improve diagnostic for a template-id that's invalid because a default
argument is not visible.

llvm-svn: 239934
2015-06-17 20:16:32 +00:00
Richard Smith 5293379374 [modules] Fix merging of default template arguments onto friend templates.
Previously we'd complain about redefinition of default arguments when we
instantiated a class with a friend template that inherits its default argument,
because we propagate the default template arguemnt onto the friend when we
reload the AST.

llvm-svn: 239857
2015-06-16 21:57:05 +00:00
Colin LeMahieu fef7dd04a4 [Hexagon] unused-local-typedef warning test is passing.
llvm-svn: 239832
2015-06-16 17:32:45 +00:00
Richard Smith 47972afd10 [modules] Simplify -cc1 interface for enabling implicit module maps.
We used to have a flag to enable module maps, and two more flags to enable
implicit module maps. This is all redundant; we don't need any flag for
enabling module maps in the abstract, and we don't usually have -fno- flags for
-cc1. We now have just a single flag, -fimplicit-module-maps, that enables
implicitly searching the file system for module map files and loading them.

The driver interface is unchanged for now. We should probably rename
-fmodule-maps to -fimplicit-module-maps at some point.

llvm-svn: 239789
2015-06-16 00:08:24 +00:00
Richard Smith 72bfb8e234 [modules] Re-enable accidentally-disabled test.
llvm-svn: 239783
2015-06-15 23:39:16 +00:00
Reid Kleckner 2c901d4859 Fix submodule test to pass on content addressable filesystems where inodes would collide
llvm-svn: 239765
2015-06-15 21:21:17 +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
Richard Smith a1431077de [modules] Apply name visibility rules to names found by ADL.
llvm-svn: 239578
2015-06-12 01:32:13 +00:00
Richard Smith c785276b92 [modules] Fix crash with multiple levels of default template argument merging.
llvm-svn: 239575
2015-06-11 23:46:11 +00:00
Richard Smith 0f192e8940 [modules] Fix assert/crash when parsing and merging a definition of a class with a base-specifier inside a namespace.
llvm-svn: 239569
2015-06-11 22:48:25 +00:00
Richard Smith 00be6d0ff8 [modules] Fix a few places where merging wasn't performed if modules was disabled but local module visibilty was enabled.
llvm-svn: 239504
2015-06-11 03:05:39 +00:00
Richard Smith 95d83959d8 [modules] Don't allow use of non-visible (inherited) default template arguments.
llvm-svn: 239487
2015-06-10 20:36:34 +00:00
Richard Smith e7bd6defd7 [modules] Track all default template arguments for a given parameter across
modules, and allow use of a default template argument if any of the parameters
providing it is visible.

llvm-svn: 239485
2015-06-10 20:30:23 +00:00
Richard Smith 8dbe7e236c Revert accidentally-committed test change from r239447.
llvm-svn: 239452
2015-06-10 01:36:14 +00:00
Richard Smith 1469b9196c Refactor storage of default template arguments.
This is just a preparatory step towards fixing visibility for default template
arguments in modules builds.

llvm-svn: 239447
2015-06-10 00:29:03 +00:00
Richard Smith 87bb569844 [modules] Fix some visibility issues with default template arguments.
There are still problems here, but this is a better starting point.

The main part of the change is: when doing a lookup that would accept visible
or hidden declarations, prefer to produce the latest visible declaration if
there are any visible declarations, rather than always producing the latest
declaration.

Thus, when we inherit default arguments (and other properties) from a previous
declaration, we inherit them from the previous visible declaration; if the
previous declaration is hidden, we already suppress inheritance of default
arguments.

There are a couple of other changes here that fix latent bugs exposed by this
change.

llvm-svn: 239371
2015-06-09 00:35:49 +00:00
Richard Smith 04765ae01e [modules] If we re-enter a submodule from within itself (when submodule
visibility is enabled) or leave and re-enter it, restore the macro and module
visibility state from last time we were in that submodule.

This allows mutually-#including header files to stand a chance at being
modularized with local visibility enabled.

llvm-svn: 237871
2015-05-21 01:20:10 +00:00
Richard Smith fd8b64eea0 [modules] Support merging a parsed default argument with an imported hidden one for non-type and template template parameters too.
llvm-svn: 237815
2015-05-20 18:24:21 +00:00
Richard Smith c7d48d1a16 [modules] Support merging a parsed default function/template argument with an imported but hidden one.
llvm-svn: 237814
2015-05-20 17:50:35 +00:00
Richard Smith 54ef4c3bb3 Revert r237609 for now.
glibc's headers use __need_* macros to selectively export parts of themselves
to each other. This requires us to enter those files repeatedly when building
a glibc module.

This can be unreverted once we have a better mechanism to deal with that
non-modular aspect of glibc (possibly some way to mark a header as "textual if
this macro is defined").

llvm-svn: 237718
2015-05-19 19:58:11 +00:00
Richard Smith 82e57fb1e8 [modules] Support for merging a parsed definition of a static data member of a class template into an imported but hidden definition.
llvm-svn: 237647
2015-05-19 00:49:29 +00:00
Richard Smith c7e6ff02d5 [modules] Support for merging a parsed class template specialization definition into an imported but hidden definition.
llvm-svn: 237612
2015-05-18 20:36:47 +00:00
Richard Smith 2d4a11fba6 [modules] When a file is listed as a non-textual header in a module map, don't
enter it more than once, even if it doesn't have #include guards -- we already
know that it is intended to have the same effect every time it's included, and
it's already had that effect. This particularly helps with local submodule
visibility builds, where the include guard macro may not be visible in the
includer, but will become visible the moment we enter the included file.

llvm-svn: 237609
2015-05-18 20:02:41 +00:00
Richard Smith a0aafa3853 [modules] If we see a #include that maps to a module, but use of precompiled modules is disabled, track submodule visibility anyway if -fmodules-local-submodule-visibility is enabled. This, in effect, gives modules semantics but without precompilation.
llvm-svn: 237550
2015-05-18 03:52:30 +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 d9ba224f66 [modules] Suport for merging a parsed enum definition into an existing imported but not visible definition.
llvm-svn: 236690
2015-05-07 03:54:19 +00:00
Peter Collingbourne b2ed4d219b Fix public-private.modulemap test case to clear the cache on every run.
llvm-svn: 236655
2015-05-06 22:31:13 +00:00
Richard Smith 36bd40df72 Switch PPCallbacks to take the new MacroDefinition instead of MacroDirective*, in order to preserve full information on module macro expansion.
llvm-svn: 236404
2015-05-04 03:15:40 +00:00
Richard Smith 38477db8c4 [modules] If a module #includes a modular header that #undef's its macro, it
should not export the macro.

... at least, not unless we have local submodule visibility enabled.

llvm-svn: 236369
2015-05-02 00:45:56 +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 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 2a553089c3 [modules] Properly attribute macros to modules if they're in a file textually included into a file in the module.
llvm-svn: 235661
2015-04-23 22:58:06 +00:00
Richard Smith d6aab59ad1 [modules] Allow a function template definition if we have a pre-existing but not visible definition of the same template.
llvm-svn: 233430
2015-03-27 21:57:41 +00:00
Richard Smith df5bf99d0b Add file forgotten from r233420.
llvm-svn: 233425
2015-03-27 21:40:57 +00:00
Richard Smith 0279375836 [modules] When merging class definitions, make the retained definition visible
if the merged definition is visible, and perform lookups into all merged copies
of the definition (not just for special members) so that we can complete the
redecl chains for members of the class.

llvm-svn: 233420
2015-03-27 21:16:39 +00:00
Richard Smith 9a71c99844 [modules] Allow a function to be redefined if the old definition is not visible.
llvm-svn: 233407
2015-03-27 20:16:58 +00:00
Richard Smith a523022b53 [modules] Handle defining a tag with a typedef name for linkage purposes on top of an existing imported-but-not-visible definition.
llvm-svn: 233345
2015-03-27 01:37:43 +00:00
Richard Smith be3980b73c [modules] Handle defining a class template on top of an existing imported-but-not-visible definition.
llvm-svn: 233341
2015-03-27 00:41:57 +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
Richard Smith 8f4d3ff146 [modules] Restrict the module use-declaration to only appear in top-level
modules, and allow sub-modules of a module with a use-declaration to make use
of the nominated modules.

llvm-svn: 233323
2015-03-26 22:10:01 +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 70a1369b34 [Modules] Add some more fun code to my modules stress test, this time
templates. Turns out all of this works correctly (so far). But it should
cover more code paths and will let me test some things that don't
actually work next.

llvm-svn: 233263
2015-03-26 08:49:55 +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
Chandler Carruth 8a3d24dcf8 [Modules] Delete a bunch of complex code for ensuring visible decls in
updated decl contexts get emitted.

Since this code was added, we have newer vastly simpler code for
handling this. The code I'm removing was very expensive and also
generated unstable order of declarations which made module outputs
non-deterministic.

All of the tests continue to pass for me and I'm able to check the
difference between the .pcm files after merging modules together.

llvm-svn: 233251
2015-03-26 04:27:10 +00:00
Richard Smith 65ebb4ac8a [modules] If we reach a definition of a class for which we already have a
non-visible definition, skip the new definition and make the old one visible
instead of trying to parse it again and failing horribly. C++'s ODR allows
us to assume that the two definitions are identical.

llvm-svn: 233250
2015-03-26 04:09:53 +00:00
Chandler Carruth e972c36221 [Modules] A second attempt at writing out on-disk hash tables for the
decl context lookup tables.

The first attepmt at this caused problems. We had significantly more
sources of non-determinism that I realized at first, and my change
essentially turned them from non-deterministic output into
use-after-free. Except that they weren't necessarily caught by tools
because the data wasn't really freed.

The new approach is much simpler. The first big simplification is to
inline the "visit" code and handle this directly. That works much
better, and I'll try to go and clean up the other caller of the visit
logic similarly.

The second key to the entire approach is that we need to *only* collect
names into a stable order at first. We then need to issue all of the
actual 'lookup()' calls in the stable order of the names so that we load
external results in a stable order. Once we have loaded all the results,
the table of results will stop being invalidated and we can walk all of
the names again and use the cheap 'noload_lookup()' method to quickly
get the results and serialize them.

To handle constructors and conversion functions (whose names can't be
stably ordered) in this approach, what we do is record only the visible
constructor and conversion function names at first. Then, if we have
any, we walk the decls of the class and add those names in the order
they occur in the AST. The rest falls out naturally.

This actually ends up simpler than the previous approach and seems much
more robust.

It uncovered a latent issue where we were building on-disk hash tables
for lookup results when the context was a linkage spec! This happened to
dodge all of the assert by some miracle. Instead, add a proper predicate
to the DeclContext class and use that which tests both for function
contexts and linkage specs.

It also uncovered PR23030 where we are forming somewhat bizarre negative
lookup results. I've just worked around this with a FIXME in place
because fixing this particular Clang bug seems quite hard.

I've flipped the first part of the test case I added for stability back
on in this commit. I'm taking it gradually to try and make sure the
build bots are happy this time.

llvm-svn: 233249
2015-03-26 03:11:40 +00:00
Daniel Jasper cb47d8d17b Temporarily disable one more non-determinism flag.
This turned the bots to red after r233172 which reverted r233156.

llvm-svn: 233173
2015-03-25 06:59:19 +00:00
Chandler Carruth d5f1db6b36 [Modules] Disable the diff of the merged module, there is still some
non-determinism here, I just got lucky a bunch of times on my system.

llvm-svn: 233163
2015-03-25 01:30:02 +00:00
Chandler Carruth 75fc6a7f61 [Modules] Make the DeclUpdates map be processed in insertion order.
This fixes my stress tests non-determinism so far. However, I've not
started playing with templates, friends, or terrible macros. I've found
at least two more seeming instabilities and am just waiting for a test
case to actually trigger them.

llvm-svn: 233162
2015-03-25 01:02:12 +00:00
Chandler Carruth 580dd296fa [Modules] Stop creating timestamps for the modules cache and trying to
prune it when we have disabled implicit module generation and thus are
not using any cached modules.

Also update a test of explicitly generated modules to pass this CC1 flag
correctly.

This fixes an issue where Clang was dropping files into the source tree
while running its tests.

llvm-svn: 233117
2015-03-24 21:44:25 +00:00
Chandler Carruth 885e78cb22 [Modules] Start making explicit modules produce deterministic output.
There are two aspects of non-determinism fixed here, which was the
minimum required to cause at least an empty module to be deterministic.

First, the random number signature is only inserted into the module when
we are building modules implicitly. The use case for these random
signatures is to work around the very fact that modules are not
deterministic in their output when working with the implicitly built and
populated module cache. Eventually this should go away entirely when
we're confident that Clang is producing deterministic output.

Second, the on-disk hash table is populated based on the order of
iteration over a DenseMap. Instead, use a MapVector so that we can walk
it in insertion order.

I've added a test that an empty module, when built twice, produces the
same binary PCM file.

llvm-svn: 233115
2015-03-24 21:18:10 +00:00
Richard Smith 9e2341d093 [modules] Remove redundant import of lexical decls when building a lookup table
for a DeclContext, and fix propagation of exception specifications along
redeclaration chains.

This reverts r232905, r232907, and r232907, which reverted r232793, r232853,
and r232853.

One additional change is present here to resolve issues with LLDB: distinguish
between whether lexical decls missing from the lookup table are local or are
provided by the external AST source, and still look in the external source if
that's where they came from.

llvm-svn: 232928
2015-03-23 03:25:59 +00:00
Benjamin Kramer b7e4a1a0b6 Remove empty files left behind by r232907.
llvm-svn: 232909
2015-03-22 10:08:31 +00:00
Vince Harron 08dcf60295 Reverting 232853 and 232870 because they depend on 232793,
which was reverted because it was causing LLDB test failures

llvm-svn: 232907
2015-03-22 08:47:07 +00:00
Vince Harron a3ea9a4e09 Reverting r232793 until some new LLDB failures are discussed
llvm-svn: 232905
2015-03-22 05:59:59 +00:00
Richard Smith decef8007f [modules] When either redecl chain merging or an update record causes us to
give an exception specification to a declaration that didn't have an exception
specification in any of our imported modules, emit an update record ourselves.
Without this, code importing the current module would not see an exception
specification that we could see and might have relied on.

llvm-svn: 232870
2015-03-21 00:58:54 +00:00
Richard Smith 5a07892dec [modules] Remove temporary IdentifierInfo lookup results when we're done with them.
llvm-svn: 232853
2015-03-20 21:56:50 +00:00
Richard Smith 625ccb3f78 [modules] Remove some redundant work when building a lookup table for a DeclContext.
When we need to build the lookup table for a DeclContext, we used to pull in
all lexical declarations for the context; instead, just build a lookup table
for the local lexical declarations. We previously didn't guarantee that the
imported declarations would be in the returned map, but in some cases we'd
happen to put them all in there regardless. Now we're even lazier about this.

This unnecessary work was papering over some other bugs:

 - LookupVisibleDecls would use the DC for name lookups in the TU in C, and
   this was not guaranteed to find all imported names (generally, the DC for
   the TU in C is not a reliable place to perform lookups). We now use an
   identifier-based lookup mechanism for this.

 - We didn't actually load in the list of eagerly-deserialized declarations
   when importing a module (so external definitions in a module wouldn't be
   emitted by users of those modules unless they happened to be deserialized
   by the user of the module).

llvm-svn: 232793
2015-03-20 02:17:21 +00:00
Richard Smith 7f330cdb31 Make module files passed to a module build via -fmodule-file= available to
consumers of that module.

Previously, such a file would only be available if the module happened to
actually import something from that module.

llvm-svn: 232583
2015-03-18 01:42:29 +00:00
Richard Smith 15e32fd215 [modules] Fix bug where an anonymous namespace could cause the containing
namespace to not merge properly.

We have an invariant here: after a declaration reads its canonical declaration,
it can assume the canonical declaration is fully merged. This invariant can be
violated if deserializing some declaration triggers the deserialization of a
later declaration, because that later declaration can in turn deserialize a
redeclaration of that first declaration before it is fully merged.

The anonymous namespace for a namespace gets stored with the first declaration
of that namespace, which may be before its parent namespace, so defer loading
it until after we've finished merging the surrounding namespace.

llvm-svn: 232455
2015-03-17 02:23:11 +00:00
Richard Smith e687bf83c0 [modules] If we find more formerly-canonical declarations of an entity while
building its redecl chains, make sure we pull in the redeclarations of those
canonical declarations.

It's pretty difficult to reach a situation where we can find more canonical
declarations of an entity while building its redecl chains; I think the
provided testcase (4 modules and 7 declarations) cannot be reduced further.

llvm-svn: 232411
2015-03-16 20:54:07 +00:00
Chandler Carruth 0d745bcf66 [modules] Teach the AST reader to handle the case of importing a module
with a subset of the existing target CPU features or mismatched CPU
names.

While we can't check that the CPU name used to build the module will end
up being able to codegen correctly for the translation unit, we actually
check that the imported features are a subset of the existing features.

While here, rewrite the code to use std::set_difference and have it
diagnose all of the differences found.

Test case added which walks the set relationships and ensures we
diagnose all the right cases and accept the others.

No functional change for implicit modules here, just better diagnostics.

llvm-svn: 232248
2015-03-14 04:47:43 +00:00
David Blaikie bdf40a62a7 Test case updates for explicit type parameter to the gep operator
llvm-svn: 232187
2015-03-13 18:21:46 +00:00
Daniel Jasper 0ab544f1a5 When building a module, all headers of submodules can be used.
This extends r232159.

llvm-svn: 232168
2015-03-13 14:29:39 +00:00
Daniel Jasper b6ba46ef30 Make a module "use" also count as use of all its submodules
llvm-svn: 232159
2015-03-13 11:26:16 +00:00
Chandler Carruth c2132d8f33 [Modules] Teach Clang to survive ambiguous macros which come from system
headers even if they arrived when merging non-system modules.

The idea of this code is that we don't want to warn the user about
macros defined multiple times by their system headers with slightly
different definitions. We should have this behavior if either the
macro comes from a system module, or the definition within the module
comes from a system header. Previously, we would warn on ambiguous
macros being merged when they came from a users modules even though they
only showed up via system headers.

By surviving this we can handle common system header macro differences
like differing 'const' qualification of pointers due to some headers
predating 'const' being valid in C code, even when those systems headers
are pre-built into a system module.

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

llvm-svn: 232149
2015-03-13 08:29:54 +00:00
Richard Smith 7474dd92d3 [modules] When merging the pattern of a class template definition into a prior
definition, be sure to update the definition data on all declarations, not just
the canonical one, since the pattern might not be in the list of pending
definitions (if it used to be canonical itself).

One-line fix by me; reduced testcase by Daniel Jasper!

llvm-svn: 231950
2015-03-11 18:21:02 +00:00
Richard Smith 9ab4ccecb3 [modules] Fix iterator invalidation issue with names being added to a module
while we're writing out the identifier table.

llvm-svn: 231890
2015-03-11 00:00:51 +00:00
Richard Smith 80969754b7 PR21687: when adding a redeclaration of a function with an implicit exception
specification, update all prior declarations if the new one has an explicit
exception specification and the prior ones don't.

Patch by Vassil Vassilev! Some minor tweaking and test case by me.

llvm-svn: 231738
2015-03-10 02:00:53 +00:00
Richard Smith f81340096d [modules] Don't clobber a destructor's operator delete when adding another one;
move the operator delete updating into a separate update record so we can cope
with updating another module's destructor's operator delete.

llvm-svn: 231735
2015-03-10 01:41:22 +00:00
Richard Smith 2708e52029 [modules] This check is run before we resolve the header, not after, so just
check that private headers are in a list matching the role. (We can't perform
the opposite checks for non-private headers because we infer those.)

llvm-svn: 231728
2015-03-10 00:19:04 +00:00
Richard Smith 00bc95ec9a [modules] Don't assert if the same header is named as both a public and a
private header within the same module.

llvm-svn: 231725
2015-03-09 23:46:50 +00:00