<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/57766>57766</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Clang (all versions) crashes on use '-Wconsumed' and loops
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
IgorNikitin
</td>
</tr>
</table>
<pre>
[files.zip](https://github.com/llvm/llvm-project/files/9578150/files.zip)
https://godbolt.org/z/hzP8We8qz
```
struct [[clang::consumable(consumed)]] Ptr
{
int id_ {};
[[clang::set_typestate(unconsumed)]]
void operator=( int in_id ) { id_ = in_id; }
[[clang::test_typestate(unconsumed)]]
operator bool() const { return id_; }
};
static void foo( Ptr in_ptr ) {
if( !in_ptr )
in_ptr = 1;
for( int n: "abc" )
in_ptr = n;
}
```
```
Stack dump:
0. Program arguments: /usr/lib/llvm-16/bin/clang -cc1 -triple x86_64-pc-linux-gnu -emit-obj -mrelax-all --mrelax-relocations -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name test.cpp -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -mllvm -treat-scalable-fixed-error-as-warning -debugger-tuning=gdb -fcoverage-compilation-dir=/home/lester -resource-dir /usr/lib/llvm-16/lib/clang/16.0.0 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/x86_64-linux-gnu/c++/12 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/backward -internal-isystem /usr/lib/llvm-16/lib/clang/16.0.0/include -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wconsumed -fdeprecated-macro -fdebug-compilation-dir=/home/lester -ferror-limit 19 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -fcolor-diagnostics -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/test-a3efa7.o -x c++ ./test.cpp
1. <eof> parser at end of file
2. ./test.cpp:12:31: parsing function body 'foo'
#0 0x00007f654aa82591 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/usr/lib/llvm-16/bin/../lib/libLLVM-16.so.1+0xf13591)
#1 0x00007f654aa80760 llvm::sys::RunSignalHandlers() (/usr/lib/llvm-16/bin/../lib/libLLVM-16.so.1+0xf11760)
#2 0x00007f654aa82a7d (/usr/lib/llvm-16/bin/../lib/libLLVM-16.so.1+0xf13a7d)
#3 0x00007f6549633520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x00007f6552739bbe clang::consumed::ConsumedBlockInfo::getInfo(clang::CFGBlock const*) (/usr/lib/llvm-16/bin/../lib/libclang-cpp.so.16+0x1dcabbe)
#5 0x00007f655273ba56 clang::consumed::ConsumedAnalyzer::run(clang::AnalysisDeclContext&) (/usr/lib/llvm-16/bin/../lib/libclang-cpp.so.16+0x1dcca56)
#6 0x00007f6551ae9a48 clang::sema::AnalysisBasedWarnings::IssueWarnings(clang::sema::AnalysisBasedWarnings::Policy, clang::sema::FunctionScopeInfo*, clang::Decl const*, clang::QualType) (/usr/lib/llvm-16/bin/../lib/libclang-cpp.so.16+0x117aa48)
#7 0x00007f6551b5cef1 clang::Sema::PopFunctionScopeInfo(clang::sema::AnalysisBasedWarnings::Policy const*, clang::Decl const*, clang::QualType) (/usr/lib/llvm-16/bin/../lib/libclang-cpp.so.16+0x11edef1)
#8 0x00007f6551ccf0aa clang::Sema::ActOnFinishFunctionBody(clang::Decl*, clang::Stmt*, bool) (/usr/lib/llvm-16/bin/../lib/libclang-cpp.so.16+0x13600aa)
#9 0x00007f6551500c95 clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/usr/lib/llvm-16/bin/../lib/libclang-cpp.so.16+0xb91c95)
#10 0x00007f655151a905 clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) (/usr/lib/llvm-16/bin/../lib/libclang-cpp.so.16+0xbab905)
#11 0x00007f6551472273 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/usr/lib/llvm-16/bin/../lib/libclang-cpp.so.16+0xb03273)
#12 0x00007f65515199ca clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/usr/lib/llvm-16/bin/../lib/libclang-cpp.so.16+0xbaa9ca)
#13 0x00007f6551519437 clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/usr/lib/llvm-16/bin/../lib/libclang-cpp.so.16+0xbaa437)
#14 0x00007f6551518759 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/usr/lib/llvm-16/bin/../lib/libclang-cpp.so.16+0xba9759)
#15 0x00007f65515169f4 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/usr/lib/llvm-16/bin/../lib/libclang-cpp.so.16+0xba79f4)
#16 0x00007f655145917e clang::ParseAST(clang::Sema&, bool, bool) (/usr/lib/llvm-16/bin/../lib/libclang-cpp.so.16+0xaea17e)
#17 0x00007f65525d49fa clang::CodeGenAction::ExecuteAction() (/usr/lib/llvm-16/bin/../lib/libclang-cpp.so.16+0x1c659fa)
#18 0x00007f6552f13026 clang::FrontendAction::Execute() (/usr/lib/llvm-16/bin/../lib/libclang-cpp.so.16+0x25a4026)
#19 0x00007f6552e90da6 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/usr/lib/llvm-16/bin/../lib/libclang-cpp.so.16+0x2521da6)
#20 0x00007f6552f8eb40 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/usr/lib/llvm-16/bin/../lib/libclang-cpp.so.16+0x261fb40)
#21 0x000055cb7968a346 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/usr/lib/llvm-16/bin/clang+0x13346)
#22 0x000055cb796884a8 (/usr/lib/llvm-16/bin/clang+0x114a8)
#23 0x000055cb796882ff clang_main(int, char**) (/usr/lib/llvm-16/bin/clang+0x112ff)
#24 0x00007f654961ad90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#25 0x00007f654961ae40 call_init ./csu/../csu/libc-start.c:128:20
#26 0x00007f654961ae40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#27 0x000055cb796853b1 _start (/usr/lib/llvm-16/bin/clang+0xe3b1)
clang: error: unable to execute command: Segmentation fault
clang: error: clang frontend command failed due to signal (use -v to see invocation)
Debian clang version 16.0.0-++20220909072630+a3a8bd00c8f1-1~exp1~20220909072734.741
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzFWl1zm7oW_TXOC4OHDwPmIQ9O3PRkpr3NbTKnjx4hhM0pRhwBqdNff9aWcGw5jpt0fM91XYyEtLXW0tbWB8lk_nQ5iq6KshLt-GfZjKL5KJiuuq5pR-FsFNzguyy7VZ-NuVwjUVWP2x-3UfIvwTskdX38plEy9SNvm6MtBunIm4-8mbkemJZ5JqtuLNUSqZ_4v_p5N_0mpn__3K80ir3hq5Ntp3reOcCNL69YvSSD4YzLuu3XLKsEOJiEyKl9kIrmzl2nBnPJlblx8CnrzinzhUOZyXwU7j069dmVegGjFd2ie2pE27GOkPT1Cy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