[clang] [clang] Fix assertion crash in alloc_size structural equivalence check (#199407) (PR #199980)
Marco Elver via cfe-commits
cfe-commits at lists.llvm.org
Wed May 27 07:58:43 PDT 2026
================
@@ -306,6 +306,19 @@ equalAttrArgs(T A1, T A2, StructuralEquivalenceContext &Context) {
return A1 == A2;
}
+// ParamIdx has an explicit specialization because it can be invalid (when
+// representing an optional parameter that was not specified). Two invalid
+// ParamIdx values compare equal; an invalid value is not equal to any valid
+// one. ParamIdx::operator== asserts both sides are valid, so we must guard
+// against the invalid case here before delegating to operator==.
+template <>
+bool equalAttrArgs<ParamIdx>(ParamIdx P1, ParamIdx P2,
+ StructuralEquivalenceContext &) {
+ if (!P1.isValid() || !P2.isValid())
----------------
melver wrote:
`P1.isValid() == P2.isValid()` is clever, but prefer explicit logical flow for clarity.
```
if (P1.isValid() != P2.isValid())
return false;
if (!P1.isValid())
return true;
...
```
https://github.com/llvm/llvm-project/pull/199980
More information about the cfe-commits
mailing list