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

Assert of 'clang_delta' #26

Closed
JVApen opened this issue May 24, 2020 · 8 comments
Closed

Assert of 'clang_delta' #26

JVApen opened this issue May 24, 2020 · 8 comments

Comments

@JVApen
Copy link

JVApen commented May 24, 2020

Found on following code (t.cpp):

#include <variant>
#include <vector>
struct A {
         std::basic_string<wchar_t> m;
       };
        struct B {
         B(A a);
         std::variant<A> m;
       };
        struct C : B {
         using B::B;
       };
        void f() {
         std::vector<C> c{
     };
         c.push_back(C{
     A{
    }
     }
      );
       }

Launch script:

py -3.6 G:\llvm\build-cvise\cvise.py --clang-delta-std c++17 --n 1 --print-diff checkIfBugExists.bat t.cpp 

The error occurs within ClangPass::remove-unused-function

checkIfBugExists.bat

SET CVISE_BUG_DETECTED=0
SET CVISE_BUG_IRREPRODUCABLE=1
setlocal enableDelayedExpansion

echo "Current dir: %cd%"
echo "Copied file: %1"
C:\Path\To\LLVM_7_0_0\bin\clang-cl.exe /c /EHsc -w /std:c++17 t.cpp > compilation.out 2> compilation.err
if %ERRORLEVEL% EQU 0 (
   echo "Compilation success"
   exit /b %CVISE_BUG_IRREPRODUCABLE%
)
echo "Failed to compile"

findstr /r /c:"Wrote crash dump file" .\compilation.err
if %ERRORLEVEL% EQU 0 (
   echo "Found crash message"
   exit /b %CVISE_BUG_DETECTED%
) else (
   echo "Not found"
   exit /b %CVISE_BUG_IRREPRODUCABLE%
)

Callstack of delta.exe (Compiled with LLVM 10.0.0)

 	issue_debug_notification(message) Line 28	C++
 	__acrt_report_runtime_error(message) Line 154	C++
 	abort() Line 61	C++
 	common_assert_to_stderr<wchar_t>(expression, file_name, line_number) Line 187	C++
 	common_assert<wchar_t>(expression, file_name, line_number, return_address) Line 420	C++
 	_wassert(expression, file_name, line_number) Line 444	C++
>	RemoveUnusedFunction::doRewriting() Line 307	C++
 	RemoveUnusedFunction::HandleTranslationUnit(Ctx) Line 284	C++
 	clang::ParseAST(S, PrintStats, SkipFunctionBodies) Line 178	C++
 	TransformationManager::doTransformation(ErrorMsg, ErrorCode) Line 308	C++
 	main(argc, argv) Line 249	C++

Issue is in void RemoveUnusedFunction::doRewriting() where TheFunctionDecl seems to be nullptr. ToCounter is on -1.

@JVApen JVApen mentioned this issue May 25, 2020
@marxin
Copy link
Owner

marxin commented May 25, 2020

Thanks for the report.
What version of LLVM do you use for CVise as a run-time library?
I can run the transformation with success:

$ clang_delta/clang_delta  --transformation=remove-unused-function  tc.C --counter=1 --std=c++17
#include <variant>
#include <vector>
struct A {
         std::basic_string<wchar_t> m;
       };
        struct B {
         B(A a);
         std::variant<A> m;
       };
        struct C : B {
         using B::B;
       };

Can you please attach output of pre-processed source file -E option for clang?

@JVApen
Copy link
Author

JVApen commented May 25, 2020

I'm using LLVM 10, let me see if I can do so easily

@JVApen
Copy link
Author

JVApen commented May 31, 2020

C:\path\to\build-cvise\clang_delta\Debug\clang_delta.exe --transformation=remove-unused-function
t.cpp.preprocessed.cpp --counter=1 --std=c++17
Warning: number of transformation instances exceeded
Assertion failed: RWBuf && "Empty RewriteBuffer!", file G:\llvm\cvise-master\clang_delta\Transformation.cpp, line 103

The file: t.cpp.preprocessed.zip

@marxin
Copy link
Owner

marxin commented May 31, 2020

I'm sorry but I can't compile it on Linux:

clang++ x.ii -std=c++17
In file included from .\t.cpp:1:
In file included from c:\path\to\Vs2019\VC\Tools\MSVC\14.24.28314\include\variant:9:
In file included from c:\path\to\Vs2019\VC\Tools\MSVC\14.24.28314\include\yvals.h:9:
In file included from c:\path\to\Vs2019\VC\Tools\MSVC\14.24.28314\include\yvals_core.h:253:
In file included from c:\path\to\Vs2019\VC\Tools\MSVC\14.24.28314\include\vcruntime.h:58:
In file included from c:\path\to\LLVM_10_0_0\lib\clang\10.0.0\include\vadefs.h:18:
c:\path\to\Vs2019\VC\Tools\MSVC\14.24.28314\include\vadefs.h:28:33: error: expected ';' after top level declarator
        typedef unsigned __int64 uintptr_t;
                                ^
In file included from .\t.cpp:1:
In file included from c:\path\to\Vs2019\VC\Tools\MSVC\14.24.28314\include\variant:9:
In file included from c:\path\to\Vs2019\VC\Tools\MSVC\14.24.28314\include\yvals.h:9:
In file included from c:\path\to\Vs2019\VC\Tools\MSVC\14.24.28314\include\yvals_core.h:253:
c:\path\to\Vs2019\VC\Tools\MSVC\14.24.28314\include\vcruntime.h:190:29: error: expected ';' after top level declarator
    typedef unsigned __int64 size_t;
                            ^
c:\path\to\Vs2019\VC\Tools\MSVC\14.24.28314\include\vcruntime.h:245:42: error: unknown type name 'size_t'
        template <typename _CountofType, size_t _SizeOfArray>
                                         ^
$ g++ x.ii -std=c++17 -fmax-errors=3
In file included from c:\path\to\LLVM_10_0_0\lib\clang\10.0.0\include\vadefs.h:18,
                 from c:\path\to\Vs2019\VC\Tools\MSVC\14.24.28314\include\vcruntime.h:58,
                 from c:\path\to\Vs2019\VC\Tools\MSVC\14.24.28314\include\yvals_core.h:253,
                 from c:\path\to\Vs2019\VC\Tools\MSVC\14.24.28314\include\yvals.h:9,
                 from c:\path\to\Vs2019\VC\Tools\MSVC\14.24.28314\include\variant:9,
                 from .\t.cpp:1:
c:\path\to\Vs2019\VC\Tools\MSVC\14.24.28314\include\vadefs.h:28:34: error: expected initializer before ‘uintptr_t’
In file included from c:\path\to\LLVM_10_0_0\lib\clang\10.0.0\include\vadefs.h:18,
                 from c:\path\to\Vs2019\VC\Tools\MSVC\14.24.28314\include\vcruntime.h:58,
                 from c:\path\to\Vs2019\VC\Tools\MSVC\14.24.28314\include\yvals_core.h:253,
                 from c:\path\to\Vs2019\VC\Tools\MSVC\14.24.28314\include\yvals.h:9,
                 from c:\path\to\Vs2019\VC\Tools\MSVC\14.24.28314\include\variant:9,
                 from .\t.cpp:1:
c:\path\to\Vs2019\VC\Tools\MSVC\14.24.28314\include\vadefs.h:112:18: error: expected initializer before ‘__va_start’
In file included from c:\path\to\Vs2019\VC\Tools\MSVC\14.24.28314\include\yvals_core.h:253,
                 from c:\path\to\Vs2019\VC\Tools\MSVC\14.24.28314\include\yvals.h:9,
                 from c:\path\to\Vs2019\VC\Tools\MSVC\14.24.28314\include\variant:9,
                 from .\t.cpp:1:
c:\path\to\Vs2019\VC\Tools\MSVC\14.24.28314\include\vcruntime.h:190:30: error: expected initializer before ‘size_t’
compilation terminated due to -fmax-errors=3.

@JVApen
Copy link
Author

JVApen commented May 31, 2020

I guess you can replace __int64 by std::int64_t if you add the include

@marxin
Copy link
Owner

marxin commented May 31, 2020

It will require much more adjustments. You can try it here:
https://godbolt.org/

@JVApen
Copy link
Author

JVApen commented Jun 1, 2020

-fms-extensions does a lot, however, I seem to always have 32bit-64bit mismatches.
Any tips for me to debug it myself?

@marxin
Copy link
Owner

marxin commented Jun 1, 2020

Maybe -m32 can help.
Anyway, that's more a LLVM issue than C-Vise issue. The code is invalid so it's partially understandable.

@marxin marxin closed this as completed Jun 1, 2020
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