Good Afternoon,
My colleagues and I are doing a study on compilers. We have some questions
related to gcc and the compilation process that we were hoping you could help
us with.
In a general sense, we were wondering what optimizations may be occurring in
the front-end stages of the compiler? We are noticing some constant
substitution (e.g., 2*15+3 being changed to 33) and some algebraic
simplifications (more later) showing up in the first intermediate file
generated using dump flags with the g++ command. Are we correct in assuming
this first IR file is indeed coming from the front end (.original file)? In
looking at the gcc source code, we are having difficulty seeing where these
optimizations might be occurring in the initial parsing phase. Do you have any
insights you might be able to share?
One algebraic simplification we are seeing is particularly interesting. Given
the following code snippet intended to check for buffer overflow, which is
actually undefined behavior in C++, we expected to maybe see the if check
optimized away entirely.
char buffer[100];
int length; //value received through argument or command line
.
.
If (buffer + length < buffer)
{
cout << "Overflow" << endl;
}
Instead, our assembly code showed that the conditional was changed to length <
0, which is not what was intended at all. Again, this showed up in the first
IR file generated with g++ so we are thinking it happened in the compiler
front-end, which is surprising. Any thoughts on this? In addition, when the
above conditional expression is not used as part of an if check (e.g., assigned
to a Boolean), it is not simplified.
Computer/compiler info:
1. Compilation command: g++ -save-temps -fdump-rtl-all-all fdump-ipa-all-all
-fdump-tree-all-all <fn.cpp>
2. g++ version: g++ (Ubuntu 4.8.2-19ubuntu1) 4.8.2
3. target: i-686
4. uname -a : Linux OptiPlex-755 3.16.0-generic#40~14.04.1-Ubuntu SMP
We look forward to hearing from you.
Thank you in advance for your time and inputs,
Jodi
Jodi A. Miller
Senior Research Assistant
Applied Research Laboratory/Penn State
(814)863-4077