<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - _Fract caused SegFault in clang"
   href="https://bugs.llvm.org/show_bug.cgi?id=49602">49602</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>_Fract caused SegFault in clang
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>10.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>C
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>jagenheim@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=24650" name="attach_24650" title="Preprocessed C file">attachment 24650</a> <a href="attachment.cgi?id=24650&action=edit" title="Preprocessed C file">[details]</a></span>
Preprocessed C file

I wanted to test converting from floats to _Fract. Clang crashed.

Clang used is 10.0.0-4ubuntu1 running Ubuntu in a WSL ubuntu environment.

========= C PROGRAM =============

#include <stdio.h>

int main() {

    float tst= 0.3f;

    // Convert float to fixed point
    tst *= 1LL  << 31;
    tst += 0.5f;
    int tst2 = (int)tst;
    _Fract fract = (_Fract)tst2;
    // Add something to fixed point
    fract += 0.5r;
    // Convert back to float again
    tst2 = (int)fract;
    tst2 /= 1LL << 31;
    tst = (float)tst2;

    printf("%f\n", tst);
}


======== STACK TRACE OUTPUT ============

Stack dump:
0.      Program arguments: /usr/lib/llvm-10/bin/clang -cc1 -triple
x86_64-pc-linux-gnu -emit-obj -mrelax-all -disable-free -disable-llvm-verifier
-discard-value-names -main-file-name test.c -mrelocation-model static
-mthread-model posix -mframe-pointer=all -fmath-errno -fno-rounding-math
-masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64
-dwarf-column-info -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir
/usr/lib/llvm-10/lib/clang/10.0.0 -internal-isystem /usr/local/include
-internal-isystem /usr/lib/llvm-10/lib/clang/10.0.0/include
-internal-externc-isystem /usr/include/x86_64-linux-gnu
-internal-externc-isystem /include -internal-externc-isystem /usr/include
-ffixed-point -fdebug-compilation-dir /home/fredde/test/fixp -ferror-limit 19
-fmessage-length 0 -fgnuc-version=4.2.1 -fobjc-runtime=gcc
-fdiagnostics-show-option -faddrsig -o /tmp/test-0b8e7e.o -x c test.c 
1.      <eof> parser at end of file
2.      test.c:3:5: LLVM IR generation of declaration 'main'
3.      test.c:3:5: Generating code for declaration 'main'
 #0 0x00007f98ecead4ff llvm::sys::PrintStackTrace(llvm::raw_ostream&)
(/lib/x86_64-linux-gnu/libLLVM-10.so.1+0x9814ff)
 #1 0x00007f98eceab7b0 llvm::sys::RunSignalHandlers()
(/lib/x86_64-linux-gnu/libLLVM-10.so.1+0x97f7b0)
 #2 0x00007f98eceadac5 (/lib/x86_64-linux-gnu/libLLVM-10.so.1+0x981ac5)
 #3 0x00007f98f367d3c0 __restore_rt
(/lib/x86_64-linux-gnu/libpthread.so.0+0x153c0)
 #4 0x00007f98ecf27b28 (/lib/x86_64-linux-gnu/libLLVM-10.so.1+0x9fbb28)
 #5 0x00007f98ecf1f2b9 (/lib/x86_64-linux-gnu/libLLVM-10.so.1+0x9f32b9)
 #6 0x00007f98ecf1d370 llvm::ConstantExpr::getCast(unsigned int,
llvm::Constant*, llvm::Type*, bool)
(/lib/x86_64-linux-gnu/libLLVM-10.so.1+0x9f1370)
 #7 0x00007f98f210239f (/lib/x86_64-linux-gnu/libclang-cpp.so.10+0x154239f)
 #8 0x00007f98f21018c6 (/lib/x86_64-linux-gnu/libclang-cpp.so.10+0x15418c6)
 #9 0x00007f98f20f5bfb (/lib/x86_64-linux-gnu/libclang-cpp.so.10+0x1535bfb)
#10 0x00007f98f20fa1b8 (/lib/x86_64-linux-gnu/libclang-cpp.so.10+0x153a1b8)
#11 0x00007f98f20f135f
clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool)
(/lib/x86_64-linux-gnu/libclang-cpp.so.10+0x153135f)
#12 0x00007f98f20b0948 clang::CodeGen::CodeGenFunction::EmitAnyExpr(clang::Expr
const*, clang::CodeGen::AggValueSlot, bool)
(/lib/x86_64-linux-gnu/libclang-cpp.so.10+0x14f0948)
#13 0x00007f98f20b08f9
clang::CodeGen::CodeGenFunction::EmitIgnoredExpr(clang::Expr const*)
(/lib/x86_64-linux-gnu/libclang-cpp.so.10+0x14f08f9)
#14 0x00007f98f21e45c4 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt
const*, llvm::ArrayRef<clang::Attr const*>)
(/lib/x86_64-linux-gnu/libclang-cpp.so.10+0x16245c4)
#15 0x00007f98f21ee2fc
clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt
const&, bool, clang::CodeGen::AggValueSlot)
(/lib/x86_64-linux-gnu/libclang-cpp.so.10+0x162e2fc)
#16 0x00007f98f222fc62
clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*)
(/lib/x86_64-linux-gnu/libclang-cpp.so.10+0x166fc62)
#17 0x00007f98f22304bf
clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl,
llvm::Function*, clang::CodeGen::CGFunctionInfo const&)
(/lib/x86_64-linux-gnu/libclang-cpp.so.10+0x16704bf)
#18 0x00007f98f2247cfd
clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl,
llvm::GlobalValue*) (/lib/x86_64-linux-gnu/libclang-cpp.so.10+0x1687cfd)
#19 0x00007f98f2241e52
clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl,
llvm::GlobalValue*) (/lib/x86_64-linux-gnu/libclang-cpp.so.10+0x1681e52)
#20 0x00007f98f224a662
clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*)
(/lib/x86_64-linux-gnu/libclang-cpp.so.10+0x168a662)
#21 0x00007f98f22b9dbf (/lib/x86_64-linux-gnu/libclang-cpp.so.10+0x16f9dbf)
#22 0x00007f98f22279c2 (/lib/x86_64-linux-gnu/libclang-cpp.so.10+0x16679c2)
#23 0x00007f98f1415ba4 clang::ParseAST(clang::Sema&, bool, bool)
(/lib/x86_64-linux-gnu/libclang-cpp.so.10+0x855ba4)
#24 0x00007f98f288be58 clang::FrontendAction::Execute()
(/lib/x86_64-linux-gnu/libclang-cpp.so.10+0x1ccbe58)
#25 0x00007f98f28448a1
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&)
(/lib/x86_64-linux-gnu/libclang-cpp.so.10+0x1c848a1)
#26 0x00007f98f28efdaf
clang::ExecuteCompilerInvocation(clang::CompilerInstance*)
(/lib/x86_64-linux-gnu/libclang-cpp.so.10+0x1d2fdaf)
#27 0x000000000041229d cc1_main(llvm::ArrayRef<char const*>, char const*,
void*) (/usr/lib/llvm-10/bin/clang+0x41229d)
#28 0x00000000004105b1 (/usr/lib/llvm-10/bin/clang+0x4105b1)
#29 0x000000000041036d main (/usr/lib/llvm-10/bin/clang+0x41036d)
#30 0x00007f98ec0140b3 __libc_start_main
(/lib/x86_64-linux-gnu/libc.so.6+0x270b3)
#31 0x000000000040d7ce _start (/usr/lib/llvm-10/bin/clang+0x40d7ce)
clang: error: unable to execute command: Segmentation fault
clang: error: clang frontend command failed due to signal (use -v to see
invocation)
clang version 10.0.0-4ubuntu1 
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
clang: note: diagnostic msg: PLEASE submit a bug report to
<a href="https://bugs.llvm.org/">https://bugs.llvm.org/</a> and include the crash backtrace, preprocessed source,
and associated run script.
clang: note: diagnostic msg: 
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang: note: diagnostic msg: /tmp/test-4fec80.c
clang: note: diagnostic msg: /tmp/test-4fec80.sh
clang: note: diagnostic msg: 

********************


======== Diagnostic msg C ==========

<attached due to filesize>

======== Diagnostic msg SH ==========

# Crash reproducer for clang version 10.0.0-4ubuntu1 
# Driver args: "-ffixed-point" "-o" "test" "test.c"
# Original command:  "/usr/lib/llvm-10/bin/clang" "-cc1" "-triple"
"x86_64-pc-linux-gnu" "-emit-obj" "-mrelax-all" "-disable-free"
"-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "test.c"
"-mrelocation-model" "static" "-mthread-model" "posix" "-mframe-pointer=all"
"-fmath-errno" "-fno-rounding-math" "-masm-verbose" "-mconstructor-aliases"
"-munwind-tables" "-target-cpu" "x86-64" "-dwarf-column-info"
"-fno-split-dwarf-inlining" "-debugger-tuning=gdb" "-resource-dir"
"/usr/lib/llvm-10/lib/clang/10.0.0" "-internal-isystem" "/usr/local/include"
"-internal-isystem" "/usr/lib/llvm-10/lib/clang/10.0.0/include"
"-internal-externc-isystem" "/usr/include/x86_64-linux-gnu"
"-internal-externc-isystem" "/include" "-internal-externc-isystem"
"/usr/include" "-ffixed-point" "-fdebug-compilation-dir"
"/home/fredde/test/fixp" "-ferror-limit" "19" "-fmessage-length" "0"
"-fgnuc-version=4.2.1" "-fobjc-runtime=gcc" "-fdiagnostics-show-option"
"-faddrsig" "-o" "/tmp/test-0b8e7e.o" "-x" "c" "test.c"
 "/usr/lib/llvm-10/bin/clang" "-cc1" "-triple" "x86_64-pc-linux-gnu"
"-emit-obj" "-mrelax-all" "-disable-free" "-disable-llvm-verifier"
"-discard-value-names" "-main-file-name" "test.c" "-mrelocation-model" "static"
"-mthread-model" "posix" "-mframe-pointer=all" "-fmath-errno"
"-fno-rounding-math" "-masm-verbose" "-mconstructor-aliases" "-munwind-tables"
"-target-cpu" "x86-64" "-dwarf-column-info" "-fno-split-dwarf-inlining"
"-debugger-tuning=gdb" "-ffixed-point" "-ferror-limit" "19" "-fmessage-length"
"0" "-fgnuc-version=4.2.1" "-fobjc-runtime=gcc" "-fdiagnostics-show-option"
"-faddrsig" "-x" "c" "test-4fec80.c"</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>