Skip to content
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

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

Open
jowillianto opened this issue May 26, 2024 · 7 comments
Assignees
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:modules C++20 modules and Clang Header Modules crash-on-invalid

Comments

@jowillianto
Copy link

jowillianto commented May 26, 2024

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.
@EugeneZelenko EugeneZelenko added clang:frontend Language frontend issues, e.g. anything involving "Sema" crash Prefer [crash-on-valid] or [crash-on-invalid] and removed new issue labels May 26, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented May 26, 2024

@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 &gt; CMakeFiles/bench.dir/tests/bench.cpp.o.ddi.tmp &amp;&amp; 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&amp;, 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&amp;) (/opt/homebrew/Cellar/llvm@<!-- -->17/17.0.6/lib/libclang-cpp.dylib+0x175388)
 #<!-- -->5 0x00000001096f1388 clang::Preprocessor::Lex(clang::Token&amp;) (/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&amp;, clang::detail::SearchDirIteratorImpl&lt;true&gt;, clang::FileEntry const*) (/opt/homebrew/Cellar/llvm@<!-- -->17/17.0.6/lib/libclang-cpp.dylib+0x139890)
 #<!-- -->8 0x00000001096b61c8 clang::Preprocessor::HandleDirective(clang::Token&amp;) (/opt/homebrew/Cellar/llvm@<!-- -->17/17.0.6/lib/libclang-cpp.dylib+0x13a1c8)
 #<!-- -->9 0x0000000109688784 clang::Lexer::LexDependencyDirectiveToken(clang::Token&amp;) (/opt/homebrew/Cellar/llvm@<!-- -->17/17.0.6/lib/libclang-cpp.dylib+0x10c784)
#<!-- -->10 0x00000001096f1388 clang::Preprocessor::Lex(clang::Token&amp;) (/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&amp;, clang::detail::SearchDirIteratorImpl&lt;true&gt;, clang::FileEntry const*) (/opt/homebrew/Cellar/llvm@<!-- -->17/17.0.6/lib/libclang-cpp.dylib+0x139890)
#<!-- -->13 0x00000001096b61c8 clang::Preprocessor::HandleDirective(clang::Token&amp;) (/opt/homebrew/Cellar/llvm@<!-- -->17/17.0.6/lib/libclang-cpp.dylib+0x13a1c8)
#<!-- -->14 0x0000000109688784 clang::Lexer::LexDependencyDirectiveToken(clang::Token&amp;) (/opt/homebrew/Cellar/llvm@<!-- -->17/17.0.6/lib/libclang-cpp.dylib+0x10c784)
#<!-- -->15 0x00000001096f1388 clang::Preprocessor::Lex(clang::Token&amp;) (/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&amp;, clang::detail::SearchDirIteratorImpl&lt;true&gt;, clang::FileEntry const*) (/opt/homebrew/Cellar/llvm@<!-- -->17/17.0.6/lib/libclang-cpp.dylib+0x139890)
#<!-- -->18 0x00000001096b61c8 clang::Preprocessor::HandleDirective(clang::Token&amp;) (/opt/homebrew/Cellar/llvm@<!-- -->17/17.0.6/lib/libclang-cpp.dylib+0x13a1c8)
#<!-- -->19 0x0000000109688784 clang::Lexer::LexDependencyDirectiveToken(clang::Token&amp;) (/opt/homebrew/Cellar/llvm@<!-- -->17/17.0.6/lib/libclang-cpp.dylib+0x10c784)
#<!-- -->20 0x00000001096f1388 clang::Preprocessor::Lex(clang::Token&amp;) (/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&amp;, clang::detail::SearchDirIteratorImpl&lt;true&gt;, clang::FileEntry const*) (/opt/homebrew/Cellar/llvm@<!-- -->17/17.0.6/lib/libclang-cpp.dylib+0x139890)
#<!-- -->23 0x00000001096b61c8 clang::Preprocessor::HandleDirective(clang::Token&amp;) (/opt/homebrew/Cellar/llvm@<!-- -->17/17.0.6/lib/libclang-cpp.dylib+0x13a1c8)
#<!-- -->24 0x0000000109688784 clang::Lexer::LexDependencyDirectiveToken(clang::Token&amp;) (/opt/homebrew/Cellar/llvm@<!-- -->17/17.0.6/lib/libclang-cpp.dylib+0x10c784)
#<!-- -->25 0x00000001096f1388 clang::Preprocessor::Lex(clang::Token&amp;) (/opt/homebrew/Cellar/llvm@<!-- -->17/17.0.6/lib/libclang-cpp.dylib+0x175388)
#<!-- -->26 0x00000001096efd30 clang::Preprocessor::LexAfterModuleImport(clang::Token&amp;) (/opt/homebrew/Cellar/llvm@<!-- -->17/17.0.6/lib/libclang-cpp.dylib+0x173d30)
#<!-- -->27 0x00000001096f1334 clang::Preprocessor::Lex(clang::Token&amp;) (/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&amp;) (/opt/homebrew/Cellar/llvm@<!-- -->17/17.0.6/lib/libclang-cpp.dylib+0x1f34608)
#<!-- -->31 0x000000010b76d22c (anonymous namespace)::DependencyScanningAction::runInvocation(std::__1::shared_ptr&lt;clang::CompilerInvocation&gt;, clang::FileManager*, std::__1::shared_ptr&lt;clang::PCHContainerOperations&gt;, 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&lt;std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt;&gt;, std::__1::allocator&lt;std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt;&gt;&gt;&gt; const&amp;, clang::tooling::dependencies::DependencyConsumer&amp;, clang::tooling::dependencies::DependencyActionController&amp;, clang::DiagnosticConsumer&amp;, std::__1::optional&lt;llvm::StringRef&gt;) (/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&lt;std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt;&gt;, std::__1::allocator&lt;std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt;&gt;&gt;&gt; const&amp;, clang::tooling::dependencies::DependencyConsumer&amp;, clang::tooling::dependencies::DependencyActionController&amp;, std::__1::optional&lt;llvm::StringRef&gt;) (/opt/homebrew/Cellar/llvm@<!-- -->17/17.0.6/lib/libclang-cpp.dylib+0x21eebf0)
#<!-- -->35 0x000000010b76f7f8 clang::tooling::dependencies::DependencyScanningTool::getP1689ModuleDependencyFile(clang::tooling::CompileCommand const&amp;, llvm::StringRef, std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt;&gt;&amp;, std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt;&gt;&amp;) (/opt/homebrew/Cellar/llvm@<!-- -->17/17.0.6/lib/libclang-cpp.dylib+0x21f37f8)
#<!-- -->36 0x0000000104c2f868 std::__1::__function::__func&lt;clang_scan_deps_main(int, char**, llvm::ToolContext const&amp;)::$_2, std::__1::allocator&lt;clang_scan_deps_main(int, char**, llvm::ToolContext const&amp;)::$_2&gt;, void ()&gt;::operator()() (/opt/homebrew/Cellar/llvm@<!-- -->17/17.0.6/bin/clang-scan-deps+0x10001f868)
#<!-- -->37 0x0000000104c2e748 std::__1::__function::__func&lt;llvm::ThreadPool::createTaskAndFuture(std::__1::function&lt;void ()&gt;)::'lambda'(), std::__1::allocator&lt;llvm::ThreadPool::createTaskAndFuture(std::__1::function&lt;void ()&gt;)::'lambda'()&gt;, void ()&gt;::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&lt;std::__1::tuple&lt;llvm::ThreadPool::grow(int)::$_0&gt;&gt;(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 &gt; 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. 
</details>

@cor3ntin cor3ntin added the clang:modules C++20 modules and Clang Header Modules label Sep 5, 2024
@cor3ntin
Copy link
Contributor

cor3ntin commented Sep 5, 2024

@ChuanqiXu9

@llvmbot
Copy link
Collaborator

llvmbot commented Sep 5, 2024

@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. 
</details>

@ChuanqiXu9
Copy link
Member

ChuanqiXu9 commented Sep 6, 2024

This maybe the root of the cause: clang::ReadPCHAndPreprocessAction::ExecuteAction(). For P1689 format, we only need PreprocessOnlyAction. So that we can make sure we will have the same behavior with preprocessor. This may be an optimization too.

Well, it is not the root cause... I'll commit that as a seperate improvement.

@EugeneZelenko EugeneZelenko removed the crash Prefer [crash-on-valid] or [crash-on-invalid] label Sep 6, 2024
@ChuanqiXu9
Copy link
Member

This is related to DependencyDirectivesScan mode. We can workaround this by -mode=preprocess. It should be fine to do so since DependencyDirectivesScan mode only benefits the batched scan as far as I know.

Given this only crash on invalid, I may not try to ask CMake to add the option. Let's try to fix it. But I spent sometimes but has no clue.

The simpler reproducer:

// a.cppm
module;
import moderna.logging
#include <fstream>
// #include <format>
#include <chrono>
// #include <source_location>
export module a;

// CMakeLists.txt
cmake_minimum_required(VERSION 3.28)
project(a)
set (CMAKE_CXX_STANDARD 23)
set (CMAKE_CXX_STANDARD_REQUIRED true)
set (CMAKE_CXX_SCAN_FOR_MODULES true)

add_library(a)
target_sources(a 
  PUBLIC 
    FILE_SET CXX_MODULES FILES a.cppm
)

And a minimal reproducer, but I am not sure if they are strictly the same:

// RUN: rm -fr %t
// RUN: mkdir -p %t
// RUN: split-file %s %t
//
// RUN: clang-scan-deps -format=p1689 -- %clang++  -std=c++20 -I%t %t/a.cppm

//--- foo.h
#pragma once

//--- a.cppm
module;
import invalid.not.end
# 1 "foo.h" 1 3

# 6 "a.cppm" 2

export module a;

From my debugging experience, it looks like the direct cause of the issue is that we invoked Lexer::LexDependencyDirectiveToken after assigning nullptr to CurLexer of the preprocessor, where the PP encounters the EOF.

CC: @Bigcheese @jansvoboda11

@jansvoboda11
Copy link
Contributor

The -mode=preprocess option will give you worse performance. IIRC @Bigcheese recently fixed crash with #include without the header path. Maybe this is the same bug?

@ChuanqiXu9
Copy link
Member

IIRC @Bigcheese recently fixed crash with #include without the header path. Maybe this is the same bug?

Maybe not, I reproduced with the trunk.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:modules C++20 modules and Clang Header Modules crash-on-invalid
Projects
None yet
Development

No branches or pull requests

6 participants