Expérience de l'équipe PVS-Studio : amélioration des performances de l'analyseur C++ sous Windows lors du passage à Clang

Dès le début, l'analyseur PVS-Studio C++ pour Windows (alors encore Viva64 version 1.00 en 2006) a été assemblé avec le compilateur MSVC. Avec la sortie des nouvelles versions C ++, le noyau de l'analyseur a appris à fonctionner sous Linux et macOS, et la structure du projet a été modifiée pour utiliser CMake. Mais sous Windows, la construction était toujours effectuée à l'aide du compilateur MSVC. Le 29 avril 2019, les développeurs de Visual Studio ont annoncé l'inclusion d'un ensemble d'utilitaires LLVM et du compilateur Clang dans leur environnement de développement. Et maintenant, nous avons enfin mis la main sur pour l'essayer en action.





Test de performance

SelfTester. . , - , , . SelfTester "".





– . , , SelfTester' . , .





C++ Clang, SelfTester 11 .





13% — , , , ?





, . 8 , 1,6 ( ~500 - ).





, LTO ( ) .





, .





Clang

CMake .





Clang Visual Studio Installer.





Clang-cl — "", clang cl.exe. , MSBuild, .





LLVM, GitHub. , Visual Studio . toolset' llvm, clangcl, .





toolchain solution Visual Studio:





cmake -G "Visual Studio 16 2019" -Tclangcl <src>

      
      



GUI:





, . , , .





lang-cl CL, , .





, /W4 /WX. Clang , . :





if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  ....

  if (WIN32)
    add_compile_options(-Wno-error=deprecated-declarations
                        -Wno-error=reorder-ctor
                        -Wno-error=format-security
                        -Wno-error=macro-redefined
                        -Wno-error=bitwise-op-parentheses
                        -Wno-error=missing-field-initializers
                        -Wno-error=overloaded-virtual
                        -Wno-error=invalid-source-encoding
                        -Wno-error=multichar
                        -Wno-unused-local-typedef
                        -Wno-c++11-narrowing)
  ....
  endif()
endif()

      
      



.





GCC Clang int128, MSVC Windows. Int128 Windows ( ifdef', C/C++). , :





if (MSVC)
  set(DEFAULT_INT128_ASM ON)
else ()
  set(DEFAULT_INT128_ASM OFF)
endif ()

      
      







if (MSVC AND NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  set(DEFAULT_INT128_ASM ON)
else ()
  set(DEFAULT_INT128_ASM OFF)
endif ()

      
      



builtin' (lld) , clang.exe clang-cl.exe. MSBuild , , . , , .





if (CMAKE_GENERATOR MATCHES "Visual Studio")

  link_libraries("$(LLVMInstallDir)\\lib\\clang\\\
${CMAKE_CXX_COMPILER_VERSION}\\lib\\windows\\\
clang_rt.builtins-x86_64.lib")

else()
  link_libraries(clang_rt.builtins-x86_64)
endif()

      
      



! . :





- IntegerInterval, :





Dataflow- Int128, SIMD-. :





MOVAPS SIMD-. , 0, 8. , :





class alignas(16) Int128
      
      



.





- Docker-:





MSVC , Clang . , Windows Microsoft Visual C++ Redistributable. , .





, , 10%.





PVS-Studio Windows Clang.





, : Alexey Govorov, Sergey Larin. PVS-Studio Team: Switching to Clang Improved PVS-Studio C++ Analyzer's Performance.








All Articles