<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=""><br class=""><div><blockquote type="cite" class=""><div class="">On Oct 26, 2016, at 3:11 PM, David Blaikie <<a href="mailto:dblaikie@gmail.com" class="">dblaikie@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" 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-stroke-width: 0px;" class=""><br class=""><br class=""><div class="gmail_quote"><div dir="ltr" class="">On Wed, Oct 26, 2016 at 3:08 PM Adrian Prantl <<a href="mailto:aprantl@apple.com" class="">aprantl@apple.com</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;">aprantl added inline comments.<br class="gmail_msg"><br class="gmail_msg"><br class="gmail_msg">================<br class="gmail_msg">Comment at: lib/DebugInfo/DWARF/DWARFFormValue.cpp:126<br class="gmail_msg">     return (FC == FC_String);<br class="gmail_msg">+  default:<br class="gmail_msg">+    break;<br class="gmail_msg">----------------<br class="gmail_msg">Here's an idea: How about adding a<br class="gmail_msg">```<br class="gmail_msg">template<typename EnumType><br class="gmail_msg">llvm::Optional<EnumType><br class="gmail_msg">getULEB128AsEnum() {<br class="gmail_msg"> <span class="Apple-converted-space"> </span>// Decode ULEB.<br class="gmail_msg"> <span class="Apple-converted-space"> </span>uint64_t Val = ...; // what about larger values?<br class="gmail_msg"> <span class="Apple-converted-space"> </span>if (Val >= EnumType::getMinValue() && Val <= EnumType::getMaxValue())<br class="gmail_msg">   <span class="Apple-converted-space"> </span>return static_cast<EnumType>(Val);<br class="gmail_msg"> <span class="Apple-converted-space"> </span>return None;<br class="gmail_msg">}<br class="gmail_msg">```<br class="gmail_msg">?<br class="gmail_msg"><br class="gmail_msg">This way we could guarantee that on of the enums if it is passed as an enum is always well-formed. Then we would never need a default case in a switch over a dwarf enum and could benefit from the not-all-enum-cases-covered-by-switch warning.<br class="gmail_msg"><br class="gmail_msg">Is that feasible?<br class="gmail_msg"></blockquote><div class=""><br class="">There's no nice way to get the min/max values of an enum (well, not of the enumerators - of the representable range, yes - which is actually probably what we want, but then we still have the issue with switches, etc).<br class=""></div></div></div></div></blockquote>Something like this seems to at least compile:<br class=""><div><br class=""></div><div><div><font face="Menlo" class="">enum class A : int { min, a0 = min, a1, a2, max = a2 };</font></div><div><font face="Menlo" class="">enum class B : int { min, b0 = min, b1, b2, b3, max = b3 };</font></div><div><font face="Menlo" class=""><br class=""></font></div><div><font face="Menlo" class="">template <typename EnumType> EnumType cast(int i) {</font></div><div><font face="Menlo" class="">  if (i >= (int)EnumType::min && i <= (int)EnumType::max)</font></div><div><font face="Menlo" class="">    return static_cast<EnumType>(i);</font></div><div><font face="Menlo" class="">  return static_cast<EnumType>(0);</font></div><div><font face="Menlo" class="">}</font></div><div><font face="Menlo" class=""><br class=""></font></div><div><font face="Menlo" class="">void f(int i) {</font></div><div><font face="Menlo" class="">  auto a = cast<A>(i);</font></div><div><font face="Menlo" class="">  auto b = cast<B>(i);</font></div><div><font face="Menlo" class="">}</font></div></div><div><br class=""></div><div>But, you are right, I completely forgot about holes in the enumerators (which exist in some places for backwards compatibility reasons) and the user space ranges.</div><div><br class=""></div><blockquote type="cite" class=""><div class=""><div dir="ltr" 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-stroke-width: 0px;" class=""><div class="gmail_quote"><div class=""><br class="">If that makes sense, (see my reply for another way we might be able to deal with the switch-covered-default warning by adding the enumerator for the implementation defined range and just never specifying that value in a switch)<br class=""><br class=""></div></div></div></div></blockquote><div><br class=""></div><div>That could work (save for the holes, but we could define placeholder enumerators there).</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" 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-stroke-width: 0px;" class=""><div class="gmail_quote"><div class="">- Dave<br class=""> </div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><br class="gmail_msg"><br class="gmail_msg">Repository:<br class="gmail_msg"> <span class="Apple-converted-space"> </span>rL LLVM<br class="gmail_msg"><br class="gmail_msg"><a href="https://reviews.llvm.org/D26013" rel="noreferrer" class="gmail_msg" target="_blank">https://reviews.llvm.org/D26013</a></blockquote></div></div></div></blockquote></div><br class=""></body></html>