[Bug c++/97907] New: error when compiling with optimization

gustavo at ugr dot es gcc-bugzilla@gcc.gnu.org
Thu Nov 19 12:23:48 GMT 2020


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97907

            Bug ID: 97907
           Summary: error when compiling with optimization
           Product: gcc
           Version: 10.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gustavo at ugr dot es
  Target Milestone: ---

Created attachment 49596
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49596&action=edit
source code and makefile, also available at https://pccito.ugr.es/bug/ and
https://pccito.ugr.es/bug.tgz

3(5) should return 2 but it only works when no optimization level is applied.
f1 and f2 are two dumb functions not intended to work.

// g++ -O1 -save-temps -std=c11 -v -Wall    popcount.cc   -o popcount

#include <iostream>

unsigned f1(unsigned u)
{
        unsigned c;
        asm("popcnt %0, %1":"+r"(c):"r"(u));
        return c;
}

unsigned f2(unsigned u)
{
        unsigned c;
        asm("popcnt %0, %1":"=r"(c),"=r"(u));
        return c;
}

unsigned f3(unsigned u)
{
        unsigned c;
        asm("popcnt %1, %0":"=r"(c):"r"(u));
        return c;
}

int main()
{
        std::cout << "f1(5) = " << f1(5) << std::endl
                  << "f2(5) = " << f2(5) << std::endl
                  << "f3(5) = " << f3(5) << std::endl;
}


More information about the Gcc-bugs mailing list