Issue 149078
Summary [clang] Compiling empty file traps ubsan
Labels clang
Assignees
Reporter tbaederr
    If clang is compiled with ubsan:

```
$ touch foo.cpp && bin/clang -c foo.cpp
```
traps ubsan:

```
/home/tbaeder/code/llvm-project/llvm/include/llvm/ADT/ArrayRef.h:387:46: runtime error: addition of unsigned offset to 0x7c7447de6e40 overflowed to 0x7c7447de6dd7
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /home/tbaeder/code/llvm-project/llvm/include/llvm/ADT/ArrayRef.h:387:46
```

Backtrace:
```
 * frame #0: 0x00000000003dfd00 clang`__ubsan_on_report
    frame #1: 0x00000000003d9c1f clang`__ubsan::Diag::~Diag() + 255
    frame #2: 0x00000000003df3ae clang`handlePointerOverflowImpl(__ubsan::PointerOverflowData*, unsigned long, unsigned long, __ubsan::ReportOptions) + 1134
    frame #3: 0x00000000003df408 clang`__ubsan_handle_pointer_overflow_abort + 56
 frame #4: 0x00007fffa36258c6 libLLVM.so.22.0git`llvm::MutableArrayRef<char>::slice(this=0x00007bff82317b30, N=18446744073709551511, M=105) const at ArrayRef.h:387:46
    frame #5: 0x00007fffaf0f5aae libLLVM.so.22.0git`llvm::MCAssembler::layout(this=0x00007d2f833e4800) at MCAssembler.cpp:714:25
    frame #6: 0x00007fffaf0f6a85 libLLVM.so.22.0git`llvm::MCAssembler::Finish(this=0x00007d2f833e4800) at MCAssembler.cpp:732:3
    frame #7: 0x00007fffaf25ac4e libLLVM.so.22.0git`llvm::MCObjectStreamer::finishImpl(this=0x00007e2f833e5500) at MCObjectStreamer.cpp:803:18
    frame #8: 0x00007fffaf1e7032 libLLVM.so.22.0git`llvm::MCELFStreamer::finishImpl(this=0x00007e2f833e5500) at MCELFStreamer.cpp:370:27
    frame #9: 0x00007fffaf2f9274 libLLVM.so.22.0git`llvm::MCStreamer::finish(this=0x00007e2f833e5500, EndLoc=(Ptr = 0x0000000000000000)) at MCStreamer.cpp:1109:3
    frame #10: 0x00007fffa7fdcd28 libLLVM.so.22.0git`llvm::AsmPrinter::doFinalization(this=0x00007d8f8341a780, M=0x00007d7f833e4c80) at AsmPrinter.cpp:2777:16
    frame #11: 0x00007fffa45e1433 libLLVM.so.22.0git`llvm::FPPassManager::doFinalization(this=0x00007d3f833e2640, M=0x00007d7f833e4c80) at LegacyPassManager.cpp:1462:41
    frame #12: 0x00007fffa45d0c67 libLLVM.so.22.0git`(anonymous namespace)::MPPassManager::runOnModule(this=0x00007d4f833e3780, M=0x00007d7f833e4c80) at LegacyPassManager.cpp:1549:41
    frame #13: 0x00007fffa45ceef2 libLLVM.so.22.0git`llvm::legacy::PassManagerImpl::run(this=0x00007d8f83416180, M=0x00007d7f833e4c80) at LegacyPassManager.cpp:531:44
    frame #14: 0x00007fffa45e19e2 libLLVM.so.22.0git`llvm::legacy::PassManager::run(this=0x00007bff8234e020, M=0x00007d7f833e4c80) at LegacyPassManager.cpp:1640:14
    frame #15: 0x00007fffe4398bc7 libclang-cpp.so.22.0git`(anonymous namespace)::EmitAssemblyHelper::RunCodegenPipeline(this=0x00007bff82476b30, Action="" OS=0x00007bff82476bf0, DwoOS=nullptr) at BackendUtil.cpp:1260:19
    frame #16: 0x00007fffe437ed7a libclang-cpp.so.22.0git`(anonymous namespace)::EmitAssemblyHelper::emitAssembly(this=0x00007bff82476b30, Action="" OS=unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream> > @ 0x00007bff82476bf0, BC=0x00007d3f833e1a40) at BackendUtil.cpp:1284:3
    frame #17: 0x00007fffe437b883 libclang-cpp.so.22.0git`clang::emitBackendOutput(CI=0x00007d2f833e26c0, CGOpts=0x00007dcf833e0a90, TDesc=(Data = "" Length = 79), M=0x00007d7f833e4c80, Action="" VFS=(Obj = 0x00007d2f833e1380), OS=nullptr, BC=0x00007d3f833e1a40) at BackendUtil.cpp:1449:13
    frame #18: 0x00007fffe5966eaa libclang-cpp.so.22.0git`clang::BackendConsumer::HandleTranslationUnit(this=0x00007d3f833e1a40, C=0x00007e9f833e0200) at CodeGenAction.cpp:316:3
    frame #19: 0x00007fffdc66c9bd libclang-cpp.so.22.0git`clang::ParseAST(S=0x00007e8f833e5200, PrintStats=false, SkipFunctionBodies=false) at ParseAST.cpp:183:13
    frame #20: 0x00007fffe93574d5 libclang-cpp.so.22.0git`clang::ASTFrontendAction::ExecuteAction(this=0x00007d0f833e3240) at FrontendAction.cpp:1342:3
    frame #21: 0x00007fffe59756f5 libclang-cpp.so.22.0git`clang::CodeGenAction::ExecuteAction(this=0x00007d0f833e3240) at CodeGenAction.cpp:1111:30
    frame #22: 0x00007fffe9355aa0 libclang-cpp.so.22.0git`clang::FrontendAction::Execute(this=0x00007d0f833e3240) at FrontendAction.cpp:1222:3
    frame #23: 0x00007fffe9031273 libclang-cpp.so.22.0git`clang::CompilerInstance::ExecuteAction(this=0x00007d2f833e26c0, Act=0x00007d0f833e3240) at CompilerInstance.cpp:1056:33

```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to