<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/149752>149752</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang] crashes when using __attribute__ ((malloc (__VA_ARGS__))) with assertion enabled
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
k-arrows
</td>
</tr>
</table>
<pre>
Reproducer:
https://godbolt.org/z/Eev6E8x7b
```c
#define A(...) __attribute__ ((malloc (__VA_ARGS__)))
void f(type, void*);
A(f) void* g(void);
```
Backtrace:
```console
clang: /root/llvm-project/llvm/include/llvm/Support/Casting.h:578: decltype(auto) llvm::cast(From*) [with To = clang::FunctionProtoType; From = const clang::FunctionType]: Assertion `isa<To>(Val) && "cast<Ty>() argument of incompatible type!"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0. Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/clang -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics <source>
1. <source>:3:19: current parser token ';'
#0 0x0000000003fc1498 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3fc1498)
#1 0x0000000003fbe8c4 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3fbe8c4)
#2 0x0000000003f03098 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#3 0x000076259f442520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x000076259f4969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#5 0x000076259f442476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#6 0x000076259f4287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#7 0x000076259f42871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
#8 0x000076259f439e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#9 0x0000000006a56913 clang::getFunctionOrMethodParamType(clang::Decl const*, unsigned int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x6a56913)
#10 0x0000000006a7c3f0 handleRestrictAttr(clang::Sema&, clang::Decl*, clang::ParsedAttr const&) SemaDeclAttr.cpp:0:0
#11 0x0000000006a92b25 ProcessDeclAttribute(clang::Sema&, clang::Scope*, clang::Decl*, clang::ParsedAttr const&, clang::Sema::ProcessDeclAttributeOptions const&) (.isra.0) SemaDeclAttr.cpp:0:0
#12 0x0000000006a954eb clang::Sema::ProcessDeclAttributes(clang::Scope*, clang::Decl*, clang::Declarator const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x6a954eb)
#13 0x0000000006a46bdc clang::Sema::ActOnFunctionDeclarator(clang::Scope*, clang::Declarator&, clang::DeclContext*, clang::TypeSourceInfo*, clang::LookupResult&, llvm::MutableArrayRef<clang::TemplateParameterList*>, bool&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x6a46bdc)
#14 0x0000000006a4d3f1 clang::Sema::HandleDeclarator(clang::Scope*, clang::Declarator&, llvm::MutableArrayRef<clang::TemplateParameterList*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x6a4d3f1)
#15 0x0000000006a4df40 clang::Sema::ActOnDeclarator(clang::Scope*, clang::Declarator&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x6a4df40)
#16 0x000000000669e4e3 clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x669e4e3)
#17 0x00000000066ad779 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::Parser::ParsedTemplateInfo&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x66ad779)
#18 0x000000000666b14e clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x666b14e)
#19 0x000000000666b8e9 clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x666b8e9)
#20 0x00000000066735ea clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x66735ea)
#21 0x0000000006674585 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x6674585)
#22 0x00000000066662ea clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x66662ea)
#23 0x0000000004970188 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4970188)
#24 0x0000000004c64025 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4c64025)
#25 0x0000000004be0e6e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4be0e6e)
#26 0x0000000004d57b01 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4d57b01)
#27 0x0000000000d9ec4f cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xd9ec4f)
#28 0x0000000000d9582a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#29 0x00000000049d7709 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#30 0x0000000003f03534 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3f03534)
#31 0x00000000049d7d1f clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0
#32 0x0000000004999d6d clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4999d6d)
#33 0x000000000499adfe clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x499adfe)
#34 0x00000000049a3945 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x49a3945)
#35 0x0000000000d9b0ff clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xd9b0ff)
#36 0x0000000000c4f5b4 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xc4f5b4)
#37 0x000076259f429d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#38 0x000076259f429e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#39 0x0000000000d952d5 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xd952d5)
clang: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzkWltzozgW_jXKi8ouEBfDQx5oJ57tqZ7qVJyaV5cQB1sbLLGSSDv767ck4WCIk05mPP2yU5lqrMvRdz6dG0JUa74VANco-YKSmyvamZ1U148zqpT8oa9KWT1f30OrZNUxUCgqUFDsjGm1fSQrRFZbWZWyMXOptois_ovI6hae0tvssChRUKA08H_M_iBRBTUXgAtEsvl8jkiONxtqjOJlZ2CzwYhkiGR72jSS2R-bzZ_Fprj_bb3ZIJL3f0HxJHmFa0Qy89wCIktsGxApbG_0BQWFXaC24vsOvEUk88_9iBdk9jkovlD2aBRl4HUccEuhZQMoKFhDxRZFBUZkpaQ0iKya5mk_a5X8N7DjT0RWXLCmq2BoWHdtK5UdsaTacLGd71BUJIvMSquANV6LjHZGWsxuWlSgqGBUG0SylZJ7rx1GyZcf3Ozwg8QousFHUCgqVp1ghktxp6SRD1Zi9AXbmX6gFNqcG-5GJjcWSqE1KNuGURpwTVG0fJAoukUk-5M2bnWSIpJiRIhDFi0fnn2_7aRq2-1BGCxrzAWT-5YaXjaAvXohIgSRBa4pb6Cao6C4-3ZbrG-x7so9N5jisttiBZYqbCSemBk3u66cM0vEkdcJ_VzrDjQiK0xFhftdwGYHmCmqd7h82WKyxK2yVs1Aa6iwlp3yzXYm1VoyTg1UWHUCa6Z4ayzetaHsEVfdvvVGEsxRkN8puVV0_6K97k1EthaTZYE3oGZwaBupQNk2uwkzeiRbz4zqxCMiq5KLYzeebasfVNWzGM-2eCatRNq2Vm5n2s7MNZ7trf54Njtk6Yzq_Uw_C0MPKLrhwkCDZ7WQsydQpdRg-_FsjWezLWMzI2XDdpQLFN28i9QO1oK2eicNntVMNlLNKk63QmrDmfZrOHZHzSha9pRGtygoQsvTqC0qIhQVYW65Yp1S1mpa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