Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When using the qt mingw compiler on windows, graphs are not generated successfully #257

Closed
tsukione opened this issue Mar 23, 2024 · 6 comments

Comments

@tsukione
Copy link

When the clang-uml.exe command is executed, the path of the mingw header file is found, but the following error message is displayed.

D:/Qt6.5/Tools/mingw1120_64/x86_64-w64-mingw32/include\stdio.h:184:63: error: expected ';' after top level declarator
  184 |   int __cdecl __mingw_printf(const char * __restrict__ , ... ) __MINGW_NOTHROW;
      |                                                               ^
      |                                                                                       ^
D:/Qt6.5/Tools/mingw1120_64/x86_64-w64-mingw32/include\stdio.h:205:92: error: expected ';' after top level declarator
  205 |   int __cdecl __mingw_vasprintf(char ** __restrict__ , const char * __restrict__ , va_list) __MINGW_NOTHROW;
      |                                                                                            ^
D:/Qt6.5/Tools/mingw1120_64/x86_64-w64-mingw32/include\stdio.h:219:60: error: expected ';' after top level declarator
  219 |   int __cdecl __ms_printf(const char * __restrict__ , ... ) __MINGW_NOTHROW;
      |                                                            ^
D:/Qt6.5/Tools/mingw1120_64/x86_64-w64-mingw32/include\stdio.h:222:65: error: expected ';' after top level declarator
  222 |   int __cdecl __ms_vprintf (const char * __restrict__ , va_list) __MINGW_NOTHROW;
      |                                                                 ^
@bkryza
Copy link
Owner

bkryza commented Mar 23, 2024

@tsukione Can you try adding the following at the top of your .clang-uml config:

add_compile_flags:
  - --target=x86_64-w64-mingw32

It's possible that your compile_commands.json does not contain this flag and I think it is necessary to use LLVM/Clang with mingw...

@tsukione
Copy link
Author

tsukione commented Mar 25, 2024

Tried it and got some new errors.

In file included from D:/Qt6.5/Tools/mingw1120_64/x86_64-w64-mingw32/include\iphlpapi.h:15:
In file included from D:/Qt6.5/Tools/mingw1120_64/x86_64-w64-mingw32/include\iprtrmib.h:12:
In file included from D:/Qt6.5/Tools/mingw1120_64/x86_64-w64-mingw32/include\mprapi.h:14:
In file included from D:/Qt6.5/Tools/mingw1120_64/x86_64-w64-mingw32/include\ras.h:17:
In file included from D:/Qt6.5/Tools/mingw1120_64/x86_64-w64-mingw32/include\naptypes.h:7:
In file included from D:/Qt6.5/Tools/mingw1120_64/x86_64-w64-mingw32/include\rpc.h:16:
In file included from D:/Qt6.5/Tools/mingw1120_64/x86_64-w64-mingw32/include\windows.h:69:
In file included from D:/Qt6.5/Tools/mingw1120_64/x86_64-w64-mingw32/include\windef.h:9:
In file included from D:/Qt6.5/Tools/mingw1120_64/x86_64-w64-mingw32/include\minwindef.h:163:
In file included from D:/Qt6.5/Tools/mingw1120_64/x86_64-w64-mingw32/include\winnt.h:1555:
In file included from D:/Qt6.5/Tools/mingw1120_64/lib/gcc/x86_64-w64-mingw32/11.2.0/include\x86intrin.h:27:
In file included from D:/Qt6.5/Tools/mingw1120_64/lib/gcc/x86_64-w64-mingw32/11.2.0/include\x86gprintrin.h:27:
D:/Qt6.5/Tools/mingw1120_64/lib/gcc/x86_64-w64-mingw32/11.2.0/include\ia32intrin.h:41:10: error: use of undeclared identifier '__builtin_ia32_bsrsi'
   41 |   return __builtin_ia32_bsrsi (__X);
      |          ^
D:/Qt6.5/Tools/mingw1120_64/lib/gcc/x86_64-w64-mingw32/11.2.0/include\ia32intrin.h:124:10: error: use of undeclared identifier '__builtin_ia32_rolqi'; did you mean '__builtin_ia32_korqi'?
  124 |   return __builtin_ia32_rolqi (__X, __C);
      |          ^
D:/Qt6.5/Tools/mingw1120_64/lib/gcc/x86_64-w64-mingw32/11.2.0/include\ia32intrin.h:41:10: note: '__builtin_ia32_korqi' declared here
   41 |   return __builtin_ia32_bsrsi (__X);
      |          ^
D:/Qt6.5/Tools/mingw1120_64/lib/gcc/x86_64-w64-mingw32/11.2.0/include\ia32intrin.h:132:10: error: use of undeclared identifier '__builtin_ia32_rolhi'; did you mean '__builtin_ia32_korhi'?
  132 |   return __builtin_ia32_rolhi (__X, __C);
      |          ^
D:/Qt6.5/Tools/mingw1120_64/lib/gcc/x86_64-w64-mingw32/11.2.0/include\ia32intrin.h:41:10: note: '__builtin_ia32_korhi' declared here
   41 |   return __builtin_ia32_bsrsi (__X);
      |          ^
D:/Qt6.5/Tools/mingw1120_64/lib/gcc/x86_64-w64-mingw32/11.2.0/include\ia32intrin.h:149:10: error: use of undeclared identifier '__builtin_ia32_rorqi'; did you mean '__builtin_ia32_korqi'?
  149 |   return __builtin_ia32_rorqi (__X, __C);
      |          ^
D:/Qt6.5/Tools/mingw1120_64/lib/gcc/x86_64-w64-mingw32/11.2.0/include\ia32intrin.h:41:10: note: '__builtin_ia32_korqi' declared here
   41 |   return __builtin_ia32_bsrsi (__X);
      |          ^
D:/Qt6.5/Tools/mingw1120_64/lib/gcc/x86_64-w64-mingw32/11.2.0/include\ia32intrin.h:157:10: error: use of undeclared identifier '__builtin_ia32_rorhi'; did you mean '__builtin_ia32_korhi'?
  157 |   return __builtin_ia32_rorhi (__X, __C);
      |          ^
D:/Qt6.5/Tools/mingw1120_64/lib/gcc/x86_64-w64-mingw32/11.2.0/include\ia32intrin.h:41:10: note: '__builtin_ia32_korhi' declared here
   41 |   return __builtin_ia32_bsrsi (__X);
      |          ^
D:/Qt6.5/Tools/mingw1120_64/lib/gcc/x86_64-w64-mingw32/11.2.0/include\ia32intrin.h:191:10: error: use of undeclared identifier '__builtin_ia32_bsrdi'
  191 |   return __builtin_ia32_bsrdi (__X);
      |          ^

How can I run clang-uml with LLVM/Clang if I compile with the mingw compiler that comes with Qt on Windows? Do I need to use the LLVM compiler to compile Qt and my project completely again?

@bkryza
Copy link
Owner

bkryza commented Mar 25, 2024

@tsukione No you don't need to compile your project with LLVM to run clang-uml, however you need to generate compile_commands.json in such a way that all compilation flags are understood by Clang - in this case it is missing some mingw specific functions or macros, probably because it's using invalid system header paths.

Can you describe how can I reproduce this error, including which Qt version I need to install?

@tsukione
Copy link
Author

tsukione commented Mar 25, 2024

just include iphlpapi.h header,it could be reproduced.
the iphlpapi.h path is D:\Qt6.5\Tools\mingw1120_64\x86_64-w64-mingw32\include\iphlpapi.h
my Qt version is 6.5.0

I've looked into it, and it does look like there are quite a few macro definitions missing, leading to the wrong branch of code. But I don't know how to get cmake to export all the definitions.

@bkryza
Copy link
Owner

bkryza commented Apr 11, 2024

@tsukione I've finally managed to reproduce your problem and have found a possible solution to it. The core of the issue is that Mingw GCC contains headers with Intel SIMD instructions which are incompatible with Clang - fortunately for the sake of just running clang-uml you can just skip them.

I've created a smallest possible project in QtCreator, included the <iphlpapi.h> file and added:

add_compile_flags:
  - --target=x86_64-w64-mingw32
  - -D__IPHLPAPI_H__=1

to my .clang-uml config so that Clang's parser does enter this header.

Here is my setup:

PS C:\Users\bkryz\Documents\clang-uml-test> ls


    Directory: C:\Users\bkryz\Documents\clang-uml-test


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----         4/11/2024   6:31 PM                build
d-----         4/11/2024   6:40 PM                docs
-a----         4/11/2024   7:11 PM            349 .clang-uml
-a----         4/11/2024   6:34 PM            741 CMakeLists.txt
-a----         4/11/2024   6:31 PM          15926 CMakeLists.txt.user
-a----         4/11/2024   6:53 PM            221 main.cpp
PS C:\Users\bkryz\Documents\clang-uml-test> cat .\main.cpp
#include <QCoreApplication>
#include <iphlpapi.h>

namespace my_app {
struct A {};

struct B : public A {};
}

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    return a.exec();
}
PS C:\Users\bkryz\Documents\clang-uml-test> cat .\CMakeLists.txt
cmake_minimum_required(VERSION 3.14)

project(clang-uml-test LANGUAGES CXX)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES})

find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core)

add_executable(clang-uml-test
  main.cpp
)
target_link_libraries(clang-uml-test Qt${QT_VERSION_MAJOR}::Core)

include(GNUInstallDirs)
install(TARGETS clang-uml-test
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
PS C:\Users\bkryz\Documents\clang-uml-test> cat .\build\Desktop_Qt_6_7_0_MinGW_64_bit-Debug\compile_commands.json
[
{
  "directory": "C:/Users/bkryz/Documents/clang-uml-test/build/Desktop_Qt_6_7_0_MinGW_64_bit-Debug",
  "command": "C:\\Qt\\Tools\\mingw1120_64\\bin\\g++.exe -DMINGW_HAS_SECURE_API=1 -DQT_CORE_LIB -DUNICODE -DWIN32 -DWIN64 -D_ENABLE_EXTENDED_ALIGNED_STORAGE -D_UNICODE -D_WIN64 -IC:/Users/bkryz/Documents/clang-uml-test/build/Desktop_Qt_6_7_0_MinGW_64_bit-Debug/clang-uml-test_autogen/include -isystem C:/Qt/6.7.0/mingw_64/include/QtCore -isystem C:/Qt/6.7.0/mingw_64/include -isystem C:/Qt/6.7.0/mingw_64/mkspecs/win32-g++ -isystem C:/Qt/Tools/mingw1120_64/lib/gcc/x86_64-w64-mingw32/11.2.0/include/c++ -isystem C:/Qt/Tools/mingw1120_64/lib/gcc/x86_64-w64-mingw32/11.2.0/include/c++/x86_64-w64-mingw32 -isystem C:/Qt/Tools/mingw1120_64/lib/gcc/x86_64-w64-mingw32/11.2.0/include/c++/backward -isystem C:/Qt/Tools/mingw1120_64/lib/gcc/x86_64-w64-mingw32/11.2.0/include -isystem C:/Qt/Tools/mingw1120_64/lib/gcc/x86_64-w64-mingw32/11.2.0/include-fixed -isystem C:/Qt/Tools/mingw1120_64/x86_64-w64-mingw32/include -DQT_QML_DEBUG -g -std=gnu++17 -fdiagnostics-color=always -o CMakeFiles\\clang-uml-test.dir\\clang-uml-test_autogen\\mocs_compilation.cpp.obj -c C:\\Users\\bkryz\\Documents\\clang-uml-test\\build\\Desktop_Qt_6_7_0_MinGW_64_bit-Debug\\clang-uml-test_autogen\\mocs_compilation.cpp",
  "file": "C:\\Users\\bkryz\\Documents\\clang-uml-test\\build\\Desktop_Qt_6_7_0_MinGW_64_bit-Debug\\clang-uml-test_autogen\\mocs_compilation.cpp",
  "output": "CMakeFiles\\clang-uml-test.dir\\clang-uml-test_autogen\\mocs_compilation.cpp.obj"
},
{
  "directory": "C:/Users/bkryz/Documents/clang-uml-test/build/Desktop_Qt_6_7_0_MinGW_64_bit-Debug",
  "command": "C:\\Qt\\Tools\\mingw1120_64\\bin\\g++.exe -DMINGW_HAS_SECURE_API=1 -DQT_CORE_LIB -DUNICODE -DWIN32 -DWIN64 -D_ENABLE_EXTENDED_ALIGNED_STORAGE -D_UNICODE -D_WIN64 -IC:/Users/bkryz/Documents/clang-uml-test/build/Desktop_Qt_6_7_0_MinGW_64_bit-Debug/clang-uml-test_autogen/include -isystem C:/Qt/6.7.0/mingw_64/include/QtCore -isystem C:/Qt/6.7.0/mingw_64/include -isystem C:/Qt/6.7.0/mingw_64/mkspecs/win32-g++ -isystem C:/Qt/Tools/mingw1120_64/lib/gcc/x86_64-w64-mingw32/11.2.0/include/c++ -isystem C:/Qt/Tools/mingw1120_64/lib/gcc/x86_64-w64-mingw32/11.2.0/include/c++/x86_64-w64-mingw32 -isystem C:/Qt/Tools/mingw1120_64/lib/gcc/x86_64-w64-mingw32/11.2.0/include/c++/backward -isystem C:/Qt/Tools/mingw1120_64/lib/gcc/x86_64-w64-mingw32/11.2.0/include -isystem C:/Qt/Tools/mingw1120_64/lib/gcc/x86_64-w64-mingw32/11.2.0/include-fixed -isystem C:/Qt/Tools/mingw1120_64/x86_64-w64-mingw32/include -DQT_QML_DEBUG -g -std=gnu++17 -fdiagnostics-color=always -o CMakeFiles\\clang-uml-test.dir\\main.cpp.obj -c C:\\Users\\bkryz\\Documents\\clang-uml-test\\main.cpp",
  "file": "C:\\Users\\bkryz\\Documents\\clang-uml-test\\main.cpp",
  "output": "CMakeFiles\\clang-uml-test.dir\\main.cpp.obj"
}
]
PS C:\Users\bkryz\Documents\clang-uml-test> cat .clang-uml
compilation_database_dir: build/Desktop_Qt_6_7_0_MinGW_64_bit-Debug
output_directory: docs/diagrams
add_compile_flags:
  - --target=x86_64-w64-mingw32
  - -D__IPHLPAPI_H__=1
diagrams:
  my_app_class_diagram:
    type: class
    glob:
      - "*.cpp"
    using_namespace:
      - my_app
    include:
      namespaces:
        - my_app
PS C:\Users\bkryz\Documents\clang-uml-test> & 'C:\Program Files\clang-uml\bin\clang-uml.exe' --version
clang-uml 0.5.1
Copyright (C) 2021-2024 Bartek Kryza <bkryza@gmail.com>
Windows, 32-bit
Built against LLVM/Clang libraries version: 17.0.6
Using LLVM/Clang libraries version: clang version 17.0.6 (https://github.com/llvm/llvm-project.git 6009708b4367171ccdbf4b5905cb6a803753fe18)
PS C:\Users\bkryz\Documents\clang-uml-test> & 'C:\Program Files\clang-uml\bin\clang-uml.exe'
fatal: not a git repository (or any of the parent directories): .git
[info] [tid 11960] [C:\clang-uml-llvm17-tmp\clang-uml\src\cli\cli_handler.cc:305] Loaded clang-uml config from .clang-uml
[info] [tid 11960] [C:\clang-uml-llvm17-tmp\clang-uml\src\cli\cli_handler.cc:333] Loading compilation database from C:\Users\bkryz\Documents\clang-uml-test\build\Desktop_Qt_6_7_0_MinGW_64_bit-Debug directory
[info] [tid 7516] [C:\clang-uml-llvm17-tmp\clang-uml\src\common\generators\generators.h:368] Generating diagram my_app_class_diagram
[info] [tid 7516] [C:\clang-uml-llvm17-tmp\clang-uml\src\common\generators\generators.cc:112] Written my_app_class_diagram diagram to C:\Users\bkryz\Documents\clang-uml-test\docs\diagrams\my_app_class_diagram.puml
PS C:\Users\bkryz\Documents\clang-uml-test> cat .\docs\diagrams\my_app_class_diagram.puml
@startuml
class "A" as C_0000693866551648885556
class C_0000693866551648885556 {
__
}
class "B" as C_0000693866414209932029
class C_0000693866414209932029 {
__
}
C_0000693866551648885556 <|-- C_0000693866414209932029

'Generated with clang-uml, version 0.5.1
'LLVM version clang version 17.0.6 (https://github.com/llvm/llvm-project.git 6009708b4367171ccdbf4b5905cb6a803753fe18)
@enduml

If you'll have problems with any other Mingw internal header files not being parsed by Clang properly, just try to defined their header guard in the add_compile_commands and it should help...

@tsukione
Copy link
Author

Thank you very much for your very detailed analysis and answers to my questions. Just like that, it also means that the API provided by these header files cannot be used. Maybe I have to isolate the API interface on the code to use clang-uml properly.

@bkryza bkryza closed this as completed Jun 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants