summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaChecking.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Add support for C++0x unicode string and character literals, from Craig Topper!Douglas Gregor2011-07-271-2/+2
| | | | llvm-svn: 136210
* Revert r136046 while fixing handling of e.g. &foo[index_one_past_size]Kaelyn Uhrain2011-07-261-68/+21
| | | | llvm-svn: 136113
* Cleanup the stray comments and variables I could dig out of Sema toChandler Carruth2011-07-261-5/+5
| | | | | | refer to 'expansion' instead of 'instantiation'. llvm-svn: 136060
* Expand array bounds checking to work in the presence of unary & and *,Kaelyn Uhrain2011-07-261-21/+68
| | | | | | | | | and to work with pointer arithmetic in addition to array indexing. The new pointer arithmetic porition of the array bounds checking can be turned on by -Warray-bounds-pointer-arithmetic (and is off by default). llvm-svn: 136046
* remove unneeded llvm:: namespace qualifiers on some core types now that ↵Chris Lattner2011-07-231-11/+11
| | | | | | | | LLVM.h imports them into the clang namespace. llvm-svn: 135852
* Remove warning for conditional operands of differend signedness from ↵Richard Trieu2011-07-211-20/+7
| | | | | | -Wsign-compare. Cases that previously warn on this will have a different warning emitted from -Wsign-conversion. llvm-svn: 135664
* Use the new APFloat::convertToInt(APSInt) function to simplify uses ofJeffrey Yasskin2011-07-151-7/+5
| | | | | | convertToInt(integerParts*) and make them more reliable. llvm-svn: 135279
* Teach -Wconversion, -Wsign-compare etc. about division and remainder.John McCall2011-07-141-4/+44
| | | | llvm-svn: 135208
* Make the integer-range analysis recognize ^= correctly,John McCall2011-07-131-2/+11
| | | | | | | | | and (while I'm at it) teach it to grok the results of simple assignments. The first is PR10336. llvm-svn: 135034
* In ARC, reclaim all return values of retainable type, not just thoseJohn McCall2011-07-071-0/+1
| | | | | | | | | | | | where we have an immediate need of a retained value. As an exception, don't do this when the call is made as the immediate operand of a __bridge retain. This is more in the way of a workaround than an actual guarantee, so it's acceptable to be brittle here. rdar://problem/9504800 llvm-svn: 134605
* objc-arc: Check on a variety of unsafe assignment of retained Fariborz Jahanian2011-06-241-4/+39
| | | | | | objects. // rdar://9495837 llvm-svn: 133806
* Rename objc_lifetime -> objc_ownership, and modify diagnostics to talk about ↵Argyrios Kyrtzidis2011-06-241-1/+1
| | | | | | | | 'ownership', not 'lifetime'. rdar://9477613. llvm-svn: 133779
* Fix some grammar nits in the comments from Nick.Chandler Carruth2011-06-211-2/+2
| | | | llvm-svn: 133571
* Introduce a new AST node describing reference binding to temporaries.Douglas Gregor2011-06-211-0/+16
| | | | | | | | | | | | | | | | | | | | | | | | | MaterializeTemporaryExpr captures a reference binding to a temporary value, making explicit that the temporary value (a prvalue) needs to be materialized into memory so that its address can be used. The intended AST invariant here is that a reference will always bind to a glvalue, and MaterializeTemporaryExpr will be used to convert prvalues into glvalues for that binding to happen. For example, given const int& r = 1.0; The initializer of "r" will be a MaterializeTemporaryExpr whose subexpression is an implicit conversion from the double literal "1.0" to an integer value. IR generation benefits most from this new node, since it was previously guessing (badly) when to materialize temporaries for the purposes of reference binding. There are likely more refactoring and cleanups we could perform there, but the introduction of MaterializeTemporaryExpr fixes PR9565, a case where IR generation would effectively bind a const reference directly to a bitfield in a struct. Addresses <rdar://problem/9552231>. llvm-svn: 133521
* Teach the warning about non-POD memset/memcpy/memmove to deal with theDouglas Gregor2011-06-161-12/+40
| | | | | | | | | __builtin_ versions of these functions as well as the normal function versions, so that it works on platforms where memset/memcpy/memmove are macros that map down to the builtins (e.g., Darwin). Fixes <rdar://problem/9372688>. llvm-svn: 133173
* Rework the warning for 'memset(p, 0, sizeof(p))' where 'p' is a pointerChandler Carruth2011-06-161-22/+69
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | and the programmer intended to write 'sizeof(*p)'. There are several elements to the new version: 1) The actual expressions are compared in order to more accurately flag the case where the pattern that works for an array has been used, or a '*' has been omitted. 2) Only do a loose type-based check for record types. This prevents us from warning when we happen to be copying around chunks of data the size of a pointer and the pointer types for the sizeof and source/dest match. 3) Move all the diagnostics behind the runtime diagnostic filter. Not sure this is really important for this particular diagnostic, but almost everything else in SemaChecking.cpp does so. 4) Make the wording of the diagnostic more precise and informative. At least to my eyes. 5) Provide highlighting for the two expressions which had the unexpected similarity. 6) Place this diagnostic under a flag: -Wsizeof-pointer-memaccess This uses the Stmt::Profile system for computing #1. Because of the potential cost, this is guarded by the warning flag. I'd be interested in feedback on how bad this is in practice; I would expect it to be quite cheap in practice. Ideas for a cheaper / better way to do this are also welcome. The diagnostic wording could likely use some further wordsmithing. Suggestions welcome here. The goals I had were to: clarify that its the interaction of 'memset' and 'sizeof' and give more reasonable suggestions for a resolution. An open question is whether these diagnostics should have the note attached for silencing by casting the dest/source pointer to void*. llvm-svn: 133155
* Skip both character pointers and void pointers when diagnosing badChandler Carruth2011-06-161-1/+3
| | | | | | | | | | | | | argument types for mem{set,cpy,move}. Character pointers, much like void pointers, often point to generic "memory", so trying to check whether they match the type of the argument to 'sizeof' (or other checks) is unproductive and often results in false positives. Nico, please review; does this miss any of the bugs you were trying to find with this warning? The array test case you had should be caught by the array-specific sizeof warning I think. llvm-svn: 133136
* Automatic Reference Counting.John McCall2011-06-151-14/+268
| | | | | | | | | | Language-design credit goes to a lot of people, but I particularly want to single out Blaine Garst and Patrick Beard for their contributions. Compiler implementation credit goes to Argyrios, Doug, Fariborz, and myself, in no particular order. llvm-svn: 133103
* Warn on memset(ptr, 0, sizeof(ptr)). Diagnostic wording by Jordy Rose.Nico Weber2011-06-141-1/+27
| | | | llvm-svn: 132996
* fix rdar://9546171 - -Wshorten-64-to-32 shouldn't warn on vector bitcasts.Chris Lattner2011-06-141-3/+6
| | | | llvm-svn: 132975
* Fix a broken index left over from before this function was converted toChandler Carruth2011-06-131-1/+1
| | | | | | handle memcpy and memmove. Spotted by Nico. llvm-svn: 132902
* Clean up the "non-POD memaccess" stuff some. This adds a properly namedChandler Carruth2011-06-031-16/+10
| | | | | | | | | | | | | | diagnostic group to cover the cases where we have definitively bad behavior: dynamic classes. It also rips out the existing support for POD-based checking. This didn't work well, and triggered too many false positives. I'm looking into a possibly more principled way to warn on the fundamental buggy construct here. POD-ness isn't the critical aspect anyways, so a clean slate is better. This also removes some silliness from the code until the new checks arrive. llvm-svn: 132534
* Add a new warning on NULL pointer constant to integer conversion.Richard Trieu2011-05-291-0/+7
| | | | | | This path was reviewed by Chandler Carruth at http://codereview.appspot.com/4538074/ llvm-svn: 132297
* A few more is(Un)signedIntegerType/is(Un)signedOrEnumerationType cleanups.Douglas Gregor2011-05-211-2/+3
| | | | llvm-svn: 131793
* Extend -Wnon-pod-memset to also encompass memcpy() and memmove(),Douglas Gregor2011-05-031-36/+44
| | | | | | | | checking both the source and the destination operands, renaming the warning group to -Wnon-pod-memaccess and tweaking the diagnostic text in the process. llvm-svn: 130786
* Separate the -Wnon-pod-memset warnings into two separate warnings:Douglas Gregor2011-05-031-10/+20
| | | | | | | - a default-on warning for pointers to dynamic classes (= classes with vtables) - a default-off warning for other non-POD types llvm-svn: 130781
* Only check the use of memset() if we're refering to a C function namedDouglas Gregor2011-05-031-1/+3
| | | | | | 'memset' with external linkage. llvm-svn: 130770
* Relax the non-POD memset warning to use the less restrictive C++11Chandler Carruth2011-04-291-12/+25
| | | | | | | | | | | definition of POD. Specifically, this allows certain non-aggregate types due to their data members being private. The representation of C++11 POD testing is pretty gross. Any suggestions for improvements there are welcome. Especially the name 'isCXX11PODType()' seems truly unfortunate. llvm-svn: 130492
* Convert assertion in memset checking to a runtime check (because real code ↵Ted Kremenek2011-04-281-1/+6
| | | | | | may provide a deviant definition of memset). llvm-svn: 130368
* Heh, funny thing, 'void' isn't a POD type. Nice of us to suggest it toChandler Carruth2011-04-271-1/+1
| | | | | | | | silence this warning. ;] Fixed that obvious bug and added a bit more testing as well. llvm-svn: 130318
* Add a warning (-Wnon-pod-memset) for calls to memset() withChandler Carruth2011-04-271-0/+34
| | | | | | | | | | a destination pointer that points to a non-POD type. This can flag such horrible bugs as overwriting vptrs when a previously POD structure is suddenly given a virtual method, or creating objects that crash on practically any use by zero-ing out a member when its changed from a const char* to a std::string, etc. llvm-svn: 130299
* Support for C++11 (non-template) alias declarations.Richard Smith2011-04-151-2/+2
| | | | llvm-svn: 129567
* fix a bunch of comment typos found by codespell. Patch byChris Lattner2011-04-151-1/+1
| | | | | | Luis Felipe Strano Moraes! llvm-svn: 129559
* C1X: implement generic selectionsPeter Collingbourne2011-04-151-19/+9
| | | | | | | As an extension, generic selection support has been added for all supported languages. The syntax is the same as for C1X. llvm-svn: 129554
* Enhance the diagnostic for literal float -> int conversions to suggestChandler Carruth2011-04-101-4/+35
| | | | | | | | | | | | rewriting the literal when the value is integral. It is not uncommon to see code written as: const int kBigNumber = 42e5; Without any real awareness that this is no longer an ICE. The note helps automate and ease the process of fixing code that violates the warning. llvm-svn: 129243
* add a __sync_swap builtin to fill out the rest of the __sync builtins. Chris Lattner2011-04-091-1/+4
| | | | | | Patch by Dave Zarzycki! llvm-svn: 129189
* Use ExprResult& instead of Expr *& in SemaJohn Wiegley2011-04-081-17/+21
| | | | | | | | | | | | | | | | | | | | | | | | | This patch authored by Eric Niebler. Many methods on the Sema class (e.g. ConvertPropertyForRValue) take Expr pointers as in/out parameters (Expr *&). This is especially true for the routines that apply implicit conversions to nodes in-place. This design is workable only as long as those conversions cannot fail. If they are allowed to fail, they need a way to report their failures. The typical way of doing this in clang is to use an ExprResult, which has an extra bit to signal a valid/invalid state. Returning ExprResult is de riguour elsewhere in the Sema interface. We suggest changing the Expr *& parameters in the Sema interface to ExprResult &. This increases interface consistency and maintainability. This interface change is important for work supporting MS-style C++ properties. For reasons explained here <http://lists.cs.uiuc.edu/pipermail/cfe-dev/2011-February/013180.html>, seemingly trivial operations like rvalue/lvalue conversions that formerly could not fail now can. (The reason is that given the semantics of the feature, getter/setter method lookup cannot happen until the point of use, at which point it may be found that the method does not exist, or it may have the wrong type, or overload resolution may fail, or it may be inaccessible.) llvm-svn: 129143
* Refactor one helper function to merely forward to another so that thereChandler Carruth2011-04-051-7/+6
| | | | | | is a single implementation. No functionality change intended. llvm-svn: 128877
* Apply the nonnull attribute to constructor expressions too.Nick Lewycky2011-03-251-5/+6
| | | | llvm-svn: 128253
* Remove warning for null characters in CFString literals. Clang handles them ↵Ted Kremenek2011-03-151-6/+0
| | | | | | | | just fine, and GCC 4.2 doesn't warn here either. We added this warning back in 2007 when we were comparing against GCC 4.0. llvm-svn: 127704
* Don't warn about null characters in Objective-C format string literals.Ted Kremenek2011-03-151-4/+6
| | | | llvm-svn: 127703
* When we're determining whether to complain about a conversion from oneDouglas Gregor2011-03-121-1/+20
| | | | | | | | enumeration type to another in C, classify enumeration constants as if they had the type of their enclosing enumeration. Fixes <rdar://problem/9116337>. llvm-svn: 127514
* Add support for the OpenCL vec_step operator, by generalising andPeter Collingbourne2011-03-111-1/+1
| | | | | | | extending the existing support for sizeof and alignof. Original patch by Guy Benyei. llvm-svn: 127475
* Profiling showed that 'CheckImplicitConversions' was very slow because of ↵Ted Kremenek2011-03-101-9/+43
| | | | | | | | | | | the call to getSpellingLoc(). On 'aes.c' in the LLVM test suite, this function was consuming 7.4% of -fsyntax-only time. This change fixes this issue by delaying the check that the warning would be issued within a system macro by as long as possible. The main negative of this change is now the logic for this check is done in multiple places in this function instead of just in one place up front. llvm-svn: 127425
* For C++, enhance -Warray-bounds to recursively analyze array subscript ↵Ted Kremenek2011-03-011-15/+38
| | | | | | accesses in ?: expressions. llvm-svn: 126766
* Provide a bit saying that a builtin undergoes custom type-checking, thenJohn McCall2011-02-261-8/+27
| | | | | | | don't let calls to such functions go down the normal type-checking path. Test this out with __builtin_classify_type and __builtin_constant_p. llvm-svn: 126539
* Don't warn about using PredefinedExprs as format string literals. These ↵Ted Kremenek2011-02-241-1/+7
| | | | | | | | never can be a real security issue. Fixes PR 9314. llvm-svn: 126447
* Fix bogus -Warray-bounds warning involving 'array[true]' reported in PR 9296.Ted Kremenek2011-02-231-1/+1
| | | | llvm-svn: 126341
* Update Sema::DiagRuntimeBehavior() to take an optional Stmt* to indicate the ↵Ted Kremenek2011-02-231-3/+3
| | | | | | | | | code the diagnostic is associated with. This Stmt* is unused, but we will use it shortly for pruning diagnostics associated with unreachable code. llvm-svn: 126286
* Change -Warray-bounds logic to use DiagRuntimeBehavior in preparation for ↵Ted Kremenek2011-02-231-7/+11
| | | | | | using basic dataflow to suppress warnings on unreachable array bounds checks. llvm-svn: 126285
OpenPOWER on IntegriCloud