summaryrefslogtreecommitdiffstats
path: root/clang/lib/AST
Commit message (Collapse)AuthorAgeFilesLines
...
* Allow any comment to be a trailing comment when -fparse-all-comments is on.James Dennett2015-07-151-7/+79
| | | | | | | | | | | | | | | | | | | | | | | | This helps with freeform documentation styles, where otherwise code like enum class E { E1, // D1 E2 // D2 }; would result in D1 being associated with E2. To properly associate E1 with D1 and E2 with D2, this patch allows all raw comments C such that C.isParseAllComments() to participate in trailing comment checks inside getRawCommentForDeclNoCache. This takes care of linking the intended documentation with the intended decls. There remains an issue with code like: foo(); // DN int x; To prevent DN from being associated with x, this patch adds a new test on preceding-line comments C (where C.isParseAllComments() and also C's kind is RCK_OrdinaryBCPL or RCK_OrdinaryC) that checks whether C is the first non-whitespace thing on C's starting line. Patch from Luke Zarko <zarko@google.com>, D11069 reviewed by rsmith. llvm-svn: 242317
* [OpenMP] Add TLS-based implementation for threadprivate directive.Samuel Antao2015-07-131-4/+8
| | | | llvm-svn: 242080
* [MS ABI] Don't generates code for unreferenced inline definitions of library ↵David Majnemer2015-07-101-2/+2
| | | | | | | | | | | builtins We should only consider declarations which were written, implicit declarations shouldn't be considered. This fixes PR24084. llvm-svn: 241941
* DeclObjC: Move computing the type of self into a separate function (NFC).Adrian Prantl2015-07-081-5/+13
| | | | | | This function will be used for emitting debug info. llvm-svn: 241748
* AST: Avoid reading an unitialized valueJustin Bogner2015-07-081-2/+2
| | | | | | | | | | Desugar doesn't necessarily initialize ShouldAKA, but as of r241542 it may read it. Fix the misuse of the API and initialize this before passing it in. Found by ubsan. llvm-svn: 241705
* [modules] When determining the visible module set during templateRichard Smith2015-07-081-3/+3
| | | | | | | instantiation, use the set of modules visible from the template definition, not from whichever declaration the specialization was instantiated from. llvm-svn: 241662
* Use AlignOf instead of alignOf so that this can go back to being a ↵Aaron Ballman2015-07-071-3/+3
| | | | | | static_assert. Amends r241577. llvm-svn: 241604
* Changing a use of alignof() into llvm::alignOf() for MSVC compatibility. ↵Aaron Ballman2015-07-071-2/+3
| | | | | | This requires changing a static_assert into an assert, too. llvm-svn: 241577
* Don't rely on the use of non-POD types within unions.Douglas Gregor2015-07-071-1/+3
| | | | | | | They aren't universally supported and we're not getting any benefit from using them. llvm-svn: 241564
* [libclang] Implement proper code-completion in an ObjC type parameter position.Douglas Gregor2015-07-071-0/+11
| | | | | | rdar://19670303 llvm-svn: 241561
* [libclang] Replace ObjC generic parameters when code-completing method ↵Douglas Gregor2015-07-071-0/+6
| | | | | | | | implementations. rdar://20643768 llvm-svn: 241559
* The AST importer had a bug where it would enter into an infinite recursionDouglas Gregor2015-07-072-17/+32
| | | | | | | | | | | | | | | | when importing type parameter lists. The reason is that type parameters have their DeclContexts set to the interface that is parameterized with those types, and the importer would follow that loop and blow the stack out. I've changed the way this works so that the type parameters are only imported after the interface that contains them has been registered via the Imported() function. This is tested by LLDB. <rdar://problem/20315663> llvm-svn: 241556
* Factor the simpleTransform() visitor so that it is not a local class.Douglas Gregor2015-07-071-288/+294
| | | | | | | Older versions of Clang cannot handle such local classes properly rdar://problem/19386032. llvm-svn: 241550
* Implement variance for Objective-C type parameters.Douglas Gregor2015-07-075-10/+91
| | | | | | | | | | | | | | | Introduce co- and contra-variance for Objective-C type parameters, which allows us to express that (for example) an NSArray is covariant in its type parameter. This means that NSArray<NSMutableString *> * is a subtype of NSArray<NSString *> *, which is expected of the immutable Foundation collections. Type parameters can be annotated with __covariant or __contravariant to make them co- or contra-variant, respectively. This feature can be detected by __has_feature(objc_generics_variance). Implements rdar://problem/20217490. llvm-svn: 241549
* Implement the Objective-C __kindof type qualifier.Douglas Gregor2015-07-076-52/+265
| | | | | | | | | | The __kindof type qualifier can be applied to Objective-C object (pointer) types to indicate id-like behavior, which includes implicit "downcasting" of __kindof types to subclasses and id-like message-send behavior. __kindof types provide better type bounds for substitutions into unspecified generic types, which preserves more type information. llvm-svn: 241548
* C++ support for Objective-C lightweight generics.Douglas Gregor2015-07-072-1/+56
| | | | | | | | | | | | | | | | | | | Teach C++'s tentative parsing to handle specializations of Objective-C class types (e.g., NSArray<NSString *>) as well as Objective-C protocol qualifiers (id<NSCopying>) by extending type-annotation tokens to handle this case. As part of this, remove Objective-C protocol qualifiers from the declaration specifiers, which never really made sense: instead, provide Sema entry points to make them part of the type annotation token. Among other things, this properly diagnoses bogus types such as "<NSCopying> id" which should have been written as "id <NSCopying>". Implements template instantiation support for, e.g., NSArray<T>* in C++. Note that parameterized classes are not templates in the C++ sense, so that cannot (for example) be used as a template argument for a template template parameter. Part of rdar://problem/6294649. llvm-svn: 241545
* Improve the Objective-C common-type computation used by the ternary operator.Douglas Gregor2015-07-073-76/+183
| | | | | | | | | | | | | | | | The Objective-C common-type computation had a few problems that required a significant rework, including: - Quadradic behavior when finding the common base type; now it's linear. - Keeping around type arguments when computing the common type between a specialized and an unspecialized type - Introducing redundant protocol qualifiers. Part of rdar://problem/6294649. Also fixes rdar://problem/19572837 by addressing a longstanding bug in ASTContext::CollectInheritedProtocols(). llvm-svn: 241544
* Substitute type arguments into uses of Objective-C interface members.Douglas Gregor2015-07-076-30/+860
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When messaging a method that was defined in an Objective-C class (or category or extension thereof) that has type parameters, substitute the type arguments for those type parameters. Similarly, substitute into property accesses, instance variables, and other references. This includes general infrastructure for substituting the type arguments associated with an ObjCObject(Pointer)Type into a type referenced within a particular context, handling all of the substitutions required to deal with (e.g.) inheritance involving parameterized classes. In cases where no type arguments are available (e.g., because we're messaging via some unspecialized type, id, etc.), we substitute in the type bounds for the type parameters instead. Example: @interface NSSet<T : id<NSCopying>> : NSObject <NSCopying> - (T)firstObject; @end void f(NSSet<NSString *> *stringSet, NSSet *anySet) { [stringSet firstObject]; // produces NSString* [anySet firstObject]; // produces id<NSCopying> (the bound) } When substituting for the type parameters given an unspecialized context (i.e., no specific type arguments were given), substituting the type bounds unconditionally produces type signatures that are too strong compared to the pre-generics signatures. Instead, use the following rule: - In covariant positions, such as method return types, replace type parameters with “id” or “Class” (the latter only when the type parameter bound is “Class” or qualified class, e.g, “Class<NSCopying>”) - In other positions (e.g., parameter types), replace type parameters with their type bounds. - When a specialized Objective-C object or object pointer type contains a type parameter in its type arguments (e.g., NSArray<T>*, but not NSArray<NSString *> *), replace the entire object/object pointer type with its unspecialized version (e.g., NSArray *). llvm-svn: 241543
* Handle Objective-C type arguments.Douglas Gregor2015-07-077-85/+257
| | | | | | | | | | | | | | | | | | | | | Objective-C type arguments can be provided in angle brackets following an Objective-C interface type. Syntactically, this is the same position as one would provide protocol qualifiers (e.g., id<NSCopying>), so parse both together and let Sema sort out the ambiguous cases. This applies both when parsing types and when parsing the superclass of an Objective-C class, which can now be a specialized type (e.g., NSMutableArray<T> inherits from NSArray<T>). Check Objective-C type arguments against the type parameters of the corresponding class. Verify the length of the type argument list and that each type argument satisfies the corresponding bound. Specializations of parameterized Objective-C classes are represented in the type system as distinct types. Both specialized types (e.g., NSArray<NSString *> *) and unspecialized types (NSArray *) are represented, separately. llvm-svn: 241542
* Parsing, semantic analysis, and AST for Objective-C type parameters.Douglas Gregor2015-07-076-10/+235
| | | | | | | | | | | | | | | | | | | | Produce type parameter declarations for Objective-C type parameters, and attach lists of type parameters to Objective-C classes, categories, forward declarations, and extensions as appropriate. Perform semantic analysis of type bounds for type parameters, both in isolation and across classes/categories/extensions to ensure consistency. Also handle (de-)serialization of Objective-C type parameter lists, along with sundry other things one must do to add a new declaration to Clang. Note that Objective-C type parameters are typedef name declarations, like typedefs and C++11 type aliases, in support of type erasure. Part of rdar://problem/6294649. llvm-svn: 241541
* StmtIterator: Put stmt and decl group pointer into a union.Benjamin Kramer2015-07-031-2/+2
| | | | | | Reduce the size of StmtIterator without changing behavior. llvm-svn: 241356
* Switch users of the 'for (StmtRange range = stmt->children(); range; ↵Benjamin Kramer2015-07-024-15/+15
| | | | | | | | | ++range)‘ pattern to range for loops. The pattern was born out of the lack of range-based for loops in C++98 and is somewhat obscure. No functionality change intended. llvm-svn: 241300
* [OPENMP 4.0] Initial support for 'omp cancel' construct.Alexey Bataev2015-07-023-0/+30
| | | | | | Implemented parsing/sema analysis + (de)serialization. llvm-svn: 241253
* [MS ABI] nullptr data member ptrs are mangled differently for classes vs fnsDavid Majnemer2015-07-021-3/+15
| | | | | | | | | | | It turns out that nullptr pointers to data members act differently in function templates vs class templates. Class templates use a variable width representation proportional to the number of fields needed to materialize it. Function templates always use a single '0' template parameter. However, using '0' all the time is problematic if the class uses single or multiple inheritance. In those cases, use -1. llvm-svn: 241251
* [OPENMP] Introduced type trait "__builtin_omp_required_simd_align" for ↵Alexey Bataev2015-07-025-1/+33
| | | | | | | | | default simd alignment. Adds type trait "__builtin_omp_required_simd_align" after discussions here http://reviews.llvm.org/D9894 Differential Revision: http://reviews.llvm.org/D10597 llvm-svn: 241237
* [modules] Don't make out-of-line member specializations of an instantiatedRichard Smith2015-07-011-0/+1
| | | | | | | class template specialization visible just because the class template specialization's definition is visible. llvm-svn: 241182
* [OPENMP 4.0] Initial support for 'omp cancellation point' construct.Alexey Bataev2015-07-013-0/+31
| | | | | | Add parsing and sema analysis for 'omp cancellation point' directive. llvm-svn: 241145
* Add a function to ExternalASTSource that returns a descriptor thatAdrian Prantl2015-06-301-0/+10
| | | | | | | abstracts the commonalities between modules and PCH files that are needed to emit debug info for a module or precompiled header. llvm-svn: 241083
* [ObjC] Add NSValue support for objc_boxed_expressionsAlex Denisov2015-06-262-1/+7
| | | | | | | | | | | | | Patch extends ObjCBoxedExpr to accept records (structs and unions): typedef struct __attribute__((objc_boxable)) _Color { int r, g, b; } Color; Color color; NSValue *boxedColor = @(color); // [NSValue valueWithBytes:&color objCType:@encode(Color)]; llvm-svn: 240761
* Replace __double_underscored type nullability qualifiers with ↵Douglas Gregor2015-06-242-10/+9
| | | | | | | | | | | | | | | | _Uppercase_underscored Addresses a conflict with glibc's __nonnull macro by renaming the type nullability qualifiers as follows: __nonnull -> _Nonnull __nullable -> _Nullable __null_unspecified -> _Null_unspecified This is the major part of rdar://problem/21530726, but does not yet provide the Darwin-specific behavior for the old names. llvm-svn: 240596
* [MS ABI] Account for the virtual inheritance quirk when manglingDavid Majnemer2015-06-232-1/+18
| | | | | | | | | | | | Virtual inheritance member pointers are always relative to the vbindex, even when the member pointer doesn't point into a virtual base. This is corrected by adjusting the non-virtual offset backwards from the vbptr back to the top of the most derived class. While we performed this adjustment when manifesting member pointers as constants or when performing conversions, we didn't perform the adjustment when mangling them. llvm-svn: 240453
* [OPENMP] Initial support for 'depend' clause (4.0).Alexey Bataev2015-06-233-0/+38
| | | | | | Parsing and sema analysis (without support for array sections in arguments) for 'depend' clause (used in 'task' directive, OpenMP 4.0). llvm-svn: 240409
* [MS ABI] Rework member pointer conversionDavid Majnemer2015-06-231-0/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Member pointers in the MS ABI are made complicated due to the following: - Virtual methods in the most derived class (MDC) might live in a vftable in a virtual base. - There are four different representations of member pointer: single inheritance, multiple inheritance, virtual inheritance and the "most general" representation. - Bases might have a *more* general representation than classes which derived from them, a most surprising result. We believed that we could treat all member pointers as-if they were a degenerate case of the multiple inheritance model. This fell apart once we realized that implementing standard member pointers using this ABI requires referencing members with a non-zero vbindex. On a bright note, all but the virtual inheritance model operate rather similarly. The virtual inheritance member pointer representation awkwardly requires a virtual base adjustment in order to refer to entities in the MDC. However, the first virtual base might be quite far from the start of the virtual base. This means that we must add a negative non-virtual displacement. However, things get even more complicated. The most general representation interprets vbindex zero differently from the virtual inheritance model: it doesn't reference the vbtable at all. It turns out that this complexity can increase for quite some time: consider a derived to base conversion from the most general model to the multiple inheritance model... To manage this complexity we introduce a concept of "normalized" member pointer which allows us to treat all three models as the most general model. Then we try to figure out how to map this generalized member pointer onto the destination member pointer model. I've done my best to furnish the code with comments explaining why each adjustment is performed. This fixes PR23878. llvm-svn: 240384
* Revert r240270 ("Fixed/added namespace ending comments using clang-tidy").Alexander Kornienko2015-06-2221-41/+41
| | | | llvm-svn: 240353
* [modules] Include merged definition information in AST dumps.Richard Smith2015-06-221-0/+4
| | | | llvm-svn: 240313
* Fixed/added namespace ending comments using clang-tidy. NFCAlexander Kornienko2015-06-2221-41/+41
| | | | | | | | | | | | The patch is generated using this command: $ tools/extra/clang-tidy/tool/run-clang-tidy.py -fix \ -checks=-*,llvm-namespace-comment -header-filter='llvm/.*|clang/.*' \ work/llvm/tools/clang To reduce churn, not touching namespaces spanning less than 10 lines. llvm-svn: 240270
* Introduce a PCHContainerOperations interface (NFC).Adrian Prantl2015-06-201-0/+1
| | | | | | | | | | | | | | | | A PCHContainerOperations abstract interface provides operations for creating and unwrapping containers for serialized ASTs (precompiled headers and clang modules). The default implementation is RawPCHContainerOperations, which uses a flat file for the output. The main application for this interface will be an ObjectFilePCHContainerOperations implementation that uses LLVM to wrap the module in an ELF/Mach-O/COFF container to store debug info alongside the AST. rdar://problem/20091852 llvm-svn: 240225
* Suppress bogus gcc -Wreturn-type warnings.Nico Weber2015-06-201-0/+1
| | | | llvm-svn: 240199
* Code completion for nullability type specifiers.Douglas Gregor2015-06-191-14/+2
| | | | | | Another part of rdar://problem/18868820. llvm-svn: 240159
* Implement the 'null_resettable' attribute for Objective-C properties.Douglas Gregor2015-06-191-2/+8
| | | | | | | | 'null_resettable' properties are those whose getters return nonnull but whose setters take nil, to "reset" the property to some default. Implements rdar://problem/19051334. llvm-svn: 240155
* Extend type nullability qualifiers for Objective-C.Douglas Gregor2015-06-193-14/+75
| | | | | | | | | | | | | | | Introduce context-sensitive, non-underscored nullability specifiers (nonnull, nullable, null_unspecified) for Objective-C method return types, method parameter types, and properties. Introduce Objective-C-specific semantics, including computation of the nullability of the result of a message send, merging of nullability information from the @interface of a class into its @implementation, etc . This is the Objective-C part of rdar://problem/18868820. llvm-svn: 240154
* Introduce type nullability specifiers for C/C++.Douglas Gregor2015-06-192-1/+187
| | | | | | | | | | | | | | | | | | | | | | | | | Introduces the type specifiers __nonnull, __nullable, and __null_unspecified that describe the nullability of the pointer type to which the specifier appertains. Nullability type specifiers improve on the existing nonnull attributes in a few ways: - They apply to types, so one can represent a pointer to a non-null pointer, use them in function pointer types, etc. - As type specifiers, they are syntactically more lightweight than __attribute__s or [[attribute]]s. - They can express both the notion of 'should never be null' and also 'it makes sense for this to be null', and therefore can more easily catch errors of omission where one forgot to annotate the nullability of a particular pointer (this will come in a subsequent patch). Nullability type specifiers are maintained as type sugar, and therefore have no effect on mangling, encoding, overloading, etc. Nonetheless, they will be used for warnings about, e.g., passing 'null' to a method that does not accept it. This is the C/C++ part of rdar://problem/18868820. llvm-svn: 240146
* [ASan] Initial support for Kernel AddressSanitizerAlexander Potapenko2015-06-191-1/+2
| | | | | | | | | This patch adds initial support for the -fsanitize=kernel-address flag to Clang. Right now it's quite restricted: only out-of-line instrumentation is supported, globals are not instrumented, some GCC kasan flags are not supported. Using this patch I am able to build and boot the KASan tree with LLVMLinux patches from github.com/ramosian-glider/kasan/tree/kasan_llvmlinux. To disable KASan instrumentation for a certain function attribute((no_sanitize("kernel-address"))) can be used. llvm-svn: 240131
* CFI: Implement bitset emission for the Microsoft ABI.Peter Collingbourne2015-06-192-3/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Clang's control flow integrity implementation works by conceptually attaching "tags" (in the form of bitset entries) to each virtual table, identifying the names of the classes that the virtual table is compatible with. Under the Itanium ABI, it is simple to assign tags to virtual tables; they are simply the address points, which are available via VTableLayout. Because any overridden methods receive an entry in the derived class's virtual table, a check for an overridden method call can always be done by checking the tag of whichever derived class overrode the method call. The Microsoft ABI is a little different, as it does not directly use address points, and overrides in a derived class do not cause new virtual table entries to be added to the derived class; instead, the slot in the base class is reused, and the compiler needs to adjust the this pointer at the call site to (generally) the base class that initially defined the method. After the this pointer has been adjusted, we cannot check for the derived class's tag, as the virtual table may not be compatible with the derived class. So we need to determine which base class we have been adjusted to. Specifically, at each call site, we use ASTRecordLayout to identify the most derived class whose virtual table is laid out at the "this" pointer offset we are using to make the call, and check the virtual table for that tag. Because address point information is unavailable, we "reconstruct" it as follows: any virtual tables we create for a non-derived class receive a tag for that class, and virtual tables for a base class inside a derived class receive a tag for the base class, together with tags for any derived classes which are laid out at the same position as the derived class (and therefore have compatible virtual tables). Differential Revision: http://reviews.llvm.org/D10520 llvm-svn: 240117
* Fix "the the" in comments/documentation/etc.Eric Christopher2015-06-191-1/+1
| | | | llvm-svn: 240110
* [OPENMP] Support for '#pragma omp taskgroup' directive.Alexey Bataev2015-06-183-1/+31
| | | | | | | | | | | | | Added parsing, sema analysis and codegen for '#pragma omp taskgroup' directive (OpenMP 4.0). The code for directive is generated the following way: #pragma omp taskgroup <body> void __kmpc_taskgroup(<loc>, thread_id); <body> void __kmpc_end_taskgroup(<loc>, thread_id); llvm-svn: 240011
* [modules] Improve diagnostic for a template-id that's invalid because a defaultRichard Smith2015-06-171-0/+5
| | | | | | argument is not visible. llvm-svn: 239934
* Honor the objc_runtime_name attribute when encoding class/protocol names.Douglas Gregor2015-06-161-6/+5
| | | | | | | | While the rest of the Objective-C metadata seems to honor objc_runtime_name, the encoding strings produced by, e.g., @encode and property meta, were not. Fixes rdar://problem/21408305. llvm-svn: 239852
* [OPENMP] Remove last iteration separation for loop-based constructs.Alexey Bataev2015-06-161-5/+5
| | | | | | Previously the last iteration for simd loop-based OpenMP constructs were generated as a separate code. This feature is not required and codegen is simplified. llvm-svn: 239810
* Wrap to 80 columns. No behavior change.Nico Weber2015-06-121-2/+3
| | | | llvm-svn: 239591
OpenPOWER on IntegriCloud