summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaExpr.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* [Sema] Fix PR27122: ICE with enable_if+ill-formed call.George Burgess IV2016-03-311-1/+16
| | | | | | | | | | | | | | | | | | | | | | | In some cases, when we encounter a direct function call with an incorrect number of arguments, we'll emit a diagnostic, and pretend that the call to the function was valid. For example, in C: int foo(); int a = foo(1); Prior to this patch, we'd get an ICE if foo had an enable_if attribute, because CheckEnableIf assumes that the number of arguments it gets passed is valid for the function it's passed. Now, we check that the number of args looks valid prior to checking enable_if conditions. This fix was not done inside of CheckEnableIf because the problem presently can only occur in one caller of CheckEnableIf (ActOnCallExpr). Additionally, checking inside of CheckEnableIf would make us emit multiple diagnostics for the same error (one "enable_if failed", one "you gave this function the wrong number of arguments"), which seems worse than just complaining about the latter. llvm-svn: 264975
* Don't warn on "use" of undefined inline function that isn't actually an ODRRichard Smith2016-03-251-15/+16
| | | | | | | | use. In order for this to fire, the function needed to be a templated function marked 'constexpr' and declared but not defined. This weird pattern appears in libstdc++'s alloc_traits.h. llvm-svn: 264471
* [NFC] Delete an unused function parameter from a static function Faisal Vali2016-03-231-3/+2
| | | | llvm-svn: 264170
* [Cxx1z] Implement Lambda Capture of *this by Value as [=,*this] (P0018R3)Faisal Vali2016-03-211-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Implement lambda capture of *this by copy. For e.g.: struct A { int d = 10; auto foo() { return [*this] (auto a) mutable { d+=a; return d; }; } }; auto L = A{}.foo(); // A{}'s lifetime is gone. // Below is still ok, because *this was captured by value. assert(L(10) == 20); assert(L(100) == 120); If the capture was implicit, or [this] (i.e. *this was captured by reference), this code would be otherwise undefined. Implementation Strategy: - amend the parser to accept *this in the lambda introducer - add a new king of capture LCK_StarThis - teach Sema::CheckCXXThisCapture to handle by copy captures of the enclosing object (i.e. *this) - when CheckCXXThisCapture does capture by copy, the corresponding initializer expression for the closure's data member direct-initializes it thus making a copy of '*this'. - in codegen, when assigning to CXXThisValue, if *this was captured by copy, make sure it points to the corresponding field member, and not, unlike when captured by reference, what the field member points to. - mark feature as implemented in svn Much gratitude to Richard Smith for his carefully illuminating reviews! llvm-svn: 263921
* Add TreatUnavailableAsInvalid for the verification-only mode in InitListChecker.Manman Ren2016-03-101-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Given the following test case: typedef struct { const char *name; id field; } Test9; extern void doSomething(Test9 arg); void test9() { Test9 foo2 = {0, 0}; doSomething(foo2); } With a release compiler, we don't emit any message and silently ignore the variable "foo2". With an assert compiler, we get an assertion failure. The root cause ————————————— Back in r140457 we gave InitListChecker a verification-only mode, and will use CanUseDecl instead of DiagnoseUseOfDecl for verification-only mode. These two functions handle unavailable issues differently: In Sema::CanUseDecl, we say the decl is invalid when the Decl is unavailable and the current context is available. In Sema::DiagnoseUseOfDecl, we say the decl is usable by ignoring the return code of DiagnoseAvailabilityOfDecl So with an assert build, we will hit an assertion in diagnoseListInit assert(DiagnoseInitList.HadError() && "Inconsistent init list check result."); The fix ------------------- If we follow what is implemented in CanUseDecl and treat Decls with unavailable issues as invalid, the variable decl of “foo2” will be marked as invalid. Since unavailable checking is processed in delayed diagnostics (r197627), we will silently ignore the diagnostics when we find out that the variable decl is invalid. We add a flag "TreatUnavailableAsInvalid" for the verification-only mode. For overload resolution, we want to say decls with unavailable issues are invalid; but for everything else, we should say they are valid and emit diagnostics. Depending on the value of the flag, CanUseDecl can return different values for unavailable issues. rdar://23557300 Differential Revision: http://reviews.llvm.org/D15314 llvm-svn: 263149
* Implement support for [[maybe_unused]] in C++1z that is based off existing ↵Aaron Ballman2016-03-091-4/+8
| | | | | | support for unused, and treat it as an extension pre-C++1z. This also means extending the existing unused attribute so that it can be placed on an enum and enumerator, in addition to the other subjects. llvm-svn: 263025
* Sema: Treat 'strict' availability flag like unavailableDuncan P. N. Exon Smith2016-03-081-9/+1
| | | | | | | | | | | | | | | | | | | | | | This is a follow-up to r261512, which made the 'strict' availability attribute flag behave like 'unavailable'. However, that fix was insufficient. The following case would (erroneously) error when the deployment target was older than 10.9: struct __attribute__((availability(macosx,strict,introduced=10.9))) A; __attribute__((availability(macosx,strict,introduced=10.9))) void f(A*); The use of A* in the argument list for f is valid here, since f and A have the same availability. The fix is to return AR_Unavailable from DeclBase::getAvailability instead of AR_NotYetIntroduced. This also reverts the special handling added in r261163, instead relying on the well-tested logic for AR_Unavailable. rdar://problem/23791325 llvm-svn: 262915
* Add null check to diagnostic path for lambda captures.Richard Trieu2016-03-051-2/+3
| | | | | | | | Previously, the failed capture of a variable in nested lambdas may crash when the lambda pointer is null. Only give the note if a location can be retreived from the lambda pointer. llvm-svn: 262765
* [OPENMP 4.0] Codegen for 'declare reduction' construct.Alexey Bataev2016-03-041-0/+1
| | | | | | | Emit function for 'combiner' part of 'declare reduction' construct and 'initialilzer' part, if any. llvm-svn: 262699
* [OPENMP 4.0] Initial support for 'omp declare reduction' construct.Alexey Bataev2016-03-031-0/+13
| | | | | | | | | | | | | | | | | Add parsing, sema analysis and serialization/deserialization for 'declare reduction' construct. User-defined reductions are defined as #pragma omp declare reduction( reduction-identifier : typename-list : combiner ) [initializer ( initializer-expr )] These custom reductions may be used in 'reduction' clauses of OpenMP constructs. The combiner specifies how partial results can be combined into a single value. The combiner can use the special variable identifiers omp_in and omp_out that are of the type of the variables being reduced with this reduction-identifier. Each of them will denote one of the values to be combined before executing the combiner. It is assumed that the special omp_out identifier will refer to the storage that holds the resulting combined value after executing the combiner. As the initializer-expr value of a user-defined reduction is not known a priori the initializer-clause can be used to specify one. Then the contents of the initializer-clause will be used as the initializer for private copies of reduction list items where the omp_priv identifier will refer to the storage to be initialized. The special identifier omp_orig can also appear in the initializer-clause and it will refer to the storage of the original variable to be reduced. Differential Revision: http://reviews.llvm.org/D11182 llvm-svn: 262582
* [OpenCL] Add Sema checks for OpenCL 2.0 blockXiuli Pan2016-02-241-0/+35
| | | | | | | | | | | | | | Summary: Add Sema checks for opencl 2.0 new features: Block. This patch is partitioned from http://reviews.llvm.org/D16047 Reviewers: Anastasia Subscribers: pekka.jaaskelainen, cfe-commits Differential Revision: http://reviews.llvm.org/D17436 llvm-svn: 261719
* Amends r252104 to evaluate the controlling expression in an unevaluated ↵Aaron Ballman2016-02-231-4/+7
| | | | | | context. This eliminates false-positive diagnostics about null pointer dereferences (etc) in the controlling expression. llvm-svn: 261669
* Addressing review comments for r261163.Manman Ren2016-02-221-4/+3
| | | | | | | | | Use "strict" instead of "nopartial". Also make strictly not-introduced share the same diagnostics as Obsolete and Unavailable. rdar://23791325 llvm-svn: 261512
* Fix my typo from r261278Richard Trieu2016-02-191-1/+1
| | | | llvm-svn: 261285
* Add -Wcomma warning to Clang.Richard Trieu2016-02-181-0/+64
| | | | | | | | | | | -Wcomma will detect and warn on most uses of the builtin comma operator. It currently whitelists the first and third statements of the for-loop. For other cases, the warning can be silenced by casting the first operand of the comma operator to void. Differential Revision: http://reviews.llvm.org/D3976 llvm-svn: 261278
* Add 'nopartial' qualifier for availability attributes.Manman Ren2016-02-171-2/+11
| | | | | | | | | | | | | | | | | | | | | | An optional nopartial can be placed after the platform name. int bar() __attribute__((availability(macosx,nopartial,introduced=10.12)) When deploying back to a platform version prior to when the declaration was introduced, with 'nopartial', Clang emits an error specifying that the function is not introduced yet; without 'nopartial', the behavior stays the same: the declaration is `weakly linked`. A member is added to the end of AttributeList to save the location of the 'nopartial' keyword. A bool member is added to AvailabilityAttr. The diagnostics for 'nopartial' not-yet-introduced is handled in the same way as we handle unavailable cases. Reviewed by Doug Gregor and Jordan Rose. rdar://23791325 llvm-svn: 261163
* Correct more typos in conditional expressionsDavid Majnemer2016-02-171-1/+16
| | | | | | | We didn't correctly handle some edge cases, causing us to bail out before correcting all the typos. llvm-svn: 261109
* [OpenCL] Added half type literal with suffix h.Anastasia Stulova2016-02-171-1/+8
| | | | | | | | | | | | | OpenCL Extension v1.2 s9.5 allows half precision floating point type literals with suffices h or H when cl_khr_fp16 is enabled. Example: half x = 1.0h; Patch by Liu Yaxun (Sam)! Differential Revision: http://reviews.llvm.org/D16865 llvm-svn: 261084
* [Sema] More changes to fix Objective-C fallout from r249995.Bob Wilson2016-02-131-5/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a follow-up to PR26085. That was fixed in r257710 but the testcase there was incomplete. There is a related issue where the overload resolution for Objective-C incorrectly picks a method that is not valid without a bridge cast. The call to Sema::CheckSingleAssignmentConstraints that was added to SemaOverload.cpp's IsStandardConversion() function does not catch that case and reports that the method is Compatible even when it is not. The root cause here is that various Objective-C-related functions in Sema do not consistently return a value to indicate whether there was an error. This was fine in the past because they would report diagnostics when needed, but r257710 changed them to suppress reporting diagnostics when checking during overload resolution. This patch adds a new ACR_error result to the ARCConversionResult enum and updates Sema::CheckObjCARCConversion to return that value when there is an error. Most of the calls to that function do not check the return value, so adding this new result does not affect them. The one exception is in SemaCast.cpp where it specifically checks for ACR_unbridged, so that is also OK. The call in Sema::CheckSingleAssignmentConstraints can then check for an ACR_okay result and identify assignments as Incompatible. To preserve the existing behavior, it only changes the return value to Incompatible when the new Diagnose argument (from r257710) is false. Similarly, the CheckObjCBridgeRelatedConversions and ConversionToObjCStringLiteralCheck need to identify when an assignment is Incompatible. Those functions already return appropriate values but they need some fixes related to the new Diagnose argument. llvm-svn: 260787
* [OPENMP] Rename OMPCapturedFieldDecl to OMPCapturedExprDecl, NFC.Alexey Bataev2016-02-111-1/+1
| | | | | | | | OMPCapturedExprDecl allows caopturing not only of fielddecls, but also other expressions. It also allows to simplify codegen for several clauses. llvm-svn: 260492
* [OPENMP 4.5] Ccapture/codegen of private non-static data members.Alexey Bataev2016-02-081-0/+1
| | | | | | | OpenMP 4.5 introduces privatization of non-static data members of current class in non-static member functions. To correctly handle such kind of privatization a new (pseudo)declaration VarDecl-based node is added. It allows to reuse an existing code for capturing variables in Lambdas/Block/Captured blocks of code for correct privatization and codegen. llvm-svn: 260077
* [OPENMP 4.0] Fixed support of array sections/array subscripts.Alexey Bataev2016-02-041-0/+13
| | | | | | Codegen for array sections/array subscripts worked only for expressions with arrays as base. Patch fixes codegen for bases with pointer/reference types. llvm-svn: 259776
* [Sema debugger support] Require non-void types to be complete in ↵Douglas Gregor2016-02-031-0/+6
| | | | | | | | | | unknown-anytype casts. When performing a cast from an __unknown_anytype function call to a non-void type, we need to make sure that type is complete. Fixes rdar://problem/23959960. llvm-svn: 259681
* Allow capture typedefs/type aliases for VLAs in lambdas/captured statements ↵Alexey Bataev2016-01-251-4/+14
| | | | | | | | chain. Previous it was allowed to capture VLAs/types with arrays of runtime bounds only inside the first lambda/capture statement in stack. Patch allows to capture these typedefs implicitly in chains of lambdas/captured statements. llvm-svn: 258669
* Fix crash for typedefs for arrays of runtime bounds in Lambdas/Captured ↵Alexey Bataev2016-01-211-114/+137
| | | | | | Statements, used in sizeof() expression only. llvm-svn: 258396
* [OPENMP 4.5] Allow to use non-static data members in non-static member ↵Alexey Bataev2016-01-201-4/+4
| | | | | | | | functions in 'private' clause. OpenMP 4.5 allows to use non-static members of current class in non-static member functions in 'private' clause. Patch adds initial support for privatizing data members. llvm-svn: 258299
* [CUDA] Bail, rather than crash, on va_arg in device code.Justin Lebar2016-01-201-3/+11
| | | | | | | | | | Reviewers: tra Subscribers: echristo, jhen, cfe-commits Differential Revision: http://reviews.llvm.org/D16331 llvm-svn: 258264
* [X86] Support 'interrupt' attribute for x86Alexey Bataev2016-01-151-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This attribute may be attached to a function definition and instructs the backend to generate appropriate function entry/exit code so that it can be used directly as an interrupt handler. The IRET instruction, instead of the RET instruction, is used to return from interrupt or exception handlers. All registers, except for the EFLAGS register which is restored by the IRET instruction, are preserved by the compiler. Any interruptible-without-stack-switch code must be compiled with -mno-red-zone since interrupt handlers can and will, because of the hardware design, touch the red zone. interrupt handler must be declared with a mandatory pointer argument: struct interrupt_frame; __attribute__ ((interrupt)) void f (struct interrupt_frame *frame) { ... } and user must properly define the structure the pointer pointing to. exception handler: The exception handler is very similar to the interrupt handler with a different mandatory function signature: #ifdef __x86_64__ typedef unsigned long long int uword_t; #else typedef unsigned int uword_t; #endif struct interrupt_frame; __attribute__ ((interrupt)) void f (struct interrupt_frame *frame, uword_t error_code) { ... } and compiler pops the error code off stack before the IRET instruction. The exception handler should only be used for exceptions which push an error code and all other exceptions must use the interrupt handler. The system will crash if the wrong handler is used. Differential Revision: http://reviews.llvm.org/D15709 llvm-svn: 257867
* [Sema] Suppress diags in overload resolution.George Burgess IV2016-01-131-17/+22
| | | | | | | | | | We were emitting diagnostics from our shiny new C-only overload resolution mode. This patch attempts to silence all such diagnostics. This fixes PR26085. Differential Revision: http://reviews.llvm.org/D16159 llvm-svn: 257710
* [Bugfix] Fix ICE on constexpr vector splat.George Burgess IV2016-01-131-16/+38
| | | | | | | | | | | | | In {CG,}ExprConstant.cpp, we weren't treating vector splats properly. This patch makes us treat splats more properly. Additionally, this patch adds a new cast kind which allows a bool->int cast to result in -1 or 0, instead of 1 or 0 (for true and false, respectively), so we can sanely model OpenCL bool->int casts in the AST. Differential Revision: http://reviews.llvm.org/D14877 llvm-svn: 257559
* [OpenCL] Pipe type supportXiuli Pan2016-01-091-0/+1
| | | | | | | | | | | | | | | Summary: Support for OpenCL 2.0 pipe type. This is a bug-fix version for bader's patch reviews.llvm.org/D14441 Reviewers: pekka.jaaskelainen, Anastasia Subscribers: bader, Anastasia, cfe-commits Differential Revision: http://reviews.llvm.org/D15603 llvm-svn: 257254
* Properly track that a character literal is UTF-8, and pretty print the ↵Aaron Ballman2016-01-071-0/+2
| | | | | | prefix properly. llvm-svn: 257097
* [Sema] Teach overload resolution about unaddressable functions.George Burgess IV2016-01-071-3/+14
| | | | | | | | | | | | Given an expression like `(&Foo)();`, we perform overload resolution as if we are calling `Foo` directly. This causes problems if `Foo` is a function that can't have its address taken. This patch teaches overload resolution to ignore functions that can't have their address taken in such cases. Differential Revision: http://reviews.llvm.org/D15590 llvm-svn: 257016
* Properly bind up any cleanups in an ExprWithCleanups afterJohn McCall2016-01-061-6/+5
| | | | | | | | | | instantiating a default argument expression. This was previously just working implicitly by reinstantiating in the current context, but caching means that we weren't registering cleanups in subsequent uses. llvm-svn: 256996
* Only instantiate a default argument once.John McCall2016-01-061-1/+8
| | | | | | | | | | | | | | | | | | | By storing the instantiated expression back in the ParmVarDecl, we remove the last need for separately storing the sub-expression of a CXXDefaultArgExpr. This makes PCH/Modules merging quite simple: CXXDefaultArgExpr records are serialized as references to the ParmVarDecl, and we ignore redundant attempts to overwrite the instantiated expression. This has some extremely marginal impact on user-facing semantics. However, the major effect is that it avoids IRGen errors about conflicting definitions due to lambdas in the argument being instantiated multiple times while sharing the same mangling. It should also slightly improve memory usage and module file size. rdar://23810407 llvm-svn: 256983
* [TrailingObjects] Convert OffsetOfExpr.James Y Knight2015-12-291-1/+0
| | | | | | That necessitated moving the OffsetOfNode class out of OffsetOfExpr. llvm-svn: 256590
* fix typos; NFCSanjay Patel2015-12-291-2/+2
| | | | llvm-svn: 256576
* Teach typo correction to properly handle mapping declarations to theirRichard Smith2015-12-291-15/+14
| | | | | | | | | | underlying decls. Preserve the found declaration throughout, and only map to the underlying declaration when we want to check whether it's the right kind. This allows us to provide the right source location for the found declaration, and prepares for the possibility of underlying decls with a different name from the found decl. llvm-svn: 256575
* Replace isa+cast with dyn_cast and obey the no else after return rule.Yaron Keren2015-12-231-6/+2
| | | | llvm-svn: 256349
* [Sema] Use range-based for loops. NFCCraig Topper2015-12-211-56/+39
| | | | llvm-svn: 256135
* Split RequireCompleteType into a function that actually requires that the typeRichard Smith2015-12-181-3/+6
| | | | | | | | | | | | | | | | | | | is complete (with an error produced if not) and a function that merely queries whether the type is complete. Either way we'll trigger instantiation if necessary, but only the former will diagnose and recover from missing module imports. The intent of this change is to prevent a class of bugs where code would call RequireCompleteType(..., 0) and then ignore the result. With modules, we must check the return value and use it to determine whether the definition of the type is visible. This also fixes a debug info quality issue: calls to isCompleteType do not trigger the emission of debug information for a type in limited-debug-info mode. This allows us to avoid emitting debug information for type definitions in more cases where we believe it is safe to do so. llvm-svn: 256049
* Wire a SourceLocation into IsDerivedFrom and move the RequireCompleteType callRichard Smith2015-12-181-3/+4
| | | | | | | | for the derived class into it. This is mostly just a cleanup, but could in principle be a bugfix if there is some codepath that reaches here and didn't previously require a complete type (I couldn't find any such codepath, though). llvm-svn: 256037
* [Sema] Add -Wparentheses warnings for '^' in '|' expressions and '&' in '^' ↵Craig Topper2015-12-131-24/+19
| | | | | | expressions to compliment '&' in '|' that is already present. Matches gcc behavior. llvm-svn: 255450
* [Sema] Write some checks for groups of BinaryOperatorKinds in terms of the ↵Craig Topper2015-12-131-6/+4
| | | | | | predicates already available in BinaryOperator. NFC llvm-svn: 255449
* Minor formatting cleanup. NFCCraig Topper2015-12-121-1/+1
| | | | llvm-svn: 255428
* [Sema] Simplify a couple if statements. Explicitly check up front that only ↵Craig Topper2015-12-121-3/+3
| | | | | | one of the expressions is a comparision op. Then if we find that either is a bitwise op, we know it must be the other one. NFC llvm-svn: 255427
* [OpenCL 2.0] In OpenCL v2.0 s6.5 all pointers are implicitly in genericAnastasia Stulova2015-12-111-1/+2
| | | | | | | | | | | address space unless address space is explicitly specified. Correct the behavior of NULL constant detection - generic AS void pointer should be accepted as a valid NULL constant. http://reviews.llvm.org/D15293 llvm-svn: 255346
* Reverting r255337 as it seems to kill bots. Needs investigation.Anastasia Stulova2015-12-111-2/+1
| | | | llvm-svn: 255339
* [OpenCL 2.0] In OpenCL v2.0 s6.5 all pointers are implicitly in genericAnastasia Stulova2015-12-111-1/+2
| | | | | | | | | | | address space unless address space is explicitly specified. Correct the behavior of NULL constant detection - generic AS void pointer should be accepted as a valid NULL constant. http://reviews.llvm.org/D15293 llvm-svn: 255337
* [Sema] Use UnaryOperatorKind and BinaryOperatorKind in parameter lists ↵Craig Topper2015-12-101-13/+13
| | | | | | instead of just unsigned. Removes a few explicit casts. NFC llvm-svn: 255232
OpenPOWER on IntegriCloud