Handmade Hero » Forums » Code » Visual Studio 2015 Update 1 + clang
mmozeiko
Mārtiņš Možeiko
1518 posts
1 project
#5295 Visual Studio 2015 Update 1 + clang
2 years ago Edited by Mārtiņš Možeiko on Dec. 2, 2015, 8:08 a.m.

Today Microsoft release Update 1 for Visual Studio 2015. It includes option to use clang frontend for compiler!

I tried to compile latest Handmade Hero - but it's not very easy :(

First of all - all the build.bat must be rewritten. Clang MSVC ships with doesn't provide clang-cl.exe which would understand MSVC style options. Also it doesn't understand link options, so compile and link commands must be split and executed separately. IDE integration of course is much simpler (just change one combo-box in project properties and that's it).

When I patched build.bat, there was couple of issues - it doesn't have _WriteBarrier definition, only declaration. Declaration is commented out in intrin.h:
1
2
3
4
5
//static __inline__ void __DEFAULT_FN_ATTRS
//__attribute__((__deprecated__("use other intrinsics or C++11 atomics instead")))
//_WriteBarrier(void) {
//  __asm__ volatile ("" : : : "memory");
//}


But that is easily patchable (just replace WriteBarrier with inline asm). After that I could at least build win32_handmade.exe and simple_preprocessor.exe files. But there are problems with compiling handmade_optimized.cpp file. Compiler fails with internal error: https://gist.github.com/mmozeiko/e8f11c6041c7c0008842
No idea why they don't support _mm_cvtps_epi32 intrinsic.

But anyways. We're getting closer for using clang :) It's pretty cool - it produces much better warning/error messages from compiler than MSVC.

Backend for is still the same, so no changes in codegen (I'm guessing for compatibility reasons).
Jim0_o
Jim R. Didriksen
53 posts
#5312 Visual Studio 2015 Update 1 + clang
2 years ago

ref. handmade_optimized.cpp error:

Doesn't this kill the building of the handmade_audio.cpp as well? or has that code been removed? (I'm only on day 155)

1
2
	__m128i L = _mm_cvtps_epi32(S0);
	__m128i R = _mm_cvtps_epi32(S1);

- Jim RMHD
mmozeiko
Mārtiņš Možeiko
1518 posts
1 project
#5313 Visual Studio 2015 Update 1 + clang
2 years ago

Probably it does. I didn't look further once the compiler stopped at first error.
Jim0_o
Jim R. Didriksen
53 posts
#5316 Visual Studio 2015 Update 1 + clang
2 years ago

Oh okay, so you haven't tried compiling just the .dll ?

I tried VS 2015 back when it was about to go out of beta and none of the few C++ projects I had would compile, (they where converted VS Com 2013 projects that 2015 had converted on load) I didn't have enough knowledge to debug the errors but the list was to long to want to anyway.

Conclusion: I have since then assumed that Visual Studio somehow has been able to not be backwards compatible with itself.

- Jim RMHD
mmozeiko
Mārtiņš Možeiko
1518 posts
1 project
#5317 Visual Studio 2015 Update 1 + clang
2 years ago Edited by Mārtiņš Možeiko on Dec. 6, 2015, 10:55 p.m.

I tried compiling dll. First thing build.bat compiles is handmade_optimized.cpp. Rest of files produced bunch of warnings that can be fixed, but I didn't bother to fix that.

Just using VS2015 with regular cl.exe compiler should be fine, there are few minor warnings to fix - no big deal.
This topic is about compiling with clang frontend that is part of VS2015 update 1.
Jim0_o
Jim R. Didriksen
53 posts
#5320 Visual Studio 2015 Update 1 + clang
2 years ago

Yeah I know, sorry if that seemed off topic, was just a anecdote regarding VS2015 development, and some question as I've been looking for a way to use Clang/LLVM in windows, was planning on compiling it with the mingw compiler to be MS free to see if that was possible.

- Jim RMHD
mmozeiko
Mārtiņš Možeiko
1518 posts
1 project
#5327 Visual Studio 2015 Update 1 + clang
2 years ago

Well you see, they try to improve compiler by making it properly support things defined in C/C++ standard. So your code compiles in same way it does for other compilers. But because currently they have few things implemented so differently, you can not implement standard by being backwards compatible. So you need to choose - better compiler or backwards compatible. Most people want proper compiler that does things the way compiler should, and that's what they are improving.
mmozeiko
Mārtiņš Možeiko
1518 posts
1 project
#5979 Visual Studio 2015 Update 1 + clang
1 year, 9 months ago Edited by Mārtiņš Možeiko on Feb. 27, 2016, 9:38 a.m.

After watching todays stream, bump - remainder about this topic about MSVC+clang.

Clang is used only as frontend for MSVC (parser). Optimizer and code-generation is still be MSVC. That's why they can do pdb support. So all the advantages Casey wants from clang (code-generation/performance/optimizer) won't be available with clang integrated in MSVC. So you really need to wait until clang-cl is finished with stuff you need (pdb support, exceptions if C++ is used, etc..)

Also as you can read in this thread - it is pretty buggy/incomplete.
cubercaleb
Caleb
12 posts

None

#5983 Visual Studio 2015 Update 1 + clang
1 year, 9 months ago

Actually, clang-cl can produce PDB information for MSVC now. Just checked it too.

None
gingerBill
Ginger Bill
215 posts
2 projects

I am ginger thus have no soul.

#5990 Visual Studio 2015 Update 1 + clang
1 year, 9 months ago

I am going to test it tonight. I will report on the results.
mmozeiko
Mārtiņš Možeiko
1518 posts
1 project
#5991 Visual Studio 2015 Update 1 + clang
1 year, 9 months ago Edited by Mārtiņš Možeiko on Feb. 27, 2016, 7:59 p.m.

From this:
Debug info: Minimal. Clang emits both CodeView line tables (similar to what MSVC emits when given the /Z7 flag) and DWARF debug information into the object file. Microsoft’s link.exe will transform the CodeView line tables into a PDB, enabling stack traces in all modern Windows debuggers. Clang does not emit any CodeView-compatible type info or description of variable layout.

It sounds like your basic debugging - setting breakpoints and stepping will work. But examining variables in watch window will not work, because currently clang is not emitting debug info on variable and types.
gingerBill
Ginger Bill
215 posts
2 projects

I am ginger thus have no soul.

#5992 Visual Studio 2015 Update 1 + clang
1 year, 9 months ago Edited by Ginger Bill on Feb. 27, 2016, 8:05 p.m.

Short answer: Clang is about 3 times _slower_ than MSVC but debug info works okay (so far).

Longer answer:
I've tried both approaches: clang, llc, link; clang-cl. They both work and produce PDBs so I can use Visual Studio to debug!!! Watch window is not working from what I can tell.

However, the compilation time for me has increased from 0.8s to 2.3s (and even more with other applications open). Without debug information, I can reduce it to 1.7s but still that is slower. I was hoping that clang would compile much quicker than MSVC but it doesn't seem to at the moment.

It seems that I will have to stay will MSVC. :'(
mmozeiko
Mārtiņš Možeiko
1518 posts
1 project
#12531 Visual Studio 2015 Update 1 + clang
5 months ago Edited by Mārtiņš Možeiko on July 18, 2017, 7:21 a.m.

RIP clang/c2: https://blogs.msdn.microsoft.com/...tures-in-vs-2017-3#comment-333176

We are unlikely to be updating Clang/C2 at any time. We originally created Clang/C2 to enable developers to bring code from other platforms to Windows. Now, the MSVC compiler is almost standards-conforming and we expect to be finished this year (https://blogs.msdn.microsoft.com/...dards-conformance-from-microsoft/). You should be able to use MSVC for almost any code that you previously would have used Clang/C2 for. Soon, MSVC should compile all code that Clang/C2 compiles, and more.