Skip to content

Segmentation fault in clang::CodeGen::CodeGenFunction::EmitScalarExpr #44656

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

Closed
jtsylve opened this issue Mar 26, 2020 · 3 comments
Closed

Segmentation fault in clang::CodeGen::CodeGenFunction::EmitScalarExpr #44656

jtsylve opened this issue Mar 26, 2020 · 3 comments
Labels
bugzilla Issues migrated from bugzilla clang:codegen IR generation bugs: mangling, exceptions, etc.

Comments

@jtsylve
Copy link

jtsylve commented Mar 26, 2020

Bugzilla Link 45311
Version 8.0
OS Linux
CC @zygoloid

Extended Description

As you can see here I'm testing my codebase against several versions of clang++ running on Linux: https://travis-ci.org/github/jtsylve/yatlib/builds/667081643

Clang 5 and 6 fail to compile for unrelated reasons which I can mitigate. Clang 8, 9, 10, and 11 all crash with a similar Segmentation fault. The code that triggers the crash can be found by checking out commit ef0cc1852c353cef024ea5cea0ea371e7259fde5 from https://github.com/jtsylve/yatlib

Clang 8 stacktrace below:

Stack dump:
0. Program arguments: /usr/lib/llvm-8/bin/clang -cc1 -triple x86_64-pc-linux-gnu -emit-obj -disable-free -disable-llvm-verifier -discard-value-names -main-file-name format_test.cpp -mrelocation-model static -mthread-model posix -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debug-info-kind=limited -dwarf-version=4 -debugger-tuning=gdb -momit-leaf-frame-pointer -coverage-notes-file /home/travis/build/jtsylve/yatlib/tests/CMakeFiles/unittests.dir/format_test.cpp.gcno -resource-dir /usr/lib/llvm-8/lib/clang/8.0.1 -I /home/travis/build/jtsylve/yatlib/thirdparty/catch2/single_include -I /home/travis/build/jtsylve/yatlib/include -D NDEBUG -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/x86_64-linux-gnu/c++/7.5.0 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/x86_64-linux-gnu/c++/7.5.0 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/backward -internal-isystem /usr/include/clang/8.0.1/include/ -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-8/lib/clang/8.0.1/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wall -Wextra -Wshadow -Wnon-virtual-dtor -Wold-style-cast -Wcast-align -Wunused -Woverloaded-virtual -Wpedantic -Wconversion -Wsign-conversion -Wnull-dereference -Wdouble-promotion -Wformat=2 -std=gnu++17 -fdeprecated-macro -fdebug-compilation-dir /home/travis/build/jtsylve/yatlib/tests -ferror-limit 19 -fmessage-length 80 -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -vectorize-loops -vectorize-slp -o CMakeFiles/unittests.dir/format_test.cpp.o -x c++ /home/travis/build/jtsylve/yatlib/tests/format_test.cpp -faddrsig

  1. parser at end of file
  2. Per-file LLVM IR generation
  3. /home/travis/build/jtsylve/yatlib/tests/format_test.cpp:72:1 <Spelling=:185:1>: Generating code for declaration '____C_A_T_C_H____T_E_S_T____4'
  4. /home/travis/build/jtsylve/yatlib/tests/format_test.cpp:86:3 <Spelling=/home/travis/build/jtsylve/yatlib/thirdparty/catch2/single_include/catch2/catch.hpp:2676:8>: LLVM IR generation of compound statement ('{}')
    #​0 0x00007fc6412cd59f llvm::sys::PrintStackTrace(llvm::raw_ostream&) (/usr/lib/x86_64-linux-gnu/libLLVM-8.so.1+0x97159f)
    #​1 0x00007fc6412cb9f0 llvm::sys::RunSignalHandlers() (/usr/lib/x86_64-linux-gnu/libLLVM-8.so.1+0x96f9f0)
    #​2 0x00007fc6412cd9a8 (/usr/lib/x86_64-linux-gnu/libLLVM-8.so.1+0x9719a8)
    #​3 0x00007fc6445b4890 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x12890)
    #​4 0x00000000008e4ed9 (/usr/lib/llvm-8/bin/clang+0x8e4ed9)
    #​5 0x00000000008d6a8f clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) (/usr/lib/llvm-8/bin/clang+0x8d6a8f)
    #​6 0x00000000008a4b06 clang::CodeGen::CodeGenFunction::EmitAnyExpr(clang::Expr const*, clang::CodeGen::AggValueSlot, bool) (/usr/lib/llvm-8/bin/clang+0x8a4b06)
    #​7 0x00000000008a4a59 clang::CodeGen::CodeGenFunction::EmitIgnoredExpr(clang::Expr const*) (/usr/lib/llvm-8/bin/clang+0x8a4a59)
    #​8 0x00000000008e7cc8 (/usr/lib/llvm-8/bin/clang+0x8e7cc8)
    #​9 0x00000000008e0c1b (/usr/lib/llvm-8/bin/clang+0x8e0c1b)
    #​10 0x00000000008d6a8f clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) (/usr/lib/llvm-8/bin/clang+0x8d6a8f)
    #​11 0x00000000008a4b06 clang::CodeGen::CodeGenFunction::EmitAnyExpr(clang::Expr const*, clang::CodeGen::AggValueSlot, bool) (/usr/lib/llvm-8/bin/clang+0x8a4b06)
    #​12 0x00000000008a4a59 clang::CodeGen::CodeGenFunction::EmitIgnoredExpr(clang::Expr const*) (/usr/lib/llvm-8/bin/clang+0x8a4a59)
    #​13 0x0000000000712b92 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/usr/lib/llvm-8/bin/clang+0x712b92)
    #​14 0x000000000071ba70 clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (/usr/lib/llvm-8/bin/clang+0x71ba70)
    #​15 0x000000000071b048 clang::CodeGen::CodeGenFunction::EmitCompoundStmt(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (/usr/lib/llvm-8/bin/clang+0x71b048)
    #​16 0x00000000007131df clang::CodeGen::CodeGenFunction::EmitSimpleStmt(clang::Stmt const*) (/usr/lib/llvm-8/bin/clang+0x7131df)
    #​17 0x0000000000712abb clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/usr/lib/llvm-8/bin/clang+0x712abb)
    #​18 0x00000000007146ae clang::CodeGen::CodeGenFunction::EmitDoStmt(clang::DoStmt const&, llvm::ArrayRef<clang::Attr const*>) (/usr/lib/llvm-8/bin/clang+0x7146ae)
    #​19 0x0000000000713056 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/usr/lib/llvm-8/bin/clang+0x713056)
    #​20 0x000000000071ba70 clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (/usr/lib/llvm-8/bin/clang+0x71ba70)
    #​21 0x000000000075545e clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) (/usr/lib/llvm-8/bin/clang+0x75545e)
    #​22 0x0000000000755cdf clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/usr/lib/llvm-8/bin/clang+0x755cdf)
    #​23 0x000000000076c512 clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/usr/lib/llvm-8/bin/clang+0x76c512)
    #​24 0x0000000000766d0b clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/usr/lib/llvm-8/bin/clang+0x766d0b)
    #​25 0x000000000075ed8e clang::CodeGen::CodeGenModule::EmitDeferred() (/usr/lib/llvm-8/bin/clang+0x75ed8e)
    #​26 0x000000000075e267 clang::CodeGen::CodeGenModule::Release() (/usr/lib/llvm-8/bin/clang+0x75e267)
    #​27 0x0000000000d58944 (/usr/lib/llvm-8/bin/clang+0xd58944)
    #​28 0x0000000000d56438 (/usr/lib/llvm-8/bin/clang+0xd56438)
    #​29 0x00000000011dcbb3 clang::ParseAST(clang::Sema&, bool, bool) (/usr/lib/llvm-8/bin/clang+0x11dcbb3)
    #​30 0x0000000000add2bf clang::FrontendAction::Execute() (/usr/lib/llvm-8/bin/clang+0xadd2bf)
    #​31 0x0000000000a9bde8 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/usr/lib/llvm-8/bin/clang+0xa9bde8)
    #​32 0x0000000000b62d96 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/usr/lib/llvm-8/bin/clang+0xb62d96)
    #​33 0x00000000006a2dec cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/usr/lib/llvm-8/bin/clang+0x6a2dec)
    #​34 0x00000000006a1336 main (/usr/lib/llvm-8/bin/clang+0x6a1336)
    #​35 0x00007fc63fc4db97 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b97)
    #​36 0x000000000069ea5a _start (/usr/lib/llvm-8/bin/clang+0x69ea5a)
    clang: error: unable to execute command: Segmentation fault (core dumped)
@jtsylve
Copy link
Author

jtsylve commented Mar 26, 2020

This commit seems to mitigate the crash, so I suspect the root cause has something to do with the friend function being defined inline to the class.

jtsylve/yatlib@2a0a091

@llvmbot
Copy link
Member

llvmbot commented Mar 26, 2020

Mind attaching the preprocessed source, as well as the relevant cc1 line from -v -save-temps? That will make it easer to repro this.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
shiltian pushed a commit to shiltian/llvm-project that referenced this issue Dec 15, 2021
…tEvaluated

We would previously try to evaluate atomic constraints of non-template functions as-is,
and since they are now unevaluated at first, this would cause incorrect evaluation (bugs llvm#44657, llvm#44656).

Substitute into atomic constraints of non-template functions as we would atomic constraints
of template functions, in order to rebuild the expressions in a constant-evaluated context.

(cherry picked from commit 713562f)
@nunoplopes
Copy link
Member

This has been fixed by the commit mentioned above.

trevor-m pushed a commit to trevor-m/llvm-project that referenced this issue Apr 20, 2023
…tEvaluated

We would previously try to evaluate atomic constraints of non-template functions as-is,
and since they are now unevaluated at first, this would cause incorrect evaluation (bugs llvm#44657, llvm#44656).

Substitute into atomic constraints of non-template functions as we would atomic constraints
of template functions, in order to rebuild the expressions in a constant-evaluated context.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla clang:codegen IR generation bugs: mangling, exceptions, etc.
Projects
None yet
Development

No branches or pull requests

3 participants