<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - [WinEH] asserting loop optimizations with captured variables"
   href="https://llvm.org/bugs/show_bug.cgi?id=26000">26000</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[WinEH] asserting loop optimizations with captured variables
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Windows XP
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>-New Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>r.sagitario@gmx.de
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Compile this code with "clang -m32 -fexceptions -c -O":

struct string 
{
    string(const char*s);
    const char* ptr;
};

bool adEq2(string& s1);

void checkContent(string s)
{
    string old = s;

    auto fail = [&]()
    {
        s = old;
    };

    try
    {
        while (s.ptr != 0)
        {
            old = s;
            if (adEq2(s)) { }
        }
    }
    catch(int e) 
    {
        fail();
    }
}

Result:
Assertion failed: Val && "isa<> used on a null pointer", file
C:\s\d\ldc\llvm\include\llvm/Support/Casting.h, line 95

It does not happen without optimizations or when compiling with -m64.

Bugpoint reports a broken function after the -licm pass, here is the IR to
reproduce:

; ModuleID = 'bugpoint-reduced-instructions.bc'
target datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"
target triple = "i386-pc-windows-msvc18.0.0"

%rtti.TypeDescriptor2.0.2.4.6.8.22 = type { i8**, i8*, [3 x i8] }
%struct.string.1.3.5.7.9.23 = type { i8* }

@"\01??_7type_info@@6B@" = external constant i8*
@"\01??_R0H@8" = external global %rtti.TypeDescriptor2.0.2.4.6.8.22

define void @"\01?checkContent@@YAXUstring@@@Z"(%struct.string.1.3.5.7.9.23*
byval align 4 %s) #0 personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to
i8*) {
entry:
  br label %while.cond

while.cond:                                       ; preds = %while.body, %entry
  %0 = ptrtoint i8* undef to i32
  br i1 undef, label %try.cont, label %while.body

while.body:                                       ; preds = %while.cond
  %call = invoke zeroext i1
@"\01?adEq2@@YA_NAAUstring@@@Z"(%struct.string.1.3.5.7.9.23* nonnull
dereferenceable(4) %s)
          to label %while.cond unwind label %catch.dispatch

catch.dispatch:                                   ; preds = %while.body
  %1 = catchswitch within none [label %catch] unwind to caller

catch:                                            ; preds = %catch.dispatch
  %2 = catchpad within %1 [%rtti.TypeDescriptor2.0.2.4.6.8.22* @"\01??_R0H@8",
i32 0, i32* undef]
  store i32 %0, i32* undef, align 4
  catchret from %2 to label %try.cont

try.cont:                                         ; preds = %catch, %while.cond
  ret void
}

; Function Attrs: argmemonly nounwind
declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture readonly,
i32, i32, i1) #1

declare zeroext i1 @"\01?adEq2@@YA_NAAUstring@@@Z"(%struct.string.1.3.5.7.9.23*
dereferenceable(4)) #0

declare i32 @__CxxFrameHandler3(...)

attributes #0 = { "disable-tail-calls"="false" "less-precise-fpmad"="false"
"no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf"
"no-infs-fp-math"="false" "no-nans-fp-math"="false"
"stack-protector-buffer-size"="8" "target-cpu"="pentium4"
"target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false"
"use-soft-float"="false" }
attributes #1 = { argmemonly nounwind }

!llvm.ident = !{!0}

!0 = !{!"clang version 3.8.0 "}</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>