New user self-registration is disabled due to spam. For an account please email bugs-admin@lists.llvm.org with your e-mail address and full name.

Bug 43268 - clang 9 rc4 regression: AST/Decl.cpp:3336: bool clang::FunctionDecl::isInlineDefinitionExternallyVisible() const: Assertion `(doesThisDeclarationHaveABody() || willHaveBody()) && "Must be a function definition"' failed
Summary: clang 9 rc4 regression: AST/Decl.cpp:3336: bool clang::FunctionDecl::isInline...
Status: RESOLVED FIXED
Alias: None
Product: clang
Classification: Unclassified
Component: -New Bugs (show other bugs)
Version: 9.0
Hardware: All All
: P release blocker
Assignee: Nick Desaulniers
URL:
Keywords:
Depends on:
Blocks: release-9.0.0
  Show dependency tree
 
Reported: 2019-09-10 12:22 PDT by Andrew Kelley
Modified: 2019-09-13 01:11 PDT (History)
8 users (show)

See Also:
Fixed By Commit(s):


Attachments
/run/user/1001/stat-ce2dd5.c (165.34 KB, text/x-csrc)
2019-09-10 12:22 PDT, Andrew Kelley
Details
/run/user/1001/stat-ce2dd5.sh (10.45 KB, application/x-shellscript)
2019-09-10 12:23 PDT, Andrew Kelley
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Kelley 2019-09-10 12:22:15 PDT
Created attachment 22482 [details]
/run/user/1001/stat-ce2dd5.c

This regressed from LLVM 9.0.0 release candidate 3.

[nix-shell:~/zig-9/build]$ ~/local-llvm9-debug/bin/clang -MD -MV -MF /home/andy/.local/share/zig/stage1/tmp/CuMHrPPk3OJv-stat.o.d -nostdinc -fno-spell-checking -isystem /home/andy/zig-9/build/lib/zig/include -march=native -g -fno-omit-frame-pointer -D_DEBUG -fno-stack-protector -fPIC -o /home/andy/.local/share/zig/stage1/tmp/CuMHrPPk3OJv-stat.o -c /home/andy/zig-9/build/lib/zig/libc/glibc/io/stat.c -std=gnu11 -fgnu89-inline -g -O2 -fmerge-all-constants -fno-stack-protector -fmath-errno -ftls-model=initial-exec -Wno-ignored-attributes -I /home/andy/zig-9/build/lib/zig/libc/glibc/include -I /home/andy/zig-9/build/lib/zig/libc/glibc/sysdeps/unix/sysv/linux/x86_64 -I /home/andy/zig-9/build/lib/zig/libc/glibc/sysdeps/unix/sysv/linux/x86 -I /home/andy/zig-9/build/lib/zig/libc/glibc/sysdeps/x86_64/nptl -I /home/andy/zig-9/build/lib/zig/libc/glibc/sysdeps/x86/nptl -I /home/andy/zig-9/build/lib/zig/libc/glibc/sysdeps/unix/sysv/linux/include -I /home/andy/zig-9/build/lib/zig/libc/glibc/sysdeps/unix/sysv/linux -I /home/andy/zig-9/build/lib/zig/libc/glibc/sysdeps/nptl -I /home/andy/zig-9/build/lib/zig/libc/glibc/sysdeps/pthread -I /home/andy/zig-9/build/lib/zig/libc/glibc/sysdeps/unix/sysv -I /home/andy/zig-9/build/lib/zig/libc/glibc/sysdeps/unix/x86_64 -I /home/andy/zig-9/build/lib/zig/libc/glibc/sysdeps/unix/x86 -I /home/andy/zig-9/build/lib/zig/libc/glibc/sysdeps/unix -I /home/andy/zig-9/build/lib/zig/libc/glibc/sysdeps/x86_64 -I /home/andy/zig-9/build/lib/zig/libc/glibc/sysdeps/x86 -I /home/andy/zig-9/build/lib/zig/libc/glibc/sysdeps/generic -I /home/andy/zig-9/build/lib/zig/libc/glibc -I /home/andy/zig-9/build/lib/zig/libc/include/x86_64-linux-gnu -I /home/andy/zig-9/build/lib/zig/libc/include/generic-glibc -I /home/andy/zig-9/build/lib/zig/libc/include/x86_64-linux-any -I /home/andy/zig-9/build/lib/zig/libc/include/any-linux-any -D_LIBC_REENTRANT -include /home/andy/zig-9/build/lib/zig/libc/glibc/include/libc-modules.h -DMODULE_NAME=libc -include /home/andy/zig-9/build/lib/zig/libc/glibc/include/libc-symbols.h -DPIC -DLIBC_NONSHARED=1 -DTOP_NAMESPACE=glibc
clang-9: /home/andy/llvm-project/clang/lib/AST/Decl.cpp:3336: bool clang::FunctionDecl::isInlineDefinitionExternallyVisible() const: Assertion `(doesThisDeclarationHaveABody() || willHaveBody()) && "Must be a function definition"' failed.
Stack dump:
0.      Program arguments: /home/andy/local-llvm9-debug/bin/clang-9 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -disable-free -main-file-name stat.c -mrelocation-model pic -pic-level 2 -mthread-model posix -fmerge-all-constants -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu broadwell -target-feature +sse2 -target-feature +cx16 -target-feature +sahf -target-feature -tbm -target-feature -avx512ifma -target-feature -sha -target-feature -gfni -target-feature -fma4 -target-feature -vpclmulqdq -target-feature +prfchw -target-feature +bmi2 -target-feature -cldemote -target-feature +fsgsbase -target-feature -ptwrite -target-feature -xsavec -target-feature +popcnt -target-feature -mpx -target-feature +aes -target-feature -avx512bitalg -target-feature -movdiri -target-feature -xsaves -target-feature -avx512er -target-feature -avx512vnni -target-feature -avx512vpopcntdq -target-feature -pconfig -target-feature -clwb -target-feature -avx512f -target-feature -clzero -target-feature -pku -target-feature +mmx -target-feature -lwp -target-feature -rdpid -target-feature -xop -target-feature +rdseed -target-feature -waitpkg -target-feature -movdir64b -target-feature -sse4a -target-feature -avx512bw -target-feature -clflushopt -target-feature +xsave -target-feature -avx512vbmi2 -target-feature +64bit -target-feature -avx512vl -target-feature +invpcid -target-feature -avx512cd -target-feature +avx -target-feature -vaes -target-feature +cx8 -target-feature +fma -target-feature +rtm -target-feature +bmi -target-feature -enqcmd -target-feature +rdrnd -target-feature -mwaitx -target-feature +sse4.1 -target-feature +sse4.2 -target-feature +avx2 -target-feature +fxsr -target-feature -wbnoinvd -target-feature +sse -target-feature +lzcnt -target-feature +pclmul -target-feature -prefetchwt1 -target-feature +f16c -target-feature +ssse3 -target-feature -sgx -target-feature -shstk -target-feature +cmov -target-feature -avx512vbmi -target-feature -avx512bf16 -target-feature +movbe -target-feature +xsaveopt -target-feature -avx512dq -target-feature +adx -target-feature -avx512pf -target-feature +sse3 -dwarf-column-info -debug-info-kind=limited -dwarf-version=4 -debugger-tuning=gdb -momit-leaf-frame-pointer -coverage-notes-file /home/andy/.local/share/zig/stage1/tmp/CuMHrPPk3OJv-stat.gcno -nostdsysteminc -nobuiltininc -resource-dir /home/andy/local-llvm9-debug/lib/clang/9.0.0 -dependency-file /home/andy/.local/share/zig/stage1/tmp/CuMHrPPk3OJv-stat.o.d -MT /home/andy/.local/share/zig/stage1/tmp/CuMHrPPk3OJv-stat.o -sys-header-deps -MV -isystem /home/andy/zig-9/build/lib/zig/include -include /home/andy/zig-9/build/lib/zig/libc/glibc/include/libc-modules.h -include /home/andy/zig-9/build/lib/zig/libc/glibc/include/libc-symbols.h -D _DEBUG -I /home/andy/zig-9/build/lib/zig/libc/glibc/include -I /home/andy/zig-9/build/lib/zig/libc/glibc/sysdeps/unix/sysv/linux/x86_64 -I /home/andy/zig-9/build/lib/zig/libc/glibc/sysdeps/unix/sysv/linux/x86 -I /home/andy/zig-9/build/lib/zig/libc/glibc/sysdeps/x86_64/nptl -I /home/andy/zig-9/build/lib/zig/libc/glibc/sysdeps/x86/nptl -I /home/andy/zig-9/build/lib/zig/libc/glibc/sysdeps/unix/sysv/linux/include -I /home/andy/zig-9/build/lib/zig/libc/glibc/sysdeps/unix/sysv/linux -I /home/andy/zig-9/build/lib/zig/libc/glibc/sysdeps/nptl -I /home/andy/zig-9/build/lib/zig/libc/glibc/sysdeps/pthread -I /home/andy/zig-9/build/lib/zig/libc/glibc/sysdeps/unix/sysv -I /home/andy/zig-9/build/lib/zig/libc/glibc/sysdeps/unix/x86_64 -I /home/andy/zig-9/build/lib/zig/libc/glibc/sysdeps/unix/x86 -I /home/andy/zig-9/build/lib/zig/libc/glibc/sysdeps/unix -I /home/andy/zig-9/build/lib/zig/libc/glibc/sysdeps/x86_64 -I /home/andy/zig-9/build/lib/zig/libc/glibc/sysdeps/x86 -I /home/andy/zig-9/build/lib/zig/libc/glibc/sysdeps/generic -I /home/andy/zig-9/build/lib/zig/libc/glibc -I /home/andy/zig-9/build/lib/zig/libc/include/x86_64-linux-gnu -I /home/andy/zig-9/build/lib/zig/libc/include/generic-glibc -I /home/andy/zig-9/build/lib/zig/libc/include/x86_64-linux-any -I /home/andy/zig-9/build/lib/zig/libc/include/any-linux-any -D _LIBC_REENTRANT -D MODULE_NAME=libc -D PIC -D LIBC_NONSHARED=1 -D TOP_NAMESPACE=glibc -O2 -Wno-ignored-attributes -std=gnu11 -fdebug-compilation-dir /home/andy/zig-9/build -ferror-limit 19 -fmessage-length 0 -ftls-model=initial-exec -fgnu89-inline -fobjc-runtime=gcc -fdiagnostics-show-option -fcolor-diagnostics -fno-spell-checking -vectorize-loops -vectorize-slp -faddrsig -o /home/andy/.local/share/zig/stage1/tmp/CuMHrPPk3OJv-stat.o -x c /home/andy/zig-9/build/lib/zig/libc/glibc/io/stat.c 
1.      <eof> parser at end of file
2.      /home/andy/zig-9/build/lib/zig/libc/glibc/io/stat.c:54:1 <Spelling=/home/andy/zig-9/build/lib/zig/libc/glibc/io/stat.c:54:28>: LLVM IR generation of declaration 'stat'
 #0 0x0000000004328c40 llvm::sys::PrintStackTrace(llvm::raw_ostream&) /home/andy/llvm-project/llvm/lib/Support/Unix/Signals.inc:533:0
 #1 0x0000000004328cd3 PrintStackTraceSignalHandler(void*) /home/andy/llvm-project/llvm/lib/Support/Unix/Signals.inc:594:0
 #2 0x0000000004326e7f llvm::sys::RunSignalHandlers() /home/andy/llvm-project/llvm/lib/Support/Signals.cpp:68:0
 #3 0x00000000043286ba SignalHandler(int) /home/andy/llvm-project/llvm/lib/Support/Unix/Signals.inc:385:0
 #4 0x00007fa62654af10 __restore_rt (/nix/store/7gx4kiv5m0i7d7qkixq2cwzbr10lvxwc-glibc-2.27/lib/libpthread.so.0+0x11f10)
 #5 0x00007fa62525fbe0 raise (/nix/store/7gx4kiv5m0i7d7qkixq2cwzbr10lvxwc-glibc-2.27/lib/libc.so.6+0x34be0)
 #6 0x00007fa625260dc1 abort (/nix/store/7gx4kiv5m0i7d7qkixq2cwzbr10lvxwc-glibc-2.27/lib/libc.so.6+0x35dc1)
 #7 0x00007fa6252586e7 __assert_fail_base (/nix/store/7gx4kiv5m0i7d7qkixq2cwzbr10lvxwc-glibc-2.27/lib/libc.so.6+0x2d6e7)
 #8 0x00007fa625258792 (/nix/store/7gx4kiv5m0i7d7qkixq2cwzbr10lvxwc-glibc-2.27/lib/libc.so.6+0x2d792)
 #9 0x00000000063f107a clang::FunctionDecl::isInlineDefinitionExternallyVisible() const (/home/andy/local-llvm9-debug/bin/clang-9+0x63f107a)
clang-9: error: unable to execute command: Aborted
clang-9: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 9.0.0 (https://github.com/llvm/llvm-project 127240acf1001b72c0c52863ffe3dc39b7c5fd6d)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/andy/local-llvm9-debug/bin
clang-9: note: diagnostic msg: PLEASE submit a bug report to  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: /run/user/1001/stat-ce2dd5.c
clang-9: note: diagnostic msg: /run/user/1001/stat-ce2dd5.sh
clang-9: note: diagnostic msg:

********************
Comment 1 Andrew Kelley 2019-09-10 12:23:05 PDT
Created attachment 22483 [details]
/run/user/1001/stat-ce2dd5.sh
Comment 2 Hans Wennborg 2019-09-11 02:03:51 PDT
Bisection points to this one:
----
commit 7b927f75f22688819d1e82e572b7524ccd31e4ab
Author: Hans Wennborg <hans@hanshq.net>
Date:   Mon Sep 9 08:44:55 2019 +0000

    Merging r369705 and r369713 for PR43243:

    ------------------------------------------------------------------------                                                                    
    r369705 | nickdesaulniers | 2019-08-22 22:47:12 +0200 (Thu, 22 Aug 2019) | 23 lines                                                         

    [Clang][CodeGen] set alias linkage on QualType

    Summary:
    It seems that CodeGen was always using ExternalLinkage when emitting a                                                                      
    GlobalDecl with __attribute__((alias)). This leads to symbol
    redefinitions (ODR) that cause failures at link time for static aliases.                                                                    
    This is readily attempting to link an ARM (32b) allyesconfig Linux
    kernel built with Clang.

    Reported-by: nathanchance
    Suggested-by: ihalip
    Link: https://bugs.llvm.org/show_bug.cgi?id=42377
    Link: https://github.com/ClangBuiltLinux/linux/issues/631

    Reviewers: rsmith, aaron.ballman, erichkeane

    Reviewed By: aaron.ballman

    Subscribers: javed.absar, kristof.beyls, cfe-commits, srhines, ihalip, nathanchance

    Tags: #clang

    Differential Revision: https://reviews.llvm.org/D66492
    ------------------------------------------------------------------------
Comment 3 Hans Wennborg 2019-09-11 02:11:03 PDT
The test case also fails on the current trunk (r371596 / b250d5ff5e7c5ebd9f3f5da6776ffc91cd01c614)
Comment 4 Nick Desaulniers 2019-09-11 08:30:47 PDT
Thanks for the report, I'll take a look.
Comment 5 Nick Desaulniers 2019-09-11 09:32:28 PDT
Looks related to `-fgnu89-inline`, I can repro with the attached .c file and just `-fgnu89-inline -O2`.  I'm running the test case through creduce now, which should produce a nice unit test for us to add.
Comment 6 Nick Desaulniers 2019-09-11 09:59:15 PDT
$ clang -fgnu89-inline stat.c
<crash>
$ cat stat.c
__inline int a(void) __attribute__((alias("")));
Comment 7 Nick Desaulniers 2019-09-11 11:04:50 PDT
Slightly better test case:

// $ clang stat.c
extern void b(void) {}
inline void a(void) __attribute__((alias("b"), gnu_inline));

(also, good to see that the Zig developers are testing compiling glibc w/ Clang)
Comment 8 Nick Desaulniers 2019-09-11 11:14:55 PDT
So I don't think there's a bug in clang/codegen, just an assertion that needs to be reworked.  The failing assertion is checking that:

  assert((doesThisDeclarationHaveABody() || willHaveBody()) &&
         "Must be a function definition");

but alias-attributed functions don't need to have a body; they simply are declared and a symbol is emitted for them.

If I remove the assertions, clang proceeds through to codegen, and the emitted object file matches GCC in behavior in regards to what symbols are emitted and what their linkage is.

This implies that the assertion simply needs to be reworked to check for the presence of an `alias` attribute on the function declaration, and a test case added.

I should be able to fix this today.
Comment 9 Nick Desaulniers 2019-09-11 11:46:48 PDT
patch: https://reviews.llvm.org/D67455
Comment 10 Andrew Kelley 2019-09-11 11:56:14 PDT
The patch looks good except I think there was a typo (See my comment on the patch).

> (also, good to see that the Zig developers are testing compiling glibc w/ Clang)

Yep :) Just FYI, the coverage is not for all of glibc; only for the start files (e.g. crt1.o, crti.o crtn.o), for the purpose of targeting a dynamic glibc when cross compiling.
Comment 11 Nick Desaulniers 2019-09-12 13:00:28 PDT
Fixed in r371766. Hans, can you please cherry-pick to release_90?
Comment 12 Hans Wennborg 2019-09-13 01:11:06 PDT
(In reply to Nick Desaulniers from comment #11)
> Fixed in r371766. Hans, can you please cherry-pick to release_90?

Merged to release_90 in r371821.