From a259671d739a20983ff446facc91aa1c2074b240 Mon Sep 17 00:00:00 2001 From: Mehdi Amini Date: Fri, 7 Oct 2016 08:25:42 +0000 Subject: [PATCH] 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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@283525 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Support/Format.h | 14 +++++++++++++- lib/Target/PowerPC/PPCVSXSwapRemoval.cpp | 3 ++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/include/llvm/Support/Format.h b/include/llvm/Support/Format.h index d5c301cd7e2..026488cc70f 100644 --- a/include/llvm/Support/Format.h +++ b/include/llvm/Support/Format.h @@ -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 struct validate_format_parameters; +template +struct validate_format_parameters { + static_assert(std::is_scalar::value, + "format can't be used with non fundamental / non pointer type"); + validate_format_parameters() { validate_format_parameters(); } +}; +template <> struct validate_format_parameters<> {}; + template class format_object final : public format_object_base { std::tuple 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(); + } int snprint(char *Buffer, unsigned BufferSize) const override { return snprint_tuple(Buffer, BufferSize, index_sequence_for()); diff --git a/lib/Target/PowerPC/PPCVSXSwapRemoval.cpp b/lib/Target/PowerPC/PPCVSXSwapRemoval.cpp index d53c8e38254..8197285b7b1 100644 --- a/lib/Target/PowerPC/PPCVSXSwapRemoval.cpp +++ b/lib/Target/PowerPC/PPCVSXSwapRemoval.cpp @@ -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 ");