<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">I committed a fix in r295675 to fix the bot. I change the function prototype to:<div class="">std::pair<std::string, std::string> getCounterInfo(unsigned ID) const;</div><div class="">I am not quite sure why I get junk if I print the option name returned as StringRef so I change that to std::string as well. </div><div class=""><br class=""></div><div class="">Steven</div><div class=""><br class=""></div><div class=""><div><blockquote type="cite" class=""><div class="">On Feb 20, 2017, at 10:14 AM, Steven Wu via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org" class="">llvm-commits@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">Hi Daniel</span><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class=""></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;">This commit is causing ASAN failure due to use after free:</div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><a href="http://lab.llvm.org:8080/green/job/clang-stage2-cmake-RgSan_check/2998/" class="">http://lab.llvm.org:8080/green/job/clang-stage2-cmake-RgSan_check/2998/</a></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class=""></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Feb 18, 2017, at 8:29 PM, Daniel Berlin via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org" class="">llvm-commits@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">Author: dannyb<br class="">Date: Sat Feb 18 22:29:50 2017<br class="">New Revision: 295595<br class=""><br class="">URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project?rev=295595&view=rev" class="">http://llvm.org/viewvc/llvm-project?rev=295595&view=rev</a><br class="">Log:<br class="">Add two files lost in rebase, causing build break<br class=""><br class="">Added:<br class=""> llvm/trunk/include/llvm/Support/DebugCounter.h<br class=""> llvm/trunk/lib/Support/DebugCounter.cpp<br class=""><br class="">Added: llvm/trunk/include/llvm/Support/DebugCounter.h<br class="">URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/DebugCounter.h?rev=295595&view=auto" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/DebugCounter.h?rev=295595&view=auto</a><br class="">==============================================================================<br class="">--- llvm/trunk/include/llvm/Support/DebugCounter.h (added)<br class="">+++ llvm/trunk/include/llvm/Support/DebugCounter.h Sat Feb 18 22:29:50 2017<br class="">@@ -0,0 +1,141 @@<br class="">+//===- llvm/Support/DebugCounter.h - Debug counter support ------*- C++ -*-===//<br class="">+//<br class="">+// The LLVM Compiler Infrastructure<br class="">+//<br class="">+// This file is distributed under the University of Illinois Open Source<br class="">+// License. See LICENSE.TXT for details.<br class="">+//<br class="">+//===----------------------------------------------------------------------===//<br class="">+// \file This file provides an implementation of debug counters. Debug counters<br class="">+// are a tool that let you narrow down a miscompilation to a specific thing<br class="">+// happening. To give a use case: Imagine you have a file, very large, and you<br class="">+// are trying to understand the minimal transformation that breaks it. Bugpoint<br class="">+// and bisection is often helpful here in narrowing it down to a specific pass,<br class="">+// but it's still a very large file, and a very complicated pass to try to<br class="">+// debug. That is where debug counting steps in. You can instrument the pass<br class="">+// with a debug counter before it does a certain thing, and depending on the<br class="">+// counts, it will either execute that thing or not. The debug counter itself<br class="">+// consists of a skip and a count. Skip is the number of times shouldExecute<br class="">+// needs to be called before it returns true. Count is the number of times to<br class="">+// return true once Skip is 0. So a skip=47, count=2 ,would skip the first 47<br class="">+// executions by returning false from shouldExecute, then execute twice, and<br class="">+// then return false again.<br class="">+// Note that a counter set to a negative number will always execute.<br class="">+<br class="">+// For a concrete example, during predicateinfo creation, the renaming pass<br class="">+// replaces each use with a renamed use.<br class="">+///<br class="">+// If I use DEBUG_COUNTER to create a counter called "predicateinfo", and<br class="">+// variable name RenameCounter, and then instrument this renaming with a debug<br class="">+// counter, like so:<br class="">+//<br class="">+// if (!DebugCounter::shouldExecute(RenameCounter)<br class="">+// <continue or return or whatever not executing looks like><br class="">+//<br class="">+// Now I can, from the command line, make it rename or not rename certain uses<br class="">+// by setting the skip and count.<br class="">+// So for example<br class="">+// bin/opt -debug-counter=predicateinfo-skip=47,predicateinfo-count=1<br class="">+// will skip renaming the first 47 uses, then rename one, then skip the rest.<br class="">+<br class="">+#ifndef LLVM_SUPPORT_DEBUGCOUNTER_H<br class="">+#define LLVM_SUPPORT_DEBUGCOUNTER_H<br class="">+<br class="">+#include "llvm/ADT/DenseMap.h"<br class="">+#include "llvm/ADT/UniqueVector.h"<br class="">+#include "llvm/Support/CommandLine.h"<br class="">+#include "llvm/Support/Debug.h"<br class="">+#include "llvm/Support/raw_ostream.h"<br class="">+#include <string><br class="">+<br class="">+namespace llvm {<br class="">+<br class="">+class DebugCounter {<br class="">+public:<br class="">+ /// \brief Returns a reference to the singleton instance.<br class="">+ static DebugCounter &instance();<br class="">+<br class="">+ // Used by the command line option parser to push a new value it parsed.<br class="">+ void push_back(const std::string &);<br class="">+<br class="">+ // Register a counter with the specified name.<br class="">+ //<br class="">+ // FIXME: Currently, counter registration is required to happen before command<br class="">+ // line option parsing. The main reason to register counters is to produce a<br class="">+ // nice list of them on the command line, but i'm not sure this is worth it.<br class="">+ static unsigned registerCounter(StringRef Name, StringRef Desc) {<br class="">+ return instance().addCounter(Name, Desc);<br class="">+ }<br class="">+ inline static bool shouldExecute(unsigned CounterName) {<br class="">+// Compile to nothing when debugging is off<br class="">+#ifdef NDEBUG<br class="">+ return true;<br class="">+#else<br class="">+ auto &Us = instance();<br class="">+ auto Result = Us.Counters.find(CounterName);<br class="">+ if (Result != Us.Counters.end()) {<br class="">+ auto &CounterPair = Result->second;<br class="">+ // We only execute while the skip (first) is zero and the count (second)<br class="">+ // is non-zero.<br class="">+ // Negative counters always execute.<br class="">+ if (CounterPair.first < 0)<br class="">+ return true;<br class="">+ if (CounterPair.first != 0) {<br class="">+ --CounterPair.first;<br class="">+ return false;<br class="">+ }<br class="">+ if (CounterPair.second < 0)<br class="">+ return true;<br class="">+ if (CounterPair.second != 0) {<br class="">+ --CounterPair.second;<br class="">+ return true;<br class="">+ }<br class="">+ return false;<br class="">+ }<br class="">+ // Didn't find the counter, should we warn?<br class="">+ return true;<br class="">+#endif // NDEBUG<br class="">+ }<br class="">+<br class="">+ // Dump or print the current counter set.<br class="">+ LLVM_DUMP_METHOD void dump() { print(dbgs()); }<br class="">+<br class="">+ void print(raw_ostream &OS);<br class="">+ <br class="">+ // Get the counter ID for a given named counter, or return 0 if none is found.<br class="">+ unsigned getCounterId(const std::string &Name) const {<br class="">+ return RegisteredCounters.idFor(Name);<br class="">+ }<br class="">+<br class="">+ // Return the number of registered counters.<br class="">+ unsigned int getNumCounters() const { return RegisteredCounters.size(); }<br class="">+<br class="">+ // Return the name and description of the counter with the given ID.<br class="">+ std::pair<StringRef, StringRef> getCounterInfo(unsigned ID) const {<br class="">+ return std::make_pair(RegisteredCounters[ID], CounterDesc.lookup(ID));<br class=""></div></div></blockquote><div class=""><br class=""></div><div class="">DenseMap::lookup returns a copy of the std::string in the map. You cannot return a StringRef pointing to the temp string whose life time ends after this statement.</div><div class=""><br class=""></div><div class="">Thanks</div><div class=""><br class=""></div><div class="">Steven</div><br class=""><blockquote type="cite" class=""><div class=""><div class="">+ }<br class="">+<br class="">+ // Iterate through the registered counters<br class="">+ typedef UniqueVector<std::string> CounterVector;<br class="">+ CounterVector::const_iterator begin() const {<br class="">+ return RegisteredCounters.begin();<br class="">+ }<br class="">+ CounterVector::const_iterator end() const { return RegisteredCounters.end(); }<br class="">+<br class="">+private:<br class="">+ unsigned addCounter(const std::string &Name, const std::string &Desc) {<br class="">+ unsigned Result = RegisteredCounters.insert(Name);<br class="">+ CounterDesc[Result] = Desc;<br class="">+ return Result;<br class="">+ }<br class="">+ DenseMap<unsigned, std::pair<long, long>> Counters;<br class="">+ DenseMap<unsigned, std::string> CounterDesc;<br class="">+ CounterVector RegisteredCounters;<br class="">+};<br class="">+<br class="">+#define DEBUG_COUNTER(VARNAME, COUNTERNAME, DESC) \<br class="">+ static const unsigned VARNAME = \<br class="">+ DebugCounter::registerCounter(COUNTERNAME, DESC);<br class="">+<br class="">+} // namespace llvm<br class="">+#endif<br class=""><br class="">Added: llvm/trunk/lib/Support/DebugCounter.cpp<br class="">URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/DebugCounter.cpp?rev=295595&view=auto" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/DebugCounter.cpp?rev=295595&view=auto</a><br class="">==============================================================================<br class="">--- llvm/trunk/lib/Support/DebugCounter.cpp (added)<br class="">+++ llvm/trunk/lib/Support/DebugCounter.cpp Sat Feb 18 22:29:50 2017<br class="">@@ -0,0 +1,108 @@<br class="">+#include "llvm/Support/DebugCounter.h"<br class="">+#include "llvm/Support/CommandLine.h"<br class="">+#include "llvm/Support/Format.h"<br class="">+#include "llvm/Support/ManagedStatic.h"<br class="">+#include "llvm/Support/Options.h"<br class="">+<br class="">+using namespace llvm;<br class="">+<br class="">+// This class overrides the default list implementation of printing so we<br class="">+// can pretty print the list of debug counter options. This type of<br class="">+// dynamic option is pretty rare (basically this and pass lists).<br class="">+class DebugCounterList : public cl::list<std::string, DebugCounter> {<br class="">+private:<br class="">+ using Base = cl::list<std::string, DebugCounter>;<br class="">+<br class="">+public:<br class="">+ template <class... Mods><br class="">+ explicit DebugCounterList(Mods &&... Ms) : Base(std::forward<Mods>(Ms)...) {}<br class="">+<br class="">+private:<br class="">+ void printOptionInfo(size_t GlobalWidth) const override {<br class="">+ // This is a variant of from generic_parser_base::printOptionInfo. Sadly,<br class="">+ // it's not easy to make it more usable. We could get it to print these as<br class="">+ // options if we were a cl::opt and registered them, but lists don't have<br class="">+ // options, nor does the parser for std::string. The other mechanisms for<br class="">+ // options are global and would pollute the global namespace with our<br class="">+ // counters. Rather than go that route, we have just overridden the<br class="">+ // printing, which only a few things call anyway.<br class="">+ outs() << " -" << ArgStr;<br class="">+ // All of the other options in CommandLine.cpp use ArgStr.size() + 6 for<br class="">+ // width, so we do the same.<br class="">+ Option::printHelpStr(HelpStr, GlobalWidth, ArgStr.size() + 6);<br class="">+ const auto &CounterInstance = DebugCounter::instance();<br class="">+ for (auto Name : CounterInstance) {<br class="">+ const auto Info =<br class="">+ CounterInstance.getCounterInfo(CounterInstance.getCounterId(Name));<br class="">+ size_t NumSpaces = GlobalWidth - Info.first.size() - 8;<br class="">+ outs() << " =" << Info.first;<br class="">+ outs().indent(NumSpaces) << " - " << Info.second << '\n';<br class="">+ }<br class="">+ }<br class="">+};<br class="">+<br class="">+// Create our command line option.<br class="">+static DebugCounterList DebugCounterOption(<br class="">+ "debug-counter",<br class="">+ cl::desc("Comma separated list of debug counter skip and count"),<br class="">+ cl::CommaSeparated, cl::ZeroOrMore, cl::location(DebugCounter::instance()));<br class="">+<br class="">+static ManagedStatic<DebugCounter> DC;<br class="">+<br class="">+DebugCounter &DebugCounter::instance() { return *DC; }<br class="">+<br class="">+// This is called by the command line parser when it sees a value for the<br class="">+// debug-counter option defined above.<br class="">+void DebugCounter::push_back(const std::string &Val) {<br class="">+ if (Val.empty())<br class="">+ return;<br class="">+ // The strings should come in as counter=value<br class="">+ auto CounterPair = StringRef(Val).split('=');<br class="">+ if (CounterPair.second.empty()) {<br class="">+ errs() << "DebugCounter Error: " << Val << " does not have an = in it\n";<br class="">+ return;<br class="">+ }<br class="">+ // Now we have counter=value.<br class="">+ // First, process value.<br class="">+ long CounterVal;<br class="">+ if (CounterPair.second.getAsInteger(0, CounterVal)) {<br class="">+ errs() << "DebugCounter Error: " << CounterPair.second<br class="">+ << " is not a number\n";<br class="">+ return;<br class="">+ }<br class="">+ // Now we need to see if this is the skip or the count, remove the suffix, and<br class="">+ // add it to the counter values.<br class="">+ if (CounterPair.first.endswith("-skip")) {<br class="">+ auto CounterName = CounterPair.first.drop_back(5);<br class="">+ unsigned CounterID = RegisteredCounters.idFor(CounterName);<br class="">+ if (!CounterID) {<br class="">+ errs() << "DebugCounter Error: " << CounterName<br class="">+ << " is not a registered counter\n";<br class="">+ return;<br class="">+ }<br class="">+<br class="">+ auto Res = Counters.insert({CounterID, {-1, -1}});<br class="">+ Res.first->second.first = CounterVal;<br class="">+ } else if (CounterPair.first.endswith("-count")) {<br class="">+ auto CounterName = CounterPair.first.drop_back(6);<br class="">+ unsigned CounterID = RegisteredCounters.idFor(CounterName);<br class="">+ if (!CounterID) {<br class="">+ errs() << "DebugCounter Error: " << CounterName<br class="">+ << " is not a registered counter\n";<br class="">+ return;<br class="">+ }<br class="">+<br class="">+ auto Res = Counters.insert({CounterID, {-1, -1}});<br class="">+ Res.first->second.second = CounterVal;<br class="">+ } else {<br class="">+ errs() << "DebugCounter Error: " << CounterPair.first<br class="">+ << " does not end with -skip or -count\n";<br class="">+ }<br class="">+}<br class="">+<br class="">+void DebugCounter::print(raw_ostream &OS) {<br class="">+ OS << "Counters and values:\n";<br class="">+ for (const auto &KV : Counters)<br class="">+ OS << left_justify(RegisteredCounters[KV.first], 32) << ": {"<br class="">+ << KV.second.first << "," << KV.second.second << "}\n";<br class="">+}<br class=""><br class=""><br class="">_______________________________________________<br class="">llvm-commits mailing list<br class=""><a href="mailto:llvm-commits@lists.llvm.org" class="">llvm-commits@lists.llvm.org</a><br class=""><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br class=""></div></div></blockquote></div><br class=""></div><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">_______________________________________________</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">llvm-commits mailing list</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="mailto:llvm-commits@lists.llvm.org" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">llvm-commits@lists.llvm.org</a><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a></div></blockquote></div><br class=""></div></body></html>