Bug 225862 - clang dumps core on head@r329155
Summary: clang dumps core on head@r329155
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-02-13 12:31 UTC by Andrey V. Elsukov
Modified: 2018-02-15 07:53 UTC (History)
1 user (show)

See Also:


Attachments
code to reproduce (7.95 KB, application/gzip)
2018-02-13 15:24 UTC, Andrey V. Elsukov
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Andrey V. Elsukov freebsd_committer freebsd_triage 2018-02-13 12:31:47 UTC
I'm trying to build not yet ready to build code to see what I can fix :)
But clang dumps core.

This is output from make command:

Assertion failed: (D.getASTContext().getLangOpts().CPlusPlus), function isDeclExternC, file /usr/src/contrib/llvm/tools/clang/lib/AST/Decl.cpp, line 1954.
cc: error: unable to execute command: Abort trap (core dumped)
cc: error: clang frontend command failed due to signal (use -v to see invocation)
FreeBSD clang version 6.0.0 (branches/release_60 324090) (based on LLVM 6.0.0)
Target: x86_64-unknown-freebsd12.0
Thread model: posix
InstalledDir: /usr/bin
cc: note: diagnostic msg: PLEASE submit a bug report to https://bugs.freebsd.org/submit/ and include the crash backtrace, preprocessed source, and associated run script.
cc: note: diagnostic msg: Error generating preprocessed source(s).
*** Error code 254

% gdb -q cc cc.core
Reading symbols from cc...Reading symbols from /usr/lib/debug//usr/bin/clang.debug...done.
done.
[New LWP 101201]
Core was generated by `/usr/bin/cc -cc1 -triple x86_64-unknown-freebsd12.0 -emit-obj -disable-free -mai'.
Program terminated with signal SIGABRT, Aborted.
#0  thr_kill () at thr_kill.S:3
3	RSYSCALL(thr_kill)
(gdb) bt
#0  thr_kill () at thr_kill.S:3
#1  0x00000000040f74af in __raise (s=6) at /usr/src/lib/libc/gen/raise.c:54
#2  0x00000000040f7476 in abort () at /usr/src/lib/libc/stdlib/abort.c:79
#3  0x0000000004166a3a in __assert (func=<optimized out>, file=<optimized out>, line=<optimized out>, failedexpr=<optimized out>) at /usr/src/lib/libc/gen/assert.c:53
#4  0x00000000024f08c7 in isDeclExternC<clang::FunctionDecl> () at /usr/src/contrib/llvm/tools/clang/lib/AST/Decl.cpp:1954
#5  isExternC () at /usr/src/contrib/llvm/tools/clang/lib/AST/Decl.cpp:2788
#6  0x0000000001c1fd60 in ActOnFunctionDeclarator () at /usr/src/contrib/llvm/tools/clang/lib/Sema/SemaDecl.cpp:8990
#7  0x0000000001c1962b in HandleDeclarator () at /usr/src/contrib/llvm/tools/clang/lib/Sema/SemaDecl.cpp:5465
#8  0x0000000001c0067c in ActOnDeclarator () at /usr/src/contrib/llvm/tools/clang/lib/Sema/SemaDecl.cpp:5145
#9  ImplicitlyDefineFunction () at /usr/src/contrib/llvm/tools/clang/lib/Sema/SemaDecl.cpp:12606
#10 0x00000000019fd61c in ActOnIdExpression () at /usr/src/contrib/llvm/tools/clang/lib/Sema/SemaExpr.cpp:2119
#11 0x00000000020369e5 in ParseCastExpression () at /usr/src/contrib/llvm/tools/clang/lib/Parse/ParseExpr.cpp:1037
#12 0x000000000202f736 in ParseCastExpression () at /usr/src/contrib/llvm/tools/clang/lib/Parse/ParseExpr.cpp:527
#13 ParseRHSOfBinaryExpression () at /usr/src/contrib/llvm/tools/clang/lib/Parse/ParseExpr.cpp:416
#14 0x000000000202f0cd in ParseAssignmentExpression () at /usr/src/contrib/llvm/tools/clang/lib/Parse/ParseExpr.cpp:175
#15 0x0000000002037929 in ParseExpression () at /usr/src/contrib/llvm/tools/clang/lib/Parse/ParseExpr.cpp:124
#16 ParseParenExpression () at /usr/src/contrib/llvm/tools/clang/lib/Parse/ParseExpr.cpp:2526
#17 0x0000000002032585 in ParseCastExpression () at /usr/src/contrib/llvm/tools/clang/lib/Parse/ParseExpr.cpp:775
#18 0x000000000202f075 in ParseCastExpression () at /usr/src/contrib/llvm/tools/clang/lib/Parse/ParseExpr.cpp:527
#19 ParseAssignmentExpression () at /usr/src/contrib/llvm/tools/clang/lib/Parse/ParseExpr.cpp:172
#20 0x000000000201d27a in ParseBracketDeclarator () at /usr/src/contrib/llvm/tools/clang/lib/Parse/ParseDecl.cpp:6549
#21 0x000000000201970b in ParseDirectDeclarator () at /usr/src/contrib/llvm/tools/clang/lib/Parse/ParseDecl.cpp:5755
#22 0x0000000002017d42 in ParseDeclaratorInternal () at /usr/src/contrib/llvm/tools/clang/lib/Parse/ParseDecl.cpp:5316
#23 0x0000000002014dc5 in ParseDeclarator () at /usr/src/contrib/llvm/tools/clang/lib/Parse/ParseDecl.cpp:5185
#24 ParseStructDeclaration () at /usr/src/contrib/llvm/tools/clang/lib/Parse/ParseDecl.cpp:3853
#25 0x0000000002015601 in ParseStructUnionBody () at /usr/src/contrib/llvm/tools/clang/lib/Parse/ParseDecl.cpp:3954
#26 0x0000000001ff2d2e in ParseClassSpecifier () at /usr/src/contrib/llvm/tools/clang/lib/Parse/ParseDeclCXX.cpp:1920
#27 0x000000000200abdc in ParseDeclarationSpecifiers () at /usr/src/contrib/llvm/tools/clang/lib/Parse/ParseDecl.cpp:3633
#28 0x0000000001fb5e6f in ParseDeclOrFunctionDefInternal () at /usr/src/contrib/llvm/tools/clang/lib/Parse/Parser.cpp:922
#29 0x0000000001fb5ad1 in ParseDeclarationOrFunctionDefinition () at /usr/src/contrib/llvm/tools/clang/lib/Parse/Parser.cpp:1028
#30 0x0000000001fb4912 in ParseExternalDeclaration () at /usr/src/contrib/llvm/tools/clang/lib/Parse/Parser.cpp:853
#31 0x0000000001fb3837 in ParseTopLevelDecl () at /usr/src/contrib/llvm/tools/clang/lib/Parse/Parser.cpp:609
#32 0x0000000001faf605 in ParseAST () at /usr/src/contrib/llvm/tools/clang/lib/Parse/ParseAST.cpp:147
#33 0x00000000019c44ee in Execute () at /usr/src/contrib/llvm/tools/clang/lib/Frontend/FrontendAction.cpp:897
#34 0x00000000027ac661 in ExecuteAction () at /usr/src/contrib/llvm/tools/clang/lib/Frontend/CompilerInstance.cpp:991
#35 0x00000000015939f3 in ExecuteCompilerInvocation () at /usr/src/contrib/llvm/tools/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:252
#36 0x00000000015887d0 in cc1_main () at /usr/src/contrib/llvm/tools/clang/tools/driver/cc1_main.cpp:221
#37 0x0000000001590e6a in ExecuteCC1Tool () at /usr/src/contrib/llvm/tools/clang/tools/driver/driver.cpp:309
#38 main () at /usr/src/contrib/llvm/tools/clang/tools/driver/driver.cpp:388
Comment 1 Dimitry Andric freebsd_committer freebsd_triage 2018-02-13 14:20:13 UTC
This looks quite a lot like https://bugs.llvm.org/show_bug.cgi?id=36157, where somebody (either accidentally or on purpose) compiles a C++ source as C.  Or at least, a .c file containing C++ constructs.  Is that the case here?

I've noticed that upstream didn't merge the fix to the 6.0 branch, so I'll put in a request for that.
Comment 2 Dimitry Andric freebsd_committer freebsd_triage 2018-02-13 14:23:36 UTC
Also, to verify that the upstream fix also fixes your crash, is there a  reproducible and self-contained test case?  Can you share the source?
Comment 3 Andrey V. Elsukov freebsd_committer freebsd_triage 2018-02-13 15:24:38 UTC
Created attachment 190581 [details]
code to reproduce

I think these files should be enough, is it reproducible on your system?
Comment 4 commit-hook freebsd_committer freebsd_triage 2018-02-13 17:06:23 UTC
A commit references this bug:

Author: dim
Date: Tue Feb 13 17:05:51 UTC 2018
New revision: 329223
URL: https://svnweb.freebsd.org/changeset/base/329223

Log:
  Pull in r323998 from upstream clang trunk (by Richard Smith):

    PR36157: When injecting an implicit function declaration in C89, find
    the right DeclContext rather than injecting it wherever we happen to
    be.

    This avoids creating functions whose DeclContext is a struct or
    similar.

  This fixes assertion failures when parsing certain not-completely-valid
  struct declarations.

  Reported by:	ae
  PR:		225862
  MFC after:	3 months
  X-MFC-With:	r327952

Changes:
  head/contrib/llvm/tools/clang/lib/Sema/SemaDecl.cpp