[clang][bytecode] Diagnose comparisons of unrelated zero-sized pointers (#140695)

This commit is contained in:
Timm Baeder 2025-05-20 12:36:18 +02:00 committed by GitHub
parent f62c379f71
commit 67440f0b83
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 0 deletions

View File

@ -1135,6 +1135,14 @@ inline bool CmpHelperEQ<Pointer>(InterpState &S, CodePtr OpPC, CompareFn Fn) {
}
}
if (LHS.isUnknownSizeArray() && RHS.isUnknownSizeArray()) {
const SourceInfo &Loc = S.Current->getSource(OpPC);
S.FFDiag(Loc, diag::note_constexpr_pointer_comparison_zero_sized)
<< LHS.toDiagnosticString(S.getASTContext())
<< RHS.toDiagnosticString(S.getASTContext());
return false;
}
S.Stk.push<BoolT>(BoolT::from(Fn(ComparisonCategoryResult::Unordered)));
return true;
}

View File

@ -243,3 +243,10 @@ namespace Volatile {
// both-note {{in call to 'f(0)'}}
};
}
namespace ZeroSizeCmp {
extern void (*start[])();
extern void (*end[])();
static_assert(&start != &end, ""); // both-error {{constant expression}} \
// both-note {{comparison of pointers '&start' and '&end' to unrelated zero-sized objects}}
}