[cfe-dev] -O4 with #include <iostream>

Chris Lattner clattner at apple.com
Sun Jul 4 09:50:12 PDT 2010


On Jul 4, 2010, at 2:47 AM, Toralf Niebuhr wrote:

> I recently asked why something doesn't compile. With the latest trunk it compiles fine under some conditions.

What version of clang are you using?  The code that is causing the error has been completely removed.  Can you try with mainline?

-Chris

> 
> //  ---- Out.h
> class Out {
> public:
>  void out();
> };
> 
> //  ---- Out.cpp
> #include "Out.h"
> #include <iostream>
> 
> void Out::out() {
>  std::cout << "Hello World" << std::endl;
> }
> 
> // ---- main.cpp
> #include "Out.h"
> 
> int main() {
>  Out o;
> 	o.out();
> 	return 0;
> }
> 
> compiling this with 
> clang++ -O4 -o main main.cpp Out.cpp 
> gives the following error
> 
> Alloca array size must be i32
>  %o = alloca %class.Out, void (%class.Out*)* @_ZN3Out3outEv, align 2 ; <%class.Out*> [#uses=1]
> Instruction does not dominate all uses!
>  %o = alloca %class.Out, void (%class.Out*)* @_ZN3Out3outEv, align 2 ; <%class.Out*> [#uses=1]
>  call void @_ZN3Out3outEv(%class.Out* %o)
> Broken module found, compilation aborted!
> Stack dump:
> 0.	Running pass 'Function Pass Manager' on module 'ld-temp.o'.
> 1.	Running pass 'Module Verifier' on function '@main'
> 
> 
> The interesting thing is the following
> 
> if I modify main.cpp to
> 
> // ---- main.cpp
> #include "Out.h"
> #include <iostream>
> 
> int main() {
>  Out o;
> 	o.out();
> 	return 0;
> }
> 
> It compiles fine and the binary runes fine too.
> 
> This makes me think that there was to much optimization done during compile time when compiling Out.cpp
> 
> Any ideas?
> 
> 
> Toralf
> 
> 
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev





More information about the cfe-dev mailing list