This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug middle-end/52985] New: Postincrement not applied after indexing ternary array expression


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52985

             Bug #: 52985
           Summary: Postincrement not applied after indexing ternary array
                    expression
    Classification: Unclassified
           Product: gcc
           Version: 4.6.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: will@benfold.com


Created attachment 27156
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=27156
Preprocessed source

[Component=middle-end was a guess, apologies if it's wrong.]

The code below prints an infinite series of zeros, as if the iterator is never
incremented.

The problem goes away if:
* the ternary expression is replaced by either tableA or tableB
* 'flag' is set to true
* the iterator increment is performed in a separate statement
* the vector and iterators are replaced with an array and (int *)
* tableA and tableB are replaced by vectors.

If the result of the array indexing is actually used, e.g. printed to cerr,
then results are the same at -O1 and above, but I see a segfault with -O0.

----------------------------------------------------------------

#include <iostream>
#include <vector>

int main (int argc, char *argv[])
{
  std::vector<int> v(1);

  int tableA[] = { 0 };
  int tableB[] = { 0 };

  bool flag = false;
  for (std::vector<int>::const_iterator it = v.begin(); it != v.end();)
  {
    (flag ? tableA : tableB)[*it++];
    std::cerr << (it - v.begin()) << "\n";
  }

  return 0;
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]