Date: Sun, 17 May 2015 20:39:29 +0000 (UTC) From: Dimitry Andric <dim@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org Subject: svn commit: r283037 - in stable/9/contrib/llvm: patches tools/clang/lib/Sema Message-ID: <201505172039.t4HKdTmt097063@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: dim Date: Sun May 17 20:39:29 2015 New Revision: 283037 URL: https://svnweb.freebsd.org/changeset/base/283037 Log: Merge r283036 from stable/10: For clang 3.4.1, when using -fformat-extensions, and warning about the FreeBSD-specific %D and %b printf format specifiers, avoid possible argument overruns. Also reduce the differences with the version added in r280031 (which has been sent upstream). Modified: stable/9/contrib/llvm/patches/patch-r208987-format-extensions.diff stable/9/contrib/llvm/tools/clang/lib/Sema/SemaChecking.cpp Directory Properties: stable/9/contrib/llvm/ (props changed) stable/9/contrib/llvm/tools/clang/ (props changed) Modified: stable/9/contrib/llvm/patches/patch-r208987-format-extensions.diff ============================================================================== --- stable/9/contrib/llvm/patches/patch-r208987-format-extensions.diff Sun May 17 20:38:01 2015 (r283036) +++ stable/9/contrib/llvm/patches/patch-r208987-format-extensions.diff Sun May 17 20:39:29 2015 (r283037) @@ -118,22 +118,25 @@ Index: tools/clang/lib/Sema/SemaChecking =================================================================== --- tools/clang/lib/Sema/SemaChecking.cpp +++ tools/clang/lib/Sema/SemaChecking.cpp -@@ -2980,6 +2980,40 @@ CheckPrintfHandler::HandlePrintfSpecifier(const an +@@ -2980,6 +2980,42 @@ CheckPrintfHandler::HandlePrintfSpecifier(const an CoveredArgs.set(argIndex); } -+ // FreeBSD extensions ++ // FreeBSD kernel extensions. + if (CS.getKind() == ConversionSpecifier::FreeBSDbArg || + CS.getKind() == ConversionSpecifier::FreeBSDDArg) { -+ // claim the second argument ++ // We need at least two arguments. ++ if (!CheckNumArgs(FS, CS, startSpecifier, specifierLen, argIndex + 1)) ++ return false; ++ ++ // Claim the second argument. + CoveredArgs.set(argIndex + 1); + -+ // Now type check the data expression that matches the -+ // format specifier. ++ // Type check the first argument (int for %b, pointer for %D) + const Expr *Ex = getDataArg(argIndex); -+ const analyze_printf::ArgType &AT = ++ const analyze_printf::ArgType &AT = + (CS.getKind() == ConversionSpecifier::FreeBSDbArg) ? -+ ArgType(S.Context.IntTy) : ArgType::CStrTy; ++ ArgType(S.Context.IntTy) : ArgType::CPointerTy; + if (AT.isValid() && !AT.matchesType(S.Context, Ex->getType())) + S.Diag(getLocationOfByte(CS.getStart()), + diag::warn_printf_conversion_argument_type_mismatch) @@ -141,8 +144,7 @@ Index: tools/clang/lib/Sema/SemaChecking + << getSpecifierRange(startSpecifier, specifierLen) + << Ex->getSourceRange(); + -+ // Now type check the data expression that matches the -+ // format specifier. ++ // Type check the second argument (char * for both %b and %D) + Ex = getDataArg(argIndex + 1); + const analyze_printf::ArgType &AT2 = ArgType::CStrTy; + if (AT2.isValid() && !AT2.matchesType(S.Context, Ex->getType())) @@ -163,7 +165,7 @@ Index: tools/clang/lib/Driver/Tools.cpp =================================================================== --- tools/clang/lib/Driver/Tools.cpp +++ tools/clang/lib/Driver/Tools.cpp -@@ -2991,6 +2991,7 @@ void Clang::ConstructJob(Compilation &C, const Job +@@ -2984,6 +2984,7 @@ void Clang::ConstructJob(Compilation &C, const Job // Forward -f (flag) options which we can pass directly. Args.AddLastArg(CmdArgs, options::OPT_femit_all_decls); Modified: stable/9/contrib/llvm/tools/clang/lib/Sema/SemaChecking.cpp ============================================================================== --- stable/9/contrib/llvm/tools/clang/lib/Sema/SemaChecking.cpp Sun May 17 20:38:01 2015 (r283036) +++ stable/9/contrib/llvm/tools/clang/lib/Sema/SemaChecking.cpp Sun May 17 20:39:29 2015 (r283037) @@ -2980,18 +2980,21 @@ CheckPrintfHandler::HandlePrintfSpecifie CoveredArgs.set(argIndex); } - // FreeBSD extensions + // FreeBSD kernel extensions. if (CS.getKind() == ConversionSpecifier::FreeBSDbArg || CS.getKind() == ConversionSpecifier::FreeBSDDArg) { - // claim the second argument + // We need at least two arguments. + if (!CheckNumArgs(FS, CS, startSpecifier, specifierLen, argIndex + 1)) + return false; + + // Claim the second argument. CoveredArgs.set(argIndex + 1); - // Now type check the data expression that matches the - // format specifier. + // Type check the first argument (int for %b, pointer for %D) const Expr *Ex = getDataArg(argIndex); - const analyze_printf::ArgType &AT = + const analyze_printf::ArgType &AT = (CS.getKind() == ConversionSpecifier::FreeBSDbArg) ? - ArgType(S.Context.IntTy) : ArgType::CStrTy; + ArgType(S.Context.IntTy) : ArgType::CPointerTy; if (AT.isValid() && !AT.matchesType(S.Context, Ex->getType())) S.Diag(getLocationOfByte(CS.getStart()), diag::warn_printf_conversion_argument_type_mismatch) @@ -2999,8 +3002,7 @@ CheckPrintfHandler::HandlePrintfSpecifie << getSpecifierRange(startSpecifier, specifierLen) << Ex->getSourceRange(); - // Now type check the data expression that matches the - // format specifier. + // Type check the second argument (char * for both %b and %D) Ex = getDataArg(argIndex + 1); const analyze_printf::ArgType &AT2 = ArgType::CStrTy; if (AT2.isValid() && !AT2.matchesType(S.Context, Ex->getType()))
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201505172039.t4HKdTmt097063>