llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.19k stars 12.04k forks source link

Windows Clang LLVM 18.1.1 error: expected ';' after top level declarator when using Criterion C++ unit testing framework #84876

Open Raduq91 opened 8 months ago

Raduq91 commented 8 months ago

Windows 10 x64

Clang llvm 18.1.1, I can't use criterion test frame work library. https://github.com/Snaipe/Criterion

C:\Users\Radu\source\repos\clang_llvm_toolset>clang++ clang_llvm_toolset.cpp -I"C:\Users\Radu\source\repos\\clang_llvm_toolset\Include" -l"C:\Users\Radu\source\repos\clang_llvm_toolset\criterion.lib"
clang_llvm_toolset.cpp:3:1: error: expected ';' after top level declarator
    3 | Test(misc, failing, .description = "Just a failing test") {
      | ^
C:\Users\Radu\source\repos\\clang_llvm_toolset\Include\criterion\internal/test.h:199:37: note: expanded from macro
      'Test'
  199 | #define Test(...)         CR_EXPAND(CR_TEST_BASE(__VA_ARGS__, .sentinel_ = 0))
      |                                     ^
C:\Users\Radu\source\repos\\clang_llvm_toolset\Include\criterion\internal/test.h:179:49: note: expanded from macro
      'CR_TEST_BASE'
  179 |         = &CR_IDENTIFIER_(Category, Name, meta) CR_SECTION_SUFFIX_;          \
      |                                                 ^
C:\Users\Radu\source\repos\\clang_llvm_toolset\Include\criterion\internal/common.h:71:14: note: expanded from macro
      'CR_SECTION_SUFFIX_'
   71 |     __pragma(data_seg(pop))
      |              ^
clang_llvm_toolset.cpp:7:1: error: expected ';' after top level declarator
    7 | Test(misc, skipped, .description = "This one is skipped", .disabled = true) {
      | ^
C:\Users\Radu\source\repos\\clang_llvm_toolset\Include\criterion\internal/test.h:199:37: note: expanded from macro
      'Test'
  199 | #define Test(...)         CR_EXPAND(CR_TEST_BASE(__VA_ARGS__, .sentinel_ = 0))
      |                                     ^
C:\Users\Radu\source\repos\\clang_llvm_toolset\Include\criterion\internal/test.h:179:49: note: expanded from macro
      'CR_TEST_BASE'
  179 |         = &CR_IDENTIFIER_(Category, Name, meta) CR_SECTION_SUFFIX_;          \
      |                                                 ^
C:\Users\Radu\source\repos\\clang_llvm_toolset\Include\criterion\internal/common.h:71:14: note: expanded from macro
      'CR_SECTION_SUFFIX_'
   71 |     __pragma(data_seg(pop))
      |              ^
2 errors generated.

( https://github.com/Snaipe/Criterion/issues/282#issuecomment-449566245 ) with --target=x86_64-w64-windows-gnu :

C:\Users\Radu\source\repos\clang_llvm_toolset>clang++ clang_llvm_toolset.cpp -I"C:\Users\Radu\source\repos\\clang_llvm_toolset\Include" -l"C:\Users\Radu\source\repos\clang_llvm_toolset\criterion.lib" --target=x86_64-w64-windows-gnu
In file included from clang_llvm_toolset.cpp:1:
In file included from C:\Users\Radu\source\repos\\clang_llvm_toolset\Include\criterion/criterion.h:31:
In file included from C:\Users\Radu\source\repos\\clang_llvm_toolset\Include\criterion\types.h:31:
C:\Users\Radu\source\repos\\clang_llvm_toolset\Include\criterion\alloc.h:32:11: fatal error: 'memory' file not found
   32 | # include <memory>
      |           ^~~~~~~~
1 error generated.

With toolset Visual Studio 2022 (v143) and intel compiler it builds without issue.


( used this to add clang llvm as toolset option in VS2022:https://github.com/zufuliu/llvm-utils ) clang llvm build error list:

Severity    Code    Description Project File    Line    Suppression State   Details
Error (active)  E0254   type name is not allowed    clang_llvm_toolset  C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\include\xtr1common    73      
Error (active)  E0254   type name is not allowed    clang_llvm_toolset  C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\include\xtr1common    73      
Error (active)  E0254   type name is not allowed    clang_llvm_toolset  C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\include\xtr1common    76      
Error (active)  E0254   type name is not allowed    clang_llvm_toolset  C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\include\xtr1common    76      
Error       expected ';' after top level declarator clang_llvm_toolset  C:\Users\Radu\source\repos\clang_llvm_toolset\clang_llvm_toolset.cpp    3       
Error       expected ';' after top level declarator clang_llvm_toolset  C:\Users\Radu\source\repos\clang_llvm_toolset\clang_llvm_toolset.cpp    7       

build log:

Build started at 7:20 AM...
1>------ Build started: Project: clang_llvm_toolset, Configuration: Debug x64 ------
1>Performing Custom Build Tools
1>clang version 18.1.1
1>Target: x86_64-pc-windows-msvc
1>Thread model: posix
1>InstalledDir: E:\LLVM\bin
1> (in-process)
1> "E:\\LLVM\\bin\\clang-cl.exe" -cc1 -triple x86_64-pc-windows-msvc19.38.33130 -emit-obj -mrelax-all -mincremental-linker-compatible -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name clang_llvm_toolset.cpp -mrelocation-model pic -pic-level 2 -mframe-pointer=none -relaxed-aliasing -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -fms-volatile -funwind-tables=2 -target-cpu x86-64 -mllvm -x86-asm-syntax=intel -tune-cpu generic -D_DEBUG -D_MT -D_DLL --dependent-lib=msvcrtd --dependent-lib=oldnames -stack-protector 2 -fcxx-exceptions -fexceptions -fexternc-nounwind -fdefault-calling-conv=cdecl -fdiagnostics-format msvc -gno-column-info -gcodeview -debug-info-kind=constructor -fjmc "-fdebug-compilation-dir=C:\\Users\\Radu\\source\\repos\\clang_llvm_toolset" "-object-file-name=C:\\Users\\Radu\\source\\repos\\clang_llvm_toolset\\x64\\Debug\\clang_llvm_toolset.obj" -v "-fcoverage-compilation-dir=C:\\Users\\Radu\\source\\repos\\clang_llvm_toolset" -resource-dir "E:\\LLVM\\lib\\clang\\18" -D __clang__ -D __llvm__ -D _DEBUG -D _CONSOLE -D _UNICODE -D UNICODE -internal-isystem "E:\\LLVM\\lib\\clang\\18\\include" -internal-isystem "C:\\Users\\Radu\\source\\repos\\clang_llvm_toolset\\include" -internal-isystem "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.38.33130\\include" -internal-isystem "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.38.33130\\atlmfc\\include" -internal-isystem "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Auxiliary\\VS\\include" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.18362.0\\ucrt" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.18362.0\\um" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.18362.0\\shared" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.18362.0\\winrt" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.18362.0\\cppwinrt" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\NETFXSDK\\4.7.1\\Include\\um" -internal-isystem "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.38.33130\\include" -internal-isystem "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.38.33130\\atlmfc\\include" -internal-isystem "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Auxiliary\\VS\\include" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.18362.0\\ucrt" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.18362.0\\um" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.18362.0\\shared" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.18362.0\\winrt" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.18362.0\\cppwinrt" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\NETFXSDK\\4.7.1\\Include\\um" -O0 -Wall -Wno-error -fdeprecated-macro -ferror-limit 19 -fno-use-cxa-atexit -fms-extensions -fms-compatibility -fms-compatibility-version=19.38.33130 -std=c++14 -fskip-odr-check-in-gmf -fno-caret-diagnostics -faddrsig -o "x64\\Debug\\clang_llvm_toolset.obj" -x c++ clang_llvm_toolset.cpp
1>clang -cc1 version 18.1.1 based upon LLVM 18.1.1 default target x86_64-pc-windows-msvc
1>ignoring duplicate directory "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\include"
1>ignoring duplicate directory "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\atlmfc\include"
1>ignoring duplicate directory "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\VS\include"
1>ignoring duplicate directory "C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt"
1>ignoring duplicate directory "C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um"
1>ignoring duplicate directory "C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\shared"
1>ignoring duplicate directory "C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\winrt"
1>ignoring duplicate directory "C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\cppwinrt"
1>ignoring duplicate directory "C:\Program Files (x86)\Windows Kits\NETFXSDK\4.7.1\Include\um"
1>#include "..." search starts here:
1>#include <...> search starts here:
1> E:\LLVM\lib\clang\18\include
1> C:\Users\Radu\source\repos\clang_llvm_toolset\include
1> C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\include
1> C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\atlmfc\include
1> C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\VS\include
1> C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt
1> C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um
1> C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\shared
1> C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\winrt
1> C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\cppwinrt
1> C:\Program Files (x86)\Windows Kits\NETFXSDK\4.7.1\Include\um
1>End of search list.
1>clang_llvm_toolset.cpp(3,1): error : expected ';' after top level declarator
1>C:\Users\Radu\source\repos\clang_llvm_toolset\include\criterion\internal/test.h(199,37): message : expanded from macro 'Test'
1>C:\Users\Radu\source\repos\clang_llvm_toolset\include\criterion\internal/test.h(179,49): message : expanded from macro 'CR_TEST_BASE'
1>C:\Users\Radu\source\repos\clang_llvm_toolset\include\criterion\internal/common.h(71,14): message : expanded from macro 'CR_SECTION_SUFFIX_'
1>clang_llvm_toolset.cpp(7,1): error : expected ';' after top level declarator
1>C:\Users\Radu\source\repos\clang_llvm_toolset\include\criterion\internal/test.h(199,37): message : expanded from macro 'Test'
1>C:\Users\Radu\source\repos\clang_llvm_toolset\include\criterion\internal/test.h(179,49): message : expanded from macro 'CR_TEST_BASE'
1>C:\Users\Radu\source\repos\clang_llvm_toolset\include\criterion\internal/common.h(71,14): message : expanded from macro 'CR_SECTION_SUFFIX_'
1>Done building project "clang_llvm_toolset.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
========== Build completed at 7:20 AM and took 00.498 seconds ==========

adding --target=x86_64-w64-windows-gnu breaks the include headers:

Build started at 7:21 AM...
1>------ Build started: Project: clang_llvm_toolset, Configuration: Debug x64 ------
1>Performing Custom Build Tools
1>clang version 18.1.1
1>Target: x86_64-w64-windows-gnu
1>Thread model: posix
1>InstalledDir: E:\LLVM\bin
1>clang-cl : warning : argument unused during compilation: '/Od' [-Wunused-command-line-argument]
1>clang-cl : warning : argument unused during compilation: '/permissive-' [-Wunused-command-line-argument]
1> (in-process)
1> "E:\\LLVM\\bin\\clang-cl.exe" -cc1 -triple x86_64-w64-windows-gnu -emit-obj -mrelax-all -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name clang_llvm_toolset.cpp -mrelocation-model pic -pic-level 2 -mframe-pointer=none -relaxed-aliasing -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -mms-bitfields -fms-volatile -funwind-tables=2 -fno-use-init-array -target-cpu x86-64 -mllvm -x86-asm-syntax=intel -tune-cpu generic -D_DEBUG -D_MT -D_DLL --dependent-lib=msvcrtd --dependent-lib=oldnames -stack-protector 2 -fcxx-exceptions -fexceptions -fexternc-nounwind -fdefault-calling-conv=cdecl -fdiagnostics-format msvc -debug-info-kind=constructor -dwarf-version=4 -debugger-tuning=gdb -fjmc "-fdebug-compilation-dir=C:\\Users\\Radu\\source\\repos\\clang_llvm_toolset" -v "-fcoverage-compilation-dir=C:\\Users\\Radu\\source\\repos\\clang_llvm_toolset" -resource-dir "E:\\LLVM\\lib\\clang\\18" -D __clang__ -D __llvm__ -D _DEBUG -D _CONSOLE -D _UNICODE -D UNICODE -internal-isystem "E:\\LLVM\\x86_64-w64-mingw32\\include\\c++" -internal-isystem "E:\\LLVM\\x86_64-w64-mingw32\\include\\c++\\x86_64-w64-mingw32" -internal-isystem "E:\\LLVM\\x86_64-w64-mingw32\\include\\c++\\backward" -internal-isystem "E:\\LLVM\\x86_64-w64-mingw32\\include\\c++\\" -internal-isystem "E:\\LLVM\\x86_64-w64-mingw32\\include\\c++\\\\x86_64-w64-mingw32" -internal-isystem "E:\\LLVM\\x86_64-w64-mingw32\\include\\c++\\\\backward" -internal-isystem "E:\\LLVM\\include\\c++\\" -internal-isystem "E:\\LLVM\\include\\c++\\\\x86_64-w64-mingw32" -internal-isystem "E:\\LLVM\\include\\c++\\\\backward" -internal-isystem "include\\c++" -internal-isystem "include\\c++\\x86_64-w64-mingw32" -internal-isystem "include\\c++\\backward" -internal-isystem "include\\g++-v0.0.0" -internal-isystem "include\\g++-v0.0.0\\x86_64-w64-mingw32" -internal-isystem "include\\g++-v0.0.0\\backward" -internal-isystem "include\\g++-v0.0" -internal-isystem "include\\g++-v0.0\\x86_64-w64-mingw32" -internal-isystem "include\\g++-v0.0\\backward" -internal-isystem "include\\g++-v0" -internal-isystem "include\\g++-v0\\x86_64-w64-mingw32" -internal-isystem "include\\g++-v0\\backward" -internal-isystem "E:\\LLVM\\lib\\clang\\18\\include" -internal-isystem "E:\\LLVM\\x86_64-w64-mingw32\\include" -internal-isystem "E:\\LLVM\\x86_64-w64-mingw32\\usr/include" -internal-isystem "E:\\LLVM\\include" -Wall -Wno-error -fdeprecated-macro -ferror-limit 19 -fno-use-cxa-atexit -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -exception-model=seh -fno-caret-diagnostics -faddrsig -o "x64\\Debug\\clang_llvm_toolset.obj" -x c++ clang_llvm_toolset.cpp
1>clang -cc1 version 18.1.1 based upon LLVM 18.1.1 default target x86_64-pc-windows-msvc
1>ignoring nonexistent directory "E:\LLVM\x86_64-w64-mingw32\include\c++"
1>ignoring nonexistent directory "E:\LLVM\x86_64-w64-mingw32\include\c++\x86_64-w64-mingw32"
1>ignoring nonexistent directory "E:\LLVM\x86_64-w64-mingw32\include\c++\backward"
1>ignoring nonexistent directory "E:\LLVM\x86_64-w64-mingw32\include\c++\"
1>ignoring nonexistent directory "E:\LLVM\x86_64-w64-mingw32\include\c++\\x86_64-w64-mingw32"
1>ignoring nonexistent directory "E:\LLVM\x86_64-w64-mingw32\include\c++\\backward"
1>ignoring nonexistent directory "E:\LLVM\include\c++\"
1>ignoring nonexistent directory "E:\LLVM\include\c++\\x86_64-w64-mingw32"
1>ignoring nonexistent directory "E:\LLVM\include\c++\\backward"
1>ignoring nonexistent directory "include\c++"
1>ignoring nonexistent directory "include\c++\x86_64-w64-mingw32"
1>ignoring nonexistent directory "include\c++\backward"
1>ignoring nonexistent directory "include\g++-v0.0.0"
1>ignoring nonexistent directory "include\g++-v0.0.0\x86_64-w64-mingw32"
1>ignoring nonexistent directory "include\g++-v0.0.0\backward"
1>ignoring nonexistent directory "include\g++-v0.0"
1>ignoring nonexistent directory "include\g++-v0.0\x86_64-w64-mingw32"
1>ignoring nonexistent directory "include\g++-v0.0\backward"
1>ignoring nonexistent directory "include\g++-v0"
1>ignoring nonexistent directory "include\g++-v0\x86_64-w64-mingw32"
1>ignoring nonexistent directory "include\g++-v0\backward"
1>ignoring nonexistent directory "E:\LLVM\x86_64-w64-mingw32\include"
1>ignoring nonexistent directory "E:\LLVM\x86_64-w64-mingw32\usr/include"
1>#include "..." search starts here:
1>#include <...> search starts here:
1> E:\LLVM\lib\clang\18\include
1> E:\LLVM\include
1>End of search list.
1>clang_llvm_toolset.cpp(1,10): fatal  error : 'criterion/criterion.h' file not found
1>Done building project "clang_llvm_toolset.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
========== Build completed at 7:21 AM and took 00.308 seconds ==========

sample code:

#include <criterion/criterion.h>

Test(misc, failing, .description = "Just a failing test") {
    cr_assert(0);
}

Test(misc, skipped, .description = "This one is skipped", .disabled = true) {
}
int WinMain(void)
{
    return 0;
}

Criterion lib: This version has windows build to download(built from src using the latest version with mingw64 and it was the same issue with clang llvm) https://github.com/Snaipe/Criterion/releases/tag/v2.3.2 I used criterion-v2.3.2-windows-msvc-x86_64.tar.bz2

zufuliu commented 8 months ago

Reduced test based on following output:

clang-cl /E /EHsc /Iinclude test.cpp > x1.cpp
clang-cl /EHsc x1.cpp

test.cpp(3,93): error: expected ';' after top level declarator
    3 |  __declspec(allocate("cr_tst")) struct criterion_test *misc_failing_ptr = &misc_failing_meta
      |                                                                                             ^
      |                                                                                             ;
test.cpp(7,93): error: expected ';' after top level declarator
    7 |  __declspec(allocate("cr_tst")) struct criterion_test *misc_skipped_ptr = &misc_skipped_meta
      |                                                                                             ^
      |                                                                                             ;
2 errors generated.

https://godbolt.org/z/PxaazWPa4

#pragma warning(push)
int a
#pragma warning(pop)
;

#pragma data_seg(push)
int x = 1
#pragma data_seg(pop)
;

#pragma const_seg(push)
const char y[] = "2"
#pragma const_seg(pop)
;

#pragma bss_seg(push)
int z
#pragma bss_seg(pop)
;
clang++: warning: argument unused during compilation: '--gcc-toolchain=/opt/compiler-explorer/gcc-snapshot' [-Wunused-command-line-argument]
<source>:7:10: error: expected ';' after top level declarator
    7 | int x = 1
      |          ^
      |          ;
<source>:12:21: error: expected ';' after top level declarator
   12 | const char y[] = "2"
      |                     ^
      |                     ;
<source>:17:6: error: expected ';' after top level declarator
   17 | int z
      |      ^
      |      ;
3 errors generated.
Compiler returned: 1
llvmbot commented 8 months ago

@llvm/issue-subscribers-clang-frontend

Author: None (Raduq91)

Windows 10 x64 Clang llvm 18.1.1, I can't use criterion test frame work library. https://github.com/Snaipe/Criterion ``` C:\Users\Radu\source\repos\clang_llvm_toolset>clang++ clang_llvm_toolset.cpp -I"C:\Users\Radu\source\repos\\clang_llvm_toolset\Include" -l"C:\Users\Radu\source\repos\clang_llvm_toolset\criterion.lib" clang_llvm_toolset.cpp:3:1: error: expected ';' after top level declarator 3 | Test(misc, failing, .description = "Just a failing test") { | ^ C:\Users\Radu\source\repos\\clang_llvm_toolset\Include\criterion\internal/test.h:199:37: note: expanded from macro 'Test' 199 | #define Test(...) CR_EXPAND(CR_TEST_BASE(__VA_ARGS__, .sentinel_ = 0)) | ^ C:\Users\Radu\source\repos\\clang_llvm_toolset\Include\criterion\internal/test.h:179:49: note: expanded from macro 'CR_TEST_BASE' 179 | = &CR_IDENTIFIER_(Category, Name, meta) CR_SECTION_SUFFIX_; \ | ^ C:\Users\Radu\source\repos\\clang_llvm_toolset\Include\criterion\internal/common.h:71:14: note: expanded from macro 'CR_SECTION_SUFFIX_' 71 | __pragma(data_seg(pop)) | ^ clang_llvm_toolset.cpp:7:1: error: expected ';' after top level declarator 7 | Test(misc, skipped, .description = "This one is skipped", .disabled = true) { | ^ C:\Users\Radu\source\repos\\clang_llvm_toolset\Include\criterion\internal/test.h:199:37: note: expanded from macro 'Test' 199 | #define Test(...) CR_EXPAND(CR_TEST_BASE(__VA_ARGS__, .sentinel_ = 0)) | ^ C:\Users\Radu\source\repos\\clang_llvm_toolset\Include\criterion\internal/test.h:179:49: note: expanded from macro 'CR_TEST_BASE' 179 | = &CR_IDENTIFIER_(Category, Name, meta) CR_SECTION_SUFFIX_; \ | ^ C:\Users\Radu\source\repos\\clang_llvm_toolset\Include\criterion\internal/common.h:71:14: note: expanded from macro 'CR_SECTION_SUFFIX_' 71 | __pragma(data_seg(pop)) | ^ 2 errors generated. ``` ( https://github.com/Snaipe/Criterion/issues/282#issuecomment-449566245 ) with --target=x86_64-w64-windows-gnu : ``` C:\Users\Radu\source\repos\clang_llvm_toolset>clang++ clang_llvm_toolset.cpp -I"C:\Users\Radu\source\repos\\clang_llvm_toolset\Include" -l"C:\Users\Radu\source\repos\clang_llvm_toolset\criterion.lib" --target=x86_64-w64-windows-gnu In file included from clang_llvm_toolset.cpp:1: In file included from C:\Users\Radu\source\repos\\clang_llvm_toolset\Include\criterion/criterion.h:31: In file included from C:\Users\Radu\source\repos\\clang_llvm_toolset\Include\criterion\types.h:31: C:\Users\Radu\source\repos\\clang_llvm_toolset\Include\criterion\alloc.h:32:11: fatal error: 'memory' file not found 32 | # include <memory> | ^~~~~~~~ 1 error generated. ``` With toolset Visual Studio 2022 (v143) and intel compiler it builds without issue. ___ ( used this to add clang llvm as toolset option in VS2022:https://github.com/zufuliu/llvm-utils ) clang llvm build error list: ``` Severity Code Description Project File Line Suppression State Details Error (active) E0254 type name is not allowed clang_llvm_toolset C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\include\xtr1common 73 Error (active) E0254 type name is not allowed clang_llvm_toolset C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\include\xtr1common 73 Error (active) E0254 type name is not allowed clang_llvm_toolset C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\include\xtr1common 76 Error (active) E0254 type name is not allowed clang_llvm_toolset C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\include\xtr1common 76 Error expected ';' after top level declarator clang_llvm_toolset C:\Users\Radu\source\repos\clang_llvm_toolset\clang_llvm_toolset.cpp 3 Error expected ';' after top level declarator clang_llvm_toolset C:\Users\Radu\source\repos\clang_llvm_toolset\clang_llvm_toolset.cpp 7 ``` build log: ``` Build started at 7:20 AM... 1>------ Build started: Project: clang_llvm_toolset, Configuration: Debug x64 ------ 1>Performing Custom Build Tools 1>clang version 18.1.1 1>Target: x86_64-pc-windows-msvc 1>Thread model: posix 1>InstalledDir: E:\LLVM\bin 1> (in-process) 1> "E:\\LLVM\\bin\\clang-cl.exe" -cc1 -triple x86_64-pc-windows-msvc19.38.33130 -emit-obj -mrelax-all -mincremental-linker-compatible -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name clang_llvm_toolset.cpp -mrelocation-model pic -pic-level 2 -mframe-pointer=none -relaxed-aliasing -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -fms-volatile -funwind-tables=2 -target-cpu x86-64 -mllvm -x86-asm-syntax=intel -tune-cpu generic -D_DEBUG -D_MT -D_DLL --dependent-lib=msvcrtd --dependent-lib=oldnames -stack-protector 2 -fcxx-exceptions -fexceptions -fexternc-nounwind -fdefault-calling-conv=cdecl -fdiagnostics-format msvc -gno-column-info -gcodeview -debug-info-kind=constructor -fjmc "-fdebug-compilation-dir=C:\\Users\\Radu\\source\\repos\\clang_llvm_toolset" "-object-file-name=C:\\Users\\Radu\\source\\repos\\clang_llvm_toolset\\x64\\Debug\\clang_llvm_toolset.obj" -v "-fcoverage-compilation-dir=C:\\Users\\Radu\\source\\repos\\clang_llvm_toolset" -resource-dir "E:\\LLVM\\lib\\clang\\18" -D __clang__ -D __llvm__ -D _DEBUG -D _CONSOLE -D _UNICODE -D UNICODE -internal-isystem "E:\\LLVM\\lib\\clang\\18\\include" -internal-isystem "C:\\Users\\Radu\\source\\repos\\clang_llvm_toolset\\include" -internal-isystem "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.38.33130\\include" -internal-isystem "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.38.33130\\atlmfc\\include" -internal-isystem "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Auxiliary\\VS\\include" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.18362.0\\ucrt" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.18362.0\\um" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.18362.0\\shared" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.18362.0\\winrt" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.18362.0\\cppwinrt" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\NETFXSDK\\4.7.1\\Include\\um" -internal-isystem "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.38.33130\\include" -internal-isystem "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.38.33130\\atlmfc\\include" -internal-isystem "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Auxiliary\\VS\\include" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.18362.0\\ucrt" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.18362.0\\um" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.18362.0\\shared" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.18362.0\\winrt" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.18362.0\\cppwinrt" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\NETFXSDK\\4.7.1\\Include\\um" -O0 -Wall -Wno-error -fdeprecated-macro -ferror-limit 19 -fno-use-cxa-atexit -fms-extensions -fms-compatibility -fms-compatibility-version=19.38.33130 -std=c++14 -fskip-odr-check-in-gmf -fno-caret-diagnostics -faddrsig -o "x64\\Debug\\clang_llvm_toolset.obj" -x c++ clang_llvm_toolset.cpp 1>clang -cc1 version 18.1.1 based upon LLVM 18.1.1 default target x86_64-pc-windows-msvc 1>ignoring duplicate directory "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\include" 1>ignoring duplicate directory "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\atlmfc\include" 1>ignoring duplicate directory "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\VS\include" 1>ignoring duplicate directory "C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt" 1>ignoring duplicate directory "C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um" 1>ignoring duplicate directory "C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\shared" 1>ignoring duplicate directory "C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\winrt" 1>ignoring duplicate directory "C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\cppwinrt" 1>ignoring duplicate directory "C:\Program Files (x86)\Windows Kits\NETFXSDK\4.7.1\Include\um" 1>#include "..." search starts here: 1>#include <...> search starts here: 1> E:\LLVM\lib\clang\18\include 1> C:\Users\Radu\source\repos\clang_llvm_toolset\include 1> C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\include 1> C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\atlmfc\include 1> C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\VS\include 1> C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt 1> C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um 1> C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\shared 1> C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\winrt 1> C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\cppwinrt 1> C:\Program Files (x86)\Windows Kits\NETFXSDK\4.7.1\Include\um 1>End of search list. 1>clang_llvm_toolset.cpp(3,1): error : expected ';' after top level declarator 1>C:\Users\Radu\source\repos\clang_llvm_toolset\include\criterion\internal/test.h(199,37): message : expanded from macro 'Test' 1>C:\Users\Radu\source\repos\clang_llvm_toolset\include\criterion\internal/test.h(179,49): message : expanded from macro 'CR_TEST_BASE' 1>C:\Users\Radu\source\repos\clang_llvm_toolset\include\criterion\internal/common.h(71,14): message : expanded from macro 'CR_SECTION_SUFFIX_' 1>clang_llvm_toolset.cpp(7,1): error : expected ';' after top level declarator 1>C:\Users\Radu\source\repos\clang_llvm_toolset\include\criterion\internal/test.h(199,37): message : expanded from macro 'Test' 1>C:\Users\Radu\source\repos\clang_llvm_toolset\include\criterion\internal/test.h(179,49): message : expanded from macro 'CR_TEST_BASE' 1>C:\Users\Radu\source\repos\clang_llvm_toolset\include\criterion\internal/common.h(71,14): message : expanded from macro 'CR_SECTION_SUFFIX_' 1>Done building project "clang_llvm_toolset.vcxproj" -- FAILED. ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== ========== Build completed at 7:20 AM and took 00.498 seconds ========== ``` adding --target=x86_64-w64-windows-gnu breaks the include headers: ``` Build started at 7:21 AM... 1>------ Build started: Project: clang_llvm_toolset, Configuration: Debug x64 ------ 1>Performing Custom Build Tools 1>clang version 18.1.1 1>Target: x86_64-w64-windows-gnu 1>Thread model: posix 1>InstalledDir: E:\LLVM\bin 1>clang-cl : warning : argument unused during compilation: '/Od' [-Wunused-command-line-argument] 1>clang-cl : warning : argument unused during compilation: '/permissive-' [-Wunused-command-line-argument] 1> (in-process) 1> "E:\\LLVM\\bin\\clang-cl.exe" -cc1 -triple x86_64-w64-windows-gnu -emit-obj -mrelax-all -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name clang_llvm_toolset.cpp -mrelocation-model pic -pic-level 2 -mframe-pointer=none -relaxed-aliasing -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -mms-bitfields -fms-volatile -funwind-tables=2 -fno-use-init-array -target-cpu x86-64 -mllvm -x86-asm-syntax=intel -tune-cpu generic -D_DEBUG -D_MT -D_DLL --dependent-lib=msvcrtd --dependent-lib=oldnames -stack-protector 2 -fcxx-exceptions -fexceptions -fexternc-nounwind -fdefault-calling-conv=cdecl -fdiagnostics-format msvc -debug-info-kind=constructor -dwarf-version=4 -debugger-tuning=gdb -fjmc "-fdebug-compilation-dir=C:\\Users\\Radu\\source\\repos\\clang_llvm_toolset" -v "-fcoverage-compilation-dir=C:\\Users\\Radu\\source\\repos\\clang_llvm_toolset" -resource-dir "E:\\LLVM\\lib\\clang\\18" -D __clang__ -D __llvm__ -D _DEBUG -D _CONSOLE -D _UNICODE -D UNICODE -internal-isystem "E:\\LLVM\\x86_64-w64-mingw32\\include\\c++" -internal-isystem "E:\\LLVM\\x86_64-w64-mingw32\\include\\c++\\x86_64-w64-mingw32" -internal-isystem "E:\\LLVM\\x86_64-w64-mingw32\\include\\c++\\backward" -internal-isystem "E:\\LLVM\\x86_64-w64-mingw32\\include\\c++\\" -internal-isystem "E:\\LLVM\\x86_64-w64-mingw32\\include\\c++\\\\x86_64-w64-mingw32" -internal-isystem "E:\\LLVM\\x86_64-w64-mingw32\\include\\c++\\\\backward" -internal-isystem "E:\\LLVM\\include\\c++\\" -internal-isystem "E:\\LLVM\\include\\c++\\\\x86_64-w64-mingw32" -internal-isystem "E:\\LLVM\\include\\c++\\\\backward" -internal-isystem "include\\c++" -internal-isystem "include\\c++\\x86_64-w64-mingw32" -internal-isystem "include\\c++\\backward" -internal-isystem "include\\g++-v0.0.0" -internal-isystem "include\\g++-v0.0.0\\x86_64-w64-mingw32" -internal-isystem "include\\g++-v0.0.0\\backward" -internal-isystem "include\\g++-v0.0" -internal-isystem "include\\g++-v0.0\\x86_64-w64-mingw32" -internal-isystem "include\\g++-v0.0\\backward" -internal-isystem "include\\g++-v0" -internal-isystem "include\\g++-v0\\x86_64-w64-mingw32" -internal-isystem "include\\g++-v0\\backward" -internal-isystem "E:\\LLVM\\lib\\clang\\18\\include" -internal-isystem "E:\\LLVM\\x86_64-w64-mingw32\\include" -internal-isystem "E:\\LLVM\\x86_64-w64-mingw32\\usr/include" -internal-isystem "E:\\LLVM\\include" -Wall -Wno-error -fdeprecated-macro -ferror-limit 19 -fno-use-cxa-atexit -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -exception-model=seh -fno-caret-diagnostics -faddrsig -o "x64\\Debug\\clang_llvm_toolset.obj" -x c++ clang_llvm_toolset.cpp 1>clang -cc1 version 18.1.1 based upon LLVM 18.1.1 default target x86_64-pc-windows-msvc 1>ignoring nonexistent directory "E:\LLVM\x86_64-w64-mingw32\include\c++" 1>ignoring nonexistent directory "E:\LLVM\x86_64-w64-mingw32\include\c++\x86_64-w64-mingw32" 1>ignoring nonexistent directory "E:\LLVM\x86_64-w64-mingw32\include\c++\backward" 1>ignoring nonexistent directory "E:\LLVM\x86_64-w64-mingw32\include\c++\" 1>ignoring nonexistent directory "E:\LLVM\x86_64-w64-mingw32\include\c++\\x86_64-w64-mingw32" 1>ignoring nonexistent directory "E:\LLVM\x86_64-w64-mingw32\include\c++\\backward" 1>ignoring nonexistent directory "E:\LLVM\include\c++\" 1>ignoring nonexistent directory "E:\LLVM\include\c++\\x86_64-w64-mingw32" 1>ignoring nonexistent directory "E:\LLVM\include\c++\\backward" 1>ignoring nonexistent directory "include\c++" 1>ignoring nonexistent directory "include\c++\x86_64-w64-mingw32" 1>ignoring nonexistent directory "include\c++\backward" 1>ignoring nonexistent directory "include\g++-v0.0.0" 1>ignoring nonexistent directory "include\g++-v0.0.0\x86_64-w64-mingw32" 1>ignoring nonexistent directory "include\g++-v0.0.0\backward" 1>ignoring nonexistent directory "include\g++-v0.0" 1>ignoring nonexistent directory "include\g++-v0.0\x86_64-w64-mingw32" 1>ignoring nonexistent directory "include\g++-v0.0\backward" 1>ignoring nonexistent directory "include\g++-v0" 1>ignoring nonexistent directory "include\g++-v0\x86_64-w64-mingw32" 1>ignoring nonexistent directory "include\g++-v0\backward" 1>ignoring nonexistent directory "E:\LLVM\x86_64-w64-mingw32\include" 1>ignoring nonexistent directory "E:\LLVM\x86_64-w64-mingw32\usr/include" 1>#include "..." search starts here: 1>#include <...> search starts here: 1> E:\LLVM\lib\clang\18\include 1> E:\LLVM\include 1>End of search list. 1>clang_llvm_toolset.cpp(1,10): fatal error : 'criterion/criterion.h' file not found 1>Done building project "clang_llvm_toolset.vcxproj" -- FAILED. ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== ========== Build completed at 7:21 AM and took 00.308 seconds ========== ``` sample code: ``` #include <criterion/criterion.h> Test(misc, failing, .description = "Just a failing test") { cr_assert(0); } Test(misc, skipped, .description = "This one is skipped", .disabled = true) { } int WinMain(void) { return 0; } ``` Criterion lib: This version has windows build to download(built from src using the latest version with mingw64 and it was the same issue with clang llvm) https://github.com/Snaipe/Criterion/releases/tag/v2.3.2 I used criterion-v2.3.2-windows-msvc-x86_64.tar.bz2
shafik commented 8 months ago

Note this looks specific to --target=x86_64-pc-windows-msvc if we remove that the diagnostics go away.

CC @AaronBallman

AaronBallman commented 8 months ago

It's specific to -fms-compatibility and the issue occurs as far back as Clang 3.5. The problem is that we're getting annotation tokens and we expect either a comma or a semicolon (https://github.com/llvm/llvm-project/blob/5c3d001668ec6117045a9750a1f9d7e3995adfee/clang/lib/Parse/ParseDecl.cpp#L2429). You can see the same issue with: https://godbolt.org/z/rjdcnzvrM