<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Sun, May 13, 2018 at 9:01 AM, Martin Pelikán <span dir="ltr"><<a href="mailto:mpel@google.com" target="_blank">mpel@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">After bebe3d626e5, b->fail_jump is prepared after vtn_create_builder<br>
which can longjmp(3) to it through its vtx_assert()s.  This corrupts<br>
the stack and creates confusing core dumps, so we need to avoid it.<br>
<br>
While there, I decided to print the offending values for debugability.<br>
---<br>
 src/compiler/spirv/spirv_to_<wbr>nir.c | 26 +++++++++++++++++++++-----<br>
 1 file changed, 21 insertions(+), 5 deletions(-)<br>
<br>
diff --git a/src/compiler/spirv/spirv_to_<wbr>nir.c b/src/compiler/spirv/spirv_to_<wbr>nir.c<br>
index 78437428aa..a05364ba2f 100644<br>
--- a/src/compiler/spirv/spirv_to_<wbr>nir.c<br>
+++ b/src/compiler/spirv/spirv_to_<wbr>nir.c<br>
@@ -4011,19 +4011,35 @@ vtn_create_builder(const uint32_t *words, size_t word_count,<br>
    b->entry_point_name = entry_point_name;<br>
    b->options = options;<br>
<br>
-   /* Handle the SPIR-V header (first 4 dwords)  */<br>
-   vtn_assert(word_count > 5);<br>
+   /*<br>
+    * Handle the SPIR-V header (first 4 dwords).<br>
+    * Can't use vtx_assert() as the setjmp(3) target isn't initialized yet.<br>
+    */<br>
+   if (word_count <= 5)<br>
+      goto fail;<br>
<br>
-   vtn_assert(words[0] == SpvMagicNumber);<br>
-   vtn_assert(words[1] >= 0x10000);<br>
+   if (words[0] != SpvMagicNumber) {<br>
+      vtn_warn("words[0] was 0x%x, want 0x%x", words[0], SpvMagicNumber);<br>
+      goto fail;<br>
+   }<br>
+   if (words[1] < 0x10000) {<br>
+      vtn_warn("words[1] was 0x%x, want >= 0x10000", words[1]);<br>
+      goto fail;<br>
+   }<br>
    /* words[2] == generator magic */<br>
    unsigned value_id_bound = words[3];<br>
-   vtn_assert(words[4] == 0);<br>
+   if (words[4] != 0) {<br>
+      vtn_warn("words[4] was %u, want 0", words[4]);<br></blockquote><div><br></div><div>I think using vtn_log_error directly would be more appropriate so that we can log it with DEBUG_LEVEL_ERROR.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+      goto fail;<br>
+   }<br>
<br>
    b->value_id_bound = value_id_bound;<br>
    b->values = rzalloc_array(b, struct vtn_value, value_id_bound);<br>
<br>
    return b;<br>
+ fail:<br>
+   ralloc_free(b);<br>
+   return NULL;<br>
 }<br>
<br>
 nir_function *<br>
<span class="HOEnZb"><font color="#888888">-- <br>
2.17.0.441.gb46fe60e1d-goog<br>
<br>
</font></span></blockquote></div><br></div></div>