teak-llvm/clang/test/Sema/format-strings-fixit.c
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

45 lines
1.2 KiB
C

// RUN: cp %s %t
// RUN: %clang_cc1 -pedantic -Wall -fixit %t || true
// RUN: %clang_cc1 -fsyntax-only -pedantic -Wall -Werror %t
/* This is a test of the various code modification hints that are
provided as part of warning or extension diagnostics. All of the
warnings will be fixed by -fixit, and the resulting file should
compile cleanly with -Werror -pedantic. */
int printf(char const *, ...);
void test() {
// Basic types
printf("%s", (int) 123);
printf("abc%0f", "testing testing 123");
printf("%u", (long) -12);
printf("%p", 123);
printf("%c\n", "x");
printf("%c\n", 1.23);
// Larger types
printf("%+.2d", (unsigned long long) 123456);
printf("%1d", (long double) 1.23);
// Flag handling
printf("%0+s", (unsigned) 31337); // 0 flag should stay
printf("%#p", (void *) 0);
printf("% +f", 1.23); // + flag should stay
printf("%0-f", 1.23); // - flag should stay
// Positional arguments
printf("%1$f:%2$.*3$f:%4$.*3$f\n", 1, 2, 3, 4);
// Precision
printf("%10.5d", 1l); // (bug 7394)
printf("%.2c", 'a');
// Ignored flags
printf("%0-f", 1.23);
// Bad length modifiers
printf("%hhs", "foo");
printf("%1$zp", (void *)0);
}