[Bug c/106381] New: DCE depends on used programming language (C vs C++)
tmayerl at student dot ethz.ch
gcc-bugzilla@gcc.gnu.org
Thu Jul 21 09:33:07 GMT 2022
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106381
Bug ID: 106381
Summary: DCE depends on used programming language (C vs C++)
Product: gcc
Version: 12.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: tmayerl at student dot ethz.ch
Target Milestone: ---
In some cases, the compiler's ability to eliminate dead code depends on the
used language (C vs C++).
GCC detects that the if expression in the following code snippet evaluates to
false and thus removes the dead code. The code is compiled as C++ code:
#include <stdio.h>
#include <stdbool.h>
static void __attribute__ ((noinline)) DCEMarker0_() {printf("DCE2.0");}
void f(unsigned s, unsigned c) {
if (((!s == !c) && c && !(s))) {
DCEMarker0_();
}
}
However, if the same code is compiled as C code, GCC cannot eliminate the dead
code anymore.
This can also be seen via the following Compiler Explorer link:
https://godbolt.org/z/a9ned9Exb
(Might be related to 106379 and 106380)
More information about the Gcc-bugs
mailing list