Commit Graph

5973 Commits

Author SHA1 Message Date
Richard Smith c2bb81860b [modules] Deserialize CXXCtorInitializer list for a constructor lazily.
Previously we'd deserialize the list of mem-initializers for a constructor when
we deserialized the declaration of the constructor. That could trigger a
significant amount of unnecessary work (pulling in all base classes
recursively, for a start) and was causing problems for the modules buildbot due
to cyclic deserializations. We now deserialize these on demand.

This creates a certain amount of duplication with the handling of
CXXBaseSpecifiers; I'll look into reducing that next.

llvm-svn: 233052
2015-03-24 06:36:48 +00:00
Richard Smith d2f887dd02 [modules] More removal of unnecessary deserialization of lexical decls.
Even if we have no external visible declarations, we may still have external
lexical decls that lookup() would import to fill its lookup table. It's simpler
and faster to always take the no-deserialization path through noload_lookup.

llvm-svn: 233046
2015-03-24 02:49:55 +00:00
Richard Smith 18b380b1e5 When looking for lexical decls from an external source, check all contexts
rather than just the primary context. This is technically correct but results
in no functionality change (in Clang nor LLDB) because all users of this
functionality only use it on single-context DCs.

llvm-svn: 233045
2015-03-24 02:44:20 +00:00
Benjamin Kramer d5748c7b9d Move private classes into anonymous namespaces
Also merge anonymous namespaces in Targets.cpp a bit. NFC.

llvm-svn: 232945
2015-03-23 12:31:05 +00:00
Alexey Bataev a63048e4fd [OPENMP] Codegen for 'copyprivate' clause ('single' directive).
If there is at least one 'copyprivate' clause is associated with the single directive, the following code is generated:

```
i32 did_it = 0;                                  \\ for 'copyprivate' clause
if(__kmpc_single(ident_t *, gtid)) {
  SingleOpGen();
  __kmpc_end_single(ident_t *, gtid);
  did_it = 1;                                    \\ for 'copyprivate' clause
}
<copyprivate_list>[0] = &var0;
...
<copyprivate_list>[n] = &varn;
call __kmpc_copyprivate(ident_t *, gtid, <copyprivate_list_size>,
                        <copyprivate_list>, <copy_func>, did_it);

...

void<copy_func>(void *LHSArg, void *RHSArg) {
  Dst = (void * [n])(LHSArg);
  Src = (void * [n])(RHSArg);
  Dst[0] = Src[0];
  ... Dst[n] = Src[n];
}
```
All list items from all 'copyprivate' clauses are gathered into single <copyprivate list> (<copyprivate_list_size> is a size in bytes of this list) and <copy_func> is used to propagate values of private or threadprivate variables from the 'single' region to other implicit threads from outer 'parallel' region.
Differential Revision: http://reviews.llvm.org/D8410

llvm-svn: 232932
2015-03-23 06:18:07 +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
Faisal Vali 2da8ed9241 Add a dump function to Stmt that takes only an output stream. No functionality change.
This allows dumping to any given output stream but without requiring a SourceManager, similar to the interface provided by Decl.

It's useful when writing certain generic debug functions, external to the clang code base (for e.g.).

llvm-svn: 232912
2015-03-22 13:35:56 +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
Alexander Musman 3276a27b5c [OPENMP] CodeGen of the 'linear' clause for the 'omp simd' directive.
The linear variable is privatized (similar to 'private') and its
value on current iteration is calculated, similar to the loop
counter variables.
Differential revision: http://reviews.llvm.org/D8375

llvm-svn: 232890
2015-03-21 10:12:56 +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
Reid Kleckner 7ffc3fbb2f C++14: Disable sized deallocation by default due to ABI breakage
There are no widely deployed standard libraries providing sized
deallocation functions, so we have to punt and ask the user if they want
us to use sized deallocation. In the future, when such libraries are
deployed, we can teach the driver to detect them and enable this
feature.

N3536 claimed that a weak thunk from sized to unsized deallocation could
be emitted to avoid breaking backwards compatibility with standard
libraries not providing sized deallocation. However, this approach and
other variations don't work in practice.

With the weak function approach, the thunk has to have default
visibility in order to ensure that it is overridden by other DSOs
providing sized deallocation. Weak, default visibility symbols are
particularly expensive on MachO, so John McCall was considering
disabling this feature by default on Darwin. It also changes behavior
ELF linking behavior, causing certain otherwise unreferenced object
files from an archive to be pulled into the link.

Our second approach was to use an extern_weak function declaration and
do an inline conditional branch at the deletion call site. This doesn't
work because extern_weak only works on MachO if you have some archive
providing the default value of the extern_weak symbol. Arranging to
provide such an archive has the same challenges as providing the symbol
in the standard library. Not to mention that extern_weak doesn't really
work on COFF.

Reviewers: rsmith, rjmccall

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

llvm-svn: 232788
2015-03-20 00:31:07 +00:00
David Majnemer 73768709f2 Don't crash-on-valid when an inline function is friend of class template
We assumed that the most recent declaration of an inline function would
also be inline.  However, a more recent declaration can come from a
friend declaration in a class template that is instantiated at the
definition of the function.

llvm-svn: 232786
2015-03-20 00:02:27 +00:00
Reid Kleckner 461c0c6934 Fix -ast-dump of dependent new and delete exprs
llvm-svn: 232748
2015-03-19 18:47:47 +00:00
Reid Kleckner 5c682bc4b8 Add -ast-dump support for new and delete expressions to help figure out which operator got selected
llvm-svn: 232740
2015-03-19 18:09:25 +00:00
Benjamin Kramer 845e32cd4d Devirtualize Attr and all subclasses.
We know all subclasses in tblgen so just generate a giant switch for
the few virtual methods or turn them into a member variable using spare
bits. The giant jump tables aren't pretty but still much smaller than
a vtable for every attribute, shrinking Release+Asserts clang by ~400k.

Also halves the size of the Attr base class. No functional change
intended.

llvm-svn: 232726
2015-03-19 16:06:49 +00:00
David Majnemer a03849b2e7 MS ABI: Don't try to emit VF/VB-Tables for extern class templates
There will be an explicit template instantiation in another translation
unit which will provide the definition of the VF/VB-Tables.

This fixes PR22932.

llvm-svn: 232680
2015-03-18 22:04:43 +00:00
David Majnemer 4deaac780c MS ABI: Empty pack expansions had their mangling changed in 2013->2015
We used to support the 2013 mangling and changed it to the more
reasonable 2015 mangling.  Let's make the mangling conditional on what
version of MSVC is targeted.

This fixes PR21888.

llvm-svn: 232609
2015-03-18 03:56:27 +00:00
Justin Bogner 0729afa4a6 MS ABI: Fix a couple of -Winconsistent-missing-override warnings
llvm-svn: 232559
2015-03-17 22:31:34 +00:00
David Majnemer 5f0dd6162c MS ABI: Emit HandlerMap entries for C++ catch
The HandlerMap describes, to the runtime, what sort of catches surround
the try.  In principle, this structure has to be emitted by the backend
because only it knows the layout of the stack (the runtime needs to know
where on the stack the destination of a copy lives, etc.) but there is
some C++ specific information that the backend can't reason about.

Stick this information in special LLVM globals with the relevant
"const", "volatile", "reference" info mangled into the name.

llvm-svn: 232538
2015-03-17 20:35:05 +00:00
Benjamin Kramer 0eb262fb28 Sort ObjCProtocolDecls with array_pod_sort.
The predicate is essentially a string comparison. NFC.

llvm-svn: 232264
2015-03-14 13:32:49 +00:00
David Majnemer bc02d32f4d MS ABI: Mangle virtual member pointer thunks with the correct CC
Virtual member pointers are implemented using a thunk.  We assumed that
the calling convention for this thunk was always __thiscall for 32-bit
targets and __cdecl for 64-bit targets.  However, this is not the case.
Mangle in whichever calling convention is appropriate for this member
function thunk.

llvm-svn: 232254
2015-03-14 06:34:41 +00:00
David Majnemer 37fd66e78b MS ABI: Generate default constructor closures
The MS ABI utilizes a compiler generated function called the "vector
constructor iterator" to construct arrays of objects with
non-trivial constructors/destructors.  For this to work, the constructor
must follow a specific calling convention.  A thunk must be created if
the default constructor has default arguments, is variadic or is
otherwise incompatible.  This thunk is called the default constructor
closure.

N.B.  Default constructor closures are only generated if the default
constructor is exported because clang itself does not utilize vector
constructor iterators.  Failing to export the default constructor
closure will result in link/load failure if a translation unit compiled
with MSVC is on the import side.

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

llvm-svn: 232229
2015-03-13 22:36:55 +00:00
David Majnemer ba3e5ecf07 MS ABI: Implement __GetExceptionInfo for std::make_exception_ptr
std::make_exception_ptr calls std::__GetExceptionInfo in order to figure
out how to properly copy the exception object.

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

llvm-svn: 232188
2015-03-13 18:26:17 +00:00
Alexey Bataev 1d160b1945 [OPENMP] Additional sema analysis for 'omp atomic[ update]'.
Adds additional semantic analysis + generation of helper expressions for proper codegen.

llvm-svn: 232164
2015-03-13 12:27:31 +00:00
David Majnemer dfa6d2067c MS ABI: Implement copy-ctor closures, finish implementing throw
This adds support for copy-constructor closures.  These are generated
when the C++ runtime has to call a copy-constructor with a particular
calling convention or with default arguments substituted in to the call.

Because the runtime has no mechanism to call the function with a
different calling convention or know-how to evaluate the default
arguments at run-time, we create a thunk which will do all the
appropriate work and package it in a way the runtime can use.

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

llvm-svn: 231952
2015-03-11 18:36:39 +00:00
Fariborz Jahanian 20cfff3d31 revert r231700 (designated initializer patch) which broke
several projects. rdar://20120666.

llvm-svn: 231939
2015-03-11 16:59:48 +00:00
Richard Smith ed1cb88c8a For PR22870: produce an error rather than asserting if a designated initializer appears in a signature.
llvm-svn: 231892
2015-03-11 00:12:17 +00:00
David Majnemer 999cbf9d21 MS ABI: Mangle the location of the catchable type into it's name
Because the catchable type has a reference to its name, mangle the
location to ensure that two catchable types with different locations are
distinct.

llvm-svn: 231819
2015-03-10 19:01:51 +00:00
Yaron Keren 09fb7c6e7a Teach raw_ostream to accept SmallString.
Saves adding .str() call to any raw_ostream << SmallString usage
and a small step towards making .str() consistent in the ADTs by
removing one of the SmallString::str() use cases, discussion at

http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20141013/240026.html

I'll update the Phabricator patch http://reviews.llvm.org/D6372
for review of the Twine SmallString support, it's more complex
than this one.

llvm-svn: 231763
2015-03-10 07:33:23 +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
Fariborz Jahanian 29dec576e6 [PATCH Sema Objective-C]. Patch to warn on missing designated initializer
override where at least a declaration of a designated initializer is in a super
class and not necessarily in the current class. rdar://19653785.

llvm-svn: 231700
2015-03-09 20:39:51 +00:00
Benjamin Kramer 8407df72a3 Make helper functions static. NFC.
Found by -Wmissing-prototypes.

llvm-svn: 231668
2015-03-09 16:47:52 +00:00
Benjamin Kramer 6afa168e31 InheritViz: Hide implementation details
NFC.

llvm-svn: 231655
2015-03-09 15:03:20 +00:00
David Blaikie 7a3cbb2997 Simplify boolean expressions in clang with clang-tidy
Patch by Richard (legalize at xmission dot com).

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

llvm-svn: 231619
2015-03-09 02:02:07 +00:00
Richard Smith f19e12794d Replace Sema's map of locally-scoped extern "C" declarations with a DeclContext
of extern "C" declarations. This is simpler and vastly more efficient for
modules builds (we no longer need to load *all* extern "C" declarations to
determine if we have a redeclaration).

No functionality change intended.

llvm-svn: 231538
2015-03-07 00:04:49 +00:00
David Majnemer e7a818fec8 MS ABI: Insert copy-constructors into the CatchableType
Find all unambiguous public classes of the exception object's class type
and reference all of their copy constructors.  Yes, this is not
conforming but it is necessary in order to implement their ABI.  This is
because the copy constructor is actually referenced by the metadata
describing which catch handlers are eligible to handle the exception
object.

N.B.  This doesn't yet handle the copy constructor closure case yet,
that work is ongoing.

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

llvm-svn: 231499
2015-03-06 18:53:55 +00:00
David Majnemer be09e8e5cf Sema: The i8 suffix should yield a literal of type char
We would make i8 literals turn into signed char instead of char.  This
is incompatible with MSVC.

This fixes PR22824.

llvm-svn: 231494
2015-03-06 18:04:22 +00:00
Benjamin Kramer f04f98d543 Use delegating ctors to reduce code duplication. NFC.
llvm-svn: 231476
2015-03-06 14:15:57 +00:00
Richard Smith fe620d26ea [modules] Rework merging of redeclaration chains on module import.
We used to save out and eagerly load a (potentially huge) table of merged
formerly-canonical declarations when we loaded each module. This was extremely
inefficient in the presence of large amounts of merging, and didn't actually
save any merging lookup work, because we still needed to perform name lookup to
check that our merged declaration lists were complete. This also resulted in a
loss of laziness -- even if we only needed an early declaration of an entity, we
would eagerly pull in all declarations that had been merged into it regardless.

We now store the relevant fragments of the table within the declarations
themselves. In detail:

 * The first declaration of each entity within a module stores a list of first
   declarations from imported modules that are merged into it.
 * Loading that declaration pre-loads those other entities, so that they appear
   earlier within the redeclaration chain.
 * The name lookup tables list the most recent local lookup result, if there
   is one, or all directly-imported lookup results if not.

llvm-svn: 231424
2015-03-05 23:24:12 +00:00
David Majnemer 7c23707174 MS ABI: Implement support for throwing a C++ exception
Throwing a C++ exception, under the MS ABI, is implemented using three
components:
- ThrowInfo structure which contains information like CV qualifiers,
  what destructor to call and a pointer to the CatchableTypeArray.
- In a significant departure from the Itanium ABI, copying by-value
  occurs in the runtime and not at the catch site.  This means we need
  to enumerate all possible types that this exception could be caught as
  and encode the necessary information to convert from the exception
  object's type to the catch handler's type.  This includes complicated
  derived to base conversions and the execution of copy-constructors.

N.B. This implementation doesn't support the execution of a
copy-constructor from within the runtime for now.  Adding support for
that functionality is quite difficult due to things like default
argument expressions which may evaluate arbitrary code hiding in the
copy-constructor's parameters.

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

llvm-svn: 231328
2015-03-05 00:46:22 +00:00
Alex Denisov e1d882c726 New ObjC warning: circular containers.
This commit adds new warning to prevent user from creating 'circular containers'.

Mutable collections from NSFoundation allows user to add collection to itself, e.g.: 

NSMutableArray *a = [NSMutableArray new]; 
[a addObject:a]; 

The code above leads to really weird behaviour (crashes, 'endless' recursion) and 
retain cycles (collection retains itself) if ARC enabled.

Patch checks the following collections: 
  - NSMutableArray, 
  - NSMutableDictionary, 
  - NSMutableSet, 
  - NSMutableOrderedSet, 
  - NSCountedSet. 

llvm-svn: 231265
2015-03-04 17:55:52 +00:00
Jacques Pienaar b92e7a992d TypePrinter print __restrict if not in C99 mode
restrict is a keyword in C99 but not in C++ while clang accepts __restrict for C++ code. Modify the TypePrinter to print __restrict when not processing C99 code.

Printing restrict in C++ was problematic as printing the argument of
  int f(int * __restrict a) { ... }
resulted in
  int *restrict a
which is incorrect.

http://reviews.llvm.org/D8048

llvm-svn: 231179
2015-03-03 23:58:09 +00:00
David Majnemer d09a51c299 Sema: Properly initialize the thrown exception object
We would create the exception object with the wrong qualifiers, ensuring
that the wrong copy constructor would get called.

llvm-svn: 231049
2015-03-03 01:50:05 +00:00
Bob Wilson b111ec94b3 Add clang support for Objective-C application extensions.
This adds the -fapplication-extension option, along with the
ios_app_extension and macosx_app_extension availability attributes.
Patch by Ted Kremenek

llvm-svn: 230989
2015-03-02 19:01:14 +00:00
Nico Weber f609839244 Fix ObjCInterfaceDecl::getCategoryMethod() and give it a caller. No behavior change.
llvm-svn: 230928
2015-03-02 01:12:28 +00:00
Petar Jovanovic d55ae6ba37 Add support for generating MIPS legacy NaN
Currently, the NaN values emitted for MIPS architectures do not cover
non-IEEE754-2008 compliant case. This change fixes the issue.

Patch by Vladimir Radosavljevic.

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

llvm-svn: 230653
2015-02-26 18:19:22 +00:00
Richard Trieu 555c9673fd Update assumption in template diffing about integer template arguments.
Fix for PR22017.  Integer template arguments are automatically bit extended to
the size of the integer type.  In template diffing, evaluated expressions were
not having their results extending, leading to comparing two APSInt's with
different widths.  Apply the proper bit extending when evaluating template
arguments.  This mainly affected bool template arguments.

llvm-svn: 230603
2015-02-26 02:40:48 +00:00
Richard Smith 8cebe37fe9 [modules] Even if we already have a definition of a class, loading in another
one can give us more lookup results (due to implicit special members). Be sure
to complete the redecl chain for every kind of DeclContext before performing a
lookup into it, rather than only doing so for NamespaceDecls.

llvm-svn: 230558
2015-02-25 22:20:13 +00:00
Reid Kleckner 1cbd9aa96d Reland (2x) r230314, "Fix codegen for virtual methods that are (re-) exported from multiple modules."
This reverts commits r230477 and r230478.

llvm-svn: 230526
2015-02-25 19:17:48 +00:00
Reid Kleckner 8b6d034cab Reland r230446, "MS ABI: Try to respect external AST source record layouts"
It broke test/PCH/headersearch.cpp because it was using -Wpadding, which
only works for Itanium layout. Before this commit, we would use Itanium
record layout when using PCH, which is crazy. Now that the test uses an
explicit Itanium triple, we can reland.

llvm-svn: 230525
2015-02-25 19:17:45 +00:00