Commit Graph

25 Commits

Author SHA1 Message Date
Alp Toker a3c494f0db Revert "clang/test/Driver/crash-report.c: This requires rewriter for -frewrite-includes. [PR20321]"
We've decided to make the core rewriter class and PP rewriters mandatory.
They're only a few hundred lines of code in total and not worth supporting as a
distinct build configuration, especially since doing so disables key compiler
features.

This reverts commit r213150.

Revert "clang/test: Introduce the feature "rewriter" for --enable-clang-rewriter."

This reverts commit r213148.

Revert "Move clang/test/Frontend/rewrite-*.c to clang/test/Frontend/Rewriter/"

This reverts commit r213146.

llvm-svn: 213159
2014-07-16 15:12:48 +00:00
NAKAMURA Takumi 692d6bb544 clang/test: Introduce the feature "rewriter" for --enable-clang-rewriter.
llvm-svn: 213148
2014-07-16 13:36:39 +00:00
Jordan Rose 202113ff5b Remove wchar_t* buffer from scanf format fix-it test.
Amends r204300 to not try to test fixing a wchar_t* to "%ls", which we don't
do correctly anyway. In C mode, wchar_t is just a typedef for a normal
primitive integer type, not a distinct type like it is in C++. To make this
work correctly, we'll need to look for the wchar_t typedef, not just the
builtin type.

Should fix the buildbots.

llvm-svn: 204349
2014-03-20 15:54:16 +00:00
NAKAMURA Takumi d49823667d Make format-strings-fixit.c aware of "%hu" uint16_t on wchar_t for targeting win32.
llvm-svn: 204334
2014-03-20 10:54:53 +00:00
Jordan Rose 177b0a3600 scanf format checking: include the buffer length in the fix-it for %s.
Patch by Zach Davis!

llvm-svn: 204300
2014-03-20 03:32:39 +00:00
Jordan Rose 1eb342920b Format strings: don't ever convert %+d to %lu.
Presumably, if the printf format has the sign explicitly requested, the user
wants to treat the data as signed.

This is a fix-up for r172739, and also includes several test changes that
didn't make it into that commit.

llvm-svn: 172762
2013-01-17 22:34:10 +00:00
Hans Wennborg 08574d3559 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".

llvm-svn: 160886
2012-07-27 19:17:46 +00:00
Hans Wennborg aa8c61cf94 -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.

llvm-svn: 152403
2012-03-09 10:10:54 +00:00
Hans Wennborg d99d688358 Make -Wformat fix-its preserve original conversion specifiers.
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".

llvm-svn: 150578
2012-02-15 09:59:46 +00:00
Hans Wennborg b1a5e09f6f Check that arguments to a scanf call match the format specifier,
and offer fixits when there is a mismatch.

llvm-svn: 146326
2011-12-10 13:20:11 +00:00
Hans Wennborg 2027de3be9 fix format specifier fixit for printf("%ld", "foo");
It should reset the length modifier (unless it's a wchar_t string).

llvm-svn: 146252
2011-12-09 10:51:29 +00:00
Hans Wennborg cc8ce7b1d7 Break out ssize_t test from Sema/format-strings-fixit.c
Move to a separate test that sets a specific target triple
so that the type of ssize_t is known.

llvm-svn: 142481
2011-10-19 07:55:50 +00:00
Hans Wennborg a5d653c7dd Another attempt at fixing format-strings-fixit.c.
Use "%f" as format string to make sure it doesn't match size_t, etc.
whatever they might be typedeffed to, so that the fixit always applies.

llvm-svn: 142348
2011-10-18 09:30:37 +00:00
Hans Wennborg 95c49c6c32 Disable the ssize_t test in format-strings-fixit.c.
Turns out this part of the test from r142342 wasn't portable.
The errors on the bots look like this:

E:\bb-win7\cmake-clang-i686-msys\build\tools\clang\test\Sema\Output\format-strings-fixit.c.tmp:58:13: error: conversion specifies type 'unsigned int' but the argument has type 'ssize_t' (aka 'long')
  printf("%zd", (ssize_t) 42);
          ~~^   ~~~~~~~~~~~~
          %zd

Obviously we can't typedef ssize_t to someting that doesn't have the same size as size_t and expect it to work.

But it's also weird that the format string "%zd" gets interpreted as "unsigned int" when it should clearly be signed.

llvm-svn: 142345
2011-10-18 08:58:16 +00:00
Hans Wennborg f99d04f841 Suggest %zu for size_t args to printf.
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.

llvm-svn: 142342
2011-10-18 08:10:06 +00:00
Richard Smith 3ab15558d7 PR10867: Work around a bug in lit. Multiple RUN: lines are joined with &&, so:
RUN: foo
  RUN: bar || true

is equivalent to:

  RUN: foo && bar || true

which is equivalent to:

  RUN: (foo && bar) || true

This resulted in several of the fixit tests not really testing anything.

llvm-svn: 139132
2011-09-06 03:01:15 +00:00
Ted Kremenek d0c2afd2c3 Revert r135147 and r135075. The consensus was that this wasn't the right thing to do.
llvm-svn: 135152
2011-07-14 17:05:32 +00:00
Ted Kremenek ba84cf53bc Reapply r135075, but modify format-strings.c and format-strings-fixit.c test cases to be more portable with an explicit target triple.
llvm-svn: 135134
2011-07-14 06:49:52 +00:00
Ted Kremenek 8dcc466886 When generating printf fixits, preserve the original formating for unsigned integers (e.g., 'x', 'o').
llvm-svn: 130164
2011-04-25 22:32:59 +00:00
Tom Care 3f272b853f Bug 7377: printf checking fails to flag some undefined behavior
http://llvm.org/bugs/show_bug.cgi?id=7377

Updated format string highlighting and fixits to take advantage of the new CharSourceRange class.
- Change HighlightRange to allow highlighting whitespace only in a CharSourceRange (for warnings about the ' ' (space) flag)
- Change format specifier range helper function to allow for half-open ranges (+1 to end)
- Enabled previously failing tests (FIXMEs/XFAILs removed)
- Small fixes and additions to format string test cases

M       test/Sema/format-strings.c
M       test/Sema/format-strings-fixit.c
M       lib/Frontend/TextDiagnosticPrinter.cpp
M       lib/Sema/SemaChecking.cpp

llvm-svn: 106480
2010-06-21 21:21:01 +00:00
Tom Care 6e4ea2db7f Printf format strings: Added some more tests and fixed some minor bugs.
- Precision toStrings shouldn't print a dot when they have no value.
- Length of char length modifier is now returned correctly.
- Added several fixit tests.

Note: fixit tests are currently broken due to a bug in HighlightRange. Marking as XFAIL for now.

M    test/Sema/format-strings-fixit.c
M    include/clang/Analysis/Analyses/PrintfFormatString.h
M    lib/Analysis/PrintfFormatString.cpp

llvm-svn: 106275
2010-06-18 03:02:16 +00:00
Ted Kremenek 98008a47a0 Fix format string checking of '%c' by treating it as an integer conversion. Fixes PR 7391.
llvm-svn: 106196
2010-06-17 01:12:20 +00:00
Ted Kremenek 64c235e4c6 Extend format string type-checking to include '%p'. Fixes remaining cases PR 4468.
llvm-svn: 106151
2010-06-16 21:23:04 +00:00
Tom Care 00554634db Small fixes regarding printf fix suggestions.
- Added some handling of flags that become invalid when changing the conversion specifier.
- Changed fixit behavior to remove unnecessary length modifiers.
- Separated some tests out and added some comments.

modified:
  lib/Analysis/PrintfFormatString.cpp
  test/Sema/format-strings-fixit.c

llvm-svn: 105807
2010-06-11 04:22:02 +00:00
Tom Care b704270779 Added FixIt support to printf format string checking.
- Refactored LengthModifier to be a class.
- Added toString methods in all member classes of FormatSpecifier.
- FixIt suggestions keep user specified flags unless incorrect.

Limitations:
- The suggestions are not conversion specifier sensitive. For example, if we have a 'pad with zeroes' flag, and the correction is a string conversion specifier, we do not remove the flag. Clang will warn us on the next compilation.

A    test/Sema/format-strings-fixit.c
M    include/clang/Analysis/Analyses/PrintfFormatString.h
M    lib/Analysis/PrintfFormatString.cpp
M    lib/Sema/SemaChecking.cpp

llvm-svn: 105680
2010-06-09 04:11:11 +00:00