<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </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 - SROA.cpp:2567: bool llvm::sroa::AllocaSliceRewriter::rewriteIntegerStore(llvm::Value *, llvm::StoreInst &, llvm::AAMDNodes): Assertion `BeginOffset >= NewAllocaBeginOffset && "Out of bounds offset"' failed."
   href="https://bugs.llvm.org/show_bug.cgi?id=37267">37267</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>SROA.cpp:2567: bool llvm::sroa::AllocaSliceRewriter::rewriteIntegerStore(llvm::Value *, llvm::StoreInst &, llvm::AAMDNodes): Assertion `BeginOffset >= NewAllocaBeginOffset && "Out of bounds offset"' failed.
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

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

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>new bugs
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>mikael.holmen@ericsson.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=20235" name="attach_20235" title="reproducer">attachment 20235</a> <a href="attachment.cgi?id=20235&action=edit" title="reproducer">[details]</a></span>
reproducer

Running

 opt -S -o - tr15934_sparc.ll -sroa

yields

opt: ../lib/Transforms/Scalar/SROA.cpp:2567: bool
llvm::sroa::AllocaSliceRewriter::rewriteIntegerStore(llvm::Value *,
llvm::StoreInst &, llvm::AAMDNodes): Assertion `BeginOffset >=
NewAllocaBeginOffset && "Out of bounds offset"' failed.
Stack dump:
0.      Program arguments: ../llvm-patch/build-all/bin/opt -S -o -
tr15934_sparc.ll -sroa 
1.      Running pass 'Function Pass Manager' on module 'tr15934_sparc.ll'.
2.      Running pass 'SROA' on function '@f2'
#0 0x0000000001f3f5d4 PrintStackTraceSignalHandler(void*)
(../llvm-patch/build-all/bin/opt+0x1f3f5d4)
#1 0x0000000001f3fd46 SignalHandler(int)
(../llvm-patch/build-all/bin/opt+0x1f3fd46)
#2 0x00007fc25d381330 __restore_rt
(/lib/x86_64-linux-gnu/libpthread.so.0+0x10330)
#3 0x00007fc25bf70c37 gsignal
/build/eglibc-ripdx6/eglibc-2.19/signal/../nptl/sysdeps/unix/sysv/linux/raise.c:56:0
#4 0x00007fc25bf74028 abort
/build/eglibc-ripdx6/eglibc-2.19/stdlib/abort.c:91:0
#5 0x00007fc25bf69bf6 __assert_fail_base
/build/eglibc-ripdx6/eglibc-2.19/assert/assert.c:92:0
#6 0x00007fc25bf69ca2 (/lib/x86_64-linux-gnu/libc.so.6+0x2fca2)
#7 0x0000000001e67547 (../llvm-patch/build-all/bin/opt+0x1e67547)
#8 0x0000000001e669b1
llvm::sroa::AllocaSliceRewriter::visitStoreInst(llvm::StoreInst&)
(../llvm-patch/build-all/bin/opt+0x1e669b1)
#9 0x0000000001e5e169 llvm::InstVisitor<llvm::sroa::AllocaSliceRewriter,
bool>::visit(llvm::Instruction&) (../llvm-patch/build-all/bin/opt+0x1e5e169)
#10 0x0000000001e4f1ba llvm::sroa::AllocaSliceRewriter::visit((anonymous
namespace)::Slice const*) (../llvm-patch/build-all/bin/opt+0x1e4f1ba)
#11 0x0000000001e4da3f llvm::SROA::rewritePartition(llvm::AllocaInst&,
llvm::sroa::AllocaSlices&, llvm::sroa::Partition&)
(../llvm-patch/build-all/bin/opt+0x1e4da3f)
#12 0x0000000001e4f991 llvm::SROA::splitAlloca(llvm::AllocaInst&,
llvm::sroa::AllocaSlices&) (../llvm-patch/build-all/bin/opt+0x1e4f991)
#13 0x0000000001e51588 llvm::SROA::runOnAlloca(llvm::AllocaInst&)
(../llvm-patch/build-all/bin/opt+0x1e51588)
#14 0x0000000001e5324b llvm::SROA::runImpl(llvm::Function&,
llvm::DominatorTree&, llvm::AssumptionCache&)
(../llvm-patch/build-all/bin/opt+0x1e5324b)
#15 0x0000000001e5bb2e
llvm::sroa::SROALegacyPass::runOnFunction(llvm::Function&)
(../llvm-patch/build-all/bin/opt+0x1e5bb2e)
#16 0x00000000019ea708 llvm::FPPassManager::runOnFunction(llvm::Function&)
(../llvm-patch/build-all/bin/opt+0x19ea708)
#17 0x00000000019ea948 llvm::FPPassManager::runOnModule(llvm::Module&)
(../llvm-patch/build-all/bin/opt+0x19ea948)
#18 0x00000000019eae25 llvm::legacy::PassManagerImpl::run(llvm::Module&)
(../llvm-patch/build-all/bin/opt+0x19eae25)
#19 0x0000000000735055 main (../llvm-patch/build-all/bin/opt+0x735055)
#20 0x00007fc25bf5bf45 __libc_start_main
/build/eglibc-ripdx6/eglibc-2.19/csu/libc-start.c:321:0
#21 0x000000000071eb1d _start (../llvm-patch/build-all/bin/opt+0x71eb1d)
Abort


This started happening with commit r322533:

    [SROA] fix assetion failure

    This patch fixes the assertion failure in SROA reported in PR35657.
    PR35657 reports the assertion failure due to r319522 (splitting for
non-whole-alloca slices), but this problem can happen even without r319522.

    The problem exists in a check for reusing an existing alloca when rewriting
partitions. As the original comment said, we can reuse the existing alloca if
the new alloca has the same type and offset with the existing one. But the code
checks only type of the alloca and then check the offset using an assert.
    In a corner case with out-of-bounds access (e.g. @PR35657 function added in
unit test), it is possible that the two allocas have the same type but
different offsets.

    This patch makes the check of the offset in the if condition, and
re-enables the splitting for non-whole-alloca slices.

    Differential Revision: <a href="https://reviews.llvm.org/D41981">https://reviews.llvm.org/D41981</a></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>