-
Notifications
You must be signed in to change notification settings - Fork 13.4k
crashed in clang::Preprocessor::EnterMainSourceFile() #139375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@llvm/issue-subscribers-clang-frontend Author: Jongmyeong Choi (jongmyeong-choi)
Stack trace
```
#0 0x00000001050c55e4 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/Users/cheese/git/llvm-project/build/bin/clang-21+0x1028515e4)
#1 0x00000001050c36ac llvm::sys::RunSignalHandlers() (/Users/cheese/git/llvm-project/build/bin/clang-21+0x10284f6ac)
#2 0x00000001050c4bb8 llvm::sys::CleanupOnSignal(unsigned long) (/Users/cheese/git/llvm-project/build/bin/clang-21+0x102850bb8)
#3 0x000000010501dc34 CrashRecoverySignalHandler(int) (/Users/cheese/git/llvm-project/build/bin/clang-21+0x1027a9c34)
#4 0x000000019ab57624 (/usr/lib/system/libsystem_platform.dylib+0x1804ab624)
#5 0x000000019ab1d88c (/usr/lib/system/libsystem_pthread.dylib+0x18047188c)
#6 0x000000019aa26c60 (/usr/lib/system/libsystem_c.dylib+0x18037ac60)
#7 0x000000019aa25eec (/usr/lib/system/libsystem_c.dylib+0x180379eec)
#8 0x0000000107d268c0 clang::Preprocessor::EnterMainSourceFile() (.cold.1) (/Users/cheese/git/llvm-project/build/bin/clang-21+0x1054b28c0)
#9 0x00000001077ef608 clang::Preprocessor::SetCodeCompletionPoint(clang::FileEntryRef, unsigned int, unsigned int) (/Users/cheese/git/llvm-project/build/bin/clang-21+0x104f7b608)
#10 0x0000000105b5ab88 EnableCodeCompletion(clang::Preprocessor&, llvm::StringRef, unsigned int, unsigned int) (/Users/cheese/git/llvm-project/build/bin/clang-21+0x1032e6b88)
#11 0x0000000105b5a978 clang::CompilerInstance::createCodeCompletionConsumer() (/Users/cheese/git/llvm-project/build/bin/clang-21+0x1032e6978)
#12 0x0000000105bcaea0 clang::ASTFrontendAction::ExecuteAction() (/Users/cheese/git/llvm-project/build/bin/clang-21+0x103356ea0)
#13 0x0000000105bca8f4 clang::FrontendAction::Execute() (/Users/cheese/git/llvm-project/build/bin/clang-21+0x1033568f4)
#14 0x0000000105b5c78c clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/Users/cheese/git/llvm-project/build/bin/clang-21+0x1032e878c)
#15 0x0000000105c44b78 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/Users/cheese/git/llvm-project/build/bin/clang-21+0x1033d0b78)
#16 0x0000000102879dec cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/Users/cheese/git/llvm-project/build/bin/clang-21+0x100005dec)
#17 0x0000000102877ddc ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) (/Users/cheese/git/llvm-project/build/bin/clang-21+0x100003ddc)
#18 0x00000001059bedf8 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::__1::optional<llvm::StringRef>>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>*, bool*) const::$_0>(long) (/Users/cheese/git/llvm-project/build/bin/clang-21+0x10314adf8)
#19 0x000000010501d8ec llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/Users/cheese/git/llvm-project/build/bin/clang-21+0x1027a98ec)
#20 0x00000001059be86c clang::driver::CC1Command::Execute(llvm::ArrayRef<std::__1::optional<llvm::StringRef>>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>*, bool*) const (/Users/cheese/git/llvm-project/build/bin/clang-21+0x10314a86c)
#21 0x0000000105989dac clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/Users/cheese/git/llvm-project/build/bin/clang-21+0x103115dac)
#22 0x0000000105989fb4 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::__1::pair<int, clang::driver::Command const*>>&, bool) const (/Users/cheese/git/llvm-project/build/bin/clang-21+0x103115fb4)
#23 0x00000001059a4970 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::__1::pair<int, clang::driver::Command const*>>&) (/Users/cheese/git/llvm-project/build/bin/clang-21+0x103130970)
#24 0x0000000102876ea0 clang_main(int, char**, llvm::ToolContext const&) (/Users/cheese/git/llvm-project/build/bin/clang-21+0x100002ea0)
#25 0x00000001028839dc main (/Users/cheese/git/llvm-project/build/bin/clang-21+0x10000f9dc)
#26 0x000000019a77eb4c
```
input.cpp
Command for reproduce |
Fixes llvm#139375 Clang expects command line source locations to be provided using 1-based indexing. Currently, Clang does not reject zero as invalid argument for column or line number, which can cause Clang to crash. This commit extends validation in `ParsedSourceLocation::FromString` to only accept (unsinged) non-zero integers.
I tried reproducing the issue using a debug build of trunk and ran into the following assert: llvm-project/clang/lib/Lex/Preprocessor.cpp Line 398 in 9eeae5a
Simplified reproducer: clang++ -cc1 -code-completion-at=input.cpp:1:0 input.cpp
# or
clang++ -cc1 -code-completion-at=input.cpp:0:1 input.cpp Clang seems to use 1-based indexing for source-location arguments and the crash is caused because Clang does not reject the invalid column-number in The PR below will cause Clang to reject the command-line input instead, same as it does for other bad inputs for column- or line-number. |
Stack trace
input.cpp
Command for reproduce
./bin/clang++ -fsyntax-only -Xclang -code-completion-at=input.cpp:5:0 input.cpp --target=x86_64-apple-macos11 --sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
input-55332e.cpp.txt
input-55332e.sh.txt
The text was updated successfully, but these errors were encountered: