llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.09k stars 12k forks source link

Clang crash with -Wunsafe-buffer-usage on assertion failure: const ASTRecordLayout &clang::ASTContext::getASTRecordLayout(const RecordDecl *) const: Assertion `D && "Cannot get layout of forward declarations!"' failed. #116286

Open ZequanWu opened 4 hours ago

ZequanWu commented 4 hours ago

Trunk clang crashes with -Wunsafe-buffer-usage: https://godbolt.org/z/Pjj413W68 and https://godbolt.org/z/j4hnY3eEz.

91991 (reverted) introduced the same crash with -Wunsafe-buffer-usage: https://godbolt.org/z/vcv8d6sYr, which is likely due to the same underlying issue.

danakj commented 4 hours ago

To help make things clear, https://github.com/llvm/llvm-project/pull/91991did not introduce the crash, it exposed the crash in Chromium code because it ran the analysis machinery on code inside field initializers. The crash happens outside of field initializers too, but the problematic code is only in a field initializer in Chromuim.

Once the underlying issue is fixed, the revert of https://github.com/llvm/llvm-project/pull/91991 can be reverted to reland it, as there's no related bug in that PR afaik.

danakj commented 4 hours ago

@haoNoQ I am no longer working in Chromium so I won't have a lot of time to follow up here. And the bug appears to be in the handling of casts in AnalysisBasedWarnings at https://github.com/llvm/llvm-project/blob/7d20ea9d32954e8e5becab8495fa509a3f67b710/clang/lib/Sema/AnalysisBasedWarnings.cpp#L2271-L2277 Could you handle triaging this?

ZequanWu commented 3 hours ago

A further reduced repro for https://godbolt.org/z/vcv8d6sYr: https://godbolt.org/z/1vn6adWhc

ziqingluo-90 commented 1 hour ago

@danakj I will work on it.