[llvm] MC: Restructure MCFragment as a fixed part and a variable tail (PR #148544)

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 17 09:05:31 PDT 2025


MaskRay wrote:

> I think this made the UBSan bot unhappy (top frames in MC):
> 
> ```
> FAIL: Clang :: ASTMerge/codegen-body/test.c (842 of 91351)
> ******************** TEST 'Clang :: ASTMerge/codegen-body/test.c' FAILED ********************
> Exit Code: 134
> Command Output (stderr):
> --
> /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build_ubsan/bin/clang -cc1 -internal-isystem /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build_ubsan/lib/clang/22/include -nostdsysteminc -emit-pch -o /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build_ubsan/tools/clang/test/ASTMerge/codegen-body/Output/test.c.tmp.1.ast /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/clang/test/ASTMerge/codegen-body/Inputs/body1.c # RUN: at line 1
> + /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build_ubsan/bin/clang -cc1 -internal-isystem /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build_ubsan/lib/clang/22/include -nostdsysteminc -emit-pch -o /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build_ubsan/tools/clang/test/ASTMerge/codegen-body/Output/test.c.tmp.1.ast /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/clang/test/ASTMerge/codegen-body/Inputs/body1.c
> /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build_ubsan/bin/clang -cc1 -internal-isystem /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build_ubsan/lib/clang/22/include -nostdsysteminc -emit-pch -o /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build_ubsan/tools/clang/test/ASTMerge/codegen-body/Output/test.c.tmp.2.ast /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/clang/test/ASTMerge/codegen-body/Inputs/body2.c # RUN: at line 2
> + /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build_ubsan/bin/clang -cc1 -internal-isystem /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build_ubsan/lib/clang/22/include -nostdsysteminc -emit-pch -o /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build_ubsan/tools/clang/test/ASTMerge/codegen-body/Output/test.c.tmp.2.ast /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/clang/test/ASTMerge/codegen-body/Inputs/body2.c
> /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build_ubsan/bin/clang -cc1 -internal-isystem /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build_ubsan/lib/clang/22/include -nostdsysteminc -emit-obj -o /dev/null -ast-merge /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build_ubsan/tools/clang/test/ASTMerge/codegen-body/Output/test.c.tmp.1.ast -ast-merge /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build_ubsan/tools/clang/test/ASTMerge/codegen-body/Output/test.c.tmp.2.ast /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/clang/test/ASTMerge/codegen-body/test.c # RUN: at line 3
> + /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build_ubsan/bin/clang -cc1 -internal-isystem /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build_ubsan/lib/clang/22/include -nostdsysteminc -emit-obj -o /dev/null -ast-merge /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build_ubsan/tools/clang/test/ASTMerge/codegen-body/Output/test.c.tmp.1.ast -ast-merge /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build_ubsan/tools/clang/test/ASTMerge/codegen-body/Output/test.c.tmp.2.ast /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/clang/test/ASTMerge/codegen-body/test.c
> PLEASE submit a bug report to [https://github.com/llvm/llvm-project/issues/](https://github.com/llvm/llvm-project/issues/?q=sort%3Aupdated-desc+is%3Aissue+is%3Aopen) and include the crash backtrace, preprocessed source, and associated run script.
> Stack dump:
> 0.	Program arguments: /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build_ubsan/bin/clang -cc1 -internal-isystem /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build_ubsan/lib/clang/22/include -nostdsysteminc -emit-obj -o /dev/null -ast-merge /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build_ubsan/tools/clang/test/ASTMerge/codegen-body/Output/test.c.tmp.1.ast -ast-merge /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build_ubsan/tools/clang/test/ASTMerge/codegen-body/Output/test.c.tmp.2.ast /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/clang/test/ASTMerge/codegen-body/test.c
> 1.	<eof> parser at end of file
> 2.	Code generation
>  #0 0x00005663a9a036ee llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/lib/Support/Unix/Signals.inc:834:13
>  #1 0x00005663a9a0030f llvm::sys::RunSignalHandlers() /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/lib/Support/Signals.cpp:105:18
>  #2 0x00005663a9a049a8 SignalHandler(int, siginfo_t*, void*) /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/lib/Support/Unix/Signals.inc:426:38
>  #3 0x00007beaafe45250 (/lib/x86_64-linux-gnu/libc.so.6+0x45250)
>  #4 0x00007beaafea3f1c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0xa3f1c)
>  #5 0x00007beaafe4519e raise (/lib/x86_64-linux-gnu/libc.so.6+0x4519e)
>  #6 0x00007beaafe28902 abort (/lib/x86_64-linux-gnu/libc.so.6+0x28902)
>  #7 0x00005663a5dcc45c (/home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build_ubsan/bin/clang+0xa72345c)
>  #8 0x00005663a5dca2fe __sanitizer::Die() /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_termination.cpp:52:5
>  #9 0x00005663a5de0099 (/home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build_ubsan/bin/clang+0xa737099)
> #10 0x00005663a9606ad0 end /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/include/llvm/ADT/ArrayRef.h:352:42
> #11 0x00005663a9606ad0 llvm::MCAssembler::layout() /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/lib/MC/MCAssembler.cpp:0:0
> #12 0x00005663a96075ee operator* /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/libcxx_install_ubsan/include/c++/v1/__memory/unique_ptr.h:268:13
> #13 0x00005663a96075ee getWriter /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/include/llvm/MC/MCAssembler.h:179:46
> #14 0x00005663a96075ee llvm::MCAssembler::Finish() /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/lib/MC/MCAssembler.cpp:735:25
> #15 0x00005663a96353c5 llvm::MCELFStreamer::finishImpl() /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/lib/MC/MCELFStreamer.cpp:371:1
> #16 0x00005663ab0827ac operator-> /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/libcxx_install_ubsan/include/c++/v1/__memory/unique_ptr.h:270:101
> #17 0x00005663ab0827ac llvm::AsmPrinter::doFinalization(llvm::Module&) /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp:2778:3
> #18 0x00005663a913f843 llvm::FPPassManager::doFinalization(llvm::Module&) /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1462:13
> #19 0x00005663a9135d7b runOnModule /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1549:13
> #20 0x00005663a9135d7b llvm::legacy::PassManagerImpl::run(llvm::Module&) /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:531:44
> #21 0x00005663aa4c5881 RunCodegenPipeline /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/clang/lib/CodeGen/BackendUtil.cpp:1261:9
> #22 0x00005663aa4c5881 emitAssembly /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/clang/lib/CodeGen/BackendUtil.cpp:1284:3
> #23 0x00005663aa4c5881 clang::emitBackendOutput(clang::CompilerInstance&, clang::CodeGenOptions&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::__1::unique_ptr<llvm::raw_pwrite_stream, std::__1::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/clang/lib/CodeGen/BackendUtil.cpp:1449:13
> #24 0x00005663aa4dd2ec reset /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/libcxx_install_ubsan/include/c++/v1/__memory/unique_ptr.h:287:21
> #25 0x00005663aa4dd2ec ~unique_ptr /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/libcxx_install_ubsan/include/c++/v1/__memory/unique_ptr.h:259:71
> #26 0x00005663aa4dd2ec clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/clang/lib/CodeGen/CodeGenAction.cpp:316:3
> #27 0x00005663ac9f4c0b clang::ParseAST(clang::Sema&, bool, bool) /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/clang/lib/Parse/ParseAST.cpp:0:13
> #28 0x00005663aadf7555 operator bool /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h:206:43
> #29 0x00005663aadf7555 getDiagnostics /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/clang/include/clang/Frontend/CompilerInstance.h:354:5
> #30 0x00005663aadf7555 clang::ASTMergeAction::ExecuteAction() /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/clang/lib/Frontend/ASTMerge.cpp:79:6
> #31 0x00005663aac46514 clang::FrontendAction::Execute() /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/clang/lib/Frontend/FrontendAction.cpp:1226:10
> #32 0x00005663aab92710 getPtr /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/include/llvm/Support/Error.h:278:42
> #33 0x00005663aab92710 operator bool /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/llvm/include/llvm/Support/Error.h:241:16
> #34 0x00005663aab92710 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/clang/lib/Frontend/CompilerInstance.cpp:1056:23
> #35 0x00005663aadb05e3 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:299:25
> #36 0x00005663a5de9e46 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/clang/tools/driver/cc1_main.cpp:297:15
> #37 0x00005663a5de3c83 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/clang/tools/driver/driver.cpp:223:12
> #38 0x00005663a5de2d85 clang_main(int, char**, llvm::ToolContext const&) /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/clang/tools/driver/driver.cpp:264:12
> #39 0x00005663a5dfb78b main /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build_ubsan/tools/clang/tools/driver/clang-driver.cpp:17:10
> #40 0x00007beaafe2a3b8 (/lib/x86_64-linux-gnu/libc.so.6+0x2a3b8)
> #41 0x00007beaafe2a47b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a47b)
> #42 0x00005663a5db47e5 _start (/home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build_ubsan/bin/clang+0xa70b7e5)
> /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build_ubsan/tools/clang/test/ASTMerge/codegen-body/Output/test.c.script: line 3: 2103241 Aborted                 (core dumped) /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build_ubsan/bin/clang -cc1 -internal-isystem /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build_ubsan/lib/clang/22/include -nostdsysteminc -emit-obj -o /dev/null -ast-merge /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build_ubsan/tools/clang/test/ASTMerge/codegen-body/Output/test.c.tmp.1.ast -ast-merge /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm_build_ubsan/tools/clang/test/ASTMerge/codegen-body/Output/test.c.tmp.2.ast /home/b/sanitizer-x86_64-linux-bootstrap-ubsan/build/llvm-project/clang/test/ASTMerge/codegen-body/test.c
> ```

I'll need help investigating what is going wrong. From the stack trace we can only see that `MCAssembler::layout` or writeObject is related, but the exact line information is missing.

A stage-1 `-DLLVM_USE_SANITIZER=Undefined -DLLVM_ENABLE_PROJECTS='clang;lld'` build does not exhibit the MC-related ubsan issues for these tests.

https://github.com/llvm/llvm-project/pull/148544


More information about the llvm-commits mailing list