llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.8k stars 11.45k forks source link

clang-scan-deps SegFaults when a .cpp file contains an import statement unbordered with ; #93390

Open jowillianto opened 3 months ago

jowillianto commented 3 months ago

Example

template<std::invocable F, typename ...Args> std::chrono::high_resolution_clock::duration bench_time(F&& f, Args&& ...args) { auto beg = std::chrono::high_resolution_clock::now(); f(std::forward(args)...); auto end = std::chrono::high_resolution_clock::now(); return end - beg; }

int main() { // std::fstream file ("default.log", std::ios_base::out); // for (int i = 0; i < 1000000; i += 1) { // file << std::format("[WARN ][2024-05-24T16:07+0900][int main():26 ] Hello Logger {}", i) << std::endl; // } moderna::logging::AsyncLogger logger; logger.info(""); auto dur = bench_time(std::format, "{}", std::source_location::current()); std::cout<<dur<<" ns\n"; }

- Example CMake

cmake_minimum_required(VERSION 3.28) project(moderna_logging) set (CMAKE_CXX_STANDARD 23) set (CMAKE_CXX_STANDARD_REQUIRED true) set (CMAKE_CXX_SCAN_FOR_MODULES true)

add_library(moderna_logging) add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/lib/thread-plus) file ( GLOB moderna_logging_src "${CMAKE_CURRENT_LIST_DIR}/src/*.ccm" ) target_sources(moderna_logging PUBLIC FILE_SET CXX_MODULES FILES ${moderna_logging_src} ) target_link_libraries(moderna_logging PUBLIC moderna_thread_plus)

if ( EXISTS ${CMAKE_CURRENT_LIST_DIR}/../test-lib/CMakeLists.txt AND EXISTS ${CMAKE_CURRENT_LIST_DIR}/../../cmake/CMakeLists.txt AND PROJECT_IS_TOP_LEVEL ) include (CTest) include (${CMAKE_CURRENT_LIST_DIR}/../../cmake/CMakeLists.txt) add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../test-lib test-lib) add_test_asan_tsan_usan_ubsan( moderna_logging_tests ${CMAKE_CURRENT_LIST_DIR}/tests/tests.cpp "moderna_test_lib;moderna_logging" ) add_executable( bench EXCLUDE_FROM_ALL ${CMAKE_CURRENT_LIST_DIR}/tests/bench.cpp ) target_link_libraries(bench PRIVATE moderna_logging) else() message("Clone Moderna Library to Test") endif()

StackTrace

[1/4] Scanning /Users/jonathanwillianto/Documents/Projects/moderna/libs/logging/tests/bench.cpp for CXX dependencies FAILED: CMakeFiles/bench.dir/tests/bench.cpp.o.ddi "/opt/homebrew/Cellar/llvm@17/17.0.6/bin/clang-scan-deps" -format=p1689 -- /opt/homebrew/opt/llvm/bin/clang++ -std=gnu++23 -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk -mmacosx-version-min=14.4 -x c++ /Users/jonathanwillianto/Documents/Projects/moderna/libs/logging/tests/bench.cpp -c -o CMakeFiles/bench.dir/tests/bench.cpp.o -MT CMakeFiles/bench.dir/tests/bench.cpp.o.ddi -MD -MF CMakeFiles/bench.dir/tests/bench.cpp.o.ddi.d > CMakeFiles/bench.dir/tests/bench.cpp.o.ddi.tmp && mv CMakeFiles/bench.dir/tests/bench.cpp.o.ddi.tmp CMakeFiles/bench.dir/tests/bench.cpp.o.ddi PLEASE submit a bug report to https://github.com/Homebrew/homebrew-core/issues and include the crash backtrace.

0 0x0000000115747e44 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libLLVM.dylib+0x153e44)

1 0x0000000115745eb4 llvm::sys::RunSignalHandlers() (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libLLVM.dylib+0x151eb4)

2 0x00000001157484f0 SignalHandler(int) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libLLVM.dylib+0x1544f0)

3 0x000000018665f584 (/usr/lib/system/libsystem_platform.dylib+0x180477584)

4 0x00000001096f1388 clang::Preprocessor::Lex(clang::Token&) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x175388)

5 0x00000001096f1388 clang::Preprocessor::Lex(clang::Token&) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x175388)

6 0x00000001096b2760 clang::Preprocessor::CheckEndOfDirective(char const*, bool) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x136760)

7 0x00000001096b5890 clang::Preprocessor::HandleIncludeDirective(clang::SourceLocation, clang::Token&, clang::detail::SearchDirIteratorImpl, clang::FileEntry const*) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x139890)

8 0x00000001096b61c8 clang::Preprocessor::HandleDirective(clang::Token&) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x13a1c8)

9 0x0000000109688784 clang::Lexer::LexDependencyDirectiveToken(clang::Token&) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x10c784)

10 0x00000001096f1388 clang::Preprocessor::Lex(clang::Token&) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x175388)

11 0x00000001096b2568 clang::Preprocessor::CheckEndOfDirective(char const*, bool) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x136568)

12 0x00000001096b5890 clang::Preprocessor::HandleIncludeDirective(clang::SourceLocation, clang::Token&, clang::detail::SearchDirIteratorImpl, clang::FileEntry const*) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x139890)

13 0x00000001096b61c8 clang::Preprocessor::HandleDirective(clang::Token&) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x13a1c8)

14 0x0000000109688784 clang::Lexer::LexDependencyDirectiveToken(clang::Token&) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x10c784)

15 0x00000001096f1388 clang::Preprocessor::Lex(clang::Token&) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x175388)

16 0x00000001096b2568 clang::Preprocessor::CheckEndOfDirective(char const*, bool) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x136568)

17 0x00000001096b5890 clang::Preprocessor::HandleIncludeDirective(clang::SourceLocation, clang::Token&, clang::detail::SearchDirIteratorImpl, clang::FileEntry const*) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x139890)

18 0x00000001096b61c8 clang::Preprocessor::HandleDirective(clang::Token&) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x13a1c8)

19 0x0000000109688784 clang::Lexer::LexDependencyDirectiveToken(clang::Token&) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x10c784)

20 0x00000001096f1388 clang::Preprocessor::Lex(clang::Token&) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x175388)

21 0x00000001096b2568 clang::Preprocessor::CheckEndOfDirective(char const*, bool) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x136568)

22 0x00000001096b5890 clang::Preprocessor::HandleIncludeDirective(clang::SourceLocation, clang::Token&, clang::detail::SearchDirIteratorImpl, clang::FileEntry const*) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x139890)

23 0x00000001096b61c8 clang::Preprocessor::HandleDirective(clang::Token&) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x13a1c8)

24 0x0000000109688784 clang::Lexer::LexDependencyDirectiveToken(clang::Token&) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x10c784)

25 0x00000001096f1388 clang::Preprocessor::Lex(clang::Token&) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x175388)

26 0x00000001096efd30 clang::Preprocessor::LexAfterModuleImport(clang::Token&) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x173d30)

27 0x00000001096f1334 clang::Preprocessor::Lex(clang::Token&) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x175334)

28 0x000000010b534560 clang::ReadPCHAndPreprocessAction::ExecuteAction() (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x1fb8560)

29 0x000000010b5301dc clang::FrontendAction::Execute() (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x1fb41dc)

30 0x000000010b4b0608 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x1f34608)

31 0x000000010b76d22c (anonymous namespace)::DependencyScanningAction::runInvocation(std::__1::shared_ptr, clang::FileManager, std::__1::shared_ptr, clang::DiagnosticConsumer) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x21f122c)

32 0x000000010b7ba7e4 clang::tooling::ToolInvocation::run() (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x223e7e4)

33 0x000000010b76bc88 clang::tooling::dependencies::DependencyScanningWorker::computeDependencies(llvm::StringRef, std::1::vector<std::1::basic_string<char, std::1::char_traits, std::1::allocator>, std::1::allocator<std::__1::basic_string<char, std::1::char_traits, std::1::allocator>>> const&, clang::tooling::dependencies::DependencyConsumer&, clang::tooling::dependencies::DependencyActionController&, clang::DiagnosticConsumer&, std::1::optional) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x21efc88)

34 0x000000010b76abf0 clang::tooling::dependencies::DependencyScanningWorker::computeDependencies(llvm::StringRef, std::1::vector<std::1::basic_string<char, std::1::char_traits, std::1::allocator>, std::1::allocator<std::__1::basic_string<char, std::1::char_traits, std::1::allocator>>> const&, clang::tooling::dependencies::DependencyConsumer&, clang::tooling::dependencies::DependencyActionController&, std::1::optional) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x21eebf0)

35 0x000000010b76f7f8 clang::tooling::dependencies::DependencyScanningTool::getP1689ModuleDependencyFile(clang::tooling::CompileCommand const&, llvm::StringRef, std::1::basic_string<char, std::__1::char_traits, std::1::allocator>&, std::1::basic_string<char, std::__1::char_traits, std::1::allocator>&) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x21f37f8)

36 0x0000000104c2f868 std::1::function::func<clang_scan_deps_main(int, char**, llvm::ToolContext const&)::$_2, std::1::allocator<clang_scan_deps_main(int, char**, llvm::ToolContext const&)::$_2>, void ()>::operator()() (/opt/homebrew/Cellar/llvm@17/17.0.6/bin/clang-scan-deps+0x10001f868)

37 0x0000000104c2e748 std::1::function::func<llvm::ThreadPool::createTaskAndFuture(std::1::function<void ()>)::'lambda'(), std::1::allocator<llvm::ThreadPool::createTaskAndFuture(std::1::function<void ()>)::'lambda'()>, void ()>::operator()() (/opt/homebrew/Cellar/llvm@17/17.0.6/bin/clang-scan-deps+0x10001e748)

38 0x00000001156ee418 llvm::ThreadPool::processTasks(llvm::ThreadPoolTaskGroup*) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libLLVM.dylib+0xfa418)

39 0x00000001156eee38 void llvm::thread::ThreadProxy<std::__1::tuple<llvm::ThreadPool::grow(int)::$_0>>(void) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libLLVM.dylib+0xfae38)

40 0x000000018662ef94 (/usr/lib/system/libsystem_pthread.dylib+0x180446f94)

41 0x0000000186629d34 (/usr/lib/system/libsystem_pthread.dylib+0x180441d34)

/bin/sh: line 1: 82810 Segmentation fault: 11 "/opt/homebrew/Cellar/llvm@17/17.0.6/bin/clang-scan-deps" -format=p1689 -- /opt/homebrew/opt/llvm/bin/clang++ -std=gnu++23 -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk -mmacosx-version-min=14.4 -x c++ /Users/jonathanwillianto/Documents/Projects/moderna/libs/logging/tests/bench.cpp -c -o CMakeFiles/bench.dir/tests/bench.cpp.o -MT CMakeFiles/bench.dir/tests/bench.cpp.o.ddi -MD -MF CMakeFiles/bench.dir/tests/bench.cpp.o.ddi.d > CMakeFiles/bench.dir/tests/bench.cpp.o.ddi.tmp ninja: build stopped: subcommand failed.



# Reproduction Steps 
- Use cmake to start a C++ modules based project. 
- compile code where `import statement` is unbordered. 

# Expected Behaviour
- Syntax check during dependency scanning. 
llvmbot commented 3 months ago

@llvm/issue-subscribers-clang-frontend

Author: Jowillianto (jowillianto)

# Example - Example Code ``` import moderna.logging #include <fstream> #include <format> #include <chrono> #include <iostream> #include <source_location> template<std::invocable F, typename ...Args> std::chrono::high_resolution_clock::duration bench_time(F&& f, Args&& ...args) { auto beg = std::chrono::high_resolution_clock::now(); f(std::forward<Args>(args)...); auto end = std::chrono::high_resolution_clock::now(); return end - beg; } int main() { // std::fstream file ("default.log", std::ios_base::out); // for (int i = 0; i < 1000000; i += 1) { // file << std::format("[WARN ][2024-05-24T16:07+0900][int main():26 ] Hello Logger {}", i) << std::endl; // } moderna::logging::AsyncLogger logger; logger.info(""); auto dur = bench_time(std::format, "{}", std::source_location::current()); std::cout<<dur<<" ns\n"; } ``` - Example CMake ``` cmake_minimum_required(VERSION 3.28) project(moderna_logging) set (CMAKE_CXX_STANDARD 23) set (CMAKE_CXX_STANDARD_REQUIRED true) set (CMAKE_CXX_SCAN_FOR_MODULES true) add_library(moderna_logging) add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/lib/thread-plus) file ( GLOB moderna_logging_src "${CMAKE_CURRENT_LIST_DIR}/src/*.ccm" ) target_sources(moderna_logging PUBLIC FILE_SET CXX_MODULES FILES ${moderna_logging_src} ) target_link_libraries(moderna_logging PUBLIC moderna_thread_plus) if ( EXISTS ${CMAKE_CURRENT_LIST_DIR}/../test-lib/CMakeLists.txt AND EXISTS ${CMAKE_CURRENT_LIST_DIR}/../../cmake/CMakeLists.txt AND PROJECT_IS_TOP_LEVEL ) include (CTest) include (${CMAKE_CURRENT_LIST_DIR}/../../cmake/CMakeLists.txt) add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../test-lib test-lib) add_test_asan_tsan_usan_ubsan( moderna_logging_tests ${CMAKE_CURRENT_LIST_DIR}/tests/tests.cpp "moderna_test_lib;moderna_logging" ) add_executable( bench EXCLUDE_FROM_ALL ${CMAKE_CURRENT_LIST_DIR}/tests/bench.cpp ) target_link_libraries(bench PRIVATE moderna_logging) else() message("Clone Moderna Library to Test") endif() ``` # StackTrace [1/4] Scanning /Users/jonathanwillianto/Documents/Projects/moderna/libs/logging/tests/bench.cpp for CXX dependencies FAILED: CMakeFiles/bench.dir/tests/bench.cpp.o.ddi "/opt/homebrew/Cellar/llvm@17/17.0.6/bin/clang-scan-deps" -format=p1689 -- /opt/homebrew/opt/llvm/bin/clang++ -std=gnu++23 -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk -mmacosx-version-min=14.4 -x c++ /Users/jonathanwillianto/Documents/Projects/moderna/libs/logging/tests/bench.cpp -c -o CMakeFiles/bench.dir/tests/bench.cpp.o -MT CMakeFiles/bench.dir/tests/bench.cpp.o.ddi -MD -MF CMakeFiles/bench.dir/tests/bench.cpp.o.ddi.d > CMakeFiles/bench.dir/tests/bench.cpp.o.ddi.tmp && mv CMakeFiles/bench.dir/tests/bench.cpp.o.ddi.tmp CMakeFiles/bench.dir/tests/bench.cpp.o.ddi PLEASE submit a bug report to https://github.com/Homebrew/homebrew-core/issues and include the crash backtrace. #0 0x0000000115747e44 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libLLVM.dylib+0x153e44) #1 0x0000000115745eb4 llvm::sys::RunSignalHandlers() (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libLLVM.dylib+0x151eb4) #2 0x00000001157484f0 SignalHandler(int) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libLLVM.dylib+0x1544f0) #3 0x000000018665f584 (/usr/lib/system/libsystem_platform.dylib+0x180477584) #4 0x00000001096f1388 clang::Preprocessor::Lex(clang::Token&) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x175388) #5 0x00000001096f1388 clang::Preprocessor::Lex(clang::Token&) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x175388) #6 0x00000001096b2760 clang::Preprocessor::CheckEndOfDirective(char const*, bool) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x136760) #7 0x00000001096b5890 clang::Preprocessor::HandleIncludeDirective(clang::SourceLocation, clang::Token&, clang::detail::SearchDirIteratorImpl<true>, clang::FileEntry const*) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x139890) #8 0x00000001096b61c8 clang::Preprocessor::HandleDirective(clang::Token&) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x13a1c8) #9 0x0000000109688784 clang::Lexer::LexDependencyDirectiveToken(clang::Token&) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x10c784) #10 0x00000001096f1388 clang::Preprocessor::Lex(clang::Token&) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x175388) #11 0x00000001096b2568 clang::Preprocessor::CheckEndOfDirective(char const*, bool) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x136568) #12 0x00000001096b5890 clang::Preprocessor::HandleIncludeDirective(clang::SourceLocation, clang::Token&, clang::detail::SearchDirIteratorImpl<true>, clang::FileEntry const*) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x139890) #13 0x00000001096b61c8 clang::Preprocessor::HandleDirective(clang::Token&) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x13a1c8) #14 0x0000000109688784 clang::Lexer::LexDependencyDirectiveToken(clang::Token&) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x10c784) #15 0x00000001096f1388 clang::Preprocessor::Lex(clang::Token&) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x175388) #16 0x00000001096b2568 clang::Preprocessor::CheckEndOfDirective(char const*, bool) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x136568) #17 0x00000001096b5890 clang::Preprocessor::HandleIncludeDirective(clang::SourceLocation, clang::Token&, clang::detail::SearchDirIteratorImpl<true>, clang::FileEntry const*) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x139890) #18 0x00000001096b61c8 clang::Preprocessor::HandleDirective(clang::Token&) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x13a1c8) #19 0x0000000109688784 clang::Lexer::LexDependencyDirectiveToken(clang::Token&) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x10c784) #20 0x00000001096f1388 clang::Preprocessor::Lex(clang::Token&) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x175388) #21 0x00000001096b2568 clang::Preprocessor::CheckEndOfDirective(char const*, bool) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x136568) #22 0x00000001096b5890 clang::Preprocessor::HandleIncludeDirective(clang::SourceLocation, clang::Token&, clang::detail::SearchDirIteratorImpl<true>, clang::FileEntry const*) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x139890) #23 0x00000001096b61c8 clang::Preprocessor::HandleDirective(clang::Token&) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x13a1c8) #24 0x0000000109688784 clang::Lexer::LexDependencyDirectiveToken(clang::Token&) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x10c784) #25 0x00000001096f1388 clang::Preprocessor::Lex(clang::Token&) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x175388) #26 0x00000001096efd30 clang::Preprocessor::LexAfterModuleImport(clang::Token&) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x173d30) #27 0x00000001096f1334 clang::Preprocessor::Lex(clang::Token&) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x175334) #28 0x000000010b534560 clang::ReadPCHAndPreprocessAction::ExecuteAction() (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x1fb8560) #29 0x000000010b5301dc clang::FrontendAction::Execute() (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x1fb41dc) #30 0x000000010b4b0608 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x1f34608) #31 0x000000010b76d22c (anonymous namespace)::DependencyScanningAction::runInvocation(std::__1::shared_ptr<clang::CompilerInvocation>, clang::FileManager*, std::__1::shared_ptr<clang::PCHContainerOperations>, clang::DiagnosticConsumer*) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x21f122c) #32 0x000000010b7ba7e4 clang::tooling::ToolInvocation::run() (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x223e7e4) #33 0x000000010b76bc88 clang::tooling::dependencies::DependencyScanningWorker::computeDependencies(llvm::StringRef, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>> const&, clang::tooling::dependencies::DependencyConsumer&, clang::tooling::dependencies::DependencyActionController&, clang::DiagnosticConsumer&, std::__1::optional<llvm::StringRef>) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x21efc88) #34 0x000000010b76abf0 clang::tooling::dependencies::DependencyScanningWorker::computeDependencies(llvm::StringRef, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>> const&, clang::tooling::dependencies::DependencyConsumer&, clang::tooling::dependencies::DependencyActionController&, std::__1::optional<llvm::StringRef>) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x21eebf0) #35 0x000000010b76f7f8 clang::tooling::dependencies::DependencyScanningTool::getP1689ModuleDependencyFile(clang::tooling::CompileCommand const&, llvm::StringRef, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>&) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x21f37f8) #36 0x0000000104c2f868 std::__1::__function::__func<clang_scan_deps_main(int, char**, llvm::ToolContext const&)::$_2, std::__1::allocator<clang_scan_deps_main(int, char**, llvm::ToolContext const&)::$_2>, void ()>::operator()() (/opt/homebrew/Cellar/llvm@17/17.0.6/bin/clang-scan-deps+0x10001f868) #37 0x0000000104c2e748 std::__1::__function::__func<llvm::ThreadPool::createTaskAndFuture(std::__1::function<void ()>)::'lambda'(), std::__1::allocator<llvm::ThreadPool::createTaskAndFuture(std::__1::function<void ()>)::'lambda'()>, void ()>::operator()() (/opt/homebrew/Cellar/llvm@17/17.0.6/bin/clang-scan-deps+0x10001e748) #38 0x00000001156ee418 llvm::ThreadPool::processTasks(llvm::ThreadPoolTaskGroup*) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libLLVM.dylib+0xfa418) #39 0x00000001156eee38 void* llvm::thread::ThreadProxy<std::__1::tuple<llvm::ThreadPool::grow(int)::$_0>>(void*) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libLLVM.dylib+0xfae38) #40 0x000000018662ef94 (/usr/lib/system/libsystem_pthread.dylib+0x180446f94) #41 0x0000000186629d34 (/usr/lib/system/libsystem_pthread.dylib+0x180441d34) /bin/sh: line 1: 82810 Segmentation fault: 11 "/opt/homebrew/Cellar/llvm@17/17.0.6/bin/clang-scan-deps" -format=p1689 -- /opt/homebrew/opt/llvm/bin/clang++ -std=gnu++23 -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk -mmacosx-version-min=14.4 -x c++ /Users/jonathanwillianto/Documents/Projects/moderna/libs/logging/tests/bench.cpp -c -o CMakeFiles/bench.dir/tests/bench.cpp.o -MT CMakeFiles/bench.dir/tests/bench.cpp.o.ddi -MD -MF CMakeFiles/bench.dir/tests/bench.cpp.o.ddi.d > CMakeFiles/bench.dir/tests/bench.cpp.o.ddi.tmp ninja: build stopped: subcommand failed. # Reproduction Steps - Use cmake to start a C++ modules based project. - compile code where `import statement` is unbordered. # Expected Behaviour - Syntax check during dependency scanning.
cor3ntin commented 11 hours ago

@ChuanqiXu9

llvmbot commented 11 hours ago

@llvm/issue-subscribers-clang-modules

Author: Jowillianto (jowillianto)

# Example - Example Code ``` import moderna.logging #include <fstream> #include <format> #include <chrono> #include <iostream> #include <source_location> template<std::invocable F, typename ...Args> std::chrono::high_resolution_clock::duration bench_time(F&& f, Args&& ...args) { auto beg = std::chrono::high_resolution_clock::now(); f(std::forward<Args>(args)...); auto end = std::chrono::high_resolution_clock::now(); return end - beg; } int main() { // std::fstream file ("default.log", std::ios_base::out); // for (int i = 0; i < 1000000; i += 1) { // file << std::format("[WARN ][2024-05-24T16:07+0900][int main():26 ] Hello Logger {}", i) << std::endl; // } moderna::logging::AsyncLogger logger; logger.info(""); auto dur = bench_time(std::format, "{}", std::source_location::current()); std::cout<<dur<<" ns\n"; } ``` - Example CMake ``` cmake_minimum_required(VERSION 3.28) project(moderna_logging) set (CMAKE_CXX_STANDARD 23) set (CMAKE_CXX_STANDARD_REQUIRED true) set (CMAKE_CXX_SCAN_FOR_MODULES true) add_library(moderna_logging) add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/lib/thread-plus) file ( GLOB moderna_logging_src "${CMAKE_CURRENT_LIST_DIR}/src/*.ccm" ) target_sources(moderna_logging PUBLIC FILE_SET CXX_MODULES FILES ${moderna_logging_src} ) target_link_libraries(moderna_logging PUBLIC moderna_thread_plus) if ( EXISTS ${CMAKE_CURRENT_LIST_DIR}/../test-lib/CMakeLists.txt AND EXISTS ${CMAKE_CURRENT_LIST_DIR}/../../cmake/CMakeLists.txt AND PROJECT_IS_TOP_LEVEL ) include (CTest) include (${CMAKE_CURRENT_LIST_DIR}/../../cmake/CMakeLists.txt) add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../test-lib test-lib) add_test_asan_tsan_usan_ubsan( moderna_logging_tests ${CMAKE_CURRENT_LIST_DIR}/tests/tests.cpp "moderna_test_lib;moderna_logging" ) add_executable( bench EXCLUDE_FROM_ALL ${CMAKE_CURRENT_LIST_DIR}/tests/bench.cpp ) target_link_libraries(bench PRIVATE moderna_logging) else() message("Clone Moderna Library to Test") endif() ``` ``` # StackTrace [1/4] Scanning /Users/jonathanwillianto/Documents/Projects/moderna/libs/logging/tests/bench.cpp for CXX dependencies FAILED: CMakeFiles/bench.dir/tests/bench.cpp.o.ddi "/opt/homebrew/Cellar/llvm@17/17.0.6/bin/clang-scan-deps" -format=p1689 -- /opt/homebrew/opt/llvm/bin/clang++ -std=gnu++23 -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk -mmacosx-version-min=14.4 -x c++ /Users/jonathanwillianto/Documents/Projects/moderna/libs/logging/tests/bench.cpp -c -o CMakeFiles/bench.dir/tests/bench.cpp.o -MT CMakeFiles/bench.dir/tests/bench.cpp.o.ddi -MD -MF CMakeFiles/bench.dir/tests/bench.cpp.o.ddi.d > CMakeFiles/bench.dir/tests/bench.cpp.o.ddi.tmp && mv CMakeFiles/bench.dir/tests/bench.cpp.o.ddi.tmp CMakeFiles/bench.dir/tests/bench.cpp.o.ddi PLEASE submit a bug report to https://github.com/Homebrew/homebrew-core/issues and include the crash backtrace. #0 0x0000000115747e44 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libLLVM.dylib+0x153e44) #1 0x0000000115745eb4 llvm::sys::RunSignalHandlers() (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libLLVM.dylib+0x151eb4) #2 0x00000001157484f0 SignalHandler(int) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libLLVM.dylib+0x1544f0) #3 0x000000018665f584 (/usr/lib/system/libsystem_platform.dylib+0x180477584) #4 0x00000001096f1388 clang::Preprocessor::Lex(clang::Token&) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x175388) #5 0x00000001096f1388 clang::Preprocessor::Lex(clang::Token&) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x175388) #6 0x00000001096b2760 clang::Preprocessor::CheckEndOfDirective(char const*, bool) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x136760) #7 0x00000001096b5890 clang::Preprocessor::HandleIncludeDirective(clang::SourceLocation, clang::Token&, clang::detail::SearchDirIteratorImpl<true>, clang::FileEntry const*) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x139890) #8 0x00000001096b61c8 clang::Preprocessor::HandleDirective(clang::Token&) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x13a1c8) #9 0x0000000109688784 clang::Lexer::LexDependencyDirectiveToken(clang::Token&) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x10c784) #10 0x00000001096f1388 clang::Preprocessor::Lex(clang::Token&) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x175388) #11 0x00000001096b2568 clang::Preprocessor::CheckEndOfDirective(char const*, bool) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x136568) #12 0x00000001096b5890 clang::Preprocessor::HandleIncludeDirective(clang::SourceLocation, clang::Token&, clang::detail::SearchDirIteratorImpl<true>, clang::FileEntry const*) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x139890) #13 0x00000001096b61c8 clang::Preprocessor::HandleDirective(clang::Token&) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x13a1c8) #14 0x0000000109688784 clang::Lexer::LexDependencyDirectiveToken(clang::Token&) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x10c784) #15 0x00000001096f1388 clang::Preprocessor::Lex(clang::Token&) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x175388) #16 0x00000001096b2568 clang::Preprocessor::CheckEndOfDirective(char const*, bool) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x136568) #17 0x00000001096b5890 clang::Preprocessor::HandleIncludeDirective(clang::SourceLocation, clang::Token&, clang::detail::SearchDirIteratorImpl<true>, clang::FileEntry const*) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x139890) #18 0x00000001096b61c8 clang::Preprocessor::HandleDirective(clang::Token&) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x13a1c8) #19 0x0000000109688784 clang::Lexer::LexDependencyDirectiveToken(clang::Token&) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x10c784) #20 0x00000001096f1388 clang::Preprocessor::Lex(clang::Token&) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x175388) #21 0x00000001096b2568 clang::Preprocessor::CheckEndOfDirective(char const*, bool) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x136568) #22 0x00000001096b5890 clang::Preprocessor::HandleIncludeDirective(clang::SourceLocation, clang::Token&, clang::detail::SearchDirIteratorImpl<true>, clang::FileEntry const*) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x139890) #23 0x00000001096b61c8 clang::Preprocessor::HandleDirective(clang::Token&) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x13a1c8) #24 0x0000000109688784 clang::Lexer::LexDependencyDirectiveToken(clang::Token&) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x10c784) #25 0x00000001096f1388 clang::Preprocessor::Lex(clang::Token&) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x175388) #26 0x00000001096efd30 clang::Preprocessor::LexAfterModuleImport(clang::Token&) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x173d30) #27 0x00000001096f1334 clang::Preprocessor::Lex(clang::Token&) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x175334) #28 0x000000010b534560 clang::ReadPCHAndPreprocessAction::ExecuteAction() (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x1fb8560) #29 0x000000010b5301dc clang::FrontendAction::Execute() (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x1fb41dc) #30 0x000000010b4b0608 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x1f34608) #31 0x000000010b76d22c (anonymous namespace)::DependencyScanningAction::runInvocation(std::__1::shared_ptr<clang::CompilerInvocation>, clang::FileManager*, std::__1::shared_ptr<clang::PCHContainerOperations>, clang::DiagnosticConsumer*) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x21f122c) #32 0x000000010b7ba7e4 clang::tooling::ToolInvocation::run() (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x223e7e4) #33 0x000000010b76bc88 clang::tooling::dependencies::DependencyScanningWorker::computeDependencies(llvm::StringRef, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>> const&, clang::tooling::dependencies::DependencyConsumer&, clang::tooling::dependencies::DependencyActionController&, clang::DiagnosticConsumer&, std::__1::optional<llvm::StringRef>) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x21efc88) #34 0x000000010b76abf0 clang::tooling::dependencies::DependencyScanningWorker::computeDependencies(llvm::StringRef, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>> const&, clang::tooling::dependencies::DependencyConsumer&, clang::tooling::dependencies::DependencyActionController&, std::__1::optional<llvm::StringRef>) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x21eebf0) #35 0x000000010b76f7f8 clang::tooling::dependencies::DependencyScanningTool::getP1689ModuleDependencyFile(clang::tooling::CompileCommand const&, llvm::StringRef, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>&) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libclang-cpp.dylib+0x21f37f8) #36 0x0000000104c2f868 std::__1::__function::__func<clang_scan_deps_main(int, char**, llvm::ToolContext const&)::$_2, std::__1::allocator<clang_scan_deps_main(int, char**, llvm::ToolContext const&)::$_2>, void ()>::operator()() (/opt/homebrew/Cellar/llvm@17/17.0.6/bin/clang-scan-deps+0x10001f868) #37 0x0000000104c2e748 std::__1::__function::__func<llvm::ThreadPool::createTaskAndFuture(std::__1::function<void ()>)::'lambda'(), std::__1::allocator<llvm::ThreadPool::createTaskAndFuture(std::__1::function<void ()>)::'lambda'()>, void ()>::operator()() (/opt/homebrew/Cellar/llvm@17/17.0.6/bin/clang-scan-deps+0x10001e748) #38 0x00000001156ee418 llvm::ThreadPool::processTasks(llvm::ThreadPoolTaskGroup*) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libLLVM.dylib+0xfa418) #39 0x00000001156eee38 void* llvm::thread::ThreadProxy<std::__1::tuple<llvm::ThreadPool::grow(int)::$_0>>(void*) (/opt/homebrew/Cellar/llvm@17/17.0.6/lib/libLLVM.dylib+0xfae38) #40 0x000000018662ef94 (/usr/lib/system/libsystem_pthread.dylib+0x180446f94) #41 0x0000000186629d34 (/usr/lib/system/libsystem_pthread.dylib+0x180441d34) /bin/sh: line 1: 82810 Segmentation fault: 11 "/opt/homebrew/Cellar/llvm@17/17.0.6/bin/clang-scan-deps" -format=p1689 -- /opt/homebrew/opt/llvm/bin/clang++ -std=gnu++23 -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk -mmacosx-version-min=14.4 -x c++ /Users/jonathanwillianto/Documents/Projects/moderna/libs/logging/tests/bench.cpp -c -o CMakeFiles/bench.dir/tests/bench.cpp.o -MT CMakeFiles/bench.dir/tests/bench.cpp.o.ddi -MD -MF CMakeFiles/bench.dir/tests/bench.cpp.o.ddi.d > CMakeFiles/bench.dir/tests/bench.cpp.o.ddi.tmp ninja: build stopped: subcommand failed. ``` # Reproduction Steps - Use cmake to start a C++ modules based project. - compile code where `import statement` is unbordered. # Expected Behaviour - Syntax check during dependency scanning.