<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 - X86 flag output parameters broken/incomplete, breaks compiling third party code"
   href="https://bugs.llvm.org/show_bug.cgi?id=40737">40737</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>X86 flag output parameters broken/incomplete, breaks compiling third party code
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

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

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>-New Bugs
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>martin@martin.st
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=21483" name="attach_21483" title="Reproduction example">attachment 21483</a> <a href="attachment.cgi?id=21483&action=edit" title="Reproduction example">[details]</a></span>
Reproduction example

Since SVN r354053 ([X86] Add clang support for X86 flag output parameters.),
compiling of the mingw-w64 runtime is broken.

The issue seems to boil down to a construct like this:

/* GCC v6 added support for outputting flags.  This allows better code to be
   produced for a number of intrinsics. */
#ifndef __GCC_ASM_FLAG_OUTPUTS__
#define __buildbitscan(x, y, z) unsigned char x(unsigned int *Index, y Mask) \
{ \
   y n; \
   __asm__ (z \
      : [Index] "=r" (n) \
      : [Mask] "r" (Mask) \
      : "cc"); \
   *Index = n; \
   return Mask!=0; \
}
#else
#define __buildbitscan(x, y, z) unsigned char x(unsigned int *Index, y Mask) \
{ \
   y n; \
   unsigned char old; \
   __asm__ (z \
      : "=@ccnz" (old), [Index] "=r" (n) \
      : [Mask] "r" (Mask)); \
   *Index = n; \
   return old; \
}
#endif

__buildbitscan(_BitScanForward, unsigned int, "bsf{l %[Mask],%[Index] |
%[Index],%[Mask]}")

(The testcase is simplified from the original form from mingw-w64, making it
buildable for any target.)

Prior to this change, clang used the older form and everything assembled fine.
After this change, compilation now fails like this:

$ bin/clang -c test.c
clang-9: ../lib/CodeGen/SelectionDAG/ScheduleDAGSDNodes.cpp:352: void
llvm::ScheduleDAGSDNodes::BuildSchedUnits(): Assertion `N->getNodeId() == -1 &&
"Node already inserted!"' failed.
Stack dump:
0.      Program arguments: /home/martin/code/llvm-bisect/build/bin/clang-9 -cc1
-triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all -disable-free
-main-file-name test.c -mrelocation-model static -mthread-model posix
-mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases
-munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info
-debugger-tuning=gdb -coverage-notes-file
/home/martin/code/llvm-bisect/build/test.gcno -resource-dir
/home/martin/code/llvm-bisect/build/lib/clang/9.0.0 -internal-isystem
/usr/local/include -internal-isystem
/home/martin/code/llvm-bisect/build/lib/clang/9.0.0/include
-internal-externc-isystem /usr/include/x86_64-linux-gnu
-internal-externc-isystem /include -internal-externc-isystem /usr/include
-fdebug-compilation-dir /home/martin/code/llvm-bisect/build -ferror-limit 19
-fmessage-length 207 -fobjc-runtime=gcc -fdiagnostics-show-option
-fcolor-diagnostics -o test.o -x c test.c -faddrsig 
1.      <eof> parser at end of file
2.      Code generation
3.      Running pass 'Function Pass Manager' on module 'test.c'.
4.      Running pass 'X86 DAG->DAG Instruction Selection' on function
'@_BitScanForward'
 #0 0x0000000001b6fb0a llvm::sys::PrintStackTrace(llvm::raw_ostream&)
(/home/martin/code/llvm-bisect/build/bin/clang-9+0x1b6fb0a)
 #1 0x0000000001b6d8ac llvm::sys::RunSignalHandlers()
(/home/martin/code/llvm-bisect/build/bin/clang-9+0x1b6d8ac)
 #2 0x0000000001b6da17 SignalHandler(int)
(/home/martin/code/llvm-bisect/build/bin/clang-9+0x1b6da17)
 #3 0x00007fde9fe93390 __restore_rt
(/lib/x86_64-linux-gnu/libpthread.so.0+0x11390)
 #4 0x00007fde9ec05428 gsignal
/build/glibc-Cl5G7W/glibc-2.23/signal/../sysdeps/unix/sysv/linux/raise.c:54:0
 #5 0x00007fde9ec0702a abort /build/glibc-Cl5G7W/glibc-2.23/stdlib/abort.c:91:0
 #6 0x00007fde9ebfdbd7 __assert_fail_base
/build/glibc-Cl5G7W/glibc-2.23/assert/assert.c:92:0
 #7 0x00007fde9ebfdc82 (/lib/x86_64-linux-gnu/libc.so.6+0x2dc82)
 #8 0x000000000264e0c8 llvm::ScheduleDAGSDNodes::BuildSchedUnits()
(/home/martin/code/llvm-bisect/build/bin/clang-9+0x264e0c8)
 #9 0x0000000002650831
llvm::ScheduleDAGSDNodes::BuildSchedGraph(llvm::AAResults*)
(/home/martin/code/llvm-bisect/build/bin/clang-9+0x2650831)
#10 0x00000000026450a8 (anonymous namespace)::ScheduleDAGRRList::Schedule()
(/home/martin/code/llvm-bisect/build/bin/clang-9+0x26450a8)
#11 0x00000000025bee2e llvm::SelectionDAGISel::CodeGenAndEmitDAG()
(/home/martin/code/llvm-bisect/build/bin/clang-9+0x25bee2e)
#12 0x00000000025c892b
llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&)
(/home/martin/code/llvm-bisect/build/bin/clang-9+0x25c892b)
#13 0x00000000025ca894
llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&)
(.part.899.constprop.925)
(/home/martin/code/llvm-bisect/build/bin/clang-9+0x25ca894)
#14 0x0000000000e00680 (anonymous
namespace)::X86DAGToDAGISel::runOnMachineFunction(llvm::MachineFunction&)
(/home/martin/code/llvm-bisect/build/bin/clang-9+0xe00680)
#15 0x00000000012b4691
llvm::MachineFunctionPass::runOnFunction(llvm::Function&)
(.part.37.constprop.38)
(/home/martin/code/llvm-bisect/build/bin/clang-9+0x12b4691)
#16 0x000000000166997c llvm::FPPassManager::runOnFunction(llvm::Function&)
(/home/martin/code/llvm-bisect/build/bin/clang-9+0x166997c)
#17 0x0000000001669b5c llvm::FPPassManager::runOnModule(llvm::Module&)
(/home/martin/code/llvm-bisect/build/bin/clang-9+0x1669b5c)
#18 0x000000000166ac79 llvm::legacy::PassManagerImpl::run(llvm::Module&)
(/home/martin/code/llvm-bisect/build/bin/clang-9+0x166ac79)
#19 0x0000000001d4feed (anonymous
namespace)::EmitAssemblyHelper::EmitAssembly(clang::BackendAction,
std::unique_ptr<llvm::raw_pwrite_stream,
std::default_delete<llvm::raw_pwrite_stream> >)
(/home/martin/code/llvm-bisect/build/bin/clang-9+0x1d4feed)
#20 0x0000000001d5187d clang::EmitBackendOutput(clang::DiagnosticsEngine&,
clang::HeaderSearchOptions const&, clang::CodeGenOptions const&,
clang::TargetOptions const&, clang::LangOptions const&, llvm::DataLayout
const&, llvm::Module*, clang::BackendAction,
std::unique_ptr<llvm::raw_pwrite_stream,
std::default_delete<llvm::raw_pwrite_stream> >)
(/home/martin/code/llvm-bisect/build/bin/clang-9+0x1d5187d)
#21 0x000000000269acc4
clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&)
(/home/martin/code/llvm-bisect/build/bin/clang-9+0x269acc4)
#22 0x0000000002f695d9 clang::ParseAST(clang::Sema&, bool, bool)
(/home/martin/code/llvm-bisect/build/bin/clang-9+0x2f695d9)
#23 0x000000000269a03f clang::CodeGenAction::ExecuteAction()
(/home/martin/code/llvm-bisect/build/bin/clang-9+0x269a03f)
#24 0x00000000021cba8e clang::FrontendAction::Execute()
(/home/martin/code/llvm-bisect/build/bin/clang-9+0x21cba8e)
#25 0x00000000021942b6
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&)
(/home/martin/code/llvm-bisect/build/bin/clang-9+0x21942b6)
#26 0x000000000226a4bd
clang::ExecuteCompilerInvocation(clang::CompilerInstance*)
(/home/martin/code/llvm-bisect/build/bin/clang-9+0x226a4bd)
#27 0x00000000009c6118 cc1_main(llvm::ArrayRef<char const*>, char const*,
void*) (/home/martin/code/llvm-bisect/build/bin/clang-9+0x9c6118)
#28 0x000000000094a4c9 main
(/home/martin/code/llvm-bisect/build/bin/clang-9+0x94a4c9)
#29 0x00007fde9ebf0830 __libc_start_main
/build/glibc-Cl5G7W/glibc-2.23/csu/../csu/libc-start.c:325:0
#30 0x00000000009c1fa9 _start
(/home/martin/code/llvm-bisect/build/bin/clang-9+0x9c1fa9)</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>