Skip to content

TySan: Assertion `D && "Cannot get layout of forward declarations!"' failed #120448

@stbergmann

Description

@stbergmann

With today's LLVM 20 trunk:

$ cat test.c
typedef struct S T;
void f(T *);
extern T x;
void g() { f(&x); }
$ clang -fsanitize=type -c test.c
clang: /home/sberg/github.com/llvm/llvm-project/clang/lib/AST/RecordLayoutBuilder.cpp:3346: const ASTRecordLayout &clang::ASTContext::getASTRecordLayout(const RecordDecl *) const: Assertion `D && "Cannot get layout of forward declarations!"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.	Program arguments: /home/sberg/llvm/inst/bin/clang -fsanitize=type -c test.c
1.	<eof> parser at end of file
2.	test.c:4:6: LLVM IR generation of declaration 'g'
3.	test.c:4:6: Generating code for declaration 'g'
 #0 0x0000000003128ce8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/sberg/github.com/llvm/llvm-project/llvm/lib/Support/Unix/Signals.inc:723:13
 #1 0x0000000003126bc0 llvm::sys::RunSignalHandlers() /home/sberg/github.com/llvm/llvm-project/llvm/lib/Support/Signals.cpp:106:18
 #2 0x00000000030a0d26 (anonymous namespace)::CrashRecoveryContextImpl::HandleCrash(int, unsigned long) /home/sberg/github.com/llvm/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:73:5
 #3 0x00000000030a0d26 CrashRecoverySignalHandler(int) /home/sberg/github.com/llvm/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:390:51
 #4 0x00007f43a91f7dd0 __restore_rt (/lib64/libc.so.6+0x19dd0)
 #5 0x00007f43a9250c94 __pthread_kill_implementation (/lib64/libc.so.6+0x72c94)
 #6 0x00007f43a91f7d1e gsignal (/lib64/libc.so.6+0x19d1e)
 #7 0x00007f43a91df942 abort (/lib64/libc.so.6+0x1942)
 #8 0x00007f43a91df85e _nl_load_domain.cold (/lib64/libc.so.6+0x185e)
 #9 0x00007f43a91efe47 (/lib64/libc.so.6+0x11e47)
#10 0x0000000006042369 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const /home/sberg/github.com/llvm/llvm-project/clang/lib/AST/RecordLayoutBuilder.cpp:3347:3
#11 0x0000000005ad8d75 clang::ASTContext::getTypeInfoImpl(clang::Type const*) const /home/sberg/github.com/llvm/llvm-project/clang/lib/AST/ASTContext.cpp:2399:37
#12 0x0000000005ada1bf clang::ASTContext::getTypeInfo(clang::Type const*) const /home/sberg/github.com/llvm/llvm-project/clang/lib/AST/ASTContext.cpp:1959:17
#13 0x0000000005ad9fa6 clang::ASTContext::getTypeInfoInChars(clang::Type const*) const /home/sberg/github.com/llvm/llvm-project/clang/lib/AST/ASTContext.cpp:1873:19
#14 0x0000000005adaa52 clang::ASTContext::getTypeSizeInChars(clang::Type const*) const /home/sberg/github.com/llvm/llvm-project/clang/lib/AST/ASTContext.cpp:2546:10
#15 0x00000000034b5e1f llvm::ValueIsPresent<clang::Type const*, void>::isPresent(clang::Type const* const&) /home/sberg/github.com/llvm/llvm-project/llvm/include/llvm/Support/Casting.h:622:55
#16 0x00000000034b5e1f bool llvm::detail::isPresent<clang::Type const*>(clang::Type const* const&) /home/sberg/github.com/llvm/llvm-project/llvm/include/llvm/Support/Casting.h:630:10
#17 0x00000000034b5e1f decltype(auto) llvm::dyn_cast<clang::BuiltinType, clang::Type const>(clang::Type const*) /home/sberg/github.com/llvm/llvm-project/llvm/include/llvm/Support/Casting.h:662:3
#18 0x00000000034b5e1f clang::CodeGen::CodeGenTBAA::getTypeInfoHelper(clang::Type const*) /home/sberg/github.com/llvm/llvm-project/clang/lib/CodeGen/CodeGenTBAA.cpp:121:32
#19 0x00000000034b6a8a clang::CodeGen::CodeGenTBAA::getTypeInfo(clang::QualType) /home/sberg/github.com/llvm/llvm-project/clang/lib/CodeGen/CodeGenTBAA.cpp:345:28
#20 0x000000000350196b clang::CodeGen::SanitizerMetadata::reportGlobal(llvm::GlobalVariable*, clang::SourceLocation, llvm::StringRef, clang::QualType, clang::SanitizerMask, bool) /home/sberg/github.com/llvm/llvm-project/clang/lib/CodeGen/SanitizerMetadata.cpp:115:8
#21 0x0000000003501cd4 clang::CodeGen::SanitizerMetadata::reportGlobal(llvm::GlobalVariable*, clang::VarDecl const&, bool) /home/sberg/github.com/llvm/llvm-project/clang/lib/CodeGen/SanitizerMetadata.cpp:0:3
#22 0x000000000344cb99 clang::ValueDecl::getType() const /home/sberg/github.com/llvm/llvm-project/clang/include/clang/AST/Decl.h:682:37
#23 0x000000000344cb99 clang::CodeGen::CodeGenModule::GetOrCreateLLVMGlobal(llvm::StringRef, llvm::Type*, clang::LangAS, clang::VarDecl const*, clang::CodeGen::ForDefinition_t) /home/sberg/github.com/llvm/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:5171:14
#24 0x000000000344fc89 clang::CodeGen::CodeGenModule::GetAddrOfGlobalVar(clang::VarDecl const*, llvm::Type*, clang::CodeGen::ForDefinition_t) /home/sberg/github.com/llvm/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:5265:3
#25 0x000000000372f468 EmitGlobalVarDeclLValue(clang::CodeGen::CodeGenFunction&, clang::Expr const*, clang::VarDecl const*) /home/sberg/github.com/llvm/llvm-project/clang/lib/CodeGen/CGExpr.cpp:2891:28
#26 0x000000000372f468 clang::CodeGen::CodeGenFunction::EmitDeclRefLValue(clang::DeclRefExpr const*) /home/sberg/github.com/llvm/llvm-project/clang/lib/CodeGen/CGExpr.cpp:3128:14
#27 0x000000000372d5f2 clang::CodeGen::CodeGenFunction::EmitLValueHelper(clang::Expr const*, clang::CodeGen::KnownNonNull_t) /home/sberg/github.com/llvm/llvm-project/clang/lib/CodeGen/CGExpr.cpp:1701:5
#28 0x000000000374a529 clang::CodeGen::CodeGenFunction::EmitLValue(clang::Expr const*, clang::CodeGen::KnownNonNull_t)::$_0::operator()() const /home/sberg/github.com/llvm/llvm-project/clang/lib/CodeGen/CGExpr.cpp:1536:30
#29 0x000000000374a529 void llvm::function_ref<void ()>::callback_fn<clang::CodeGen::CodeGenFunction::EmitLValue(clang::Expr const*, clang::CodeGen::KnownNonNull_t)::$_0>(long) /home/sberg/github.com/llvm/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:46:12
#30 0x00000000062651ef clang::StackExhaustionHandler::runWithSufficientStackSpace(clang::SourceLocation, llvm::function_ref<void ()>) /home/sberg/github.com/llvm/llvm-project/clang/lib/Basic/StackExhaustionHandler.cpp:21:1
#31 0x00000000037213c6 clang::CodeGen::CodeGenFunction::EmitLValue(clang::Expr const*, clang::CodeGen::KnownNonNull_t) /home/sberg/github.com/llvm/llvm-project/clang/lib/CodeGen/CGExpr.cpp:1538:7
#32 0x0000000003781c46 (anonymous namespace)::ScalarExprEmitter::VisitUnaryAddrOf(clang::UnaryOperator const*) /home/sberg/github.com/llvm/llvm-project/clang/lib/CodeGen/CGExprScalar.cpp:664:51
#33 0x000000000377485d (anonymous namespace)::ScalarExprEmitter::Visit(clang::Expr*) /home/sberg/github.com/llvm/llvm-project/clang/lib/CodeGen/CGExprScalar.cpp:447:52
#34 0x000000000377485d clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) /home/sberg/github.com/llvm/llvm-project/clang/lib/CodeGen/CGExprScalar.cpp:5581:8
#35 0x0000000003720ca6 clang::CodeGen::RValue::RValue() /home/sberg/github.com/llvm/llvm-project/clang/lib/CodeGen/CGValue.h:62:18
#36 0x0000000003720ca6 clang::CodeGen::RValue::get(llvm::Value*) /home/sberg/github.com/llvm/llvm-project/clang/lib/CodeGen/CGValue.h:99:12
#37 0x0000000003720ca6 clang::CodeGen::CodeGenFunction::EmitAnyExpr(clang::Expr const*, clang::CodeGen::AggValueSlot, bool) /home/sberg/github.com/llvm/llvm-project/clang/lib/CodeGen/CGExpr.cpp:245:12
#38 0x000000000372155f clang::CodeGen::CodeGenFunction::EmitAnyExprToTemp(clang::Expr const*) /home/sberg/github.com/llvm/llvm-project/clang/lib/CodeGen/CGExpr.cpp:265:1
#39 0x00000000036cf81f clang::CodeGen::CallArgList::add(clang::CodeGen::RValue, clang::QualType) /home/sberg/github.com/llvm/llvm-project/clang/lib/CodeGen/CGCall.h:0:0
#40 0x00000000036cf81f clang::CodeGen::CodeGenFunction::EmitCallArg(clang::CodeGen::CallArgList&, clang::Expr const*, clang::QualType) /home/sberg/github.com/llvm/llvm-project/clang/lib/CodeGen/CGCall.cpp:4792:8
#41 0x00000000036ce8ab clang::CodeGen::CodeGenFunction::EmitCallArgs(clang::CodeGen::CallArgList&, clang::CodeGen::CodeGenFunction::PrototypeWrapper, llvm::iterator_range<clang::Stmt::CastIterator<clang::Expr, clang::Expr const* const, clang::Stmt const* const>>, clang::CodeGen::CodeGenFunction::AbstractCallee, unsigned int, clang::CodeGen::CodeGenFunction::EvaluationOrder) /home/sberg/github.com/llvm/llvm-project/clang/lib/CodeGen/CGCall.cpp:4624:5
#42 0x0000000003746c7a clang::CodeGen::CodeGenFunction::EmitCall(clang::QualType, clang::CodeGen::CGCallee const&, clang::CallExpr const*, clang::CodeGen::ReturnValueSlot, llvm::Value*, llvm::CallBase**, clang::CodeGen::CGFunctionInfo const**) /home/sberg/github.com/llvm/llvm-project/clang/lib/CodeGen/CGExpr.cpp:6151:34
#43 0x00000000037458f3 clang::CodeGen::CodeGenFunction::EmitCallExpr(clang::CallExpr const*, clang::CodeGen::ReturnValueSlot, llvm::CallBase**) /home/sberg/github.com/llvm/llvm-project/clang/lib/CodeGen/CGExpr.cpp:0:10
#44 0x000000000378724a clang::CodeGen::RValue::isScalar() const /home/sberg/github.com/llvm/llvm-project/clang/lib/CodeGen/CGValue.h:64:41
#45 0x000000000378724a clang::CodeGen::RValue::getScalarVal() const /home/sberg/github.com/llvm/llvm-project/clang/lib/CodeGen/CGValue.h:72:5
#46 0x000000000378724a (anonymous namespace)::ScalarExprEmitter::VisitCallExpr(clang::CallExpr const*) /home/sberg/github.com/llvm/llvm-project/clang/lib/CodeGen/CGExprScalar.cpp:626:36
#47 0x000000000377485d (anonymous namespace)::ScalarExprEmitter::Visit(clang::Expr*) /home/sberg/github.com/llvm/llvm-project/clang/lib/CodeGen/CGExprScalar.cpp:447:52
#48 0x000000000377485d clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) /home/sberg/github.com/llvm/llvm-project/clang/lib/CodeGen/CGExprScalar.cpp:5581:8
#49 0x0000000003720bba clang::CodeGen::CodeGenFunction::EmitIgnoredExpr(clang::Expr const*) /home/sberg/github.com/llvm/llvm-project/clang/lib/CodeGen/CGExpr.cpp:220:5
#50 0x00000000033b1588 llvm::IRBuilderBase::GetInsertBlock() const /home/sberg/github.com/llvm/llvm-project/llvm/include/llvm/IR/IRBuilder.h:171:47
#51 0x00000000033b1588 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) /home/sberg/github.com/llvm/llvm-project/clang/lib/CodeGen/CGStmt.cpp:130:42
#52 0x00000000033be86c clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) /home/sberg/github.com/llvm/llvm-project/clang/lib/CodeGen/CGStmt.cpp:542:22
#53 0x000000000342915a clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) /home/sberg/github.com/llvm/llvm-project/clang/lib/CodeGen/CodeGenFunction.cpp:0:5
#54 0x000000000342915a clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) /home/sberg/github.com/llvm/llvm-project/clang/lib/CodeGen/CodeGenFunction.cpp:1585:5
#55 0x000000000345086b clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) /home/sberg/github.com/llvm/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:6090:3
#56 0x00000000034490f6 llvm::TimeTraceScope::~TimeTraceScope() /home/sberg/github.com/llvm/llvm-project/llvm/include/llvm/Support/TimeProfiler.h:198:9
#57 0x00000000034490f6 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) /home/sberg/github.com/llvm/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:4219:3
#58 0x000000000344d5e0 clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) /home/sberg/github.com/llvm/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:3930:5
#59 0x0000000003447dc1 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) /home/sberg/github.com/llvm/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:6978:5
#60 0x000000000388c3cc (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) /home/sberg/github.com/llvm/llvm-project/clang/lib/CodeGen/ModuleBuilder.cpp:189:73
#61 0x0000000003883706 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) /home/sberg/github.com/llvm/llvm-project/clang/lib/CodeGen/CodeGenAction.cpp:198:7
#62 0x0000000004ff855a clang::ParseAST(clang::Sema&, bool, bool) /home/sberg/github.com/llvm/llvm-project/clang/lib/Parse/ParseAST.cpp:175:11
#63 0x0000000003ab9c60 clang::FrontendAction::Execute() /home/sberg/github.com/llvm/llvm-project/clang/lib/Frontend/FrontendAction.cpp:1081:10
#64 0x0000000003a3210d llvm::Error::getPtr() const /home/sberg/github.com/llvm/llvm-project/llvm/include/llvm/Support/Error.h:279:42
#65 0x0000000003a3210d llvm::Error::operator bool() /home/sberg/github.com/llvm/llvm-project/llvm/include/llvm/Support/Error.h:242:16
#66 0x0000000003a3210d clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) /home/sberg/github.com/llvm/llvm-project/clang/lib/Frontend/CompilerInstance.cpp:1062:23
#67 0x0000000003b83c79 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) /home/sberg/github.com/llvm/llvm-project/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:296:25
#68 0x0000000000be6e7a cc1_main(llvm::ArrayRef<char const*>, char const*, void*) /home/sberg/github.com/llvm/llvm-project/clang/tools/driver/cc1_main.cpp:286:15
#69 0x0000000000be33b5 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) /home/sberg/github.com/llvm/llvm-project/clang/tools/driver/driver.cpp:218:12
#70 0x00000000038c83e9 clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::$_0::operator()() const /home/sberg/github.com/llvm/llvm-project/clang/lib/Driver/Job.cpp:437:30
#71 0x00000000038c83e9 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::$_0>(long) /home/sberg/github.com/llvm/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:46:12
#72 0x00000000030a0a6e llvm::function_ref<void ()>::operator()() const /home/sberg/github.com/llvm/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:0:12
#73 0x00000000030a0a6e llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) /home/sberg/github.com/llvm/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:426:3
#74 0x00000000038c7b23 clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const /home/sberg/github.com/llvm/llvm-project/clang/lib/Driver/Job.cpp:437:7
#75 0x00000000038918dc clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const /home/sberg/github.com/llvm/llvm-project/clang/lib/Driver/Compilation.cpp:196:15
#76 0x0000000003891af7 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const /home/sberg/github.com/llvm/llvm-project/clang/lib/Driver/Compilation.cpp:250:13
#77 0x00000000038ab378 llvm::SmallVectorBase<unsigned int>::empty() const /home/sberg/github.com/llvm/llvm-project/llvm/include/llvm/ADT/SmallVector.h:81:46
#78 0x00000000038ab378 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) /home/sberg/github.com/llvm/llvm-project/clang/lib/Driver/Driver.cpp:2019:23
#79 0x0000000000be2c88 clang_main(int, char**, llvm::ToolContext const&) /home/sberg/github.com/llvm/llvm-project/clang/tools/driver/driver.cpp:396:21
#80 0x0000000000bf1577 main /home/sberg/llvm/build/tools/clang/tools/driver/clang-driver.cpp:17:10
#81 0x00007f43a91e1248 __libc_start_call_main (/lib64/libc.so.6+0x3248)
#82 0x00007f43a91e130b __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x330b)
#83 0x0000000000be0eb5 _start (/home/sberg/llvm/inst/bin/clang+0xbe0eb5)
clang: error: clang frontend command failed with exit code 134 (use -v to see invocation)
clang version 20.0.0git ([email protected]:llvm/llvm-project.git c5d0e5d1a4344ac6893bfb19fb38a67901a5c411)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/sberg/llvm/inst/bin
Build config: +assertions
clang: note: diagnostic msg: 
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang: note: diagnostic msg: /tmp/test-3e2b6d.c
clang: note: diagnostic msg: /tmp/test-3e2b6d.sh
clang: note: diagnostic msg: 

********************

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:codegenIR generation bugs: mangling, exceptions, etc.compiler-rt:tysanType sanitizercrashPrefer [crash-on-valid] or [crash-on-invalid]

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions