<div dir="ltr"><div>On Tue, Sep 20, 2016 at 4:37 PM, Ted Woodward via lldb-dev <span dir="ltr"><<a href="mailto:lldb-dev@lists.llvm.org" target="_blank">lldb-dev@lists.llvm.org</a>></span> wrote:<br></div><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
From: lldb-dev [mailto:<a href="mailto:lldb-dev-bounces@lists.llvm.org">lldb-dev-bounces@<wbr>lists.llvm.org</a>] On Behalf Of Zachary Turner via lldb-dev<br>
Sent: Tuesday, September 20, 2016 12:47 PM<br>
<span class=""><br>
> This kind of philisophical debate is probably worthy of a separate thread :)  That being said, I think asserts are typically used in places where the assert firing means "You're going to crash *anyway*"<br>
<br>
</span>This is emphatically NOT the case.<br>
<br>
One of the first tasks I was given when I started at Qualcomm was to fix the disassembler for Hexagon. It was a mess - it would assert if the disassembly tables couldn't identify an opcode. Maybe that's fine for an assembler, assert if you can't generate an opcode, but an unidentified opcode should print a warning and move on. It's not a fatal error to disassemble data!<br>
<br>
There are other instances of this in llvm. I agree with Greg - libraries shouldn't assert.  Send an error back to the caller, and let the caller handle it. A typo in my expression that lldb sends to clang shouldn't crash my debug session.<br></blockquote><div><br></div><div>It depends on what you use the assert for, right? If it's used to document invariants that you control, then having them crash is ok, since those should always be true. You shouldn't assert on input you don't control.</div><div><br></div><div>So in a public api, you'd do:</div><div><br></div><div>my_err my_public_api(int p) {</div><div>  if (p < 0 || p > 10) {</div><div>    return make_err("p must be between 0 and 10");</div><div>  internal_fun(p);</div><div>}</div><div><br></div><div>But then in internal_fun you can do</div><div><br></div><div>void internal_fun(int p) {</div><div>  assert((p >= 0 && p <= 10) && "must pass correct p");</div><div>}</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
--<br>
Qualcomm Innovation Center, Inc.<br>
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
______________________________<wbr>_________________<br>
lldb-dev mailing list<br>
<a href="mailto:lldb-dev@lists.llvm.org">lldb-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/lldb-dev</a><br>
</div></div></blockquote></div><br></div></div>