[LLVMbugs] [Bug 24080] New: Infinite loop with any optimization if control reaches end of non-void function

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu Jul 9 19:43:05 PDT 2015


https://llvm.org/bugs/show_bug.cgi?id=24080

            Bug ID: 24080
           Summary: Infinite loop with any optimization if control reaches
                    end of non-void function
           Product: clang
           Version: 3.4
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: mkoval at cs.cmu.edu
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Created attachment 14572
  --> https://llvm.org/bugs/attachment.cgi?id=14572&action=edit
test.cpp

Overview:

Enabling any form of optimization (-O1, -O2, or -Os) causes a 'for' loop to
enter an infinite loop if control reaches the end of non-void function. The
loop terminates correctly, but the program crashes with 'SIGILL, Illegal
instruction', when compiled with -O0.


Steps to Reproduce:

Compile the attached program with 'clang++ -O1 -o test test.cpp' and run it
with './test'.


Actual Results (with -O1, -O2, or -Os):

i = 0
i = 1
i = 2
i = 3
i = 4
i = 5
i = 6
i = 12
// ...


Actual Results (with -O0):

i = 0
i = 1
i = 2
i = 3
Illegal instruction


Expected results:

i = 0
i = 1
i = 2
i = 3


Build Date & Platform:

I am using the latest version of Clang available in the Ubuntu Apt repository
for Ubuntu 14.04:

Ubuntu clang version 3.4-1ubuntu3 (tags/RELEASE_34/final) (based on LLVM 3.4)
Target: x86_64-pc-linux-gnu
Thread model: posix


Additional Builds and Platforms:

I was not able to replicate this behavior on OS X with the version of Clang
shipped with X Code:

Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn)
Target: x86_64-apple-darwin14.3.0
Thread model: posix


Additional Information:

Adding additional statements in 'f' causes even more strange behavior. For
example, modifying the function as follows produces different behavior:

bool f()
{
  std::cout << "b" << std::endl;
  for (size_t i = 0; i < 4; ++i) {
    std::cout << "i = " << i << std::endl;
  }
  std::cout << "c" << std::endl;
}

With -O1 the program produces the following output in an infinite loop:

b
i = 0
i = 1
i = 2
i = 3
c

With -Os or -O2 it crashes with:

b
i = 0
i = 1
i = 2
i = 3
c
terminate called after throwing an instance of 'std::bad_cast'
  what():  std::bad_cast
Aborted

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20150710/4eca81b4/attachment.html>


More information about the llvm-bugs mailing list