<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Feb 20, 2015 at 10:51 AM, Duncan P. N. Exon Smith <span dir="ltr"><<a href="mailto:dexonsmith@apple.com" target="_blank">dexonsmith@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br>
> On 2015-Feb-19, at 21:51, David Blaikie <<a href="mailto:dblaikie@gmail.com">dblaikie@gmail.com</a>> wrote:<br>
><br>
><br>
><br>
> On Thu, Feb 19, 2015 at 6:28 PM, Duncan P. N. Exon Smith <<a href="mailto:dexonsmith@apple.com">dexonsmith@apple.com</a>> wrote:<br>
> Author: dexonsmith<br>
> Date: Thu Feb 19 20:28:49 2015<br>
> New Revision: 229953<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=229953&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=229953&view=rev</a><br>
> Log:<br>
> IR: Extract macros from DILocation, NFC<br>
><br>
> `DILocation` is a lightweight wrapper.  Its accessors check for null and<br>
> the correct type, and then forward to `MDLocation`.<br>
><br>
> Extract a couple of macros to do the `dyn_cast_or_null<>`<br>
><br>
> Any evidence that cast_or_null would be insufficient? (this would only occur if we had code actually querying the fields of DILocation that referred to some other metadata node than an MDLocation? That seems like a clear bug - but I could believe we could have such things, I just want to check that that's the case before we settle for code that would allow such bugs if we could avoid having the bar that low at all)<br>
<br>
</span>The bar is *already* set that low.</blockquote><div><br>I know it's set that low in the sense that it's not enforced to be any stronger - but what I meant was: are we actually violating this (does the bar need to be that low today). If, today, we never trigger the assert if we use cast_or_null, I'd be inclined to use that now rather than waiting until later.<br><br>Does it exhibit in existing test cases? (otherwise I wouldn't mind having a test case to demonstrate the problem)<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">  I plan to raise it, but<br>
I'm trying to minimize semantic changes until the new<br>
hierarchy is in place.<br>
<br>
In particular, these should be `cast<>`s (`cast_or_null<>` is<br>
fair too friendly).  Any place that asserts seems like a<br>
clear bug to me (in the exceedingly rare (and possibly non-<br>
existent) case that the caller wants the 0/nullptr/"" value,<br>
the caller should do this check itself).<br>
<div class="HOEnZb"><div class="h5"><br>
><br>
> and default<br>
> return logic.  I'll be using these to minimize error-prone boilerplate<br>
> when I move the new hierarchy into place -- since all the other<br>
> subclasses of `DIDescriptor` will similarly become lightweight wrappers.<br>
><br>
> (Note that I hope to obsolete these wrappers fairly quickly, with the<br>
> goal of renaming the underlying types (e.g., I'll rename `MDLocation` to<br>
> `DILocation` once the name is free).)<br>
><br>
> Modified:<br>
>     llvm/trunk/include/llvm/IR/DebugInfo.h<br>
><br>
> Modified: llvm/trunk/include/llvm/IR/DebugInfo.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/DebugInfo.h?rev=229953&r1=229952&r2=229953&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/DebugInfo.h?rev=229953&r1=229952&r2=229953&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/include/llvm/IR/DebugInfo.h (original)<br>
> +++ llvm/trunk/include/llvm/IR/DebugInfo.h Thu Feb 19 20:28:49 2015<br>
> @@ -252,6 +252,19 @@ public:<br>
>    void replaceAllUsesWith(MDNode *D);<br>
>  };<br>
><br>
> +#define RETURN_FROM_RAW(VALID, DEFAULT)                                        \<br>
> +  do {                                                                         \<br>
> +    if (auto *N = getRaw())                                                    \<br>
> +      return VALID;                                                            \<br>
> +    return DEFAULT;                                                            \<br>
> +  } while (false)<br>
> +#define RETURN_DESCRIPTOR_FROM_RAW(DESC, VALID)                                \<br>
> +  do {                                                                         \<br>
> +    if (auto *N = getRaw())                                                    \<br>
> +      return DESC(dyn_cast_or_null<MDNode>(VALID));                            \<br>
> +    return DESC(static_cast<const MDNode *>(nullptr));                         \<br>
> +  } while (false)<br>
> +<br>
>  /// \brief This is used to represent ranges, for array bounds.<br>
>  class DISubrange : public DIDescriptor {<br>
>    friend class DIDescriptor;<br>
> @@ -933,25 +946,13 @@ class DILocation : public DIDescriptor {<br>
>  public:<br>
>    explicit DILocation(const MDNode *N) : DIDescriptor(N) {}<br>
><br>
> -  unsigned getLineNumber() const {<br>
> -    if (auto *L = getRaw())<br>
> -      return L->getLine();<br>
> -    return 0;<br>
> -  }<br>
> -  unsigned getColumnNumber() const {<br>
> -    if (auto *L = getRaw())<br>
> -      return L->getColumn();<br>
> -    return 0;<br>
> -  }<br>
> +  unsigned getLineNumber() const { RETURN_FROM_RAW(N->getLine(), 0); }<br>
> +  unsigned getColumnNumber() const { RETURN_FROM_RAW(N->getColumn(), 0); }<br>
>    DIScope getScope() const {<br>
> -    if (auto *L = getRaw())<br>
> -      return DIScope(dyn_cast_or_null<MDNode>(L->getScope()));<br>
> -    return DIScope(nullptr);<br>
> +    RETURN_DESCRIPTOR_FROM_RAW(DIScope, N->getScope());<br>
>    }<br>
>    DILocation getOrigLocation() const {<br>
> -    if (auto *L = getRaw())<br>
> -      return DILocation(dyn_cast_or_null<MDNode>(L->getInlinedAt()));<br>
> -    return DILocation(nullptr);<br>
> +    RETURN_DESCRIPTOR_FROM_RAW(DILocation, N->getInlinedAt());<br>
>    }<br>
>    StringRef getFilename() const { return getScope().getFilename(); }<br>
>    StringRef getDirectory() const { return getScope().getDirectory(); }<br>
> @@ -1042,6 +1043,9 @@ public:<br>
>    bool Verify() const;<br>
>  };<br>
><br>
> +#undef RETURN_FROM_RAW<br>
> +#undef RETURN_DESCRIPTOR_FROM_RAW<br>
> +<br>
>  /// \brief Find subprogram that is enclosing this scope.<br>
>  DISubprogram getDISubprogram(const MDNode *Scope);<br>
><br>
><br>
><br>
> _______________________________________________<br>
> llvm-commits mailing list<br>
> <a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
><br>
<br>
</div></div></blockquote></div><br></div></div>