Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 this issue Nov 14, 2024 · 4 comments
Labels
clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer crash Prefer [crash-on-valid] or [crash-on-invalid]

Comments

@ZequanWu
Copy link
Contributor

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.

@github-actions github-actions bot added the clang Clang issues not falling into any other category label Nov 14, 2024
@danakj
Copy link
Contributor

danakj commented Nov 14, 2024

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 #91991 can be reverted to reland it, as there's no related bug in that PR afaik.

@danakj
Copy link
Contributor

danakj commented Nov 14, 2024

@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

} else if (const auto *ECE = dyn_cast<ExplicitCastExpr>(Operation)) {
QualType destType = ECE->getType();
if (!isa<PointerType>(destType))
return;
const uint64_t dSize =
Ctx.getTypeSize(destType.getTypePtr()->getPointeeType());
Could you handle triaging this?

@EugeneZelenko EugeneZelenko added clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer crash Prefer [crash-on-valid] or [crash-on-invalid] and removed clang Clang issues not falling into any other category labels Nov 14, 2024
@ZequanWu
Copy link
Contributor Author

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

@ziqingluo-90
Copy link
Contributor

@danakj I will work on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer crash Prefer [crash-on-valid] or [crash-on-invalid]
Projects
None yet
Development

No branches or pull requests

4 participants