[llvm-bugs] [Bug 48246] New: Clang can crash (or freeze) after static_assert() has failed

via llvm-bugs llvm-bugs at lists.llvm.org
Sat Nov 21 00:26:23 PST 2020


https://bugs.llvm.org/show_bug.cgi?id=48246

            Bug ID: 48246
           Summary: Clang can crash (or freeze) after static_assert() has
                    failed
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: ripper37 at gmail.com
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

Created attachment 24190
  --> https://bugs.llvm.org/attachment.cgi?id=24190&action=edit
Contains autogenerated reproduction-7c6556.sh and reproduction-7c6556.cpp files

During my work on side-project, I've reproduced clang crashes which were
preceded by freeze of my PC machine (up to the point where I couldn't even move
my cursor). I've managed to find a minimal reproduction scenario by compiling
this code:

#include <cstddef>
#include <type_traits>
#include <utility>

int main() {
  constexpr size_t x = 1;
  constexpr size_t y = 2;

  static_assert(x >= y, "|x| must not be smaller than |y|");
  using type = std::void_t<std::make_index_sequence<x-y>>;

  return 0;
}

with a command like this: 

clang++ -std=c++17 reproduction.cpp

which gives me this error:

reproduction.cpp:9:3: error: static_assert failed due to requirement 'x >= y'
"|x| must not be smaller than |y|"
  static_assert(x >= y, "|x| must not be smaller than |y|");
  ^             ~~~~~~
clang: error: unable to execute command: Killed
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
https://bugs.llvm.org/ 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/reproduction-7c6556.cpp
clang: note: diagnostic msg: /tmp/reproduction-7c6556.sh
clang: note: diagnostic msg:

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

----------------------------------------------------

I've tested this on multiple clang versions and they all fail, on the other
hand GCC and ICC just report error and don't crash/freeze machine.

For the context in which I've found it - I was writing my own std::bind()-like
implementation which deduced number of function arguments and number of bounded
arguments and computed how many (and which ones) are left. In this case, the
bug reproduced if I provided more arguments for binding than the function took,
even though there were 2 static_asserts for this along the way.

As for the severity, I think that due to how it can freeze the machine and the
fact that some IDEs (e.g. QtCretor) use clang as a backend for understanding
code ("Clang Code Model") which constantly respawns after a crash leading to
complete machine freeze (nothing but to reboot, just by opening a file with
such code), the severity should be high.

Best regards,
Damian Dyńdo.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20201121/905df930/attachment.html>


More information about the llvm-bugs mailing list