public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/97907] New: error when compiling with optimization
@ 2020-11-19 12:23 gustavo at ugr dot es
2020-11-19 12:58 ` [Bug c++/97907] " schwab@linux-m68k.org
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: gustavo at ugr dot es @ 2020-11-19 12:23 UTC (permalink / raw)
To: gcc-bugs
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;
}
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/97907] error when compiling with optimization
2020-11-19 12:23 [Bug c++/97907] New: error when compiling with optimization gustavo at ugr dot es
@ 2020-11-19 12:58 ` schwab@linux-m68k.org
2020-11-19 13:18 ` gustavo at ugr dot es
2020-11-19 14:08 ` schwab@linux-m68k.org
2 siblings, 0 replies; 4+ messages in thread
From: schwab@linux-m68k.org @ 2020-11-19 12:58 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97907
--- Comment #1 from Andreas Schwab <schwab@linux-m68k.org> ---
f1 invokes undefined behaviour by modifying an input-only asm operand.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/97907] error when compiling with optimization
2020-11-19 12:23 [Bug c++/97907] New: error when compiling with optimization gustavo at ugr dot es
2020-11-19 12:58 ` [Bug c++/97907] " schwab@linux-m68k.org
@ 2020-11-19 13:18 ` gustavo at ugr dot es
2020-11-19 14:08 ` schwab@linux-m68k.org
2 siblings, 0 replies; 4+ messages in thread
From: gustavo at ugr dot es @ 2020-11-19 13:18 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97907
--- Comment #2 from gustavo <gustavo at ugr dot es> ---
(In reply to Andreas Schwab from comment #1)
> f1 invokes undefined behaviour by modifying an input-only asm operand.
as expected... this is a test for students.
only f3 matters.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/97907] error when compiling with optimization
2020-11-19 12:23 [Bug c++/97907] New: error when compiling with optimization gustavo at ugr dot es
2020-11-19 12:58 ` [Bug c++/97907] " schwab@linux-m68k.org
2020-11-19 13:18 ` gustavo at ugr dot es
@ 2020-11-19 14:08 ` schwab@linux-m68k.org
2 siblings, 0 replies; 4+ messages in thread
From: schwab@linux-m68k.org @ 2020-11-19 14:08 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97907
Andreas Schwab <schwab@linux-m68k.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |INVALID
--- Comment #3 from Andreas Schwab <schwab@linux-m68k.org> ---
No, everything matters. The call to f1 overwrites the argument that is passed
to f3.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-11-19 14:08 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-19 12:23 [Bug c++/97907] New: error when compiling with optimization gustavo at ugr dot es
2020-11-19 12:58 ` [Bug c++/97907] " schwab@linux-m68k.org
2020-11-19 13:18 ` gustavo at ugr dot es
2020-11-19 14:08 ` schwab@linux-m68k.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).