forked from OSchip/llvm-project
Revert "Revert "Add a static_assert to enforce that parameters to llvm::format() are not totally unsafe""
This reverts commit r283510 and reapply r283509, with updates to clang-tools-extra as well. llvm-svn: 283525
This commit is contained in:
parent
948625633f
commit
9ff8e87ca4
|
@ -777,7 +777,7 @@ void IdentifierNamingCheck::check(const MatchFinder::MatchResult &Result) {
|
|||
DEBUG(llvm::dbgs()
|
||||
<< Decl->getLocStart().printToString(*Result.SourceManager)
|
||||
<< llvm::format(": unable to split words for %s '%s'\n",
|
||||
KindName.c_str(), Name));
|
||||
KindName.c_str(), Name.str().c_str()));
|
||||
}
|
||||
} else {
|
||||
NamingCheckFailure &Failure = NamingCheckFailures[NamingCheckId(
|
||||
|
@ -811,7 +811,7 @@ void IdentifierNamingCheck::checkMacro(SourceManager &SourceMgr,
|
|||
DEBUG(
|
||||
llvm::dbgs() << MacroNameTok.getLocation().printToString(SourceMgr)
|
||||
<< llvm::format(": unable to split words for %s '%s'\n",
|
||||
KindName.c_str(), Name));
|
||||
KindName.c_str(), Name.str().c_str()));
|
||||
}
|
||||
} else {
|
||||
NamingCheckId ID(MI->getDefinitionLoc(), Name);
|
||||
|
|
|
@ -75,6 +75,16 @@ public:
|
|||
/// printed, this synthesizes the string into a temporary buffer provided and
|
||||
/// returns whether or not it is big enough.
|
||||
|
||||
// Helper to validate that format() parameters are scalars or pointers.
|
||||
template <typename... Args> struct validate_format_parameters;
|
||||
template <typename Arg, typename... Args>
|
||||
struct validate_format_parameters<Arg, Args...> {
|
||||
static_assert(std::is_scalar<Arg>::value,
|
||||
"format can't be used with non fundamental / non pointer type");
|
||||
validate_format_parameters() { validate_format_parameters<Args...>(); }
|
||||
};
|
||||
template <> struct validate_format_parameters<> {};
|
||||
|
||||
template <typename... Ts>
|
||||
class format_object final : public format_object_base {
|
||||
std::tuple<Ts...> Vals;
|
||||
|
@ -91,7 +101,9 @@ class format_object final : public format_object_base {
|
|||
|
||||
public:
|
||||
format_object(const char *fmt, const Ts &... vals)
|
||||
: format_object_base(fmt), Vals(vals...) {}
|
||||
: format_object_base(fmt), Vals(vals...) {
|
||||
validate_format_parameters<Ts...>();
|
||||
}
|
||||
|
||||
int snprint(char *Buffer, unsigned BufferSize) const override {
|
||||
return snprint_tuple(Buffer, BufferSize, index_sequence_for<Ts...>());
|
||||
|
|
|
@ -962,7 +962,8 @@ void PPCVSXSwapRemoval::dumpSwapVector() {
|
|||
DEBUG(dbgs() << format("%6d", ID));
|
||||
DEBUG(dbgs() << format("%6d", EC->getLeaderValue(ID)));
|
||||
DEBUG(dbgs() << format(" BB#%3d", MI->getParent()->getNumber()));
|
||||
DEBUG(dbgs() << format(" %14s ", TII->getName(MI->getOpcode())));
|
||||
DEBUG(dbgs() << format(" %14s ",
|
||||
TII->getName(MI->getOpcode()).str().c_str()));
|
||||
|
||||
if (SwapVector[EntryIdx].IsLoad)
|
||||
DEBUG(dbgs() << "load ");
|
||||
|
|
Loading…
Reference in New Issue