зеркало из https://github.com/microsoft/clang-1.git
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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@106275 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
23d90f9041
Коммит
4c60219950
|
@ -166,6 +166,7 @@ public:
|
|||
default:
|
||||
return 1;
|
||||
case AsLongLong:
|
||||
case AsChar:
|
||||
return 2;
|
||||
case None:
|
||||
return 0;
|
||||
|
@ -218,12 +219,13 @@ public:
|
|||
}
|
||||
|
||||
const char *getStart() const {
|
||||
return start;
|
||||
// We include the . character if it is given.
|
||||
return start - UsesDotPrefix;
|
||||
}
|
||||
|
||||
unsigned getConstantLength() const {
|
||||
assert(hs == Constant);
|
||||
return length;
|
||||
return length + UsesDotPrefix;
|
||||
}
|
||||
|
||||
ArgTypeResult getArgType(ASTContext &Ctx) const;
|
||||
|
|
|
@ -611,20 +611,21 @@ const char *LengthModifier::toString() const {
|
|||
//===----------------------------------------------------------------------===//
|
||||
|
||||
void OptionalAmount::toString(llvm::raw_ostream &os) const {
|
||||
if (UsesDotPrefix)
|
||||
os << ".";
|
||||
|
||||
switch (hs) {
|
||||
case Invalid:
|
||||
case NotSpecified:
|
||||
return;
|
||||
case Arg:
|
||||
if (UsesDotPrefix)
|
||||
os << ".";
|
||||
if (usesPositionalArg())
|
||||
os << "*" << getPositionalArgIndex() << "$";
|
||||
else
|
||||
os << "*";
|
||||
break;
|
||||
case Constant:
|
||||
if (UsesDotPrefix)
|
||||
os << ".";
|
||||
os << amt;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
// RUN: cp %s %t
|
||||
// RUN: %clang_cc1 -pedantic -Wall -fixit %t || true
|
||||
// RUN: %clang_cc1 -fsyntax-only -pedantic -Wall -Werror %t
|
||||
// XFAIL: *
|
||||
// FIXME: Some of these tests currently fail due to a bug in the HighlightRange
|
||||
// function in lib/Frontend/TextDiagnosticPrinter.cpp.
|
||||
|
||||
/* This is a test of the various code modification hints that are
|
||||
provided as part of warning or extension diagnostics. All of the
|
||||
|
@ -25,7 +28,19 @@ void test() {
|
|||
// Flag handling
|
||||
printf("%0+s", (unsigned) 31337); // flags should stay
|
||||
printf("%0f", "test"); // flag should be removed
|
||||
printf("%#p", (void *) 0);
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче