llvm / llvm-project

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

Clang shouldn't mangle `thiscall` into member function pointers when it is the default instance method CC #39454

Open llvmbot opened 5 years ago

llvmbot commented 5 years ago
Bugzilla Link 40107
Version unspecified
OS Windows NT
Attachments log_x86_test
Reporter LLVM Bugzilla Contributor
CC @kbeyls,@mstorsjo,@rjmccall,@rnk,@TNorthover

Extended Description

LLVM failed to run TEST 'Clang :: CodeGenCXX/cxx2a-compare.cpp' and TEST 'Clang :: CodeGenCXX/pr33080.cpp' on both x86|debug and x86|release congigurations with MSVC.

Repro steps: 1 git clone -c core.autocrlf=false https://github.com/llvm-mirror/llvm D:\llvm\src\
2 git clone -c core.autocrlf=false https://github.com/llvm-mirror/clang D:\llvm\src\tools\clang 3 open a VS 2017 x86 command prompt and browse to D:\llvm 4 mkdir build_x86 && pushd build_x86 5 cmake -G "Visual Studio 15 2017" -DCMAKE_SYSTEM_VERSION=10.0.17134.0 ..\src\ 6 msbuild /maxcpucount:4 /p:Platform=Win32 /p:Configuration=RelWithDebInfo build_x86\ALL_BUILD.vcxproj /t:Rebuild

  1. python.exe ./src/utils/lit/lit.py -v --no-progress-bar --param build_mode=RelWithDebInfo --param clang_site_config=./build_x86/tools/clang/test/lit.site.cfg ./build_x86/tools/clang/test/CodeGenCXX/cxx2a-compare.cpp -j 4
  2. python.exe ./src/utils/lit/lit.py -v --no-progress-bar --param build_mode=RelWithDebInfo --param clang_site_config=./build_x86/tools/clang/test/lit.site.cfg ./build_x86/tools/clang/test/CodeGenCXX/pr33080.cpp -j 4

Failures:

-- Testing: 1 tests, 1 threads -- FAIL: Clang :: CodeGenCXX/cxx2a-compare.cpp (1 of 1) **** TEST 'Clang :: CodeGenCXX/cxx2a-compare.cpp' FAILED **** Script:

: 'RUN: at line 1'; d:\llvm\build_x86\relwithdebinfo\bin\clang.EXE -cc1 -internal-isystem d:\llvm\build_x86\relwithdebinfo\lib\clang\8.0.0\include -nostdsysteminc -std=c++2a -emit-llvm D:\LLVM\src\tools\clang\test\CodeGenCXX\cxx2a-compare.cpp -o - -triple i686-pc-windows-gnu | D:\LLVM\build_x86\RelWithDebInfo\bin\FileCheck.EXE D:\LLVM\src\tools\clang\test\CodeGenCXX\cxx2a-compare.cpp '-DWE="class.std::1::weak_equality"' '-DSO="class.std::__1::strong_ordering"' '-DSE="class.std::1::strong_equality"' '-DPO="class.std::__1::partial_ordering"' -DEQ=0 -DLT=-1 -DGT=1 -DUNORD=-127 -DNE=1

Exit Code: 1

Command Output (stdout):

$ ":" "RUN: at line 1" $ "d:\llvm\build_x86\relwithdebinfo\bin\clang.EXE" "-cc1" "-internal-isystem" "d:\llvm\build_x86\relwithdebinfo\lib\clang\8.0.0\include" "-nostdsysteminc" "-std=c++2a" "-emit-llvm" "D:\LLVM\src\tools\clang\test\CodeGenCXX\cxx2a-compare.cpp" "-o" "-" "-triple" "i686-pc-windows-gnu" $ "D:\LLVM\build_x86\RelWithDebInfo\bin\FileCheck.EXE" "D:\LLVM\src\tools\clang\test\CodeGenCXX\cxx2a-compare.cpp" "-DWE="class.std::1::weak_equality"" "-DSO="class.std::__1::strong_ordering"" "-DSE="class.std::1::strong_equality"" "-DPO="class.std::__1::partial_ordering"" "-DEQ=0" "-DLT=-1" "-DGT=1" "-DUNORD=-127" "-DNE=1"

command stderr:

D:\LLVM\src\tools\clang\test\CodeGenCXX\cxx2a-compare.cpp:76:17: error: CHECK-LABEL: expected string not found in input // CHECK-LABEL: @​_Z12mem_ptrtestM6MemPtrFvvES1 ^

:77:37: note: scanning from here define dso_local i8 @​_Z8ptr_testPiS_(i32* %x, i32* %y) #​0 { ^ :98:21: note: possible intended match here define dso_local i8 @​_Z12mem_ptr_testM6MemPtrU8thiscallFvvES1_({ i32, i32 }* byval align 4, { i32, i32 }* byval align 4) #​0 { ^ error: command failed with exit status: 1 -- ******************** Testing Time: 0.48s ******************** Failing Tests (1): Clang :: CodeGenCXX/cxx2a-compare.cpp Unexpected Failures: 1 -- Testing: 1 tests, 1 threads -- FAIL: Clang :: CodeGenCXX/pr33080.cpp (1 of 1) ******************** TEST 'Clang :: CodeGenCXX/pr33080.cpp' FAILED ******************** Script: -- : 'RUN: at line 1'; d:\llvm\build_x86\relwithdebinfo\bin\clang.EXE -cc1 -internal-isystem d:\llvm\build_x86\relwithdebinfo\lib\clang\8.0.0\include -nostdsysteminc -triple i686-pc-windows-gnu -fms-extensions -emit-llvm -o- D:\LLVM\src\tools\clang\test\CodeGenCXX\pr33080.cpp | D:\LLVM\build_x86\RelWithDebInfo\bin\FileCheck.EXE D:\LLVM\src\tools\clang\test\CodeGenCXX\pr33080.cpp -- Exit Code: 1 Command Output (stdout): -- $ ":" "RUN: at line 1" $ "d:\llvm\build_x86\relwithdebinfo\bin\clang.EXE" "-cc1" "-internal-isystem" "d:\llvm\build_x86\relwithdebinfo\lib\clang\8.0.0\include" "-nostdsysteminc" "-triple" "i686-pc-windows-gnu" "-fms-extensions" "-emit-llvm" "-o-" "D:\LLVM\src\tools\clang\test\CodeGenCXX\pr33080.cpp" $ "D:\LLVM\build_x86\RelWithDebInfo\bin\FileCheck.EXE" "D:\LLVM\src\tools\clang\test\CodeGenCXX\pr33080.cpp" # command stderr: D:\LLVM\src\tools\clang\test\CodeGenCXX\pr33080.cpp:26:11: error: CHECK: expected string not found in input // CHECK: define {{.*}} @​_Z6memptrM1AU11__unalignedFviE( ^ :69:83: note: scanning from here define dso_local void @​_Z2jaPU11__unaligned1APU11__unalignedS1_PU11__unalignedS3_(%struct.A*, %struct.A**, %struct.A***) #​0 { ^ :81:20: note: possible intended match here define dso_local void @​_Z6memptrM1AU8thiscallU11__unalignedFviE({ i32, i32 }* byval align 4) #​0 { ^ error: command failed with exit status: 1 -- ******************** Testing Time: 0.47s ******************** Failing Tests (1): Clang :: CodeGenCXX/pr33080.cpp Unexpected Failures: 1
rnk commented 5 years ago

An unfortunate consequence of our unfortunate decision to represent the thiscall explicitly in the AST.

I don't think it was a mistake, actually. I think for the Microsoft C++ ABI implementation, it's mostly been the right decision.

Anyway, I reverted the "thiscall" part of r349212 in r349872. We still mangle fastcall and stdcall.

I could leave this issue open to cover fixing explicit 'thiscall' conventions, but it doesn't seem very high priority.

rjmccall commented 5 years ago

Re-titling, this uncovered an actual ABI compatibility bug in r349414.

GCC 8.1 doesn't mangle U8thiscall into member function pointer types, since it's the default convention for member pointers, and it probably would've change a lot of manglings for code that doesn't use explicit calling conventions.

Consider: struct Foo {}; void mem_ptr_test(Foo o, void (Foo::mp)()) { (o->*mp)(); }

GCC produces the name: __Z12mem_ptr_testP3FooMS_FvvE Clang now produces: __Z12mem_ptr_testP3FooMS_U8thiscallFvvE

I'll undo the change just for thiscall for now.

An unfortunate consequence of our unfortunate decision to represent the thiscall explicitly in the AST.

rnk commented 5 years ago

Re-titling, this uncovered an actual ABI compatibility bug in r349414.

GCC 8.1 doesn't mangle U8thiscall into member function pointer types, since it's the default convention for member pointers, and it probably would've change a lot of manglings for code that doesn't use explicit calling conventions.

Consider: struct Foo {}; void mem_ptr_test(Foo o, void (Foo::mp)()) { (o->*mp)(); }

GCC produces the name: __Z12mem_ptr_testP3FooMS_FvvE Clang now produces: __Z12mem_ptr_testP3FooMS_U8thiscallFvvE

I'll undo the change just for thiscall for now.

llvmbot commented 2 months ago

@llvm/issue-subscribers-clang-codegen

Author: None (llvmbot)

| | | | --- | --- | | Bugzilla Link | [40107](https://llvm.org/bz40107) | | Version | unspecified | | OS | Windows NT | | Attachments | [log_x86_test](https://user-images.githubusercontent.com/60944935/143758482-6b2fc2d8-6e1a-4adb-a6a9-1d15729cbebc.gz) | | Reporter | LLVM Bugzilla Contributor | | CC | @kbeyls,@mstorsjo,@rjmccall,@rnk,@TNorthover | ## Extended Description LLVM failed to run TEST 'Clang :: CodeGenCXX/cxx2a-compare.cpp' and TEST 'Clang :: CodeGenCXX/pr33080.cpp' on both x86|debug and x86|release congigurations with MSVC. Repro steps: 1 git clone -c core.autocrlf=false https://github.com/llvm-mirror/llvm D:\llvm\src\ 2 git clone -c core.autocrlf=false https://github.com/llvm-mirror/clang D:\llvm\src\tools\clang 3 open a VS 2017 x86 command prompt and browse to D:\llvm 4 mkdir build_x86 && pushd build_x86 5 cmake -G "Visual Studio 15 2017" -DCMAKE_SYSTEM_VERSION=10.0.17134.0 ..\src\ 6 msbuild /maxcpucount:4 /p:Platform=Win32 /p:Configuration=RelWithDebInfo build_x86\ALL_BUILD.vcxproj /t:Rebuild 7. python.exe ./src/utils/lit/lit.py -v --no-progress-bar --param build_mode=RelWithDebInfo --param clang_site_config=./build_x86/tools/clang/test/lit.site.cfg ./build_x86/tools/clang/test/CodeGenCXX/cxx2a-compare.cpp -j 4 8. python.exe ./src/utils/lit/lit.py -v --no-progress-bar --param build_mode=RelWithDebInfo --param clang_site_config=./build_x86/tools/clang/test/lit.site.cfg ./build_x86/tools/clang/test/CodeGenCXX/pr33080.cpp -j 4 Failures: -- Testing: 1 tests, 1 threads -- FAIL: Clang :: CodeGenCXX/cxx2a-compare.cpp (1 of 1) ******************** TEST 'Clang :: CodeGenCXX/cxx2a-compare.cpp' FAILED ******************** Script: -- : 'RUN: at line 1'; d:\llvm\build_x86\relwithdebinfo\bin\clang.EXE -cc1 -internal-isystem d:\llvm\build_x86\relwithdebinfo\lib\clang\8.0.0\include -nostdsysteminc -std=c++2a -emit-llvm D:\LLVM\src\tools\clang\test\CodeGenCXX\cxx2a-compare.cpp -o - -triple i686-pc-windows-gnu | D:\LLVM\build_x86\RelWithDebInfo\bin\FileCheck.EXE D:\LLVM\src\tools\clang\test\CodeGenCXX\cxx2a-compare.cpp '-DWE="class.std::__1::weak_equality"' '-DSO="class.std::__1::strong_ordering"' '-DSE="class.std::__1::strong_equality"' '-DPO="class.std::__1::partial_ordering"' -DEQ=0 -DLT=-1 -DGT=1 -DUNORD=-127 -DNE=1 -- Exit Code: 1 Command Output (stdout): -- $ ":" "RUN: at line 1" $ "d:\llvm\build_x86\relwithdebinfo\bin\clang.EXE" "-cc1" "-internal-isystem" "d:\llvm\build_x86\relwithdebinfo\lib\clang\8.0.0\include" "-nostdsysteminc" "-std=c++2a" "-emit-llvm" "D:\LLVM\src\tools\clang\test\CodeGenCXX\cxx2a-compare.cpp" "-o" "-" "-triple" "i686-pc-windows-gnu" $ "D:\LLVM\build_x86\RelWithDebInfo\bin\FileCheck.EXE" "D:\LLVM\src\tools\clang\test\CodeGenCXX\cxx2a-compare.cpp" "-DWE="class.std::__1::weak_equality"" "-DSO="class.std::__1::strong_ordering"" "-DSE="class.std::__1::strong_equality"" "-DPO="class.std::__1::partial_ordering"" "-DEQ=0" "-DLT=-1" "-DGT=1" "-DUNORD=-127" "-DNE=1" # command stderr: D:\LLVM\src\tools\clang\test\CodeGenCXX\cxx2a-compare.cpp:76:17: error: CHECK-LABEL: expected string not found in input // CHECK-LABEL: @&#8203;_Z12mem_ptr_testM6MemPtrFvvES1_ ^ <stdin>:77:37: note: scanning from here define dso_local i8 @&#8203;_Z8ptr_testPiS_(i32* %x, i32* %y) #&#8203;0 { ^ <stdin>:98:21: note: possible intended match here define dso_local i8 @&#8203;_Z12mem_ptr_testM6MemPtrU8thiscallFvvES1_({ i32, i32 }* byval align 4, { i32, i32 }* byval align 4) #&#8203;0 { ^ error: command failed with exit status: 1 -- ******************** Testing Time: 0.48s ******************** Failing Tests (1): Clang :: CodeGenCXX/cxx2a-compare.cpp Unexpected Failures: 1 -- Testing: 1 tests, 1 threads -- FAIL: Clang :: CodeGenCXX/pr33080.cpp (1 of 1) ******************** TEST 'Clang :: CodeGenCXX/pr33080.cpp' FAILED ******************** Script: -- : 'RUN: at line 1'; d:\llvm\build_x86\relwithdebinfo\bin\clang.EXE -cc1 -internal-isystem d:\llvm\build_x86\relwithdebinfo\lib\clang\8.0.0\include -nostdsysteminc -triple i686-pc-windows-gnu -fms-extensions -emit-llvm -o- D:\LLVM\src\tools\clang\test\CodeGenCXX\pr33080.cpp | D:\LLVM\build_x86\RelWithDebInfo\bin\FileCheck.EXE D:\LLVM\src\tools\clang\test\CodeGenCXX\pr33080.cpp -- Exit Code: 1 Command Output (stdout): -- $ ":" "RUN: at line 1" $ "d:\llvm\build_x86\relwithdebinfo\bin\clang.EXE" "-cc1" "-internal-isystem" "d:\llvm\build_x86\relwithdebinfo\lib\clang\8.0.0\include" "-nostdsysteminc" "-triple" "i686-pc-windows-gnu" "-fms-extensions" "-emit-llvm" "-o-" "D:\LLVM\src\tools\clang\test\CodeGenCXX\pr33080.cpp" $ "D:\LLVM\build_x86\RelWithDebInfo\bin\FileCheck.EXE" "D:\LLVM\src\tools\clang\test\CodeGenCXX\pr33080.cpp" # command stderr: D:\LLVM\src\tools\clang\test\CodeGenCXX\pr33080.cpp:26:11: error: CHECK: expected string not found in input // CHECK: define {{.*}} @&#8203;_Z6memptrM1AU11__unalignedFviE( ^ <stdin>:69:83: note: scanning from here define dso_local void @&#8203;_Z2jaPU11__unaligned1APU11__unalignedS1_PU11__unalignedS3_(%struct.A*, %struct.A**, %struct.A***) #&#8203;0 { ^ <stdin>:81:20: note: possible intended match here define dso_local void @&#8203;_Z6memptrM1AU8thiscallU11__unalignedFviE({ i32, i32 }* byval align 4) #&#8203;0 { ^ error: command failed with exit status: 1 -- ******************** Testing Time: 0.47s ******************** Failing Tests (1): Clang :: CodeGenCXX/pr33080.cpp Unexpected Failures: 1