Граф коммитов

50 Коммитов

Автор SHA1 Сообщение Дата
Jordan Rose 670941c28c Format strings: offer a fixit for Darwin's %D/%U/%O to ISO %d/%u/%o.
<rdar://problem/12061922>

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@163772 91177308-0d34-0410-b5e6-96231b3b80d8
2012-09-13 02:11:15 +00:00
Jordan Rose 275b6f52c7 Format strings: %D, %U, and %O are valid on Darwin (same as %d, %u, %o).
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-13 02:11:03 +00:00
Jordan Rose 8be066e673 Format strings: suggest %lld instead of %qd and %Ld with -Wformat-non-iso.
As a corollary to the previous commit, even when an extension is
available, we can still offer a fixit to the standard modifier.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@163453 91177308-0d34-0410-b5e6-96231b3b80d8
2012-09-08 04:00:12 +00:00
Jordan Rose bbb6bb4952 Format strings: %Ld isn't available on Darwin or Windows.
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-09-08 04:00:03 +00:00
Hans Wennborg 58e1e54476 Remove ScanfArgType and bake that logic into ArgType.
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-07 08:59:46 +00:00
Hans Wennborg f3749f4168 Rename analyze_format_string::ArgTypeResult to ArgType
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-08-07 08:11:26 +00:00
Hans Wennborg 5deddafd3e -Wformat: better handling of qualifiers on pointer arguments
Warn about using pointers to const-qualified types as arguments to
scanf. Ignore the volatile qualifier when checking if types match.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@161052 91177308-0d34-0410-b5e6-96231b3b80d8
2012-07-31 16:37:47 +00:00
Hans Wennborg 4684778993 Make -Wformat walk the typedef chain when looking for size_t, etc.
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-07-27 19:17:46 +00:00
Jordan Rose ee0259d308 Teach printf/scanf about enums with fixed underlying types.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@157961 91177308-0d34-0410-b5e6-96231b3b80d8
2012-06-04 22:48:57 +00:00
Hans Wennborg 101d4e0c8f Make -Wformat accept printf("%hhx", c); with -funsigned-char
For "%hhx", printf expects an unsigned char. This makes Clang
accept a 'char' argument for that also when using -funsigned-char.

This fixes PR12761.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@156388 91177308-0d34-0410-b5e6-96231b3b80d8
2012-05-08 17:21:31 +00:00
James Molloy 392da48160 Fix handling of wint_t - we can't assume wint_t is purely an integer 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



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@156165 91177308-0d34-0410-b5e6-96231b3b80d8
2012-05-04 10:55:22 +00:00
Ted Kremenek afcd1954be Support '%p' format specifier with block pointers.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@152839 91177308-0d34-0410-b5e6-96231b3b80d8
2012-03-15 21:22:27 +00:00
Hans Wennborg f856264531 -Wformat-non-iso: warn about positional arguments (pr12017)
This renames the -Wformat-non-standard flag to -Wformat-non-iso,
rewords the current warnings a bit (pointing out that a format string
is not supported by ISO C rather than being "non standard"),
and adds a warning about positional arguments.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@152403 91177308-0d34-0410-b5e6-96231b3b80d8
2012-03-09 10:10:54 +00:00
Hans Wennborg 76517426dc Warn about non-standard format strings (pr12017)
This adds the -Wformat-non-standard flag (off by default,
enabled by -pedantic), which warns about non-standard
things in format strings (such as the 'q' length modifier,
the 'S' conversion specifier, etc.)

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@151154 91177308-0d34-0410-b5e6-96231b3b80d8
2012-02-22 10:17:01 +00:00
Hans Wennborg 32addd519c Format string analysis: give 'q' its own enumerator.
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-16 16:34:54 +00:00
Ted Kremenek b4a3ef783c Tweak format string checking to work with %@ and ObjC toll-free bridging. <rdar://problem/10814120>
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@149907 91177308-0d34-0410-b5e6-96231b3b80d8
2012-02-06 21:45:29 +00:00
Hans Wennborg 7da1f46793 Format string warnings: don't a.k.a. wchar_t with wchar_t.
This fixes the case where Clang would output:
 error: format specifies type 'wchar_t *' (aka 'wchar_t *')

ArgTypeResult::getRepresentativeTypeName needs to take into account
that wchar_t can be a built-in type (as opposed to in C, where it is a
typedef).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@149387 91177308-0d34-0410-b5e6-96231b3b80d8
2012-01-31 14:59:59 +00:00
Ted Kremenek e6ca97f2ae Fix NSLog format string checking for %@.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148885 91177308-0d34-0410-b5e6-96231b3b80d8
2012-01-25 00:04:09 +00:00
Ted Kremenek 9d24c2cbd9 Teach scanf/printf checking about '%Ld' and friends (a GNU extension). Fixes PR 9466.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148859 91177308-0d34-0410-b5e6-96231b3b80d8
2012-01-24 21:29:54 +00:00
Ted Kremenek ef1440b6ec The 'l' length modifier makes sense with the scanlist conversion specifier.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148586 91177308-0d34-0410-b5e6-96231b3b80d8
2012-01-20 22:11:52 +00:00
David Blaikie 3026348bd4 More dead code removal (using -Wunreachable-code)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148577 91177308-0d34-0410-b5e6-96231b3b80d8
2012-01-20 21:50:17 +00:00
Hans Wennborg 37969b7e14 scanf: parse the 'm' length modifier, and check that the right arguments
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
2012-01-12 17:11:12 +00:00
Hans Wennborg 28058d179a scanf analysis: the 'a' length modifier is valid with a scanlist
Before r148025 we (accidentally) didn't check whether a length modifier is
appropriate for a scanlist, but now we do.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148026 91177308-0d34-0410-b5e6-96231b3b80d8
2012-01-12 15:07:16 +00:00
Hans Wennborg 5294c792c7 Support the 'a' scanf length modifier as an extension in C++.
It should not be supported in C++11, since that uses the C99 standard
library, in which 'a' is a format specifier.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@147310 91177308-0d34-0410-b5e6-96231b3b80d8
2011-12-28 13:10:50 +00:00
Hans Wennborg d02deebce5 Support the 'a' length modifier in scanf format strings as a C90
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-15 10:25:47 +00:00
Hans Wennborg f4f0c6095d Make printf warnings refer to wint_t and wchar_t by name
in addition to underlying type.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@146254 91177308-0d34-0410-b5e6-96231b3b80d8
2011-12-09 12:22:12 +00:00
Hans Wennborg b8ec3e35d2 Move definition of ConversionSpecifier::toString() to FormatString.cpp
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-09 11:11:07 +00:00
Hans Wennborg a792aff1c7 Make printf warnings refer to intmax_t et al. by name
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-07 10:33:11 +00:00
Nick Lewycky 687b5df89d Revert r145697 and dependent patch r145702. It added a dependency from
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-02 23:21:43 +00:00
Hans Wennborg 5fdc1b993d Make conversion specifier warning refer to typedef if possible.
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-12-02 19:22:15 +00:00
Ted Kremenek 6ca4a9ae99 Tweak printf format string parsing to accept 'hh' conversion specifier to 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-25 04:20:41 +00:00
David Blaikie eb2d1f1c88 Removing a bunch of dead returns/breaks after llvm_unreachables.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140407 91177308-0d34-0410-b5e6-96231b3b80d8
2011-09-23 20:26:49 +00:00
David Blaikie b219cfc4d7 Switch assert(0/false) llvm_unreachable.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140367 91177308-0d34-0410-b5e6-96231b3b80d8
2011-09-23 05:06:16 +00:00
Chris Lattner 5f9e272e63 remove unneeded llvm:: namespace qualifiers on some core types now that 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-07-23 10:55:15 +00:00
Ted Kremenek 1ad35bebcc Revert r135147 and r135075. The consensus was that this wasn't the right thing to do.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@135152 91177308-0d34-0410-b5e6-96231b3b80d8
2011-07-14 17:05:32 +00:00
Ted Kremenek 9dbe16eb80 Add extra sanity checking in FormatString::matchesType() that we are comparing integers to integers. This happens not to be an issue now, but the extra check helps future proof in case of future refactorings.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@135147 91177308-0d34-0410-b5e6-96231b3b80d8
2011-07-14 15:43:21 +00:00
Ted Kremenek 826d5b4782 Reapply r135075, but modify format-strings.c and format-strings-fixit.c test cases to be more portable with an explicit target triple.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@135134 91177308-0d34-0410-b5e6-96231b3b80d8
2011-07-14 06:49:52 +00:00
NAKAMURA Takumi 13d99bf2e9 Revert r135075, "format string checking: long and int have the same widths on 32-bit, so we shouldn't warn about using"
It fails on freebsd, mingw and msvc10.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@135129 91177308-0d34-0410-b5e6-96231b3b80d8
2011-07-14 05:16:18 +00:00
Ted Kremenek 8da9316c5a format string checking: long and int have the same widths on 32-bit, so we shouldn't warn about using
an "int" format specifier with a "long" type in 32-bit.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@135075 91177308-0d34-0410-b5e6-96231b3b80d8
2011-07-13 20:20:58 +00:00
Ted Kremenek dc00d8158d Re-relax conversion specifier checking for printf format strings and conversion specifiers. My recent change was a mistake.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@135048 91177308-0d34-0410-b5e6-96231b3b80d8
2011-07-13 17:35:14 +00:00
Ted Kremenek 45eb7022ff Fix inversion in argument type checking for format strings with conversion specifiers for character types.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@135046 91177308-0d34-0410-b5e6-96231b3b80d8
2011-07-13 17:25:47 +00:00
Daniel Dunbar d6a4d18f52 Revert r133024, "[format strings] correctly suggest correct type for '%@'
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-28 23:33:55 +00:00
Ted Kremenek 84862f6a0b [format strings] correctly suggest correct type for '%@' specifiers. Fixes <rdar://problem/9607158>.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@133024 91177308-0d34-0410-b5e6-96231b3b80d8
2011-06-14 22:56:51 +00:00
Anders Carlsson 6242599844 Don't warn when matching %p to nullptr.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@118344 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-06 14:58:53 +00:00
Ted Kremenek 9325eaf08f Fix printf format string checking for '%lc' (which expects a wint_t or compatible argument). Fixes PR 7981.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@111978 91177308-0d34-0410-b5e6-96231b3b80d8
2010-08-24 22:24:51 +00:00
Eli Friedman a7e6845660 Detabify.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@111768 91177308-0d34-0410-b5e6-96231b3b80d8
2010-08-22 01:00:03 +00:00
Michael J. Spencer 96827eb524 Revert r109428 "Hoist argument type checking into CheckFormatHandler. This is prep for scanf format"
Got errors about ASTContext being undefined with Visual Studio 2010.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@109491 91177308-0d34-0410-b5e6-96231b3b80d8
2010-07-27 04:46:02 +00:00
Ted Kremenek f762905bde Hoist argument type checking into CheckFormatHandler. This is prep for scanf format
string argument type checking.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@109428 91177308-0d34-0410-b5e6-96231b3b80d8
2010-07-26 19:45:54 +00:00
Ted Kremenek a412a49916 Move 'hasValidLengthModifier' from PrintfFormatSpecifier to FormatSpecifier.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@108906 91177308-0d34-0410-b5e6-96231b3b80d8
2010-07-20 20:04:42 +00:00
Ted Kremenek 826a3457f7 Add most of the boilerplate support for scanf format string checking. This includes
handling the parsing of scanf format strings and hooking the checking into Sema.
Most of this checking logic piggybacks on what was already there for checking printf format
strings, but the checking logic has been refactored to support both.

What is left to be done is to support argument type checking in format strings and of course
fix the usual tail of bugs that will follow.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@108500 91177308-0d34-0410-b5e6-96231b3b80d8
2010-07-16 02:11:22 +00:00