Skip to content

Core dump running iwyu on bazel sources #2

Description

@katre

When testing iwyu v0.0.4 on the Bazel sources, I got a crash dump from inside clang.

Environment:

This is on an amd64 Dell laptop running Ubuntu 24.04. Bazel is from head and tests are using Bazel 9.1.0.

Reproduction:

Bazel commit: bazelbuild/bazel@3c2c7cf

Add bazel-iwyu:

 git diff 3c2c7cf23ca9b83d23800fc19ee1e55ec2c12f38
diff --git a/MODULE.bazel b/MODULE.bazel
index 15b177f90d..c9e57eebd3 100644
--- a/MODULE.bazel
+++ b/MODULE.bazel
@@ -494,3 +494,6 @@ register_toolchains("@local_config_winsdk//:all")
 register_toolchains("//src/main/res:empty_rc_toolchain")
 
 register_toolchains("@graalvm_ce_toolchains//:gvm")
+
+# ICYU
+bazel_dep(name = "bazel_iwyu", version = "0.0.4")

Run iwyu on //src/main/cpp:rc_file:

$ bazel build --compilation_mode=dbg --host_compilation_mode=dbg  --aspects @bazel_iwyu//:iwyu.bzl%iwyu_aspect --output_groups=report -s -- //src/main/cpp:rc_file 
INFO: Analyzed target //src/main/cpp:rc_file (90 packages loaded, 3271 targets configured, 1 aspect application).
SUBCOMMAND: # aspects [@@bazel_iwyu+//bazel/iwyu:iwyu.bzl%iwyu_aspect] on cc_library rule target //src/main/cpp:rc_file [action 'Run include-what-you-use on src/main/cpp/rc_file.cc', configuration: 0fcdb6284b9e2b9f5f620fe4086f538394a679570c6f76470a1d9f540fcf2dae, execution platform: //:default_host_platform, mnemonic: iwyu]
(cd /home/jcater/.cache/bazel/_bazel_jcater/c3f78d9b26355df6196e2a7ad0273cae/execroot/_main && \
  exec env - \
  bazel-out/k8-dbg/bin/external/bazel_iwyu+/bazel/iwyu/iwyu_prebuilt_toolchain_impl_wrapper.sh bazel-out/k8-dbg/bin/src/main/cpp/rc_file.rc_file.cc.iwyu.txt -Xiwyu --cxx17ns -Xiwyu '--error=1' -Xiwyu '--max_line_length=127' -Xiwyu --no_fwd_decls -Xiwyu --transitive_includes_only -Xiwyu '--mapping_file=external/bazel_iwyu+/mappings/gtest.imp' -U_FORTIFY_SOURCE -fstack-protector -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer -g '-std=c++17' -Wno-builtin-macro-redefined '-D__DATE__="redacted"' '-D__TIMESTAMP__="redacted"' '-D__TIME__="redacted"' -x c++ -DBLAZE_OPENSOURCE -iquote . -iquote bazel-out/k8-dbg/bin -iquote external/abseil-cpp+ -iquote bazel-out/k8-dbg/bin/external/abseil-cpp+ -iquote external/re2+ -iquote bazel-out/k8-dbg/bin/external/re2+ src/main/cpp/rc_file.cc)
# Configuration: 0fcdb6284b9e2b9f5f620fe4086f538394a679570c6f76470a1d9f540fcf2dae
# Execution platform: //:default_host_platform
# Runner: processwrapper-sandbox
ERROR: /home/jcater/src/bazel/bazel/src/main/cpp/BUILD:264:11: Run include-what-you-use on src/main/cpp/rc_file.cc failed: (Exit 1): iwyu_prebuilt_toolchain_impl_wrapper.sh failed: error executing iwyu command (from aspects [@@bazel_iwyu+//bazel/iwyu:iwyu.bzl%iwyu_aspect] on cc_library rule target //src/main/cpp:rc_file) bazel-out/k8-dbg/bin/external/bazel_iwyu+/bazel/iwyu/iwyu_prebuilt_toolchain_impl_wrapper.sh bazel-out/k8-dbg/bin/src/main/cpp/rc_file.rc_file.cc.iwyu.txt -Xiwyu --cxx17ns -Xiwyu '--error=1' -Xiwyu ... (remaining 35 arguments skipped)

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
bazel-out/k8-dbg/bin/external/bazel_iwyu+/bazel/iwyu/iwyu_prebuilt_toolchain_impl_wrapper.sh: line 23: 199561 Segmentation fault      (core dumped) "${IWYU_BINARY}" -Xclang -resource-dir -Xclang "external/bazel_iwyu++iwyu+iwyu_prebuilt_pkg/lib/clang/22" "$@" 2> "${OUTPUT}"
[ERROR] IWYU violation found. Fixes have been written to bazel-out/k8-dbg/bin/src/main/cpp/rc_file.rc_file.cc.iwyu.txt
Aspect @@bazel_iwyu+//bazel/iwyu:iwyu.bzl%iwyu_aspect of //src/main/cpp:rc_file failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 2.636s, Critical Path: 1.49s
INFO: 2 processes: 1 action cache hit, 2 internal.
ERROR: Build did NOT complete successfully

Core dump

I was able to find the core file and extract a backtrace. I've attached the entire trace, but here's the start:

backtrace:
Core was generated by `external/bazel_iwyu++iwyu+iwyu_prebuilt_pkg/bin/include-what-you-use -Xclang -r'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x00006216dc3ef261 in clang::Decl::getASTContext() const ()
(gdb) bt
#0  0x00006216dc3ef261 in clang::Decl::getASTContext() const ()
#1  0x00006216d9e6af32 in include_what_you_use::GetWrittenQualifiedNameAsString[abi:cxx11](clang::NamedDecl const*, bool) ()
#2  0x00006216d9f2b06c in include_what_you_use::FullUseCache::GetPrecomputedResugarMap(clang::TemplateSpecializationType const*, clang::LangOptions const&) ()
#3  0x00006216d9dca4e2 in include_what_you_use::InstantiatedTemplateVisitor::ReplayClassMemberUsesFromPrecomputedList(clang::TemplateSpecializationType const*) ()
#4  0x00006216d9dca3c4 in include_what_you_use::InstantiatedTemplateVisitor::TraverseDataAndTypeMembersOfClassHelper(clang::TemplateSpecializationType const*) ()
#5  0x00006216d9dcb3d8 in include_what_you_use::BaseAstVisitor<include_what_you_use::InstantiatedTemplateVisitor>::TraverseTypeLoc(clang::TypeLoc, bool) ()
#6  0x00006216d9dd4142 in clang::RecursiveASTVisitor<include_what_you_use::InstantiatedTemplateVisitor>::TraverseNestedNameSpecifierLoc(clang::NestedNameSpecifierLoc) ()
#7  0x00006216d9dd3ec4 in include_what_you_use::BaseAstVisitor<include_what_you_use::InstantiatedTemplateVisitor>::TraverseNestedNameSpecifierLoc(clang::NestedNameSpecifierLoc) ()
#8  0x00006216d9ddc8fe in clang::RecursiveASTVisitor<include_what_you_use::InstantiatedTemplateVisitor>::TraverseDependentScopeDeclRefExpr(clang::DependentScopeDeclRefExpr*, llvm::SmallVectorImpl<llvm::PointerIntPair<clang::Stmt*, 1u, bool, llvm::PointerLikeTypeTraits<clang::Stmt*>, llvm::PointerIntPairInfo<clang::Stmt*, 1u, llvm::PointerLikeTypeTraits<clang::Stmt*> > > >*) ()
#9  0x00006216d9dd7c4f in clang::RecursiveASTVisitor<include_what_you_use::InstantiatedTemplateVisitor>::TraverseStmt(clang::Stmt*, llvm::SmallVectorImpl<llvm::PointerIntPair<clang::Stmt*, 1u, bool, llvm::PointerLikeTypeTraits<clang::Stmt*>, llvm::PointerIntPairInfo<clang::Stmt*, 1u, llvm::PointerLikeTypeTraits<clang::Stmt*> > > >*) ()

Let me know if you need more details.

iwyu-crash.log

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions