aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/Sema.cpp
AgeCommit message (Collapse)AuthorFilesLines
2016-06-09[Temporary] Add an ExprWithCleanups for each C++ MaterializeTemporaryExpr.Tim Shen1-2/+3
These ExprWithCleanups are added for holding a RunCleanupsScope not for destructor calls; rather, they are for lifetime marks. This requires ExprWithCleanups to keep a bit to indicate whether it have cleanups with side effects (e.g. dtor calls). Differential Revision: http://reviews.llvm.org/D20498 llvm-svn: 272296
2016-05-26Produce better pretty stack traces from crashes in template instantiation: addRichard Smith1-4/+4
pretty stack trace entries for all cases where we instantiate the definition of something, and include the fully-qualified name with template arguments in the name of the instantiated entity. llvm-svn: 270904
2016-05-19Make Sema::getPrintingPolicy less ridiculously expensive. This used to performRichard Smith1-4/+5
an identifier table lookup, *and* copy the LangOptions (including various std::vector<std::string>s). Twice. We call this function once each time we start parsing a declaration specifier sequence, and once for each call to Sema::Diag. This reduces the compile time for a sample .c file from the linux kernel by 20%. llvm-svn: 270009
2016-05-17[OPENMP] Pass scalar firstprivate vars by value.Alexey Bataev1-1/+2
For better performance and to unify code with offloading part we pass scalar firstprivate values by value, instead of by reference. It will remove some extra copying operations. llvm-svn: 269751
2016-05-16[OpenCL] Add supported OpenCL extensions to target info.Yaxun Liu1-1/+7
Add supported OpenCL extensions to target info. It serves as default values to save the users of the burden setting each supported extensions and optional core features in command line. Re-commit after fixing build error due to missing override attribute. Differential Revision: http://reviews.llvm.org/D19484 llvm-svn: 269670
2016-05-13Revert "[OpenCL] Add supported OpenCL extensions to target info."Yaxun Liu1-7/+1
Revert r269431 due to build failure caused by warning msg: llvm/tools/clang/lib/Basic/Targets.cpp:2090:9: error: 'setSupportedOpenCLOpts' overrides a member function but is not marked 'override' [-Werror,-Winconsistent-missing-override] void setSupportedOpenCLOpts() { llvm-svn: 269435
2016-05-13[OpenCL] Add supported OpenCL extensions to target info.Yaxun Liu1-1/+7
Add supported OpenCL extensions to target info. It serves as default values to save the users of the burden setting each supported extensions and optional core features in command line. Differential Revision: http://reviews.llvm.org/D19484 llvm-svn: 269431
2016-04-29Method Pool in modules: we make sure that if a module contains an entry forManman Ren1-0/+1
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[MS] Make #pragma pack use PragmaStack<> class.Denis Zobnin1-4/+4
Make implementation of #pragma pack consistent with other "stack" pragmas. Use PragmaStack<> class instead of old representation of internal stack. Don't change compiler's behavior. TODO: 1. Introduce diagnostics on popping named slots from pragma stacks. Reviewer: rnk Differential revision: http://reviews.llvm.org/D19727 llvm-svn: 268085
2016-04-29Recommit "[MS] Improved implementation of stack pragmas (vtordisp, *_seg)"Denis Zobnin1-1/+1
Slightly updated version, double-checked build and tests. Improve implementation of MS pragmas that use stack + compatibility fixes. This patch: 1. Changes implementation of #pragma vtordisp to use PragmaStack class that other stack pragmas use; 2. Fixes "#pragma vtordisp()" behavior - it shouldn't affect the stack; 3. Supports "save-restore" of pragma stacks on enter / exit a C++ method body, as MSVC does. TODO: 1. Change implementation of #pragma pack to use the same approach; 2. Introduce diagnostics on popping named stack slots, as MSVC does. Reviewers: rnk, thakis Differential revision: http://reviews.llvm.org/D19361 llvm-svn: 268029
2016-04-28Revert "[MS] Improved implementation of MS stack pragmas (vtordisp, *_seg)"Denis Zobnin1-1/+1
This reverts commit r267866. llvm-svn: 267870
2016-04-28[MS] Improved implementation of MS stack pragmas (vtordisp, *_seg)Denis Zobnin1-1/+1
Rework implementation of several MS pragmas that use internal stack: vtordisp, {bss|code|const|data}_seg. This patch: 1. Makes #pragma vtordisp use PragmaStack class as *_seg pragmas do; 2. Fixes "#pragma vtordisp()" behavior: it shouldn't affect stack; 3. Saves/restores the stacks on enter/exit a C++ method body. llvm-svn: 267866
2016-04-08[OpenCL] Complete image types support.Alexey Bader1-14/+0
I. Current implementation of images is not conformant to spec in the following points: 1. It makes no distinction with respect to access qualifiers and therefore allows to use images with different access type interchangeably. The following code would compile just fine: void write_image(write_only image2d_t img); kernel void foo(read_only image2d_t img) { write_image(img); } // Accepted code which is disallowed according to s6.13.14. 2. It discards access qualifier on generated code, which leads to generated code for the above example: call void @write_image(%opencl.image2d_t* %img); In OpenCL2.0 however we can have different calls into write_image with read_only and wite_only images. Also generally following compiler steps have no easy way to take different path depending on the image access: linking to the right implementation of image types, performing IR opts and backend codegen differently. 3. Image types are language keywords and can't be redeclared s6.1.9, which can happen currently as they are just typedef names. 4. Default access qualifier read_only is to be added if not provided explicitly. II. This patch corrects the above points as follows: 1. All images are encapsulated into a separate .def file that is inserted in different points where image handling is required. This avoid a lot of code repetition as all images are handled the same way in the code with no distinction of their exact type. 2. The Cartesian product of image types and image access qualifiers is added to the builtin types. This simplifies a lot handling of access type mismatch as no operations are allowed by default on distinct Builtin types. Also spec intended access qualifier as special type qualifier that are combined with an image type to form a distinct type (see statement above - images can't be created w/o access qualifiers). 3. Improves testing of images in Clang. Author: Anastasia Stulova Reviewers: bader, mgrang. Subscribers: pxli168, pekka.jaaskelainen, yaxunl. Differential Revision: http://reviews.llvm.org/D17821 llvm-svn: 265783
2016-03-25Store list of undefined-but-used objects in a deterministic order to fixRichard Smith1-27/+12
non-deterministic diagnostics (and non-deterministic PCH files). Check these when building a module rather than serializing it; it's not reasonable for a module's use to be satisfied by a definition in the user of the module. llvm-svn: 264466
2016-02-04Fix predefine for __NSConstantString struct typeBen Langmuir1-4/+5
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-03Reapply r259624, it is likely not the commit causing the bot failures.Quentin Colombet1-0/+4
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-03Revert r259624 - Make CF constant string decl visible to name lookup to fix ↵Quentin Colombet1-4/+0
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-03Make CF constant string decl visible to name lookup to fix module errorsBen Langmuir1-0/+4
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
2015-12-14[Sema] Make nullness warnings appear in C++.George Burgess IV1-12/+15
Given the following code: int *_Nullable ptr; int *_Nonnull nn = ptr; ...In C, clang will warn you about `nn = ptr`, because you're assigning a nonnull pointer to a nullable pointer. In C++, clang issues no such warning. This patch helps ensure that clang doesn't ever miss an opportunity to complain about C++ code. N.B. Though this patch has a differential revision link, the actual review took place over email. Differential Revision: http://reviews.llvm.org/D14938 llvm-svn: 255556
2015-11-15[Sema] Use getLangOpts in Sema instead of Preprocessor. Call getTargetInfo ↵Craig Topper1-7/+6
on the AST context instead of Preprocessor. NFC llvm-svn: 253175
2015-11-15Use Sema::getLocForEndOfToken instead of Preprocessor::getLocForEndOfToken. NFCCraig Topper1-1/+1
llvm-svn: 253155
2015-10-28Refine r251469 to give better (and more localizable) diagnosticsJohn McCall1-2/+2
for all the reasons that ARC makes things implicitly unavailable. llvm-svn: 251496
2015-10-20Roll-back r250822.Angel Garcia Gomez1-1/+1
Summary: It breaks the build for the ASTMatchers Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D13893 llvm-svn: 250827
2015-10-20Apply modernize-use-default to clang.Angel Garcia Gomez1-1/+1
Summary: Replace empty bodies of default constructors and destructors with '= default'. Reviewers: bkramer, klimek Subscribers: klimek, alexfh, cfe-commits Differential Revision: http://reviews.llvm.org/D13890 llvm-svn: 250822
2015-09-18Fix for assertion fail for pragma weak on typedef.Alexander Musman1-2/+9
Example: typedef int __td3; #pragma weak td3 = __td3 Differential Revision: http://reviews.llvm.org/D12904 llvm-svn: 247975
2015-09-17Support __builtin_ms_va_list.Charles Davis1-0/+6
Summary: This change adds support for `__builtin_ms_va_list`, a GCC extension for variadic `ms_abi` functions. The existing `__builtin_va_list` support is inadequate for this because `va_list` is defined differently in the Win64 ABI vs. the System V/AMD64 ABI. Depends on D1622. Reviewers: rsmith, rnk, rjmccall CC: cfe-commits Differential Revision: http://reviews.llvm.org/D1623 llvm-svn: 247941
2015-09-15[OpenCL] Add new types for OpenCL 2.0.Alexey Bader1-0/+12
Patch by Pedro Ferreira. Reviewers: pekka.jaaskelainen Differential Revision: http://reviews.llvm.org/D12855 llvm-svn: 247676
2015-08-18Initialize the AST consumer as soon as we have both an ASTConsumer and anRichard Smith1-4/+0
ASTContext. Fixes some cases where we could previously initialize the AST consumer more than once. llvm-svn: 245346
2015-08-15Delay emitting members of dllexport classes until the class is fully parsed ↵Hans Wennborg1-0/+3
(PR23542) This enables Clang to correctly handle code such as: struct __declspec(dllexport) S { int x = 42; }; where it would otherwise error due to trying to generate the default constructor before the in-class initializer for x has been parsed. Differential Revision: http://reviews.llvm.org/D11850 llvm-svn: 245139
2015-07-22[modules] Stop performing PCM lookups for all identifiers when building with ↵Richard Smith1-0/+3
C++ modules. Instead, serialize a list of interesting identifiers and mark those ones out of date on module import. Avoiding the identifier lookups here gives a 20-30% speedup in builds with large numbers of modules. No functionality change intended. llvm-svn: 242868
2015-07-19Remove two unused includes.Nico Weber1-1/+0
llvm-svn: 242648
2015-06-26[ObjC] Add NSValue support for objc_boxed_expressionsAlex Denisov1-1/+2
Patch extends ObjCBoxedExpr to accept records (structs and unions): typedef struct __attribute__((objc_boxable)) _Color { int r, g, b; } Color; Color color; NSValue *boxedColor = @(color); // [NSValue valueWithBytes:&color objCType:@encode(Color)]; llvm-svn: 240761
2015-06-19Diagnose unsafe uses of nil and __nonnull pointers.Douglas Gregor1-0/+13
This generalizes the checking of null arguments to also work with values of pointer-to-function, reference-to-function, and block pointer type, using the nullability information within the underling function prototype to extend non-null checking, and diagnoses returns of 'nil' within a function with a __nonnull return type. Note that we don't warn about nil returns from Objective-C methods, because it's common for Objective-C methods to mimic the nil-swallowing behavior of the receiver by checking ostensibly non-null parameters and returning nil from otherwise non-null methods in that case. It also diagnoses (via a separate flag) conversions from nullable to nonnull pointers. It's a separate flag because this warning can be noisy. llvm-svn: 240153
2015-06-18Wrap to 80 columns, no behavior change.Nico Weber1-4/+4
llvm-svn: 240041
2015-06-12push_back() loop -> append() for random access iterators.Benjamin Kramer1-5/+1
append will resize the vector to the optimal size. No functional change intended. llvm-svn: 239607
2015-05-18Detect uses of mismatching forms of 'new' and 'delete'Ismail Pazarbasi1-0/+19
Emit warning when operand to `delete` is allocated with `new[]` or operand to `delete[]` is allocated with `new`. rev 2 update: `getNewExprFromInitListOrExpr` should return `dyn_cast_or_null` instead of `dyn_cast`, since `E` might be null. Reviewers: rtrieu, jordan_rose, rsmith Subscribers: majnemer, cfe-commits Differential Revision: http://reviews.llvm.org/D4661 llvm-svn: 237608
2015-05-15[modules] Add local submodule visibility support for declarations.Richard Smith1-0/+1
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-14Revert "Detect uses of mismatching forms of 'new' and 'delete'"Diego Novillo1-19/+0
This reverts commit 742dc9b6c9686ab52860b7da39c3a126d8a97fbc. This is generating multiple segfaults in our internal builds. Test case coming up shortly. llvm-svn: 237391
2015-05-14Detect uses of mismatching forms of 'new' and 'delete'Ismail Pazarbasi1-0/+19
Emit warning when operand to `delete` is allocated with `new[]` or operand to `delete[]` is allocated with `new`. Reviewers: rtrieu, jordan_rose, rsmith Subscribers: majnemer, cfe-commits Differential Revision: http://reviews.llvm.org/D4661 llvm-svn: 237368
2015-03-26[Modules] Make "#pragma weak" undeclared identifiers be trackedChandler Carruth1-16/+7
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-18OpenCL: CL2.0 atomic typesAnastasia Stulova1-0/+23
OpenCL C Spec v2.0 Section 6.13.11 - Made c11 _Atomic being not accepted for OpenCL - Implemented CL2.0 atomics by aliasing them to the corresponding c11 atomic types using implicit typedef - Added diagnostics for atomics Khronos extension enabling llvm-svn: 232631
2015-03-11Reverted OpenCL2.0 atomic type commits r231932, r231935Anastasia Stulova1-23/+0
(caused undesirable update of -std flag to use _Atomic) llvm-svn: 231942
2015-03-11OpenCL: CL2.0 atomic typesAnastasia Stulova1-0/+23
OpenCL C Spec v2.0 Section 6.13.11 - Made c11 _Atomic being accepted only for c11 compilations - Implemented CL2.0 atomics by aliasing them to the corresponding c11 atomic types using implicit typedef - Added diagnostics for atomics Khronos extension enabling llvm-svn: 231932
2015-02-28Rework our handling of key functions. We used to track a complete list of allRichard Smith1-16/+2
dynamic classes in the translation unit and check whether each one's key function is defined when we got to the end of the TU (and when we got to the end of each module). This is really terrible for modules performance, since it causes unnecessary deserialization of every dynamic class in every compilation. We now use a much simpler (and, in a modules build, vastly more efficient) system: when we see an out-of-line definition of a virtual function, we check whether that function was in fact its class's key function. (If so, we need to emit the vtable.) llvm-svn: 230830
2015-02-18Sema: size_t is available in C when -fms-compatibility is enabledDavid Majnemer1-2/+3
llvm-svn: 229616
2015-02-17Sema: Replace some push_backs of expensive to move objects with emplace_back.Benjamin Kramer1-3/+1
NFC. llvm-svn: 229557
2015-02-03Thread Safety Analysis: add support for before/after annotations on mutexes.DeLesley Hutchins1-1/+3
These checks detect potential deadlocks caused by inconsistent lock ordering. The checks are implemented under the -Wthread-safety-beta flag. This patch also replaces calls to getAttrs() with calls to attrs() throughout ThreadSafety.cpp, which fixes the earlier issue that cause assert failures. llvm-svn: 228051
2015-02-03Revert "Thread Safety Analysis: add support for before/after annotations on ↵Reid Kleckner1-3/+1
mutexes." This reverts r227997, as well as r228009. It does not pass check-clang for me locally on Linux. llvm-svn: 228020
2015-02-03Thread Safety Analysis: add support for before/after annotations on mutexes.DeLesley Hutchins1-1/+3
These checks detect potential deadlocks caused by inconsistent lock ordering. The checks are implemented under the -Wthread-safety-beta flag. llvm-svn: 227997
2015-01-26Don't let virtual calls and dynamic casts call Sema::MarkVTableUsed().Nico Weber1-12/+0
clang currently calls MarkVTableUsed() for classes that get their virtual methods called or that participate in a dynamic_cast. This is unnecessary, since CodeGen only emits vtables when it generates constructor, destructor, and vtt code. (*) Note that Sema::MarkVTableUsed() doesn't cause the emission of a vtable. Its main user-visible effect is that it instantiates virtual member functions of template classes, to make sure that if codegen decides to write a vtable all the entries in the vtable are defined. While this shouldn't change the behavior of codegen (other than being faster), it does make clang more permissive: virtual methods of templates (in particular destructors) end up being instantiated less often. In particular, classes that have members that are smart pointers to incomplete types will now get their implicit virtual destructor instantiated less frequently. For example, this used to not compile but does now compile: template <typename T> struct OwnPtr { ~OwnPtr() { static_assert((sizeof(T) > 0), "TypeMustBeComplete"); } }; class ScriptLoader; struct Base { virtual ~Base(); }; struct Sub : public Base { virtual void someFun() const {} OwnPtr<ScriptLoader> m_loader; }; void f(Sub *s) { s->someFun(); } The more permissive behavior matches both gcc (where this is not often observable, since in practice most things with virtual methods have a key function, and Sema::DefineUsedVTables() skips vtables for classes with key functions) and cl (which is my motivation for this change) – this fixes PR20337. See this issue and the review thread for some discussions about optimizations. This is similar to r213109 in spirit. r225761 was a prerequisite for this change. Various tests relied on "a->f()" marking a's vtable as used (in the sema sense), switch these to just construct a on the stack. This forces instantiation of the implicit constructor, which will mark the vtable as used. (*) The exception is -fapple-kext mode: In this mode, qualified calls to virtual functions (`a->Base::f()`) still go through the vtable, and since the vtable pointer off this doesn't point to Base's vtable, this needs to reference Base's vtable directly. To keep this working, keep referencing the vtable for virtual calls in apple kext mode. llvm-svn: 227073