svn commit: r207121 - in
projects/clangbsd/contrib/llvm/tools/clang:
include/clang/Analysis/Analyses lib/Analysis lib/Sema
Roman Divacky
rdivacky at freebsd.org
Fri Apr 23 16:15:01 UTC 2010
for those interested in reviewing this.
this testcase: http://vlakno.cz/~rdivacky/kprintf.c produces
these warnings: http://vlakno.cz/~rdivacky/kprintf.txt
On Fri, Apr 23, 2010 at 04:13:10PM +0000, Roman Divacky wrote:
> Author: rdivacky
> Date: Fri Apr 23 16:13:09 2010
> New Revision: 207121
> URL: http://svn.freebsd.org/changeset/base/207121
>
> Log:
> Implement FreeBSD printf modifiers - b/D/r
>
> Requested by: kmacy
>
> Modified:
> projects/clangbsd/contrib/llvm/tools/clang/include/clang/Analysis/Analyses/PrintfFormatString.h
> projects/clangbsd/contrib/llvm/tools/clang/lib/Analysis/PrintfFormatString.cpp
> projects/clangbsd/contrib/llvm/tools/clang/lib/Sema/SemaChecking.cpp
>
> Modified: projects/clangbsd/contrib/llvm/tools/clang/include/clang/Analysis/Analyses/PrintfFormatString.h
> ==============================================================================
> --- projects/clangbsd/contrib/llvm/tools/clang/include/clang/Analysis/Analyses/PrintfFormatString.h Fri Apr 23 15:51:13 2010 (r207120)
> +++ projects/clangbsd/contrib/llvm/tools/clang/include/clang/Analysis/Analyses/PrintfFormatString.h Fri Apr 23 16:13:09 2010 (r207121)
> @@ -57,6 +57,7 @@ public:
> InvalidSpecifier = 0,
> // C99 conversion specifiers.
> dArg, // 'd'
> + DArg, // 'D' FreeBSD specific specifiers
> iArg, // 'i',
> oArg, // 'o',
> uArg, // 'u',
> @@ -82,6 +83,7 @@ public:
> ObjCObjArg, // '@'
> // GlibC specific specifiers.
> PrintErrno, // 'm'
> + bArg, // FreeBSD specific specifiers
> // Specifier ranges.
> IntArgBeg = dArg,
> IntArgEnd = iArg,
>
> Modified: projects/clangbsd/contrib/llvm/tools/clang/lib/Analysis/PrintfFormatString.cpp
> ==============================================================================
> --- projects/clangbsd/contrib/llvm/tools/clang/lib/Analysis/PrintfFormatString.cpp Fri Apr 23 15:51:13 2010 (r207120)
> +++ projects/clangbsd/contrib/llvm/tools/clang/lib/Analysis/PrintfFormatString.cpp Fri Apr 23 16:13:09 2010 (r207121)
> @@ -369,11 +369,18 @@ static FormatSpecifierResult ParseFormat
> case '@': k = ConversionSpecifier::ObjCObjArg; break;
> // Glibc specific.
> case 'm': k = ConversionSpecifier::PrintErrno; break;
> + // FreeBSD format extensions
> + case 'b': k = ConversionSpecifier::bArg; break; /* check for int and then char * */
> + case 'r': k = ConversionSpecifier::xArg; break;
> + case 'D': k = ConversionSpecifier::DArg; break; /* check for u_char * pointer and a char * string */
> }
> ConversionSpecifier CS(conversionPosition, k);
> FS.setConversionSpecifier(CS);
> if (CS.consumesDataArgument() && !FS.usesPositionalArg())
> FS.setArgIndex(argIndex++);
> + // FreeBSD extension
> + if (k == ConversionSpecifier::bArg || k == ConversionSpecifier::DArg)
> + argIndex++;
>
> if (k == ConversionSpecifier::InvalidSpecifier) {
> // Assume the conversion takes one argument.
>
> Modified: projects/clangbsd/contrib/llvm/tools/clang/lib/Sema/SemaChecking.cpp
> ==============================================================================
> --- projects/clangbsd/contrib/llvm/tools/clang/lib/Sema/SemaChecking.cpp Fri Apr 23 15:51:13 2010 (r207120)
> +++ projects/clangbsd/contrib/llvm/tools/clang/lib/Sema/SemaChecking.cpp Fri Apr 23 16:13:09 2010 (r207121)
> @@ -1273,6 +1273,39 @@ CheckPrintfHandler::HandleFormatSpecifie
> CoveredArgs.set(argIndex);
> }
>
> + // FreeBSD extensions
> + if (CS.getKind() == ConversionSpecifier::bArg || CS.getKind() == ConversionSpecifier::DArg) {
> + // claim the second argument
> + CoveredArgs.set(argIndex + 1);
> +
> + // Now type check the data expression that matches the
> + // format specifier.
> + const Expr *Ex = getDataArg(argIndex);
> + QualType type = (CS.getKind() == ConversionSpecifier::bArg) ? S.Context.IntTy : S.Context.getPointerType(S.Context.UnsignedCharTy);
> + //const analyze_printf::ArgTypeResult &ATR = S.Context.IntTy;
> + const analyze_printf::ArgTypeResult &ATR = type;
> + if (ATR.isValid() && !ATR.matchesType(S.Context, Ex->getType()))
> + S.Diag(getLocationOfByte(CS.getStart()),
> + diag::warn_printf_conversion_argument_type_mismatch)
> + << ATR.getRepresentativeType(S.Context) << Ex->getType()
> + << getFormatSpecifierRange(startSpecifier, specifierLen)
> + << Ex->getSourceRange();
> +
> + // Now type check the data expression that matches the
> + // format specifier.
> + Ex = getDataArg(argIndex + 1);
> + const analyze_printf::ArgTypeResult &ATR2 = ArgTypeResult::CStrTy;
> + if (ATR2.isValid() && !ATR2.matchesType(S.Context, Ex->getType()))
> + S.Diag(getLocationOfByte(CS.getStart()),
> + diag::warn_printf_conversion_argument_type_mismatch)
> + << ATR2.getRepresentativeType(S.Context) << Ex->getType()
> + << getFormatSpecifierRange(startSpecifier, specifierLen)
> + << Ex->getSourceRange();
> +
> + return true;
> + }
> + // END OF FREEBSD EXTENSIONS
> +
> // Check for using an Objective-C specific conversion specifier
> // in a non-ObjC literal.
> if (!IsObjCLiteral && CS.isObjCArg()) {
More information about the svn-src-projects
mailing list