summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaChecking.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Dont cast away const needlessly. Found by gcc48 -Wcast-qual.Roman Divacky2012-09-061-1/+1
| | | | llvm-svn: 163325
* Format strings: suggest casts for NS(U)Integer and [SU]Int32 on Darwin.Jordan Rose2012-09-051-23/+126
| | | | | | | | | | | | | | | These types are defined differently on 32-bit and 64-bit platforms, and trying to offer a fixit for one platform would only mess up the format string for the other. The Apple-recommended solution is to cast to a type that is known to be large enough and always use that to print the value. This should only have an impact on compile time if the format string is incorrect; in cases where the format string matches the definition on the current platform, no warning will be emitted. <rdar://problem/9135072&12164284> llvm-svn: 163266
* Format string checking: change long if-statement to early returns.Jordan Rose2012-09-051-66/+69
| | | | | | No functionality change. llvm-svn: 163265
* objective-C ARC; detect and warn on retain cycle whenFariborz Jahanian2012-08-311-0/+6
| | | | | | | property-dot syntax is used on an object whose capture causes retain cycle. // rdar://11702054 llvm-svn: 163017
* Change the representation of builtin functions in the ASTEli Friedman2012-08-311-5/+5
| | | | | | | | | (__builtin_* etc.) so that it isn't possible to take their address. Specifically, introduce a new type to represent a reference to a builtin function, and a new cast kind to convert it to a function pointer in the operand of a call. Fixes PR13195. llvm-svn: 162962
* Warn about suspicious implicit conversions from floating point to boolHans Wennborg2012-08-281-0/+64
| | | | | | | | | | | | | | | | | | | | | This warns in two specific situations: 1) For potentially swapped function arguments, e.g. void foo(bool, float); foo(1.7, false); 2) Misplaced brackets around function call arguments, e.g. bool InRange = fabs(a - b < delta); Where the last argument in a function call is implicitly converted from bool to float, and the function returns a float which gets implicitly converted to bool. Patch by Andreas Eckleder! llvm-svn: 162763
* Support MIPS DSP Rev2 intrinsics.Simon Atanasyan2012-08-271-0/+5
| | | | | | The patch reviewed by Akira Hatanaka. llvm-svn: 162669
* Push ArrayRef through the Expr hierarchy.Benjamin Kramer2012-08-241-4/+2
| | | | | | No functionality change. llvm-svn: 162552
* Rip out remnants of move semantic emulation and smart pointers in Sema.Benjamin Kramer2012-08-231-4/+4
| | | | | | | These were nops for quite a while and only lead to confusion. ASTMultiPtr now behaves like a proper dumb array reference. llvm-svn: 162475
* Fix a bunch of -Wdocumentation warnings.Dmitri Gribenko2012-08-231-2/+2
| | | | llvm-svn: 162452
* Add support for "type safety" attributes that allow checking that 'void *'Dmitri Gribenko2012-08-171-0/+414
| | | | | | | | | | | | | | function arguments and arguments for variadic functions are of a particular type which is determined by some other argument to the same function call. Usecases include: * MPI library implementations, where these attributes enable checking that buffer type matches the passed MPI_Datatype; * for HDF5 library there is a similar usecase as MPI; * checking types of variadic functions' arguments for functions like fcntl() and ioctl(). llvm-svn: 162067
* Store SourceManager pointer on PrintingPolicy in the case where we're dumping,Richard Smith2012-08-161-3/+3
| | | | | | | | | and remove ASTContext reference (which was frequently bound to a dereferenced null pointer) from the recursive lump of printPretty functions. In so doing, fix (at least) one case where we intended to use the 'dump' mode, but that failed because a null ASTContext reference had been passed in. llvm-svn: 162011
* Fix undefined behavior (and wrong code, as far as I can tell) in NEON builtinRichard Smith2012-08-141-2/+2
| | | | | | | | | tablegen code, found by -fcatch-undefined-behavior. I would appreciate if someone more familiar with the NEON code could point me in the direction of how to write a test for this. We appear to have essentially no test coverage whatsoever for these builtins. llvm-svn: 161827
* Address code review comments for Wstrncat-size warning (r161440).Anna Zaks2012-08-081-24/+26
| | | | llvm-svn: 161527
* Remove ScanfArgType and bake that logic into ArgType.Hans Wennborg2012-08-071-4/+4
| | | | | | | | This is useful for example for %n in printf, which expects a pointer to int with the same logic for checking as %d would have in scanf. llvm-svn: 161407
* Rename analyze_format_string::ArgTypeResult to ArgTypeHans Wennborg2012-08-071-17/+17
| | | | | | Also remove redundant constructors and unused member functions. llvm-svn: 161403
* Refactor checks for unevaluated contexts into a common utility function.David Blaikie2012-08-061-1/+1
| | | | | | | | | The one caller that's surrounded by nearby code manipulating the underlying evaluation context list is left unmodified for readability. Review by Sean Silva and Richard Smith. llvm-svn: 161355
* Do not warn on correct use of the '%n' format specifier.Matt Beaumont-Gay2012-07-301-9/+0
| | | | | | | | While '%n' can be used for evil in an attacker-controlled format string, there isn't any acute danger in using it in a literal format string with an argument of the appropriate type. llvm-svn: 160984
* Make -Wformat check the argument type for %n.Hans Wennborg2012-07-301-2/+0
| | | | | | | This makes Clang check that the corresponding argument for "%n" in a format string is a pointer to int. llvm-svn: 160966
* Change APInt to APSInt in one instance. Also change a call to operator==() toRichard Trieu2012-07-231-1/+1
| | | | | | APSInt::isSameValue() when comparing different sized APSInt's. llvm-svn: 160641
* Fix a typo (the the => the)Sylvestre Ledru2012-07-231-1/+1
| | | | llvm-svn: 160622
* For varargs, diagnose passing ObjC objects by value like other non-POD types.Jordan Rose2012-07-191-30/+40
| | | | | | | | | | | | | | While we still want to consider this a hard error (non-POD variadic args are normally a DefaultError warning), delaying the diagnostic allows us to give better error messages, which also match the usual non-POD errors more closely. In addition, this change improves the diagnostic messages for format string argument type mismatches by passing down the type of the callee, so we can say "variadic method" or "variadic function" appropriately. <rdar://problem/11825593> llvm-svn: 160517
* Don't crash checking a format string if one of the arguments is invalid.Jordan Rose2012-07-191-7/+20
| | | | | | | | | Previously, we would ask for the SourceLocation of an argument even if it were NULL (i.e. if Sema resulted in an ExprError trying to build it). <rdar://problem/11890818> llvm-svn: 160515
* Simplify float comparison checks by using early return.David Blaikie2012-07-161-24/+16
| | | | | | Found while investigating PR13330 llvm-svn: 160318
* MIPS: Range check __builtin_mips_wrdsp / __builtin_mips_rddsp arguments ↵Simon Atanasyan2012-07-081-0/+34
| | | | | | against the upper/lower values. llvm-svn: 159911
* objc-arc: warn when assigning retained object toFariborz Jahanian2012-07-061-1/+11
| | | | | | | a 'weak' property just as we do the same for 'weak' variables. // rdar://11814185 llvm-svn: 159859
* When a builtin that requires a constant is given a type- orDouglas Gregor2012-06-291-2/+16
| | | | | | | value-dependent expression, don't complain that it wasn't the constant we wanted. Fixes <rdar://problem/11688587> and PR11074. llvm-svn: 159404
* Unrevert r158887, reverted in r158949, along with a fix for the bug whichRichard Smith2012-06-251-120/+271
| | | | | | | | | | | | | | | | | | | | resulted in it being reverted. A test for that bug was added in r158950. Original comment: If an object (such as a std::string) with an appropriate c_str() member function is passed to a variadic function in a position where a format string indicates that c_str()'s return type is desired, provide a note suggesting that the user may have intended to call the c_str() member. Factor the non-POD-vararg checking out of DefaultVariadicArgumentPromotion and move it to SemaChecking in order to facilitate this. Factor the call checking out of function call checking and block call checking, and extend it to cover constructor calls too. Patch by Sam Panzer! llvm-svn: 159159
* Revert r158887. This fixes pr13168.Rafael Espindola2012-06-211-271/+120
| | | | | | | | Revert "If an object (such as a std::string) with an appropriate c_str() member function" This reverts commit 7d96f6106bfbd85b1af06f34fdbf2834aad0e47e. llvm-svn: 158949
* PR13165: False positive when initializing member data pointers with NULL.David Blaikie2012-06-211-2/+1
| | | | | | | | | This now correctly covers, I believe, all the pointer types: * 'any' pointers (both function and data normal pointers and ObjC object pointers) * member pointers (both function and data) * block pointers llvm-svn: 158931
* If an object (such as a std::string) with an appropriate c_str() member functionRichard Smith2012-06-211-120/+271
| | | | | | | | | | | | | | | is passed to a variadic function in a position where a format string indicates that c_str()'s return type is desired, provide a note suggesting that the user may have intended to call the c_str() member. Factor the non-POD-vararg checking out of DefaultVariadicArgumentPromotion and move it to SemaChecking in order to facilitate this. Factor the call checking out of function call checking and block call checking, and extend it to cover constructor calls too. Patch by Sam Panzer! llvm-svn: 158887
* Enable -Wnull-conversion for non-integral target types (eg: double).David Blaikie2012-06-191-5/+6
| | | | llvm-svn: 158744
* Fix Sema and IRGen for atomic compound assignment so it has the right ↵Eli Friedman2012-06-161-1/+1
| | | | | | | | semantics when promotions are involved. (As far as I can tell, this only affects some edge cases.) llvm-svn: 158591
* PR13099: Teach -Wformat about raw string literals, UTF-8 strings and Unicode ↵Richard Smith2012-06-131-1/+1
| | | | | | escape sequences. llvm-svn: 158390
* Teach format string checking about compile-time CFString constants.Jordan Rose2012-06-041-20/+24
| | | | | | | | | | | | | Within the guts of CheckFormatHandler, the IsObjCLiteral flag was being used in two ways: to see if null bytes were allowed, and to see if the '%@' specifier is allowed.* The former usage has been changed to an explicit test and the latter pushed down to CheckPrintfHandler and renamed ObjCContext, since it applies to CFStrings as well. * This also changes how wide chars are interpreted; in OS X Foundation, the wide character type is 'unichar', a typedef for short, rather than wchar_t. llvm-svn: 157968
* Teach printf/scanf about enums with fixed underlying types.Jordan Rose2012-06-041-10/+19
| | | | llvm-svn: 157961
* Change wording of 'memcpy' type mismatch warning and remove fixit.Anna Zaks2012-05-301-16/+10
| | | | | | As per comments following r157659. llvm-svn: 157722
* Add fixits for memory access warnings.Anna Zaks2012-05-301-5/+35
| | | | | | | Also, do not display the builtin name and macro expansion when the function is a builtin. llvm-svn: 157659
* Use the argument location instead of the format string location when warningMatt Beaumont-Gay2012-05-171-8/+8
| | | | | | | | | | | | | | | | | | about argument type mismatch. This gives a nicer diagnostic in cases like printf(fmt, i); where previously the snippet just pointed at 'fmt' (with a note at the definition of fmt). It's a wash for cases like printf("%f", i); where previously we snippeted the offending portion of the format string, but didn't indicate which argument was at fault. llvm-svn: 156968
* Don't warn when NULL is used within a macro but its conversion is outside a ↵David Blaikie2012-05-151-9/+10
| | | | | | | | | | | | | | | | | | macro. This fixes the included test case & was reported by Nico Weber. It's a little bit nasty using the difference in the conversion context, but seems to me like a not unreasonable solution. I did have to fix up the conversion context for conditional operators (it seems correct to me to include the context for which we're actually doing the comparison - across all the nested conditionals, rather than the innermost conditional which might not actually have the problematic implicit conversion at all) and template default arguments (this is a bit of a hack, since we don't have the source location of the '=' anymore, so I just used the start of the parameter - open to suggestions there) llvm-svn: 156861
* Changing std::string to SmallString for r156826.David Blaikie2012-05-151-2/+2
| | | | | | Based on code review feedback by Jordan Rose. llvm-svn: 156827
* Improve some of the conversion warnings to fire on conversion to bool.David Blaikie2012-05-151-3/+17
| | | | | | | | | | | Moves the bool bail-out down a little in SemaChecking - so now -Wnull-conversion and -Wliteral-conversion can fire when the target type is bool. Also improve the wording/details in the -Wliteral-conversion warning to match the -Wconstant-conversion. llvm-svn: 156826
* Merge branch 'format-string-braced-init'Matt Beaumont-Gay2012-05-111-1/+7
| | | | llvm-svn: 156653
* Teach IsTailPaddedMemberArray() (used by -Warray-bounds) that a FieldDecl ↵Ted Kremenek2012-05-091-4/+12
| | | | | | | | may have a Typedef type, and not always a ConstantArrayType. Fixes <rdar://problem/11387038>. llvm-svn: 156464
* Inhibit ObjC format warning only in system headers (NSLocalizedString).Jean-Daniel Dupas2012-05-041-1/+2
| | | | | | Add a test case for the related NSAssert workaround. llvm-svn: 156205
* IsTailPaddedMemberArray uses a FieldDecl'sSean Callanan2012-05-041-5/+9
| | | | | | | | | | | | | getTypeSourceInfo() without checking for NULL. FieldDecls may have NULL TypeSourceInfo, and in fact some FieldDecls generated by Clang -- and all FieldDecls generated by LLDB -- have no TypeSourceInfo. This patch makes IsTailPaddedMemberArray check for NULL. llvm-svn: 156186
* Move Sema::RequireCompleteType() and Sema::RequireCompleteExprType()Douglas Gregor2012-05-041-1/+1
| | | | | | | | | | | off PartialDiagnostic. PartialDiagnostic is rather heavyweight for something that is in the critical path and is rarely used. So, switch over to an abstract-class-based callback mechanism that delays most of the work until a diagnostic is actually produced. Good for ~11k code size reduction in the compiler and 1% speedup in -fsyntax-only on the code in <rdar://problem/11004361>. llvm-svn: 156176
* Fix handling of wint_t - we can't assume wint_t is purely an integer ↵James Molloy2012-05-041-1/+2
| | | | | | | | | | | | promotion of wchar_t - they may differ in signedness. Teach ASTContext about WIntType, and have it taken from TargetInfo like WCharType. Should fix test/Sema/format-strings.c for ARM, with the exception of one subtest which will fail if wint_t and wchar_t are the same size and wint_t is signed, wchar_t is unsigned. There'll be a followup commit to fix that. Reviewed by Chandler and Hans at http://llvm.org/reviews/r/8 llvm-svn: 156165
* Disable -Wformat-extra-args for arguments defined in system headers.Bob Wilson2012-05-031-3/+6
| | | | | | | | | | | | | Some of the NSAssert macros in OS X 10.7 are implemented in a way that adds extra arguments that trigger the -Wformat-extra-args warning. Earlier versions of clang failed to detect those -Wformat issues, but now that clang is reporting those problems, we need to quiet them since there's nothing to be done to fix them. <rdar://problem/11317765> I don't know how to write a testcase for this. Suggestions welcome. Patch by Ted Kremenek! llvm-svn: 156092
* Turn the mixed-sign-comparison diagnostic into a runtime behaviorDouglas Gregor2012-05-011-3/+4
| | | | | | diagnostic, from Eitan Adler! llvm-svn: 155876
OpenPOWER on IntegriCloud