<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 - clang crashes on x86_64-linux-gnu on invalid code of a flexible array member in a union"
   href="https://bugs.llvm.org/show_bug.cgi?id=43117">43117</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>clang crashes on x86_64-linux-gnu on invalid code of a flexible array member in a union
          </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>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>shuo.d@outlook.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>The current clang trunk crashes when compiling the following invalid code on
x86_64-linux-gnu.


$ clang-trunk -v
clang version 9.0.0 (trunk 355785)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/bin
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/8
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/9
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.4
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.4.7
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.6
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.6.4
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8.5
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5.5.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6.5.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.4.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Candidate multilib: x32;@mx32
Selected multilib: .;@m64


$ clang-trunk crash.c 
crash.c:1:15: error: flexible array member 'a' in a union is not allowed
union { short a [ ] ; } u = { { 1 } } ; 
              ^
clang-9: /home/absozero/trunk/llvm/include/llvm/Support/Casting.h:105: static
bool llvm::isa_impl_cl<To, const From*>::doit(const From*) [with To =
clang::Expr; From = clang::Stmt]: Assertion `Val && "isa<> used on a null
pointer"' failed.
Stack dump:
0.      Program arguments: /home/absozero/trunk/root-clang/bin/clang-9 -cc1
-triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all -disable-free
-main-file-name crash.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 -resource-dir
/home/absozero/trunk/root-clang/lib/clang/9.0.0 -internal-isystem
/usr/local/include -internal-isystem
/home/absozero/trunk/root-clang/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/sding/experiments/nonuniform3/bugs/reduced
-ferror-limit 19 -fmessage-length 113 -fobjc-runtime=gcc
-fdiagnostics-show-option -fcolor-diagnostics -o /tmp/crash-07b3b4.o -x c
crash.c -faddrsig 
1.      crash.c:1:39: current parser token ';'
 #0 0x0000564d6dae5d6a llvm::sys::PrintStackTrace(llvm::raw_ostream&)
(/home/absozero/trunk/root-clang/bin/clang-9+0x298fd6a)
 #1 0x0000564d6dae3c34 llvm::sys::RunSignalHandlers()
(/home/absozero/trunk/root-clang/bin/clang-9+0x298dc34)
 #2 0x0000564d6dae3d72 SignalHandler(int)
(/home/absozero/trunk/root-clang/bin/clang-9+0x298dd72)
 #3 0x00007f8d7aa85890 __restore_rt
(/lib/x86_64-linux-gnu/libpthread.so.0+0x12890)
 #4 0x00007f8d796dfe97 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x3ee97)
 #5 0x00007f8d796e1801 abort (/lib/x86_64-linux-gnu/libc.so.6+0x40801)
 #6 0x00007f8d796d139a (/lib/x86_64-linux-gnu/libc.so.6+0x3039a)
 #7 0x00007f8d796d1412 (/lib/x86_64-linux-gnu/libc.so.6+0x30412)
 #8 0x0000564d6f1214aa (anonymous
namespace)::SelfReferenceChecker::CheckExpr(clang::Expr*)
(/home/absozero/trunk/root-clang/bin/clang-9+0x3fcb4aa)
 #9 0x0000564d6f13b910 clang::Sema::AddInitializerToDecl(clang::Decl*,
clang::Expr*, bool) (/home/absozero/trunk/root-clang/bin/clang-9+0x3fe5910)
#10 0x0000564d6ef3b15e
clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&,
clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*)
(/home/absozero/trunk/root-clang/bin/clang-9+0x3de515e)
#11 0x0000564d6ef4a05b clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&,
clang::DeclaratorContext, clang::SourceLocation*, clang::Parser::ForRangeInit*)
(/home/absozero/trunk/root-clang/bin/clang-9+0x3df405b)
#12 0x0000564d6ef24a60
clang::Parser::ParseDeclOrFunctionDefInternal(clang::Parser::ParsedAttributesWithRange&,
clang::ParsingDeclSpec&, clang::AccessSpecifier)
(/home/absozero/trunk/root-clang/bin/clang-9+0x3dcea60)
#13 0x0000564d6ef25171
clang::Parser::ParseDeclarationOrFunctionDefinition(clang::Parser::ParsedAttributesWithRange&,
clang::ParsingDeclSpec*, clang::AccessSpecifier) (.part.221)
(/home/absozero/trunk/root-clang/bin/clang-9+0x3dcf171)
#14 0x0000564d6ef29150
clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&,
clang::ParsingDeclSpec*)
(/home/absozero/trunk/root-clang/bin/clang-9+0x3dd3150)
#15 0x0000564d6ef2a4b9
clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&)
(/home/absozero/trunk/root-clang/bin/clang-9+0x3dd44b9)
#16 0x0000564d6ef2a7b2
clang::Parser::ParseFirstTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&)
(/home/absozero/trunk/root-clang/bin/clang-9+0x3dd47b2)
#17 0x0000564d6ef1fdab clang::ParseAST(clang::Sema&, bool, bool)
(/home/absozero/trunk/root-clang/bin/clang-9+0x3dc9dab)
#18 0x0000564d6e681758 clang::CodeGenAction::ExecuteAction()
(/home/absozero/trunk/root-clang/bin/clang-9+0x352b758)
#19 0x0000564d6e18838e clang::FrontendAction::Execute()
(/home/absozero/trunk/root-clang/bin/clang-9+0x303238e)
#20 0x0000564d6e14a6b6
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&)
(/home/absozero/trunk/root-clang/bin/clang-9+0x2ff46b6)
#21 0x0000564d6e22cc2f
clang::ExecuteCompilerInvocation(clang::CompilerInstance*)
(/home/absozero/trunk/root-clang/bin/clang-9+0x30d6c2f)
#22 0x0000564d6bfc8f48 cc1_main(llvm::ArrayRef<char const*>, char const*,
void*) (/home/absozero/trunk/root-clang/bin/clang-9+0xe72f48)
#23 0x0000564d6bf3aef9 main
(/home/absozero/trunk/root-clang/bin/clang-9+0xde4ef9)
#24 0x00007f8d796c2b97 __libc_start_main
(/lib/x86_64-linux-gnu/libc.so.6+0x21b97)
#25 0x0000564d6bfc4aaa _start
(/home/absozero/trunk/root-clang/bin/clang-9+0xe6eaaa)
clang-9: error: unable to execute command: Aborted (core dumped)
clang-9: error: clang frontend command failed due to signal (use -v to see
invocation)
clang version 9.0.0 (trunk 355785)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/bin
clang-9: 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-9: note: diagnostic msg: 
********************

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

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


$ cat crash.c 
union { short a [ ] ; } u = { { 1 } } ;</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>