<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/60987>60987</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[Clang] Parse crash since Clang 14 when with scanf code.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
red1bluelost
</td>
</tr>
</table>
<pre>
Godbolt Link to example code: https://clangbug.godbolt.org/z/Kv5W9f4fn
Minimal recreation:
```c++
#include <stdio.h>
void f(void) { scanf("%3s\n"); }
```
Stack Trace:
```
<source>:2:25: warning: more '%' conversions than data arguments [-Wformat-insufficient-args]
void f(void) { scanf("%3s\n"); }
~~^
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-15.0.0/bin/clang++ -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -S --gcc-toolchain=/opt/compiler-explorer/gcc-12.2.0 -fcolor-diagnostics -fno-crash-diagnostics <source>
1. <source>:2:29: current parser token ')'
2. <source>:2:14: parsing function body 'f'
3. <source>:2:14: in compound statement ('{}')
#0 0x00005631565b8f84 PrintStackTraceSignalHandler(void*) Signals.cpp:0:0
#1 0x00005631565b6dac llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-15.0.0/bin/clang+++0x38c8dac)
#2 0x00005631564f4be8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#3 0x00007fc3662ce420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
#4 0x000056315993fc4b clang::Expr::tryEvaluateObjectSize(unsigned long&, clang::ASTContext&, unsigned int) const (/opt/compiler-explorer/clang-15.0.0/bin/clang+++0x6c51c4b)
#5 0x0000563158b53f9d llvm::Optional<llvm::APSInt> llvm::function_ref<llvm::Optional<llvm::APSInt> (unsigned int)>::callback_fn<clang::Sema::checkFortifiedBuiltinMemoryFunction(clang::FunctionDecl*, clang::CallExpr*)::'lambda5'(unsigned int)>(long, unsigned int) SemaChecking.cpp:0:0
#6 0x0000563158b4fb8d (anonymous namespace)::ScanfDiagnosticFormatHandler::HandleScanfSpecifier(clang::analyze_scanf::ScanfSpecifier const&, char const*, unsigned int) SemaChecking.cpp:0:0
#7 0x0000563159a47164 clang::analyze_format_string::ParseScanfString(clang::analyze_format_string::FormatStringHandler&, char const*, char const*, clang::LangOptions const&, clang::TargetInfo const&) (/opt/compiler-explorer/clang-15.0.0/bin/clang+++0x6d59164)
#8 0x0000563158b65c82 clang::Sema::checkFortifiedBuiltinMemoryFunction(clang::FunctionDecl*, clang::CallExpr*) (/opt/compiler-explorer/clang-15.0.0/bin/clang+++0x5e77c82)
#9 0x0000563158ebb16a clang::Sema::BuildResolvedCallExpr(clang::Expr*, clang::NamedDecl*, clang::SourceLocation, llvm::ArrayRef<clang::Expr*>, clang::SourceLocation, clang::Expr*, bool, clang::CallExpr::ADLCallKind) (/opt/compiler-explorer/clang-15.0.0/bin/clang+++0x61cd16a)
#10 0x00005631591d7ed3 FinishOverloadedCallExpr(clang::Sema&, clang::Scope*, clang::Expr*, clang::UnresolvedLookupExpr*, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, clang::Expr*, clang::OverloadCandidateSet*, clang::OverloadCandidate**, clang::OverloadingResult, bool) SemaOverload.cpp:0:0
#11 0x00005631591d8ced clang::Sema::BuildOverloadedCallExpr(clang::Scope*, clang::Expr*, clang::UnresolvedLookupExpr*, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, clang::Expr*, bool, bool) (/opt/compiler-explorer/clang-15.0.0/bin/clang+++0x64eaced)
#12 0x0000563158eb6cc3 clang::Sema::BuildCallExpr(clang::Scope*, clang::Expr*, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, clang::Expr*, bool, bool) (/opt/compiler-explorer/clang-15.0.0/bin/clang+++0x61c8cc3)
#13 0x0000563158ebca8b clang::Sema::ActOnCallExpr(clang::Scope*, clang::Expr*, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, clang::Expr*) (/opt/compiler-explorer/clang-15.0.0/bin/clang+++0x61cea8b)
#14 0x0000563158a11ea8 clang::Parser::ParsePostfixExpressionSuffix(clang::ActionResult<clang::Expr*, true>) (/opt/compiler-explorer/clang-15.0.0/bin/clang+++0x5d23ea8)
#15 0x0000563158a09b97 clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, bool&, clang::Parser::TypeCastState, bool, bool*) (/opt/compiler-explorer/clang-15.0.0/bin/clang+++0x5d1bb97)
#16 0x0000563158a0c6be clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, clang::Parser::TypeCastState, bool, bool*) (/opt/compiler-explorer/clang-15.0.0/bin/clang+++0x5d1e6be)
#17 0x0000563158a0c8ad clang::Parser::ParseAssignmentExpression(clang::Parser::TypeCastState) (/opt/compiler-explorer/clang-15.0.0/bin/clang+++0x5d1e8ad)
#18 0x0000563158a1119d clang::Parser::ParseExpression(clang::Parser::TypeCastState) (/opt/compiler-explorer/clang-15.0.0/bin/clang+++0x5d2319d)
#19 0x0000563158a90c2e clang::Parser::ParseExprStatement(clang::Parser::ParsedStmtContext) (/opt/compiler-explorer/clang-15.0.0/bin/clang+++0x5da2c2e)
#20 0x0000563158a85f45 clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::ParsedAttributes&, clang::ParsedAttributes&) (/opt/compiler-explorer/clang-15.0.0/bin/clang+++0x5d97f45)
#21 0x0000563158a86923 clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*) (/opt/compiler-explorer/clang-15.0.0/bin/clang+++0x5d98923)
#22 0x0000563158a87846 clang::Parser::ParseCompoundStatementBody(bool) (/opt/compiler-explorer/clang-15.0.0/bin/clang+++0x5d99846)
#23 0x0000563158a88c12 clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/opt/compiler-explorer/clang-15.0.0/bin/clang+++0x5d9ac12)
#24 0x00005631589ae4b4 clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) (/opt/compiler-explorer/clang-15.0.0/bin/clang+++0x5cc04b4)
#25 0x00005631589de14f clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-15.0.0/bin/clang+++0x5cf014f)
#26 0x00005631589a8aa5 clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-15.0.0/bin/clang+++0x5cbaaa5)
#27 0x00005631589a9a20 clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (.part.0) Parser.cpp:0:0
#28 0x00005631589b14f6 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-15.0.0/bin/clang+++0x5cc34f6)
#29 0x00005631589b290a clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-15.0.0/bin/clang+++0x5cc490a)
#30 0x00005631589a20ba clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-15.0.0/bin/clang+++0x5cb40ba)
#31 0x00005631577d5cc5 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-15.0.0/bin/clang+++0x4ae7cc5)
#32 0x00005631570de1d1 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-15.0.0/bin/clang+++0x43f01d1)
#33 0x0000563157065ed3 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-15.0.0/bin/clang+++0x4377ed3)
#34 0x00005631571bcadb clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-15.0.0/bin/clang+++0x44ceadb)
#35 0x0000563153f13b64 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-15.0.0/bin/clang+++0x1225b64)
#36 0x0000563153f0d10b ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#37 0x0000563156ecf969 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#38 0x00005631564f4ce7 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-15.0.0/bin/clang+++0x3806ce7)
#39 0x0000563156ecff5c clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0
#40 0x0000563156e99fce clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-15.0.0/bin/clang+++0x41abfce)
#41 0x0000563156e9a9ed clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-15.0.0/bin/clang+++0x41ac9ed)
#42 0x0000563156ea583c clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-15.0.0/bin/clang+++0x41b783c)
#43 0x0000563153f118e9 clang_main(int, char**) (/opt/compiler-explorer/clang-15.0.0/bin/clang+++0x12238e9)
#44 0x00007fc365d7c083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#45 0x0000563153f0cd1e _start (/opt/compiler-explorer/clang-15.0.0/bin/clang+++0x121ed1e)
clang-15: error: clang frontend command failed with exit code 139 (use -v to see invocation)
Compiler returned: 139
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzkW0tz4za2_jX0BiUVCb4XXsiylduJ-9rV8r1ZukDgUMY0BXAA0C1nkd8-BVCSBYpSdxJ1JpOp8oMCAfB833ng8AAiWvOVALgO0psgvb0inXmR6loBi6qmg0Zqc1VJ9nb9g2SVbAy65-IzMhLBhqzbBhCVDIJ4hl6MaXUQzwK8CPCCNkSsqm41XfXDplKtArz4JcCLn17Tn8s6qUUQ3gbhrP_7kQu-Jg1SQBUQw6WwU_UdsrD_oQG-sT99K465oE3HAAXxXBvG5fQliO_6u6-SM1QHuLAXAS5RkN8gTYmwbQHGAU5jHaRz4a7LIL5BQX47eN6hfEtD6Gf0pAiFY8G2H-O5lp2yHe6CeIbtb2qZ-UKU4GJlL9dSAQpwHuA0wDmiUryC0lwKjcwLEYgRQxBRq24NwmgUpDeTn2up1sRMuNBdXXPKQZgJUSsdpLd_HCz69dcg3ZL2eH83W94h3VVrbhBBVbdCClqpjNW3r98VNy9dNaVyHeBF07zu_k1aJf8B1AR4wbXuQAd4gYhgaKcs8wKIKqJfUEXoZ-MIxXPUKmiVpKA1MLSlEc_dSKK1pJwYYEh1AmmqeGumh2ph3brdayWcBmH5qORKkfU7lZb8AC9kayWjct3yBtQENm0jFaidwU6idBpOwwAvKi52jb3VocmKfSGqniRoskITaWcjbWvn7EzbmalGk7VlAE0mmyKbEL2e6DdhyCaIb7kw0KDJEk0mK0onRsqGvhAugvj2rFC2c4SneBqiSU1lI9WEcbISUhtONZrUQk4cmV6zZ4iOk8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