diff options
author | rdivacky <rdivacky@FreeBSD.org> | 2010-06-10 16:13:32 +0000 |
---|---|---|
committer | rdivacky <rdivacky@FreeBSD.org> | 2010-06-10 16:13:32 +0000 |
commit | 970bcaaade62f997fe73cc23cab599c5b941ce93 (patch) | |
tree | 76a7a5a5050a10cbf87b2fd97e3018f723a711a7 /contrib/llvm/tools/clang/lib/Sema/SemaChecking.cpp | |
parent | fb808063cd6ca3766528a3fd83fb51fb7070200d (diff) | |
download | FreeBSD-src-970bcaaade62f997fe73cc23cab599c5b941ce93.zip FreeBSD-src-970bcaaade62f997fe73cc23cab599c5b941ce93.tar.gz |
Introduce -fformat-extensions. A local FreeBSD extension used
for additional printf modifiers in kernel.
Approved by: ed (mentor)
Diffstat (limited to 'contrib/llvm/tools/clang/lib/Sema/SemaChecking.cpp')
-rw-r--r-- | contrib/llvm/tools/clang/lib/Sema/SemaChecking.cpp | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/contrib/llvm/tools/clang/lib/Sema/SemaChecking.cpp b/contrib/llvm/tools/clang/lib/Sema/SemaChecking.cpp index 4f3f41b..6fc36c2 100644 --- a/contrib/llvm/tools/clang/lib/Sema/SemaChecking.cpp +++ b/contrib/llvm/tools/clang/lib/Sema/SemaChecking.cpp @@ -1276,6 +1276,39 @@ CheckPrintfHandler::HandleFormatSpecifier(const analyze_printf::FormatSpecifier 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()) { @@ -1400,7 +1433,8 @@ void Sema::CheckPrintfString(const StringLiteral *FExpr, isa<ObjCStringLiteral>(OrigFormatExpr), Str, HasVAListArg, TheCall, format_idx); - if (!analyze_printf::ParseFormatString(H, Str, Str + StrLen)) + bool FormatExtensions = getLangOptions().FormatExtensions; + if (!analyze_printf::ParseFormatString(H, Str, Str + StrLen, FormatExtensions)) H.DoneProcessing(); } |