<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Feb 19, 2015 at 6:28 PM, 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">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<>` </blockquote><div><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> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">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>
</blockquote></div><br></div></div>