aboutsummaryrefslogtreecommitdiff
path: root/lib/Analysis/PrintfFormatString.cpp
AgeCommit message (Collapse)Author
2012-09-13Format strings: %D, %U, and %O are valid on Darwin (same as %d, %u, %o).Jordan Rose
These will warn under -Wformat-non-iso, and will still be rejected outright on other platforms. <rdar://problem/12061922> git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@163771 91177308-0d34-0410-b5e6-96231b3b80d8
2012-09-10Remove redundant semicolons which are null statements.Dmitri Gribenko
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@163546 91177308-0d34-0410-b5e6-96231b3b80d8
2012-09-08Format strings: %Ld isn't available on Darwin or Windows.Jordan Rose
This seems to be a GNU libc extension; we offer a fixit to %lld on these platforms. <rdar://problem/11518237> git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@163452 91177308-0d34-0410-b5e6-96231b3b80d8
2012-08-07Properly check length modfiers for %n in format strings.Hans Wennborg
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@161408 91177308-0d34-0410-b5e6-96231b3b80d8
2012-08-07Remove ScanfArgType and bake that logic into ArgType.Hans Wennborg
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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@161407 91177308-0d34-0410-b5e6-96231b3b80d8
2012-08-07Rename analyze_format_string::ArgTypeResult to ArgTypeHans Wennborg
Also remove redundant constructors and unused member functions. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@161403 91177308-0d34-0410-b5e6-96231b3b80d8
2012-07-30Make -Wformat check the argument type for %n.Hans Wennborg
This makes Clang check that the corresponding argument for "%n" in a format string is a pointer to int. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@160966 91177308-0d34-0410-b5e6-96231b3b80d8
2012-07-27Make -Wformat walk the typedef chain when looking for size_t, etc.Hans Wennborg
Clang's -Wformat fix-its currently suggest using "%zu" for values of type size_t (in C99 or C++11 mode). However, for a type such as std::vector<T>::size_type, it does not notice that type is actually typedeffed to size_t, and instead suggests a format for the underlying type, such as "%lu" or "%u". This commit makes the format string fix mechanism walk the typedef chain so that it notices if the type is size_t, even if that isn't "at the top". git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@160886 91177308-0d34-0410-b5e6-96231b3b80d8
2012-06-04Make suggestions for mismatched enum arguments to printf/scanf.Jordan Rose
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@157962 91177308-0d34-0410-b5e6-96231b3b80d8
2012-05-30Suggest '%@' for Objective-C objects in ObjC format strings.Jordan Rose
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@157716 91177308-0d34-0410-b5e6-96231b3b80d8
2012-02-16Format string analysis: give 'q' its own enumerator.Hans Wennborg
This is in preparation for being able to warn about 'q' and other non-standard format string features. It also allows us to print its name correctly. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150697 91177308-0d34-0410-b5e6-96231b3b80d8
2012-02-15Make -Wformat fix-its preserve original conversion specifiers.Hans Wennborg
This commit makes PrintfSpecifier::fixType() and ScanfSpecifier::fixType() only fix a conversion specification enough that Clang wouldn't warn about it, as opposed to always changing it to use the "canonical" conversion specifier. (PR11975) This preserves the user's choice of conversion specifier in cases like: printf("%a", (long double)1); where we previously suggested "%Lf", we now suggest "%La" printf("%x", (long)1); where we previously suggested "%ld", we now suggest "%lx". git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150578 91177308-0d34-0410-b5e6-96231b3b80d8
2012-01-31Let %S, %ls, %C match 16bit types in NSStrings.Nico Weber
As discussed at http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20120130/052200.html git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@149325 91177308-0d34-0410-b5e6-96231b3b80d8
2012-01-25Fix NSLog format string checking for %@.Ted Kremenek
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148885 91177308-0d34-0410-b5e6-96231b3b80d8
2012-01-24Teach scanf/printf checking about '%Ld' and friends (a GNU extension). ↵Ted Kremenek
Fixes PR 9466. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148859 91177308-0d34-0410-b5e6-96231b3b80d8
2012-01-12scanf: parse the 'm' length modifier, and check that the right argumentsHans Wennborg
are used with that and the 'a' length modifier. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148029 91177308-0d34-0410-b5e6-96231b3b80d8
2011-12-15Support the 'a' length modifier in scanf format strings as a C90Hans Wennborg
extension. This fixes gcc.dg/format/c90-scanf-3.c and ext-4.c (test for excess errors). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@146649 91177308-0d34-0410-b5e6-96231b3b80d8
2011-12-09Remove unnecessary braces from my previous commit.Hans Wennborg
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@146259 91177308-0d34-0410-b5e6-96231b3b80d8
2011-12-09Make printf warnings refer to wint_t and wchar_t by nameHans Wennborg
in addition to underlying type. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@146254 91177308-0d34-0410-b5e6-96231b3b80d8
2011-12-09Move definition of ConversionSpecifier::toString() to FormatString.cppHans Wennborg
It's declared in FormatString.h, so it shouldn't be defined in PrintfFormatString.cpp. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@146253 91177308-0d34-0410-b5e6-96231b3b80d8
2011-12-09fix format specifier fixit for printf("%ld", "foo");Hans Wennborg
It should reset the length modifier (unless it's a wchar_t string). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@146252 91177308-0d34-0410-b5e6-96231b3b80d8
2011-12-07Make printf warnings refer to intmax_t et al. by nameHans Wennborg
in addition to underlying type. For example, the warning for printf("%zu", 42.0); changes from "conversion specifies type 'unsigned long'" to "conversion specifies type 'size_t' (aka 'unsigned long')" (This is a second attempt after r145697, which got reverted.) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@146032 91177308-0d34-0410-b5e6-96231b3b80d8
2011-12-02Revert r145697 and dependent patch r145702. It added a dependency fromNick Lewycky
lib/Analysis to lib/Sema which is cyclical. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@145724 91177308-0d34-0410-b5e6-96231b3b80d8
2011-12-02Make r145697 actually work.Hans Wennborg
Use the canonical type of the typedef to compare with the underlying type. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@145702 91177308-0d34-0410-b5e6-96231b3b80d8
2011-12-02Make conversion specifier warning refer to typedef if possible.Hans Wennborg
For example, the warning for printf("%zu", 42.0); changes from "conversion specifies type 'unsigned long'" to "conversion specifies type 'size_t' (aka 'unsigned long')" git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@145697 91177308-0d34-0410-b5e6-96231b3b80d8
2011-10-27Teach format string analysis that "%zu" means size_t.Hans Wennborg
The code had it backwards, thinking size_t was signed, and using that for "%zd". Also let the analysis get the types for (u)intmax_t while we are at it. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143099 91177308-0d34-0410-b5e6-96231b3b80d8
2011-10-25Tweak printf format string parsing to accept 'hh' conversion specifier to ↵Ted Kremenek
accept any char, not just signed char. Fixes <rdar://problem/10303638>. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@142908 91177308-0d34-0410-b5e6-96231b3b80d8
2011-10-18More metaprogramming with builtin types.John McCall
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@142433 91177308-0d34-0410-b5e6-96231b3b80d8
2011-10-18Suggest %zu for size_t args to printf.Hans Wennborg
For PR11152. Make PrintSpecifier::fixType() suggest "%zu" for size_t, etc. rather than looking at the underlying type and suggesting "%llu" or other platform-specific length modifiers. Applies to C99 and C++11. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@142342 91177308-0d34-0410-b5e6-96231b3b80d8
2011-10-17Add a new placeholder type to represent "unbridged"John McCall
casts in ARC. No semantic analysis yet. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@142208 91177308-0d34-0410-b5e6-96231b3b80d8
2011-10-14Provide half floating point support as a storage only type.Anton Korobeynikov
Lack of half FP was a regression compared to llvm-gcc. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@142016 91177308-0d34-0410-b5e6-96231b3b80d8
2011-09-23Switch assert(0/false) llvm_unreachable.David Blaikie
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140367 91177308-0d34-0410-b5e6-96231b3b80d8
2011-08-17Fix else style. No functionality change intended.Chad Rosier
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@137896 91177308-0d34-0410-b5e6-96231b3b80d8
2011-07-23remove unneeded llvm:: namespace qualifiers on some core types now that ↵Chris Lattner
LLVM.h imports them into the clang namespace. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@135852 91177308-0d34-0410-b5e6-96231b3b80d8
2011-06-28Revert r133024, "[format strings] correctly suggest correct type for '%@'Daniel Dunbar
specifiers. Fixes <rdar://problem/9607158>." because it causes false positives on some code that uses CF toll free bridging. - I'll let Doug or Ted figure out the right fix here, possibly just to accept any pointer type. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@134041 91177308-0d34-0410-b5e6-96231b3b80d8
2011-06-14[format strings] correctly suggest correct type for '%@' specifiers. Fixes ↵Ted Kremenek
<rdar://problem/9607158>. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@133024 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-27Don't print fixits for format specifiers in cases where the fixit does not ↵Eli Friedman
actually fix the warning. PR8781. I'm not sure what the preferred way to write a test for whether a fixit is emitted. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@130335 91177308-0d34-0410-b5e6-96231b3b80d8
2011-04-25When generating printf fixits, preserve the original formating for unsigned ↵Ted Kremenek
integers (e.g., 'x', 'o'). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@130164 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-27Fix whitespace.NAKAMURA Takumi
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@124364 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-277bit-ize.NAKAMURA Takumi
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@124363 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-08Add semantic checking that the "thousands grouping"Ted Kremenek
prefix in a printf format string is matched with the appropriate conversion specifier. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@123055 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-08Add printf format string parsing support for 'Ted Kremenek
prefix to format conversions (POSIX extension). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@123054 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-25The -fshort-wchar option causes wchar_t to become unsigned, in addition to beingChris Lattner
16-bits in size. Implement this by splitting WChar into two enums, like we have for char. This fixes a miscompmilation of XULRunner, PR8856. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@122558 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-02Fix range in printf warnings for invalid conversion specifiers.Ted Kremenek
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@120735 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-21The 'X' printf type has a valid alternative form. Fixes PR8641.Anders Carlsson
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@119946 91177308-0d34-0410-b5e6-96231b3b80d8
2010-10-21Previously, the printf warnings would say your arguments type was 'int' when ↵Ted Kremenek
it was really a 'char' or a 'short'. This fixes that and allows the hints to suggest 'h' modifiers for small ints. Patch by Justin Bogner! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@116996 91177308-0d34-0410-b5e6-96231b3b80d8
2010-08-24Fix printf format string checking for '%lc' (which expects a wint_t or ↵Ted Kremenek
compatible argument). Fixes PR 7981. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@111978 91177308-0d34-0410-b5e6-96231b3b80d8
2010-07-20Move 'hasValidLengthModifier' from PrintfFormatSpecifier to FormatSpecifier.Ted Kremenek
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@108906 91177308-0d34-0410-b5e6-96231b3b80d8
2010-07-20Cleanup whitespace in switch statement. No functionality change.Ted Kremenek
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@108905 91177308-0d34-0410-b5e6-96231b3b80d8
2010-07-20Add 'ConversionSpecifier' root class in 'analyze_format_string' namespace andTed Kremenek
derived 'PrintfConversionSpecifier' from this class. We will do the same for 'ScanfConversionSpecifier'. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@108903 91177308-0d34-0410-b5e6-96231b3b80d8