Regular Visual Studio versus ClangCL (2024)

Regular Visual Studio versus ClangCL (lemire.me)
53 points by zdw on Feb 27, 2023 | hide | past | favorite | 36comments
Regular Visual Studio versus ClangCL (1)

rurban on Feb 28, 2023 | next [–]


I also tested MSVC vs ClangCL recently, because someone requested MSVC support, and I have no Windows machine. mingw cross worked fine for several years. on apple and linux. So I installed clangcl and cross-compiled the project on linux to windows via clangcl, fixed all missing compat pieces (not much, because MS got much better recently, mostly adding some _ prefixes to std functions), and then tried a native MSVC CI (Github Actions and appveyor).

clangcl indeed caught a lot of problems, but not all. msvc still deviated more than with chrome. The clangcl/msvc wrong size reports were very good!Here are the additional MSVC fixes I had to add, over clangcl:

 VS2019 specific fixes, __VA_ARGS__, __attribute__, suppress warnings * __VA_ARGS__ macro support (illegal ...) * __attribute__ only with __GCC__ * suppress C4101 uninitialized recount warnings, and strcpy insecure warnings. * no proper const var support (with the even weirder error: cannot allocate an array of constant size) * much stricter typecasts (silly cl compiler) * strict dllexport/dllimport decls: fix various omissions

clangcl is not error compatible to msvc, msvc errors much more.

While I was there: tcc was fine, for chibicc I had to file some PR's with large files, and pcc is currently broken, some tricky cpp regressions, which I couldn't fix.

Regular Visual Studio versus ClangCL (2)

planede on Feb 28, 2023 | prev | next [–]


An other option that is not mentioned is cross compiling with clang-cl on a Linux host to a Windows target. I believe this is much harder to set up, but it could have better compile performance than compiling on Windows. It would be pretty funny if compiling with clang-cl on WSL would be faster than compiling with clang-cl on Windows natively.

Regular Visual Studio versus ClangCL (3)

rurban on Feb 28, 2023 | parent | next [–]


Did that. Fastest is msvc natively via cmake (3m). Slowest is mingw on windows via autotools (>30m).clangcl vs msvc was not much difference (less than 30s diff).linux builds are from 3m (cmake) to 8m (autotools).

clangcl on WSL it would be much faster, but msvc natively would beat it, esp. if you turn off the virus scanner and inherited filesystem permissions.The sheer amount of additional msvc warnings (integer promotion should not really warn) would slow it down though.

Regular Visual Studio versus ClangCL (4)

xvilka on Feb 28, 2023 | prev | next [–]


So basically no reason to keep flogging this incompatible dead horse of MSVC. Microsoft should just join the project and help to improve the LLVM ecosystem, just like many other companies do. One thing they can help is the project of separating C and C++ compilation in multiple steps by creating something was referred as CIL[1] (C intermediate language for LLVM), like some other LLVM languages do - Rust, Swift, etc.

[1] https://llvm.org/devmtg/2020-09/slides/CIL_Common_MLIR_Abstr...

Regular Visual Studio versus ClangCL (5)

frutiger on Feb 28, 2023 | parent | next [–]


Except MSVC is far ahead of Clang[1] (and leagues ahead of Apple Clang) when it comes to C++ standards conformance.

1. https://en.cppreference.com/w/cpp/compiler_support#cpp20

Regular Visual Studio versus ClangCL (6)

Kranar on Feb 28, 2023 | root | parent | next [–]


MSVC tends to like to tick off checkmarks that the other compilers would be hesitant to check off. So yes, MSVC can claim to implement modules and co-routines and pretty much all of the standard library, but in actuality it does so in a way that is unreliable and full of bugs.

GCC and clang have those same features, but they avoid including them in their main distribution and instead have experimental/development forks that people can use, opting to include them only when they meet a much higher standard than Microsoft.

Regular Visual Studio versus ClangCL (7)

jcelerier on Feb 28, 2023 | root | parent | prev | next [–]


in theory yes, in practice this morning again I tried the new version of VS and encountered dozens and dozens of compile errors in standards-confirming C++20 code (which works fine in gcc and clang), some for fairly basic C++20 stuff.

Regular Visual Studio versus ClangCL (8)

swatcoder on Feb 28, 2023 | root | parent | next [–]


This might not be your issue, but if you haven’t tried that transition before, the first batch of errors is often because secondary header includes incidentally let your code work in those other toolchains despite you not including required headers yourself. It happens annoyingly often, but it’s not a flaw in the toolchain. The MS headers are just structured differently.

Regular Visual Studio versus ClangCL (9)

jcelerier on Feb 28, 2023 | root | parent | next [–]


No, those were actual language issues, not missing headers or things like that. For instance: https://developercommunity.visualstudio.com/t/if-constexprre...

Which is extremely frustrating when i reported a very similar issue in 17.4 which was reported as fixed (https://developercommunity.visualstudio.com/t/if-constexprre...), etc.

I try building my code every once in a while against MSVC because it has some useful warnings but am very burn out with code breaking on almost every minor version - I shifted all my serious work to clang+libc++ on windows a few years ago already. E.g. I've reported something like 50+ bugs, internal compiler errors, etc... to MS over the years and only a couple for clang even though I use it much much more.

Regular Visual Studio versus ClangCL (10)

simplotek on Feb 28, 2023 | root | parent | prev | next [–]


> Except MSVC is far ahead of Clang[1] (and leagues ahead of Apple Clang) when it comes to C++ standards conformance.

I feel this is a red herring.

People use AppleClang because it ships with Xcode and is integrated with it. Those who are stuck with Xcode will not choose msvc's support for C++20 as a good enough reason to drop everything.

With Clang, the main differences with MSVC boil down to a couple of minor features that are hardly showstoppers, such as simplifying implicit lambda captures.

Between being able to use clang and all it's tooling and being stuck with msvc, using clang is far above in importance.

Regular Visual Studio versus ClangCL (11)

xvilka on Feb 28, 2023 | root | parent | prev | next [–]


It absolutely worse in pure C standards and library support though.

Regular Visual Studio versus ClangCL (12)

hvs on Feb 28, 2023 | root | parent | next [–]


Until recently Microsoft didn't even pretend to support C, they basically just built a C++ compiler. But they have really stepped up their support in the past couple years: https://learn.microsoft.com/en-us/cpp/overview/install-c17-s...

Regular Visual Studio versus ClangCL (13)

riskneutral on Feb 28, 2023 | parent | prev | next [–]


There are a lot of great things about both the MSVC and LLVM C++ compilers and the world is a better place because there are multiple, actively maintained and highly capable compilers for C++.

Regular Visual Studio versus ClangCL (14)

cmovq on Feb 28, 2023 | parent | prev | next [–]


Did you read the article? MSVC compiles twice as fast as clang and has double the perf in debug builds.

LLVM has an amazing optimizer but the compiler is just so much slower even on unoptimized builds.

Regular Visual Studio versus ClangCL (15)

xvilka on Feb 28, 2023 | root | parent | next [–]


Not for a release builds though. Moreover, in general Windows compilation is always slower than on Linux, they should improve their OS FS IO performance.

Regular Visual Studio versus ClangCL (16)

FrostKiwi on Feb 28, 2023 | root | parent | next [–]


This is in part because of how Windows Defender works. It scans created binaries, blocking them whilst doing so and interferes with compilation. This is the reason there often exists a hidden Windows Defender exception folder for developers. I have seen IT of 2 different companies setting this up now and there really is a time difference.

Whilst not quite on topic, this is especially catastrophic for anything that uses fork() and friends via Cygwin. (i.e. the MSYS2 ecosystem and the MinGW64 compiler suite). MSYS2 native `git add -> [tab]` halts the freezes command line for a second and turning off Windows Defender or using folder exceptions easily cuts compilation time by for Makefiles with multiple small files 30%.

Regular Visual Studio versus ClangCL (17)

ynik on Feb 28, 2023 | root | parent | prev | next [–]


Note that while Windows small file IO is slow; it's extra-slow on C:.I have two partitions (C: and D:) on the same SSD, and creating a whole bunch of empty files (1.txt to 10000.txt) runs 2x faster on D: than it does on C:.

I believe there's two reasons for this:

* C: has extra IO filter drivers for system integrity that eat up CPU

* C:, by default, enables 8dot3names for compatibility (e.g. with software that expects C:\Progra~1\ to work as an alias to C:\Program Files\). On other partitions, 8dot3names are disabled by default.

So I recommend putting the OS on a separate partition from all development activities. Also, don't forget to exclude D: from Windows Defender.

Regular Visual Studio versus ClangCL (18)

TinkersW on Feb 28, 2023 | root | parent | prev | next [–]


This was measuring a full build, but in the real world what matters most is incremental builds.. where MSVC performs very well since it has incremental linking & compiling.

Also who even knows what this build was doing as it used CMake(garbage). It isn't clear what compiler settings were enabled either since again CMake.

Regular Visual Studio versus ClangCL (19)

gpderetta on Feb 28, 2023 | root | parent | prev | next [–]


That's surprising. I haven't used MSVC in almost a decade, but I remember being significantly slower to compile than both GCC and clang. Did it improve since?

Regular Visual Studio versus ClangCL (20)

nurettin on Feb 28, 2023 | root | parent | next [–]


That's surprising. I haven't used MSVC 6 in over two decades, but I remember gcc2.95 (redhat patch was 2.96) being significantly slower and clang didn't even exist. But we had pretty cool trance music at the time.

Regular Visual Studio versus ClangCL (21)

simplotek on Feb 28, 2023 | root | parent | prev | next [–]


> Did you read the article? MSVC compiles twice as fast as clang and has double the perf in debug builds.

To me that means absolutely nothing, as visual studio and msbuild fails to support basic features like compiler launchers, which enable using compiler cache tools like ccache or sscache.

While you're benchmarking compilers, I plug ccache and build projects with dozen of subpackages in under a minute with build servers maxing out on IO.

Regular Visual Studio versus ClangCL (22)

rcme on Feb 28, 2023 | root | parent | prev | next [–]


MSVC was faster than Clang on Windows, but both were slower than Clang on Linux and Mac. And Clang was faster in release builds.

Regular Visual Studio versus ClangCL (23)

gkfasdfasdf on Feb 28, 2023 | root | parent | prev | next [–]


The debug build took 2 min with Visual Studio vs 2:51 for ClangCL. That's not twice as fast.

Regular Visual Studio versus ClangCL (24)

pjmlp on Feb 28, 2023 | parent | prev | next [–]


Not only VC++ is better in ISO C++ support.

clang doesn't come with a state of the art IDE, GUI frameworks, hot code reloading, among lots of other goodies.

Then again, maybe Microsoft should join the other C and C++ vendors that have forked clang and hardly contribute anything to upstream other than LLVM stuff, which is why clang is now enjoying a comfty third place in ISO conformance, after Apple and Google decided to re-focus on their own languages.

Regular Visual Studio versus ClangCL (25)

crabbone on Feb 28, 2023 | root | parent | next [–]


> state of the art IDE

Is that MSVS you are talking about? I don't think even Microsoft's own marketing team would've been so bold as to actually say something like that...

Regular Visual Studio versus ClangCL (26)

xvilka on Feb 28, 2023 | root | parent | prev | next [–]


> hardly contribute anything to upstream other than LLVM stuff

Still better than contributing nothing.

> clang doesn't come with a state of the art IDE, GUI frameworks, hot code reloading, among lots of other goodies.

These features are compiler-agnostic and can be easily built on top of clangd, cling, etc.

Regular Visual Studio versus ClangCL (27)

pjmlp on Feb 28, 2023 | root | parent | next [–]


Enjoy 3rd place then.

No they cannot, clangd isn't compiler agnostic, and Clion's dependency on it is now being hindered by clang's slow pace, even if the goal is to target another compiler.

Regular Visual Studio versus ClangCL (28)

gpderetta on Feb 28, 2023 | root | parent | next [–]


To be fair, from a language point of view, clang is not actually lagging that badly. I don't know how reliable is this: https://en.cppreference.com/w/cpp/compiler_support, but language-wise clang is sort of keeping up.

libc++ is indeed in a sorry state, but at least on linux clang is usually used against libstdc++ so it is not a huge deal. Personally I'm worried about clangd falling behind, but so far I see very very little that it doesn't understand.

Regular Visual Studio versus ClangCL (29)

simplotek on Feb 28, 2023 | root | parent | prev | next [–]


> clang doesn't come with a state of the art IDE,

What are you talking about? I use Clion just fine regardless of compiler.

> GUI frameworks, hot code reloading, among lots of other goodies.

Do you understand that those features have absolutely zero to do with compilers?

Regular Visual Studio versus ClangCL (30)

maxloh on Feb 28, 2023 | root | parent | prev | next [–]


Which is the first/second one?

Regular Visual Studio versus ClangCL (31)

pjmlp on Feb 28, 2023 | root | parent | next [–]


VC++, and GCC.

Then there are plenty of other ones following up clang.

https://en.cppreference.com/w/cpp/compiler_support/20

The list still misses a few proprietary ones on the embedded space.

Regular Visual Studio versus ClangCL (32)

cma on Feb 28, 2023 | parent | prev | next [–]


Would they have to write off MSVC as a capital loss?

Regular Visual Studio versus ClangCL (33)

samsaga2 on Feb 28, 2023 | prev [–]


Resume, avoid Windows to compile anything.

Regular Visual Studio versus ClangCL (34)

pjmlp on Feb 28, 2023 | parent [–]


Like the gaming industry I gather.

Regular Visual Studio versus ClangCL (35)

samsaga2 on Feb 28, 2023 | root | parent [–]


Calculate the build time of the same source code on Windows and Mac or Linux and take your own conclusions.The game industry is attached to Windows, not because it's better for programming. It's because of the drivers and the available tools.

Regular Visual Studio versus ClangCL (36)

pjmlp on Feb 28, 2023 | root | parent [–]


Indeed, they lack incremental linking and hot code reload like Visual Studio, unless one is willing to buy something like Live++.

Regular Visual Studio versus ClangCL (2024)

FAQs

Why use clang-cl? ›

clang-cl.exe is an alias to clang.exe that automatically configure it in MSVC compatible mode. It still do all the work itself but support MSCV flag syntax, MSCV library search path, MSVC ABI, etc. clang-cl.exe is designed to replace cl.exe as transparently as possible.

Does Visual Studio use clang? ›

For Windows projects, Visual Studio by default invokes Clang in clang-cl mode. It links with the Microsoft implementation of the Standard Library.

Should I use clang or GCC on Windows? ›

Clang is much faster and uses far less memory than GCC. Clang aims to provide extremely clear and concise diagnostics (error and warning messages), and includes support for expressive diagnostics. GCC's warnings are sometimes acceptable, but are often confusing and it does not support expressive diagnostics.

Do you need clang for C++? ›

Current Status. Clang is considered to be a production quality C, Objective-C, C++ and Objective-C++ compiler when targeting any target supported by LLVM. As example, Clang is used in production to build performance-critical software like Chrome or Firefox.

What are the advantages of clang? ›

End-User Features
  • Fast compiles and Low Memory Use. ...
  • Expressive Diagnostics. ...
  • GCC Compatibility. ...
  • Library Based Architecture. ...
  • Support Diverse Clients. ...
  • Use the LLVM 'Apache 2' License. ...
  • A real-world, production quality compiler. ...
  • A simple and hackable code base.

Does Microsoft use clang? ›

Clang is compatible with Microsoft's implementation of lambdas except for providing overloads for conversion to function pointer for different calling conventions. However, Microsoft's extension is non-conforming.

Is Clang replacing GCC? ›

It acts as a drop-in replacement for the GNU Compiler Collection (GCC), supporting most of its compiling flags and unofficial language extensions. It includes a static analyzer, and several code analysis tools. Clang operates in tandem with the LLVM compiler back end and has been a subproject of LLVM 2.6 and later.

What compiler does Microsoft Visual Studio use? ›

Microsoft Visual C++ (MSVC) is a compiler for the C, C++, C++/CLI and C++/CX programming languages by Microsoft.

Does Google use Clang? ›

Google's Chrome browser is now built using the Clang compiler on Windows. Previously built using the Microsoft C++ compiler, Google is now using the same compiler for Windows, macOS, Linux, and Android, and the switch makes Chrome arguably the first major software project to use Clang on Windows.

Is GCC slower than clang? ›

clang is 100x slower than gcc when compiling a large assembly source code #68445.

How do I use clang instead of GCC make? ›

If you want to use clang instead of GCC, you can add -DCMAKE_C_COMPILER=/path/to/clang -DCMAKE_CXX_COMPILER=/path/to/clang++ . You can also use ccmake , which provides a curses interface to configure CMake variables in an interactive manner.

Which is better, clang or MinGW? ›

MingW (GCC on windows)/MSVC/Clang, all are good C++17 conformant compilers. clang has better template error messages. GCC is most used one. MSVC (not cross platform) has best IDE Visual Studio with it.

Is Clang an AC or C++ compiler? ›

Clang is a C, C++, Objective-C, or Objective-C++ compiler that is compiled in C++ based on LLVM and released under the Apache 2.0 license. Clang is mainly used to provide performance superior to that of GCC.

Is LLVM the same as Clang? ›

There are 2 different things here. LLVM is a backend compiler meant to build compilers on top of it. It deals with optimizations and production of code adapted to the target architecture. CLang is a front end which parses C, C++ and Objective C code and translates it into a representation suitable for LLVM.

Does Unreal Engine use Clang? ›

Unreal Engine uses LLVM/Clang as its compiler toolset on MacOS. Refer to Microsoft's documentation on Using Clang for Visual Studio Code for full instructions on how to install and enable it.

What is the purpose of clang-tidy? ›

clang-tidy is a clang-based C++ “linter” tool. Its purpose is to provide an extensible framework for diagnosing and fixing typical programming errors, like style violations, interface misuse, or bugs that can be deduced via static analysis.

What is the purpose of clang-format? ›

clang-format can be used for several purposes: Quickly reformat a block of code to the kernel style. Specially useful when moving code around and aligning/sorting.

What is the use of clang static analyzer? ›

The Clang Static Analyzer is a source code analysis tool that finds bugs in C, C++, and Objective-C programs. Currently it can be run either from the command line or if you use macOS then within Xcode. When invoked from the command line, it is intended to be run in tandem with a build of a codebase.

Should I use clang-format? ›

clang-format is a tool to automatically format C/C++/Objective-C code, so that developers don't need to worry about style issues during code reviews. It is highly recommended to format your changed C++ code before opening pull requests, which will save you and the reviewers' time.

Top Articles
Configure Mobile VPN with IKEv2 for a Cloud-Managed Firebox
Alaska, Delaware, and West Virginia are the only states that still don't have a single billionaire resident
Xre-02022
The Blackening Showtimes Near Century Aurora And Xd
Woodward Avenue (M-1) - Automotive Heritage Trail - National Scenic Byway Foundation
craigslist: south coast jobs, apartments, for sale, services, community, and events
Fallout 4 Pipboy Upgrades
[PDF] INFORMATION BROCHURE - Free Download PDF
Aquatic Pets And Reptiles Photos
Love Compatibility Test / Calculator by Horoscope | MyAstrology
How to watch free movies online
House Of Budz Michigan
Best Forensic Pathology Careers + Salary Outlook | HealthGrad
Simplify: r^4+r^3-7r^2-r+6=0 Tiger Algebra Solver
Uktulut Pier Ritual Site
Craigslist Toy Hauler For Sale By Owner
Vrachtwagens in Nederland kopen - gebruikt en nieuw - TrucksNL
Www.publicsurplus.com Motor Pool
Grimes County Busted Newspaper
Sullivan County Image Mate
Chase Bank Pensacola Fl
Mybiglots Net Associates
Litter Robot 3 RED SOLID LIGHT
Обзор Joxi: Что это такое? Отзывы, аналоги, сайт и инструкции | APS
Nk 1399
NV Energy issues outage watch for South Carson City, Genoa and Glenbrook
Marlene2995 Pagina Azul
Vivification Harry Potter
Japanese Emoticons Stars
Calvin Coolidge: Life in Brief | Miller Center
Guide to Cost-Benefit Analysis of Investment Projects Economic appraisal tool for Cohesion Policy 2014-2020
Bad Business Private Server Commands
Ni Hao Kai Lan Rule 34
Wildfangs Springfield
Omnistorm Necro Diablo 4
Retire Early Wsbtv.com Free Book
Mydocbill.com/Mr
Banana Republic Rewards Login
Tiny Pains When Giving Blood Nyt Crossword
South Bend Tribune Online
How to Get a Better Signal on Your iPhone or Android Smartphone
Tedit Calamity
Home Auctions - Real Estate Auctions
Blackwolf Run Pro Shop
✨ Flysheet for Alpha Wall Tent, Guy Ropes, D-Ring, Metal Runner & Stakes Included for Hunting, Family Camping & Outdoor Activities (12'x14', PE) — 🛍️ The Retail Market
Vagicaine Walgreens
Willkommen an der Uni Würzburg | WueStart
CPM Homework Help
Roller Znen ZN50QT-E
Obituary Roger Schaefer Update 2020
Equinox Great Neck Class Schedule
login.microsoftonline.com Reviews | scam or legit check
Latest Posts
Article information

Author: Arielle Torp

Last Updated:

Views: 5673

Rating: 4 / 5 (61 voted)

Reviews: 84% of readers found this page helpful

Author information

Name: Arielle Torp

Birthday: 1997-09-20

Address: 87313 Erdman Vista, North Dustinborough, WA 37563

Phone: +97216742823598

Job: Central Technology Officer

Hobby: Taekwondo, Macrame, Foreign language learning, Kite flying, Cooking, Skiing, Computer programming

Introduction: My name is Arielle Torp, I am a comfortable, kind, zealous, lovely, jolly, colorful, adventurous person who loves writing and wants to share my knowledge and understanding with you.