<div dir="ltr">Interesting. I seem to remember fixing a bug where we were accidentally adding null users for real, but i honestly can't remember if it ever made it into trunk or was just in a local dev branch of mine.<div><div><br></div></div><div>In any case, you should be able to catch whatever is doing this by adding an assert in addAdditionalUsers.</div><div><div><br></div><div>void NewGVN::addAdditionalUsers(Value *To, Value *User) const {</div><div>  assert(User && To != User);</div><div>  if (isa<Instruction>(To))</div><div>    AdditionalUsers[To].insert(User);</div><div>}</div></div><div><br></div><div>That should crash when it tries to add the null value in the first place.</div><div><br></div><div>If it's the bug i remember, you will find it is doing this while adding additional users in makePossiblePhiOfOps.</div><div>(If so, i believe that bug is already fixed).</div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Sep 17, 2017 at 1:06 PM, Andrew Kelley <span dir="ltr"><<a href="mailto:superjoe30@gmail.com" target="_blank">superjoe30@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Valgrind is strictly better than address sanitizer, is that right? It runs valgrind-clean:</div><div><br></div><div>[nix-shell:~/dev/zig/build-<wbr>llvm5-debug]$ valgrind ./zig build-obj test.zig --release-safe</div><div>==4585== Memcheck, a memory error detector</div><div>==4585== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.</div><div>==4585== Using Valgrind-3.12.0 and LibVEX; rerun with -h for copyright info</div><div>==4585== Command: ./zig build-obj test.zig --release-safe</div><div>==4585== </div><span class=""><div>zig: /home/andy/downloads/llvm-<wbr>project/llvm/include/llvm/<wbr>Support/Casting.h:106: static bool llvm::isa_impl_cl<To, const From*>::doit(const From*) [with To = llvm::Instruction; From = llvm::Value]: Assertion `Val && "isa<> used on a null pointer"' failed.</div></span><div>==4585== </div><div>==4585== Process terminating with default action of signal 6 (SIGABRT)</div><div>==4585==    at 0xAF8D3D4: raise (in /nix/store/<wbr>s7dw1yngwiskqa2ac1bkc6m9g7740a<wbr>gg-glibc-2.25/lib/<a href="http://libc-2.25.so" target="_blank">libc-2.25.so</a><wbr>)</div><div>==4585==    by 0xAF8E839: abort (in /nix/store/<wbr>s7dw1yngwiskqa2ac1bkc6m9g7740a<wbr>gg-glibc-2.25/lib/<a href="http://libc-2.25.so" target="_blank">libc-2.25.so</a><wbr>)</div><div>==4585==    by 0xAF861A6: __assert_fail_base (in /nix/store/<wbr>s7dw1yngwiskqa2ac1bkc6m9g7740a<wbr>gg-glibc-2.25/lib/<a href="http://libc-2.25.so" target="_blank">libc-2.25.so</a><wbr>)</div><div>==4585==    by 0xAF86251: __assert_fail (in /nix/store/<wbr>s7dw1yngwiskqa2ac1bkc6m9g7740a<wbr>gg-glibc-2.25/lib/<a href="http://libc-2.25.so" target="_blank">libc-2.25.so</a><wbr>)</div><div>==4585==    by 0x2D70538: llvm::isa_impl_cl<llvm::<wbr>Instruction, llvm::Value const*>::doit(llvm::Value const*) (Casting.h:106)</div><div>==4585==    by 0x2D4FA5E: llvm::isa_impl_wrap<llvm::<wbr>Instruction, llvm::Value const*, llvm::Value const*>::doit(llvm::Value const* const&) (Casting.h:133)</div><div>==4585==    by 0x2ECEB52: llvm::isa_impl_wrap<llvm::<wbr>Instruction, llvm::Value const* const, llvm::Value const*>::doit(llvm::Value const* const&) (Casting.h:125)</div><div>==4585==    by 0x2ECD6A3: bool llvm::isa<llvm::Instruction, llvm::Value const*>(llvm::Value const* const&) (Casting.h:144)</div><div>==4585==    by 0x4B59017: (anonymous namespace)::NewGVN::<wbr>InstrToDFSNum(llvm::Value const*) const (NewGVN.cpp:735)</div><div>==4585==    by 0x4B688BC: void (anonymous namespace)::NewGVN::<wbr>touchAndErase<llvm::DenseMap<<wbr>llvm::Value const*, llvm::SmallPtrSet<llvm::Value*<wbr>, 2u>, llvm::DenseMapInfo<llvm::Value const*>, llvm::detail::DenseMapPair<<wbr>llvm::Value const*, llvm::SmallPtrSet<llvm::Value*<wbr>, 2u> > >, llvm::Value*>(llvm::DenseMap<<wbr>llvm::Value const*, llvm::SmallPtrSet<llvm::Value*<wbr>, 2u>, llvm::DenseMapInfo<llvm::Value const*>, llvm::detail::DenseMapPair<<wbr>llvm::Value const*, llvm::SmallPtrSet<llvm::Value*<wbr>, 2u> > >&, llvm::Value* const&) (NewGVN.cpp:1930)</div><div>==4585==    by 0x4B5DB66: (anonymous namespace)::NewGVN::<wbr>markUsersTouched(llvm::Value*) (NewGVN.cpp:1946)</div><div>==4585==    by 0x4B5F2F0: (anonymous namespace)::NewGVN::<wbr>performCongruenceFinding(llvm:<wbr>:Instruction*, llvm::GVNExpression::<wbr>Expression const*) (NewGVN.cpp:2269)</div><div><br></div><div><br></div><div>The test case that triggers the assertion yields IR that clang from the same build can compile without hitting the assertion. I don't think an IR test case to trigger this necessarily exists.<br></div><div><br></div><div>What path would I go down to come up with this IR?</div><div><div class="h5"><div><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Sep 17, 2017 at 3:47 PM, Daniel Berlin <span dir="ltr"><<a href="mailto:dberlin@dberlin.org" target="_blank">dberlin@dberlin.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span>So, 90% of the time I've seen this, it was memory corruption, usually use after free. I know I fixed one after 5.0 branched.</span><div>You should compile with address sanitizer enabled, and I suspect you will find the issue quicky.</div><div>If not, we really need ir that reproduces it.<div><div class="m_-8828230150585643700gmail-h5"><br><br><div class="gmail_quote"><div dir="ltr">On Sun, Sep 17, 2017, 12:27 PM Andrew Kelley via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">I think I forgot to mention, the IR does not reproduce the problem. It has to be using the LLVM API. Some kind of in-memory state that gets fixed when serialized and deserialized with IR.</div><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Sep 17, 2017 at 2:12 PM, Davide Italiano <span dir="ltr"><<a href="mailto:davide@freebsd.org" target="_blank">davide@freebsd.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto">Can you please open a bug on bugzilla and attach the ir testcase? Your fix doesn't look right (just hiding the assertion failure)</div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="m_-8828230150585643700gmail-m_3089521913074755796m_2999575009278887877h5">On Sep 17, 2017 10:45 AM, "Andrew Kelley via llvm-dev" <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br type="attribution"></div></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div class="m_-8828230150585643700gmail-m_3089521913074755796m_2999575009278887877h5"><div dir="ltr">What do you think about this patch?<div><br></div><div><div>--- a/llvm/lib/Transforms/Scalar/N<wbr>ewGVN.cpp</div><div>+++ b/llvm/lib/Transforms/Scalar/N<wbr>ewGVN.cpp</div><div>@@ -732,7 +732,7 @@ private:</div><div>   MemoryPhi *getMemoryAccess(const BasicBlock *) const;</div><div>   template <class T, class Range> T *getMinDFSOfRange(const Range &) const;</div><div>   unsigned InstrToDFSNum(const Value *V) const {</div><div>-    assert(isa<Instruction>(V) && "This should not be used for MemoryAccesses");</div><div>+    assert(V == nullptr || (isa<Instruction>(V) && "This should not be used for MemoryAccesses"));</div><div>     return InstrDFS.lookup(V);</div><div>   }</div><div> </div></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Sep 16, 2017 at 1:48 PM, Andrew Kelley <span dir="ltr"><<a href="mailto:superjoe30@gmail.com" target="_blank">superjoe30@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">When zig updated to llvm 5 we started hitting this assertion:<div><br></div><div><div>zig: /home/andy/downloads/llvm-proj<wbr>ect/llvm/include/llvm/Support/<wbr>Casting.h:106: static bool llvm::isa_impl_cl<To, const From*>::doit(const From*) [with To = llvm::Instruction; From = llvm::Value]: Assertion `Val && "isa<> used on a null pointer"' failed.</div></div><div><br></div><div>I wonder if however this was caused by an invalid assertion, because up the stack is</div><div><div>#8  0x0000000004b58e68 in (anonymous namespace)::NewGVN::InstrToDFS<wbr>Num (this=0x7fffffffaf80, </div><div>    V=0x0) at /home/andy/downloads/llvm-proj<wbr>ect/llvm/lib/Transforms/Scalar<wbr>/NewGVN.cpp:735</div><div>735<span class="m_-8828230150585643700gmail-m_3089521913074755796m_2999575009278887877m_-1933392896347851475m_4703477741751884082m_5462106975215116428gmail-Apple-tab-span" style="white-space:pre-wrap">    </span>    assert(isa<Instruction>(V) && "This should not be used for MemoryAccesses");</div></div><div><br></div><div><br></div><div>With assertions off the code works fine.</div><div>Can anyone provide some guidance?</div><div><br></div><div>Here is a full backtrace:</div><div><br></div><div><div>zig: /home/andy/downloads/llvm-proj<wbr>ect/llvm/include/llvm/Support/<wbr>Casting.h:106: static bool llvm::isa_impl_cl<To, const From*>::doit(const From*) [with To = llvm::Instruction; From = llvm::Value]: Assertion `Val && "isa<> used on a null pointer"' failed.</div><div><br></div><div>Program received signal SIGABRT, Aborted.</div><div>0x00007ffff698f3d4 in raise ()</div><div>   from /nix/store/s7dw1yngwiskqa2ac1b<wbr>kc6m9g7740agg-glibc-2.25/lib/<wbr>libc.so.6</div><div>(gdb) bt</div><div>#0  0x00007ffff698f3d4 in raise ()</div><div>   from /nix/store/s7dw1yngwiskqa2ac1b<wbr>kc6m9g7740agg-glibc-2.25/lib/<wbr>libc.so.6</div><div>#1  0x00007ffff699083a in abort ()</div><div>   from /nix/store/s7dw1yngwiskqa2ac1b<wbr>kc6m9g7740agg-glibc-2.25/lib/<wbr>libc.so.6</div><div>#2  0x00007ffff69881a7 in __assert_fail_base ()</div><div>   from /nix/store/s7dw1yngwiskqa2ac1b<wbr>kc6m9g7740agg-glibc-2.25/lib/<wbr>libc.so.6</div><div>#3  0x00007ffff6988252 in __assert_fail ()</div><div>   from /nix/store/s7dw1yngwiskqa2ac1b<wbr>kc6m9g7740agg-glibc-2.25/lib/<wbr>libc.so.6</div><div>#4  0x0000000002d70389 in llvm::isa_impl_cl<llvm::Instru<wbr>ction, llvm::Value const*>::doit (</div><div>    Val=0x0) at /home/andy/downloads/llvm-proj<wbr>ect/llvm/include/llvm/Support/<wbr>Casting.h:106</div><div>#5  0x0000000002d4f8af in llvm::isa_impl_wrap<llvm::Inst<wbr>ruction, llvm::Value const*, llvm::Value const*>::doit (Val=@0x7fffffffa678: 0x0)</div><div>    at /home/andy/downloads/llvm-proj<wbr>ect/llvm/include/llvm/Support/<wbr>Casting.h:133</div><div>#6  0x0000000002ece9a3 in llvm::isa_impl_wrap<llvm::Inst<wbr>ruction, llvm::Value const* const, llvm::Value const*>::doit (Val=@0x7fffffffa6b0: 0x0)</div><div>    at /home/andy/downloads/llvm-proj<wbr>ect/llvm/include/llvm/Support/<wbr>Casting.h:125</div><div>#7  0x0000000002ecd4f4 in llvm::isa<llvm::Instruction, llvm::Value const*> (</div><div>    Val=@0x7fffffffa6b0: 0x0)</div><div>    at /home/andy/downloads/llvm-proj<wbr>ect/llvm/include/llvm/Support/<wbr>Casting.h:144</div><div>#8  0x0000000004b58e68 in (anonymous namespace)::NewGVN::InstrToDFS<wbr>Num (this=0x7fffffffaf80, </div><div>    V=0x0) at /home/andy/downloads/llvm-proj<wbr>ect/llvm/lib/Transforms/Scalar<wbr>/NewGVN.cpp:735</div><div>#9  0x0000000004b6870d in (anonymous namespace)::NewGVN::touchAndEr<wbr>ase<llvm::DenseMap<llvm::Value const*, llvm::SmallPtrSet<llvm::Value*<wbr>, 2u> >, llvm::Value*> (this=0x7fffffffaf80, M=..., </div><div>    Key=@0x7fffffffa790: 0x9154cf8)</div><div>    at /home/andy/downloads/llvm-proj<wbr>ect/llvm/lib/Transforms/Scalar<wbr>/NewGVN.cpp:1930</div><div>#10 0x0000000004b5d9b7 in (anonymous namespace)::NewGVN::markUsersT<wbr>ouched (this=0x7fffffffaf80, </div><div>    V=0x9154cf8) at /home/andy/downloads/llvm-proj<wbr>ect/llvm/lib/Transforms/Scalar<wbr>/NewGVN.cpp:1946</div><div>#11 0x0000000004b5f141 in (anonymous namespace)::NewGVN::performCon<wbr>gruenceFinding (</div><div>    this=0x7fffffffaf80, I=0x9154cf8, E=0x91d7b70)</div><div>    at /home/andy/downloads/llvm-proj<wbr>ect/llvm/lib/Transforms/Scalar<wbr>/NewGVN.cpp:2269</div><div>#12 0x0000000004b62174 in (anonymous namespace)::NewGVN::valueNumbe<wbr>rInstruction (</div><div>    this=0x7fffffffaf80, I=0x9154cf8)</div><div>    at /home/andy/downloads/llvm-proj<wbr>ect/llvm/lib/Transforms/Scalar<wbr>/NewGVN.cpp:2801</div><div>#13 0x0000000004b63b4f in (anonymous namespace)::NewGVN::iterateTou<wbr>chedInstructions (</div><div>    this=0x7fffffffaf80)</div><div>    at /home/andy/downloads/llvm-proj<wbr>ect/llvm/lib/Transforms/Scalar<wbr>/NewGVN.cpp:3094</div><div>#14 0x0000000004b6431c in (anonymous namespace)::NewGVN::runGVN (this=0x7fffffffaf80)</div><div>    at /home/andy/downloads/llvm-proj<wbr>ect/llvm/lib/Transforms/Scalar<wbr>/NewGVN.cpp:3165</div><div>#15 0x0000000004b678db in (anonymous namespace)::NewGVNLegacyPass::<wbr>runOnFunction (</div><div>    this=0x910ea50, F=...)</div><div>    at /home/andy/downloads/llvm-proj<wbr>ect/llvm/lib/Transforms/Scalar<wbr>/NewGVN.cpp:3904</div><div>#16 0x00000000054d10fd in llvm::FPPassManager::runOnFunc<wbr>tion (this=0x9102260, F=...)</div><div>    at /home/andy/downloads/llvm-proj<wbr>ect/llvm/lib/IR/LegacyPassMana<wbr>ger.cpp:1514</div><div>#17 0x0000000004f2a375 in (anonymous namespace)::CGPassManager::Run<wbr>PassOnSCC (this=0x9100f00, </div><div>    P=0x9102260, CurSCC=..., CG=..., CallGraphUpToDate=@0x7fffffffb<wbr>c2f: true, </div><div>    DevirtualizedCall=@0x7fffffffb<wbr>ccf: false)</div><div>    at /home/andy/downloads/llvm-proj<wbr>ect/llvm/lib/Analysis/CallGrap<wbr>hSCCPass.cpp:149</div><div>#18 0x0000000004f2b349 in (anonymous namespace)::CGPassManager::Run<wbr>AllPassesOnSCC (</div><div>    this=0x9100f00, CurSCC=..., CG=..., DevirtualizedCall=@0x7fffffffb<wbr>ccf: false)</div><div>    at /home/andy/downloads/llvm-proj<wbr>ect/llvm/lib/Analysis/CallGrap<wbr>hSCCPass.cpp:419</div><div>#19 0x0000000004f2b643 in (anonymous namespace)::CGPassManager::run<wbr>OnModule (this=0x9100f00, </div><div>    M=...) at /home/andy/downloads/llvm-proj<wbr>ect/llvm/lib/Analysis/CallGrap<wbr>hSCCPass.cpp:474</div><div>#20 0x00000000054d15c1 in (anonymous namespace)::MPPassManager::run<wbr>OnModule (this=0x90f9970, </div><div>---Type <return> to continue, or q <return> to quit---</div><div>    M=...) at /home/andy/downloads/llvm-proj<wbr>ect/llvm/lib/IR/LegacyPassMana<wbr>ger.cpp:1591</div><div>#21 0x00000000054d1c73 in llvm::legacy::PassManagerImpl:<wbr>:run (this=0x90f9480, M=...)</div><div>    at /home/andy/downloads/llvm-proj<wbr>ect/llvm/lib/IR/LegacyPassMana<wbr>ger.cpp:1694</div><div>#22 0x00000000054d1e7f in llvm::legacy::PassManager::run (this=0x7fffffffc010, M=...)</div><div>    at /home/andy/downloads/llvm-proj<wbr>ect/llvm/lib/IR/LegacyPassMana<wbr>ger.cpp:1725</div><div>#23 0x0000000001d4017d in ZigLLVMTargetMachineEmitToFile (targ_machine_ref=0x9080d50, </div><div>    module_ref=0x907e870, filename=0x90cf360 "./zig-cache/test.o", file_type=LLVMObjectFile, </div><div>    error_message=0x7fffffffc2f8, is_debug=false) at /home/andy/dev/zig/src/zig_llv<wbr>m.cpp:166</div><div>#24 0x0000000001cd041d in do_code_gen (g=0x907a980) at /home/andy/dev/zig/src/codegen<wbr>.cpp:4379</div><div>#25 0x0000000001cd4634 in codegen_build (g=0x907a980) at /home/andy/dev/zig/src/codegen<wbr>.cpp:5484</div><div>#26 0x0000000001d1d564 in main (argc=4, argv=0x7fffffffca18)</div><div>    at /home/andy/dev/zig/src/main.cp<wbr>p:666</div></div><div><br></div><div><br></div><div><br></div><div>Here's the smallest zig test case to cause the problem:</div><div><br></div><div><br></div><div><div>export fn entry() {</div><div>    var bytes: []const u8 = "format";</div><div>    write(bytes);</div><div>}</div><div><br></div><div>pub fn write(bytes: []const u8) {</div><div>    var index: usize = 0;</div><div><br></div><div>    var src_index: usize = 0;</div><div><br></div><div>    while (src_index < bytes.len) {</div><div>        const dest_space_left = 1 - index;</div><div>        const b = bytes.len - src_index;</div><div>        const copy_amt = if (dest_space_left < b) dest_space_left else b;</div><div>        index += copy_amt;</div><div>        src_index += copy_amt;</div><div>    }</div><div>}</div><div><br></div><div>pub fn panic(msg: []const u8) -> noreturn { while (true) {} }</div></div><div><br></div><div><br></div><div>compile with ./zig build_obj test.zig --release-safe</div><div>This does the equivalent of -O3</div><div><br></div><div>The IR that it produces; ModuleID = 'test'</div><div>source_filename = "test"</div><div>target datalayout = "e-m:e-i64:64-f80:128-n8:16:32<wbr>:64-S128"</div><div>target triple = "x86_64-unknown-linux-gnu"</div><div><br></div><div>%"[]u8" = type { i8*, i64 }</div><div><br></div><div>@__zig_panic_implementation_pr<wbr>ovided = internal unnamed_addr constant i1 true, align 1</div><div>@0 = internal unnamed_addr constant i8* getelementptr inbounds ([6 x i8], [6 x i8]* @1, i64 0, i64 0), align 8</div><div>@1 = internal unnamed_addr constant [6 x i8] c"format", align 1</div><div>@2 = internal unnamed_addr constant { i8*, i64 } { i8* getelementptr inbounds ([6 x i8], [6 x i8]* @1, i64 0, i64 0), i64 6 }, align 8</div><div>@3 = internal unnamed_addr constant i8* getelementptr inbounds ([16 x i8], [16 x i8]* @4, i64 0, i64 0), align 8</div><div>@4 = internal unnamed_addr constant [16 x i8] c"integer overflow", align 1</div><div>@5 = internal unnamed_addr constant { i8*, i64 } { i8* getelementptr inbounds ([16 x i8], [16 x i8]* @4, i64 0, i64 0), i64 16 }, align 8</div><div><br></div><div>; Function Attrs: nobuiltin nounwind</div><div>define void @entry() #0 !dbg !16 {</div><div>Entry:</div><div>  %bytes = alloca %"[]u8", align 8</div><div>  %0 = bitcast %"[]u8"* %bytes to i8*, !dbg !31</div><div>  call void @llvm.memcpy.p0i8.p0i8.i64(i8* %0, i8* bitcast ({ i8*, i64 }* @2 to i8*), i64 16, i32 8, i1 false), !dbg !31</div><div>  call void @llvm.dbg.declare(metadata %"[]u8"* %bytes, metadata !22, metadata !32), !dbg !31</div><div>  call fastcc void @write(%"[]u8"* byval %bytes), !dbg !33</div><div>  ret void, !dbg !35</div><div>}</div><div><br></div><div>; Function Attrs: cold nobuiltin noreturn nounwind</div><div>define linkonce coldcc void @__zig_panic(i8* nonnull readonly, i64) #1 !dbg !36 {</div><div>Entry:</div><div>  %2 = alloca %"[]u8", align 8</div><div>  %message_ptr = alloca i8*, align 8</div><div>  %message_len = alloca i64, align 8</div><div>  store i8* %0, i8** %message_ptr, align 8</div><div>  call void @llvm.dbg.declare(metadata i8** %message_ptr, metadata !41, metadata !32), !dbg !44</div><div>  store i64 %1, i64* %message_len, align 8</div><div>  call void @llvm.dbg.declare(metadata i64* %message_len, metadata !42, metadata !32), !dbg !45</div><div>  %3 = load i64, i64* %message_len, align 8, !dbg !46</div><div>  %4 = load i8*, i8** %message_ptr, align 8, !dbg !50</div><div>  %5 = getelementptr inbounds %"[]u8", %"[]u8"* %2, i32 0, i32 0, !dbg !50</div><div>  %6 = getelementptr inbounds i8, i8* %4, i64 0, !dbg !50</div><div>  store i8* %6, i8** %5, align 8, !dbg !50</div><div>  %7 = getelementptr inbounds %"[]u8", %"[]u8"* %2, i32 0, i32 1, !dbg !50</div><div>  %8 = sub nsw i64 %3, 0, !dbg !50</div><div>  store i64 %8, i64* %7, align 8, !dbg !50</div><div>  call fastcc void @panic(%"[]u8"* byval %2), !dbg !51</div><div>  unreachable, !dbg !51</div><div>}</div><div><br></div><div>; Function Attrs: nobuiltin nounwind</div><div>define internal fastcc void @write(%"[]u8"* byval nonnull readonly) unnamed_addr #0 !dbg !52 {</div><div>Entry:</div><div>  %index = alloca i64, align 8</div><div>  %src_index = alloca i64, align 8</div><div>  %dest_space_left = alloca i64, align 8</div><div>  %b = alloca i64, align 8</div><div>  %copy_amt = alloca i64, align 8</div><div>  call void @llvm.dbg.declare(metadata %"[]u8"* %0, metadata !57, metadata !32), !dbg !70</div><div>  store i64 0, i64* %index, align 8, !dbg !71</div><div>  call void @llvm.dbg.declare(metadata i64* %index, metadata !58, metadata !32), !dbg !71</div><div>  store i64 0, i64* %src_index, align 8, !dbg !72</div><div>  call void @llvm.dbg.declare(metadata i64* %src_index, metadata !61, metadata !32), !dbg !72</div><div>  br label %WhileCond, !dbg !73</div><div><br></div><div>WhileCond:                                        ; preds = %OverflowOk6, %Entry</div><div>  %1 = load i64, i64* %src_index, align 8, !dbg !74</div><div>  %2 = getelementptr inbounds %"[]u8", %"[]u8"* %0, i32 0, i32 1, !dbg !75</div><div>  %3 = load i64, i64* %2, align 8, !dbg !75</div><div>  %4 = icmp ult i64 %1, %3, !dbg !76</div><div>  br i1 %4, label %WhileBody, label %WhileEnd, !dbg !76</div><div><br></div><div>WhileBody:                                        ; preds = %WhileCond</div><div>  %5 = load i64, i64* %index, align 8, !dbg !77</div><div>  %6 = call { i64, i1 } @llvm.usub.with.overflow.i64(i<wbr>64 1, i64 %5), !dbg !78</div><div>  %7 = extractvalue { i64, i1 } %6, 0, !dbg !78</div><div>  %8 = extractvalue { i64, i1 } %6, 1, !dbg !78</div><div>  br i1 %8, label %OverflowFail, label %OverflowOk, !dbg !78</div><div><br></div><div>WhileEnd:                                         ; preds = %WhileCond</div><div>  ret void, !dbg !79</div><div><br></div><div>Then:                                             ; preds = %OverflowOk2</div><div>  %9 = load i64, i64* %dest_space_left, align 8, !dbg !80</div><div>  br label %EndIf, !dbg !81</div><div><br></div><div>Else:                                             ; preds = %OverflowOk2</div><div>  %10 = load i64, i64* %b, align 8, !dbg !82</div><div>  br label %EndIf, !dbg !81</div><div><br></div><div>EndIf:                                            ; preds = %Else, %Then</div><div>  %11 = phi i64 [ %9, %Then ], [ %10, %Else ], !dbg !81</div><div>  store i64 %11, i64* %copy_amt, align 8, !dbg !83</div><div>  call void @llvm.dbg.declare(metadata i64* %copy_amt, metadata !68, metadata !32), !dbg !83</div><div>  %12 = load i64, i64* %index, align 8, !dbg !84</div><div>  %13 = load i64, i64* %copy_amt, align 8, !dbg !86</div><div>  %14 = call { i64, i1 } @llvm.uadd.with.overflow.i64(i<wbr>64 %12, i64 %13), !dbg !87</div><div>  %15 = extractvalue { i64, i1 } %14, 0, !dbg !87</div><div>  %16 = extractvalue { i64, i1 } %14, 1, !dbg !87</div><div>  br i1 %16, label %OverflowFail3, label %OverflowOk4, !dbg !87</div><div><br></div><div>OverflowFail:                                     ; preds = %WhileBody</div><div>  %17 = load i8*, i8** getelementptr inbounds ({ i8*, i64 }, { i8*, i64 }* @5, i32 0, i32 0), align 8, !dbg !78</div><div>  %18 = load i64, i64* getelementptr inbounds ({ i8*, i64 }, { i8*, i64 }* @5, i32 0, i32 1), align 8, !dbg !78</div><div>  call coldcc void @__zig_panic(i8* %17, i64 %18), !dbg !78</div><div>  unreachable, !dbg !78</div><div><br></div><div>OverflowOk:                                       ; preds = %WhileBody</div><div>  store i64 %7, i64* %dest_space_left, align 8, !dbg !88</div><div>  call void @llvm.dbg.declare(metadata i64* %dest_space_left, metadata !63, metadata !32), !dbg !88</div><div>  %19 = getelementptr inbounds %"[]u8", %"[]u8"* %0, i32 0, i32 1, !dbg !89</div><div>  %20 = load i64, i64* %19, align 8, !dbg !89</div><div>  %21 = load i64, i64* %src_index, align 8, !dbg !90</div><div>  %22 = call { i64, i1 } @llvm.usub.with.overflow.i64(i<wbr>64 %20, i64 %21), !dbg !91</div><div>  %23 = extractvalue { i64, i1 } %22, 0, !dbg !91</div><div>  %24 = extractvalue { i64, i1 } %22, 1, !dbg !91</div><div>  br i1 %24, label %OverflowFail1, label %OverflowOk2, !dbg !91</div><div><br></div><div>OverflowFail1:                                    ; preds = %OverflowOk</div><div>  %25 = load i8*, i8** getelementptr inbounds ({ i8*, i64 }, { i8*, i64 }* @5, i32 0, i32 0), align 8, !dbg !91</div><div>  %26 = load i64, i64* getelementptr inbounds ({ i8*, i64 }, { i8*, i64 }* @5, i32 0, i32 1), align 8, !dbg !91</div><div>  call coldcc void @__zig_panic(i8* %25, i64 %26), !dbg !91</div><div>  unreachable, !dbg !91</div><div><br></div><div>OverflowOk2:                                      ; preds = %OverflowOk</div><div>  store i64 %23, i64* %b, align 8, !dbg !92</div><div>  call void @llvm.dbg.declare(metadata i64* %b, metadata !66, metadata !32), !dbg !92</div><div>  %27 = load i64, i64* %dest_space_left, align 8, !dbg !93</div><div>  %28 = load i64, i64* %b, align 8, !dbg !94</div><div>  %29 = icmp ult i64 %27, %28, !dbg !95</div><div>  br i1 %29, label %Then, label %Else, !dbg !95</div><div><br></div><div>OverflowFail3:                                    ; preds = %EndIf</div><div>  %30 = load i8*, i8** getelementptr inbounds ({ i8*, i64 }, { i8*, i64 }* @5, i32 0, i32 0), align 8, !dbg !87</div><div>  %31 = load i64, i64* getelementptr inbounds ({ i8*, i64 }, { i8*, i64 }* @5, i32 0, i32 1), align 8, !dbg !87</div><div>  call coldcc void @__zig_panic(i8* %30, i64 %31), !dbg !87</div><div>  unreachable, !dbg !87</div><div><br></div><div>OverflowOk4:                                      ; preds = %EndIf</div><div>  store i64 %15, i64* %index, align 8, !dbg !87</div><div>  %32 = load i64, i64* %src_index, align 8, !dbg !96</div><div>  %33 = load i64, i64* %copy_amt, align 8, !dbg !97</div><div>  %34 = call { i64, i1 } @llvm.uadd.with.overflow.i64(i<wbr>64 %32, i64 %33), !dbg !98</div><div>  %35 = extractvalue { i64, i1 } %34, 0, !dbg !98</div><div>  %36 = extractvalue { i64, i1 } %34, 1, !dbg !98</div><div>  br i1 %36, label %OverflowFail5, label %OverflowOk6, !dbg !98</div><div><br></div><div>OverflowFail5:                                    ; preds = %OverflowOk4</div><div>  %37 = load i8*, i8** getelementptr inbounds ({ i8*, i64 }, { i8*, i64 }* @5, i32 0, i32 0), align 8, !dbg !98</div><div>  %38 = load i64, i64* getelementptr inbounds ({ i8*, i64 }, { i8*, i64 }* @5, i32 0, i32 1), align 8, !dbg !98</div><div>  call coldcc void @__zig_panic(i8* %37, i64 %38), !dbg !98</div><div>  unreachable, !dbg !98</div><div><br></div><div>OverflowOk6:                                      ; preds = %OverflowOk4</div><div>  store i64 %35, i64* %src_index, align 8, !dbg !98</div><div>  br label %WhileCond, !dbg !73</div><div>}</div><div><br></div><div>; Function Attrs: nobuiltin noreturn nounwind</div><div>define internal fastcc void @panic(%"[]u8"* byval nonnull readonly) unnamed_addr #2 !dbg !99 {</div><div>Entry:</div><div>  call void @llvm.dbg.declare(metadata %"[]u8"* %0, metadata !101, metadata !32), !dbg !102</div><div>  br label %WhileCond, !dbg !103</div><div><br></div><div>WhileCond:                                        ; preds = %WhileCond, %Entry</div><div>  br label %WhileCond, !dbg !103</div><div>}</div><div><br></div><div>; Function Attrs: argmemonly nounwind</div><div>declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture writeonly, i8* nocapture readonly, i64, i32, i1) #3</div><div><br></div><div>; Function Attrs: nounwind readnone speculatable</div><div>declare void @llvm.dbg.declare(metadata, metadata, metadata) #4</div><div><br></div><div>; Function Attrs: nounwind readnone speculatable</div><div>declare { i64, i1 } @llvm.usub.with.overflow.i64(i<wbr>64, i64) #4</div><div><br></div><div>; Function Attrs: nounwind readnone speculatable</div><div>declare { i64, i1 } @llvm.uadd.with.overflow.i64(i<wbr>64, i64) #4</div><div><br></div><div>attributes #0 = { nobuiltin nounwind }</div><div>attributes #1 = { cold nobuiltin noreturn nounwind }</div><div>attributes #2 = { nobuiltin noreturn nounwind }</div><div>attributes #3 = { argmemonly nounwind }</div><div>attributes #4 = { nounwind readnone speculatable }</div><div><br></div><div>!llvm.module.flags = !{!0}</div><div>!<a href="http://llvm.dbg.cu" target="_blank">llvm.dbg.cu</a> = !{!1}</div><div><br></div><div>!0 = !{i32 2, !"Debug Info Version", i32 3}</div><div>!1 = distinct !DICompileUnit(language: DW_LANG_C99, file: !2, producer: "zig 0.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !3, globals: !12)</div><div>!2 = !DIFile(filename: "test", directory: ".")</div><div>!3 = !{!4}</div><div>!4 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "GlobalLinkage", scope: !5, file: !5, line: 138, baseType: !6, size: 8, align: 8, elements: !7)</div><div>!5 = !DIFile(filename: "builtin.zig", directory: "/home/andy/dev/zig/build-llvm<wbr>5-debug/zig-cache")</div><div>!6 = !DIBasicType(name: "u3", size: 8, encoding: DW_ATE_unsigned)</div><div>!7 = !{!8, !9, !10, !11}</div><div>!8 = !DIEnumerator(name: "Internal", value: 0)</div><div>!9 = !DIEnumerator(name: "Strong", value: 1)</div><div>!10 = !DIEnumerator(name: "Weak", value: 2)</div><div>!11 = !DIEnumerator(name: "LinkOnce", value: 3)</div><div>!12 = !{!13}</div><div>!13 = !DIGlobalVariableExpression(va<wbr>r: !14)</div><div>!14 = distinct !DIGlobalVariable(name: "__zig_panic_implementation_pr<wbr>ovided", linkageName: "__zig_panic_implementation_pr<wbr>ovided", scope: !5, file: !5, line: 201, type: !15, isLocal: true, isDefinition: true)</div><div>!15 = !DIBasicType(name: "bool", size: 8, encoding: DW_ATE_boolean)</div><div>!16 = distinct !DISubprogram(name: "entry", scope: !17, file: !17, type: !18, isLocal: false, isDefinition: true, isOptimized: true, unit: !1, variables: !21)</div><div>!17 = !DIFile(filename: "test.zig", directory: "/home/andy/dev/zig/build-llvm<wbr>5-debug")</div><div>!18 = !DISubroutineType(types: !19)</div><div>!19 = !{!20}</div><div>!20 = !DIBasicType(name: "void", encoding: DW_ATE_unsigned)</div><div>!21 = !{!22}</div><div>!22 = !DILocalVariable(name: "bytes", scope: !23, file: !17, line: 2, type: !24)</div><div>!23 = distinct !DILexicalBlock(scope: !16, file: !17, line: 1, column: 19)</div><div>!24 = !DICompositeType(tag: DW_TAG_structure_type, name: "[]u8", size: 128, align: 64, elements: !25)</div><div>!25 = !{!26, !29}</div><div>!26 = !DIDerivedType(tag: DW_TAG_member, name: "ptr", scope: !24, baseType: !27, size: 64, align: 64)</div><div>!27 = !DIDerivedType(tag: DW_TAG_pointer_type, name: "&u8", baseType: !28, size: 64, align: 64)</div><div>!28 = !DIBasicType(name: "u8", size: 8, encoding: DW_ATE_unsigned_char)</div><div>!29 = !DIDerivedType(tag: DW_TAG_member, name: "len", scope: !24, baseType: !30, size: 64, align: 64, offset: 64)</div><div>!30 = !DIBasicType(name: "usize", size: 64, encoding: DW_ATE_unsigned)</div><div>!31 = !DILocation(line: 2, column: 5, scope: !23)</div><div>!32 = !DIExpression()</div><div>!33 = !DILocation(line: 3, column: 10, scope: !34)</div><div>!34 = distinct !DILexicalBlock(scope: !23, file: !17, line: 2, column: 5)</div><div>!35 = !DILocation(line: 1, column: 19, scope: !16)</div><div>!36 = distinct !DISubprogram(name: "__zig_panic", scope: !37, file: !37, line: 7, type: !38, isLocal: false, isDefinition: true, scopeLine: 7, isOptimized: true, unit: !1, variables: !40)</div><div>!37 = !DIFile(filename: "zigrt.zig", directory: "/home/andy/dev/zig/build-llvm<wbr>5-debug/lib/zig/std/special")</div><div>!38 = !DISubroutineType(types: !39)</div><div>!39 = !{!20, !27, !30}</div><div>!40 = !{!41, !42}</div><div>!41 = !DILocalVariable(name: "message_ptr", arg: 1, scope: !36, file: !37, line: 7, type: !27)</div><div>!42 = !DILocalVariable(name: "message_len", arg: 2, scope: !43, file: !37, line: 7, type: !30)</div><div>!43 = distinct !DILexicalBlock(scope: !36, file: !37, line: 7, column: 30)</div><div>!44 = !DILocation(line: 7, column: 30, scope: !36)</div><div>!45 = !DILocation(line: 7, column: 54, scope: !43)</div><div>!46 = !DILocation(line: 12, column: 48, scope: !47)</div><div>!47 = distinct !DILexicalBlock(scope: !48, file: !37, line: 11, column: 54)</div><div>!48 = distinct !DILexicalBlock(scope: !49, file: !37, line: 7, column: 86)</div><div>!49 = distinct !DILexicalBlock(scope: !43, file: !37, line: 7, column: 54)</div><div>!50 = !DILocation(line: 12, column: 43, scope: !47)</div><div>!51 = !DILocation(line: 12, column: 31, scope: !47)</div><div>!52 = distinct !DISubprogram(name: "write", scope: !17, file: !17, line: 6, type: !53, isLocal: true, isDefinition: true, scopeLine: 6, isOptimized: true, unit: !1, variables: !56)</div><div>!53 = !DISubroutineType(types: !54)</div><div>!54 = !{!20, !55}</div><div>!55 = !DIDerivedType(tag: DW_TAG_pointer_type, name: "&[]const u8", baseType: !24, size: 64, align: 64)</div><div>!56 = !{!57, !58, !61, !63, !66, !68}</div><div>!57 = !DILocalVariable(name: "bytes", arg: 1, scope: !52, file: !17, line: 6, type: !24)</div><div>!58 = !DILocalVariable(name: "index", scope: !59, file: !17, line: 7, type: !30)</div><div>!59 = distinct !DILexicalBlock(scope: !60, file: !17, line: 6, column: 33)</div><div>!60 = distinct !DILexicalBlock(scope: !52, file: !17, line: 6, column: 14)</div><div>!61 = !DILocalVariable(name: "src_index", scope: !62, file: !17, line: 9, type: !30)</div><div>!62 = distinct !DILexicalBlock(scope: !59, file: !17, line: 7, column: 5)</div><div>!63 = !DILocalVariable(name: "dest_space_left", scope: !64, file: !17, line: 12, type: !30)</div><div>!64 = distinct !DILexicalBlock(scope: !65, file: !17, line: 11, column: 35)</div><div>!65 = distinct !DILexicalBlock(scope: !62, file: !17, line: 9, column: 5)</div><div>!66 = !DILocalVariable(name: "b", scope: !67, file: !17, line: 13, type: !30)</div><div>!67 = distinct !DILexicalBlock(scope: !64, file: !17, line: 12, column: 9)</div><div>!68 = !DILocalVariable(name: "copy_amt", scope: !69, file: !17, line: 14, type: !30)</div><div>!69 = distinct !DILexicalBlock(scope: !67, file: !17, line: 13, column: 9)</div><div>!70 = !DILocation(line: 6, column: 14, scope: !52)</div><div>!71 = !DILocation(line: 7, column: 5, scope: !59)</div><div>!72 = !DILocation(line: 9, column: 5, scope: !62)</div><div>!73 = !DILocation(line: 11, column: 5, scope: !65)</div><div>!74 = !DILocation(line: 11, column: 12, scope: !65)</div><div>!75 = !DILocation(line: 11, column: 29, scope: !65)</div><div>!76 = !DILocation(line: 11, column: 22, scope: !65)</div><div>!77 = !DILocation(line: 12, column: 37, scope: !64)</div><div>!78 = !DILocation(line: 12, column: 35, scope: !64)</div><div>!79 = !DILocation(line: 11, column: 5, scope: !60)</div><div>!80 = !DILocation(line: 14, column: 51, scope: !69)</div><div>!81 = !DILocation(line: 14, column: 26, scope: !69)</div><div>!82 = !DILocation(line: 14, column: 72, scope: !69)</div><div>!83 = !DILocation(line: 14, column: 9, scope: !69)</div><div>!84 = !DILocation(line: 15, column: 9, scope: !85)</div><div>!85 = distinct !DILexicalBlock(scope: !69, file: !17, line: 14, column: 9)</div><div>!86 = !DILocation(line: 15, column: 18, scope: !85)</div><div>!87 = !DILocation(line: 15, column: 15, scope: !85)</div><div>!88 = !DILocation(line: 12, column: 9, scope: !64)</div><div>!89 = !DILocation(line: 13, column: 24, scope: !67)</div><div>!90 = !DILocation(line: 13, column: 31, scope: !67)</div><div>!91 = !DILocation(line: 13, column: 29, scope: !67)</div><div>!92 = !DILocation(line: 13, column: 9, scope: !67)</div><div>!93 = !DILocation(line: 14, column: 30, scope: !69)</div><div>!94 = !DILocation(line: 14, column: 48, scope: !69)</div><div>!95 = !DILocation(line: 14, column: 46, scope: !69)</div><div>!96 = !DILocation(line: 16, column: 9, scope: !85)</div><div>!97 = !DILocation(line: 16, column: 22, scope: !85)</div><div>!98 = !DILocation(line: 16, column: 19, scope: !85)</div><div>!99 = distinct !DISubprogram(name: "panic", scope: !17, file: !17, line: 20, type: !53, isLocal: true, isDefinition: true, scopeLine: 20, isOptimized: true, unit: !1, variables: !100)</div><div>!100 = !{!101}</div><div>!101 = !DILocalVariable(name: "msg", arg: 1, scope: !99, file: !17, line: 20, type: !24)</div><div>!102 = !DILocation(line: 20, column: 14, scope: !99)</div><div>!103 = !DILocation(line: 20, column: 45, scope: !104)</div><div>!104 = distinct !DILexicalBlock(scope: !105, file: !17, line: 20, column: 43)</div><div>!105 = distinct !DILexicalBlock(scope: !99, file: !17, line: 20, column: 14)</div><div> is the following, however clang 5 with assertions on does not hit the assertion when run on this IR:</div><div><br></div><div><br></div><div><br></div><div>Any pointers would be appreciated.</div></div>
</blockquote></div><br></div>
<br></div></div>______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div></div>
</blockquote></div><br></div></div>
______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
</blockquote></div></div></div></div>
</blockquote></div><br></div></div></div></div>
</blockquote></div><br></div>