================
@@ -149,24 +149,40 @@ static bool typesCompatible(ASTContext &C, QualType A,
QualType B) {
if (A.getTypePtr() == B.getTypePtr())
return true;
+ const PointerType *ptrA = A->getAs<PointerType>();
+ const PointerType *ptrB = B->getAs<PointerType>();
+
// When neither type is a pointer and exactly one is a record type, check
// target-specific size and alignment. This avoids false positives for
// types that wrap another type with the same layout (e.g.
// std::atomic<int32_t> vs int32_t, or struct{int32_t x;} vs int32_t),
// while preserving warnings for unrelated types that happen to share a
// size (e.g. long vs double, struct A vs struct B).
- if (!A->getAs<PointerType>() && !B->getAs<PointerType>() &&
- (A->isRecordType() != B->isRecordType()) && !A->isIncompleteType() &&
- !B->isIncompleteType() && C.getTypeSize(A) == C.getTypeSize(B) &&
- C.getTypeAlign(A) <= C.getTypeAlign(B))
- return true;
-
- if (const PointerType *ptrA = A->getAs<PointerType>())
- if (const PointerType *ptrB = B->getAs<PointerType>()) {
- A = ptrA->getPointeeType();
- B = ptrB->getPointeeType();
- continue;
+ if (!ptrA && !ptrB && (A->isRecordType() != B->isRecordType()) &&
+ !A->isIncompleteType() && !B->isIncompleteType()) {
+ const RecordType *RecTy = A->getAs<RecordType>();
+ QualType Scalar = B;
+ if (!RecTy) {
+ RecTy = B->getAs<RecordType>();
+ Scalar = A;
}
----------------
steakhal wrote:
I think a declarative style would yield more readable code here. In other
words, coding patterns that avoid mutation.
For example:
```c++
QualType Scalar = ptrA ? A : B;
const RecordType *RecTy = (ptrA ? B : A)->getAs<RecordType>();
```
EDIT: oh, nvm. `ptrA` and `ptrB` can't be null here. Disregard this comment.
https://github.com/llvm/llvm-project/pull/200253
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits