<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 --- - NVPTX: NaryReassociate.cpp : heap-use-after-free" href="https://urldefense.proofpoint.com/v2/url?u=https-3A__llvm.org_bugs_show-5Fbug.cgi-3Fid-3D24301&d=AwMBaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=pF93YEPyB-J_PERP4DUZOJDzFVX5ZQ57vQk33wu0vio&m=0DfVJyk1OUrcCEpCtm8AHtdyCKp_u7BMHK9lIN_mFh4&s=1st_U2uQc15c95bpC7Q1vR5y1Olq8Wvq5DEtgCaXQ8A&e=">24301</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>NVPTX: NaryReassociate.cpp : heap-use-after-free
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </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>normal
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>Backend: PTX
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>tobias@grosser.es
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=14663" name="attach_14663" title="Test input to reproduce this example.">attachment 14663</a> <a href="attachment.cgi?id=14663&action=edit" title="Test input to reproduce this example.">[details]</a></span>
Test input to reproduce this example.

If I compile llc (r243247) with address sanitizer and run it on the attached
input I get the following report:

READ of size 8 at 0x60b00012c2d0 thread T0
    #0 0x153a3a3 in getParent
/home/grosser/Projects/polly/git/include/llvm/IR/Instruction.h:72:55
    #1 0x153a3a3 in llvm::DominatorTree::dominates(llvm::Instruction const*,
llvm::Instruction const*) const
/home/grosser/Projects/polly/git/lib/IR/Dominators.cpp:80
    #2 0x1946381 in (anonymous
namespace)::NaryReassociate::findClosestMatchingDominator(llvm::SCEV const*,
llvm::Instruction*)
/home/grosser/Projects/polly/git/lib/Transforms/Scalar/NaryReassociate.cpp:500:9
    #3 0x1946d80 in (anonymous
namespace)::NaryReassociate::tryReassociatedAdd(llvm::SCEV const*,
llvm::Value*, llvm::Instruction*)
/home/grosser/Projects/polly/git/lib/Transforms/Scalar/NaryReassociate.cpp:477:15
    #4 0x1946a5f in (anonymous
namespace)::NaryReassociate::tryReassociateAdd(llvm::Value*, llvm::Value*,
llvm::Instruction*)
/home/grosser/Projects/polly/git/lib/Transforms/Scalar/NaryReassociate.cpp:461:24
    #5 0x1941b6f in tryReassociateAdd
/home/grosser/Projects/polly/git/lib/Transforms/Scalar/NaryReassociate.cpp:440:20
    #6 0x1941b6f in tryReassociate
/home/grosser/Projects/polly/git/lib/Transforms/Scalar/NaryReassociate.cpp:278
    #7 0x1941b6f in doOneIteration
/home/grosser/Projects/polly/git/lib/Transforms/Scalar/NaryReassociate.cpp:238
    #8 0x1941b6f in (anonymous
namespace)::NaryReassociate::runOnFunction(llvm::Function&)
/home/grosser/Projects/polly/git/lib/Transforms/Scalar/NaryReassociate.cpp:210
    #9 0x1687d2b in llvm::FPPassManager::runOnFunction(llvm::Function&)
/home/grosser/Projects/polly/git/lib/IR/LegacyPassManager.cpp:1520:23
    #10 0x16881b5 in llvm::FPPassManager::runOnModule(llvm::Module&)
/home/grosser/Projects/polly/git/lib/IR/LegacyPassManager.cpp:1540:16
    #11 0x1688e39 in runOnModule
/home/grosser/Projects/polly/git/lib/IR/LegacyPassManager.cpp:1596:23
    #12 0x1688e39 in llvm::legacy::PassManagerImpl::run(llvm::Module&)
/home/grosser/Projects/polly/git/lib/IR/LegacyPassManager.cpp:1698
    #13 0x64e0f9 in compileModule
/home/grosser/Projects/polly/git/tools/llc/llc.cpp:381:5
    #14 0x64e0f9 in main /home/grosser/Projects/polly/git/tools/llc/llc.cpp:204
    #15 0x7fdd2ae26ec4 in __libc_start_main
/build/buildd/glibc-2.19/csu/libc-start.c:287
    #16 0x59d50e in _start
(/home/grosser/Projects/polly/build_sanitize/bin/llc+0x59d50e)

0x60b00012c2d0 is located 96 bytes inside of 112-byte region
[0x60b00012c270,0x60b00012c2e0)
freed by thread T0 here:
    #0 0x643f62 in operator delete(void*)
(/home/grosser/Projects/polly/build_sanitize/bin/llc+0x643f62)
    #1 0x162b2f7 in deleteNode
/home/grosser/Projects/polly/git/include/llvm/ADT/ilist.h:113:39
    #2 0x162b2f7 in erase
/home/grosser/Projects/polly/git/include/llvm/ADT/ilist.h:466
    #3 0x162b2f7 in llvm::Instruction::eraseFromParent()
/home/grosser/Projects/polly/git/lib/IR/Instruction.cpp:71
    #4 0x2237a97 in
llvm::RecursivelyDeleteTriviallyDeadInstructions(llvm::Value*,
llvm::TargetLibraryInfo const*)
/home/grosser/Projects/polly/git/lib/Transforms/Utils/Local.cpp:368:5
    #5 0x19424aa in doOneIteration
/home/grosser/Projects/polly/git/lib/Transforms/Scalar/NaryReassociate.cpp:242:11
    #6 0x19424aa in (anonymous
namespace)::NaryReassociate::runOnFunction(llvm::Function&)
/home/grosser/Projects/polly/git/lib/Transforms/Scalar/NaryReassociate.cpp:210
    #7 0x1687d2b in llvm::FPPassManager::runOnFunction(llvm::Function&)
/home/grosser/Projects/polly/git/lib/IR/LegacyPassManager.cpp:1520:23
    #8 0x16881b5 in llvm::FPPassManager::runOnModule(llvm::Module&)
/home/grosser/Projects/polly/git/lib/IR/LegacyPassManager.cpp:1540:16
    #9 0x1688e39 in runOnModule
/home/grosser/Projects/polly/git/lib/IR/LegacyPassManager.cpp:1596:23
    #10 0x1688e39 in llvm::legacy::PassManagerImpl::run(llvm::Module&)
/home/grosser/Projects/polly/git/lib/IR/LegacyPassManager.cpp:1698
    #11 0x64e0f9 in compileModule
/home/grosser/Projects/polly/git/tools/llc/llc.cpp:381:5
    #12 0x64e0f9 in main /home/grosser/Projects/polly/git/tools/llc/llc.cpp:204
    #13 0x7fdd2ae26ec4 in __libc_start_main
/build/buildd/glibc-2.19/csu/libc-start.c:287

previously allocated by thread T0 here:
    #0 0x6439a2 in operator new(unsigned long)
(/home/grosser/Projects/polly/build_sanitize/bin/llc+0x6439a2)
    #1 0x16faa12 in llvm::User::operator new(unsigned long, unsigned int)
/home/grosser/Projects/polly/git/lib/IR/User.cpp:96:19
    #2 0x16461d4 in operator new
/home/grosser/Projects/polly/git/include/llvm/IR/InstrTypes.h:150:12
    #3 0x16461d4 in llvm::BinaryOperator::Create(llvm::Instruction::BinaryOps,
llvm::Value*, llvm::Value*, llvm::Twine const&, llvm::Instruction*)
/home/grosser/Projects/polly/git/lib/IR/Instructions.cpp:1701
    #4 0x24b3e68 in llvm::LLParser::ParseArithmetic(llvm::Instruction*&,
llvm::LLParser::PerFunctionState&, unsigned int, unsigned int)
/home/grosser/Projects/polly/git/lib/AsmParser/LLParser.cpp:4969:10
    #5 0x24ac288 in llvm::LLParser::ParseInstruction(llvm::Instruction*&,
llvm::BasicBlock*, llvm::LLParser::PerFunctionState&)
/home/grosser/Projects/polly/git/lib/AsmParser/LLParser.cpp:4545:9
    #6 0x24aad0f in
llvm::LLParser::ParseBasicBlock(llvm::LLParser::PerFunctionState&)
/home/grosser/Projects/polly/git/lib/AsmParser/LLParser.cpp:4482:13
    #7 0x2462e69 in llvm::LLParser::ParseFunctionBody(llvm::Function&)
/home/grosser/Projects/polly/git/lib/AsmParser/LLParser.cpp:4430:9
    #8 0x24506dc in llvm::LLParser::ParseDefine()
/home/grosser/Projects/polly/git/lib/AsmParser/LLParser.cpp:391:10
    #9 0x244cdf7 in llvm::LLParser::ParseTopLevelEntities()
/home/grosser/Projects/polly/git/lib/AsmParser/LLParser.cpp:197:33
    #10 0x244c8c1 in llvm::LLParser::Run()
/home/grosser/Projects/polly/git/lib/AsmParser/LLParser.cpp:47:10
    #11 0x243ee75 in llvm::parseAssemblyInto(llvm::MemoryBufferRef,
llvm::Module&, llvm::SMDiagnostic&, llvm::SlotMapping*)
/home/grosser/Projects/polly/git/lib/AsmParser/Parser.cpp:31:10
    #12 0x243f65d in llvm::parseAssembly(llvm::MemoryBufferRef,
llvm::SMDiagnostic&, llvm::LLVMContext&, llvm::SlotMapping*)
/home/grosser/Projects/polly/git/lib/AsmParser/Parser.cpp:41:7
    #13 0x1791125 in llvm::parseIR(llvm::MemoryBufferRef, llvm::SMDiagnostic&,
llvm::LLVMContext&)
/home/grosser/Projects/polly/git/lib/IRReader/IRReader.cpp:80:10
    #14 0x1791ce3 in llvm::parseIRFile(llvm::StringRef, llvm::SMDiagnostic&,
llvm::LLVMContext&)
/home/grosser/Projects/polly/git/lib/IRReader/IRReader.cpp:93:10
    #15 0x64a78f in compileModule
/home/grosser/Projects/polly/git/tools/llc/llc.cpp:228:11
    #16 0x64a78f in main /home/grosser/Projects/polly/git/tools/llc/llc.cpp:204
    #17 0x7fdd2ae26ec4 in __libc_start_main
/build/buildd/glibc-2.19/csu/libc-start.c:287

I unfortunately can not reduce this input as bugpoint finds someother bugs in
NVPTX that get reduced instead.

Regarding the bug itself. It seems we delete an instruction without
removing it from the dominator tree, but still query the dominator tree after.</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>