[cfe-dev] When two functions are the same could clang optimize out one of them?

Csaba Raduly rcsaba at gmail.com
Tue Mar 8 01:14:31 PST 2011


On Tue, Mar 8, 2011 at 6:55 AM, 邓尧  wrote:
> Hi,
> When the generated instructions of two functions "f()" & "g()" are the
> same(when templates are used it isn't unusual), could clang remove the
> function "f()" in the object file and translate "f()" calls to "g()" calls?

Templates aren't even needed. At least on x86, accessor functions like

int getFoo() const { return m_foo; }

all boil down to "return *(this + offset)". I've seen Visual C++ 7.1
merge these functions across different classes during optimization. I
was quite the WTF moment during debugging.

Csaba
-- 
GCS a+ e++ d- C++ ULS$ L+$ !E- W++ P+++$ w++$ tv+ b++ DI D++ 5++
The Tao of math: The numbers you can count are not the real numbers.
Life is complex, with real and imaginary parts.
"Ok, it boots. Which means it must be bug-free and perfect. " -- Linus Torvalds
"People disagree with me. I just ignore them." -- Linus Torvalds




More information about the cfe-dev mailing list