[clang] [Sema] Fix false positive warnings for misaligned member access (PR #150025)
Vladimir Vuksanovic via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 25 06:15:08 PDT 2025
================
@@ -15534,17 +15534,28 @@ void Sema::AddPotentialMisalignedMembers(Expr *E, RecordDecl *RD, ValueDecl *MD,
MisalignedMembers.emplace_back(E, RD, MD, Alignment);
}
-void Sema::DiagnoseMisalignedMembers() {
- for (MisalignedMember &m : MisalignedMembers) {
- const NamedDecl *ND = m.RD;
+void Sema::DiagnoseMisalignedMembers(const Expr *E) {
+ // Only emit diagnostics related to the current expression.
+ const auto *EmitFrom = MisalignedMembers.begin();
+ if (E->getSourceRange().isValid()) {
----------------
vvuksanovic wrote:
The idea was to only emit diagnostics for candidates that are contained within the expression that is currently being processed. The candidates that are skipped here will get processed when the appropriate expr is completed, when false positives related to that expr have been discarded.
I agree, we shouldn't rely on source locations for this. I'm working on a fix that makes `MisalignedMembers` a stack similar to `ExprEvalContext` which will be more reliable.
https://github.com/llvm/llvm-project/pull/150025
More information about the cfe-commits
mailing list