[cfe-commits] r149394 - in /cfe/trunk: lib/Sema/SemaChecking.cpp test/Sema/format-strings-scanf.c test/Sema/format-strings.c
Jean-Daniel Dupas
devlists at shadowlab.org
Tue Jan 31 10:12:08 PST 2012
Author: jddupas
Date: Tue Jan 31 12:12:08 2012
New Revision: 149394
URL: http://llvm.org/viewvc/llvm-project?rev=149394&view=rev
Log:
FormatCheckers should emit all diagnostics using EmitFormatDiagnostic().
Modified:
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/Sema/format-strings-scanf.c
cfe/trunk/test/Sema/format-strings.c
Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=149394&r1=149393&r2=149394&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Tue Jan 31 12:12:08 2012
@@ -2198,11 +2198,14 @@
os.str()));
}
else {
- S.Diag(getLocationOfByte(CS.getStart()),
- diag::warn_printf_conversion_argument_type_mismatch)
- << ATR.getRepresentativeTypeName(S.Context) << Ex->getType()
- << getSpecifierRange(startSpecifier, specifierLen)
- << Ex->getSourceRange();
+ EmitFormatDiagnostic(
+ S.PDiag(diag::warn_printf_conversion_argument_type_mismatch)
+ << ATR.getRepresentativeTypeName(S.Context) << Ex->getType()
+ << getSpecifierRange(startSpecifier, specifierLen)
+ << Ex->getSourceRange(),
+ getLocationOfByte(CS.getStart()),
+ true,
+ getSpecifierRange(startSpecifier, specifierLen));
}
}
@@ -2313,12 +2316,13 @@
// Check the length modifier is valid with the given conversion specifier.
const LengthModifier &LM = FS.getLengthModifier();
if (!FS.hasValidLengthModifier()) {
- S.Diag(getLocationOfByte(LM.getStart()),
- diag::warn_format_nonsensical_length)
- << LM.toString() << CS.toString()
- << getSpecifierRange(startSpecifier, specifierLen)
- << FixItHint::CreateRemoval(getSpecifierRange(LM.getStart(),
- LM.getLength()));
+ const CharSourceRange &R = getSpecifierRange(LM.getStart(), LM.getLength());
+ EmitFormatDiagnostic(S.PDiag(diag::warn_format_nonsensical_length)
+ << LM.toString() << CS.toString()
+ << getSpecifierRange(startSpecifier, specifierLen),
+ getLocationOfByte(LM.getStart()),
+ /*IsStringLocation*/true, R,
+ FixItHint::CreateRemoval(R));
}
// The remaining checks depend on the data arguments.
@@ -2352,11 +2356,13 @@
getSpecifierRange(startSpecifier, specifierLen),
os.str()));
} else {
- S.Diag(getLocationOfByte(CS.getStart()),
- diag::warn_printf_conversion_argument_type_mismatch)
+ EmitFormatDiagnostic(
+ S.PDiag(diag::warn_printf_conversion_argument_type_mismatch)
<< ATR.getRepresentativeTypeName(S.Context) << Ex->getType()
- << getSpecifierRange(startSpecifier, specifierLen)
- << Ex->getSourceRange();
+ << Ex->getSourceRange(),
+ getLocationOfByte(CS.getStart()),
+ /*IsStringLocation*/true,
+ getSpecifierRange(startSpecifier, specifierLen));
}
}
Modified: cfe/trunk/test/Sema/format-strings-scanf.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/format-strings-scanf.c?rev=149394&r1=149393&r2=149394&view=diff
==============================================================================
--- cfe/trunk/test/Sema/format-strings-scanf.c (original)
+++ cfe/trunk/test/Sema/format-strings-scanf.c Tue Jan 31 12:12:08 2012
@@ -53,6 +53,10 @@
const char kFormat2[] = "%["; // expected-note{{format string is defined here}}}
scanf(kFormat2, str); // expected-warning{{no closing ']' for '%[' in scanf format string}}
scanf("%[", str); // expected-warning{{no closing ']' for '%[' in scanf format string}}
+ const char kFormat3[] = "%hu"; // expected-note{{format string is defined here}}}
+ scanf(kFormat3, &i); // expected-warning {{format specifies type 'unsigned short *' but the argument}}
+ const char kFormat4[] = "%lp"; // expected-note{{format string is defined here}}}
+ scanf(kFormat4, &i); // expected-warning {{length modifier 'l' results in undefined behavior or no effect with 'p' conversion specifier}}
}
void test_variants(int *i, const char *s, ...) {
Modified: cfe/trunk/test/Sema/format-strings.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/format-strings.c?rev=149394&r1=149393&r2=149394&view=diff
==============================================================================
--- cfe/trunk/test/Sema/format-strings.c (original)
+++ cfe/trunk/test/Sema/format-strings.c Tue Jan 31 12:12:08 2012
@@ -468,6 +468,9 @@
// Make sure that the "format string is defined here" note is not emitted
// when the original string is within the argument expression.
printf(1 ? "yes %d" : "no %d"); // expected-warning 2{{more '%' conversions than data arguments}}
+
+ const char kFormat17[] = "%hu"; // expected-note{{format string is defined here}}}
+ printf(kFormat17, (int[]){0}); // expected-warning{{format specifies type 'unsigned short' but the argument}}
}
// PR 9466: clang: doesn't know about %Lu, %Ld, and %Lx
More information about the cfe-commits
mailing list