Skip to content

Commit 0ddc83c

Browse files
authored
Invertibility for unchecked pointers (#1127)
* Allow addition and subtraction operators to be invertible for unchecked pointer types * Add tests for checked and unchecked pointer invertibility * Update equivalent expression tests to account for invertible unchecked pointer arithmetic
1 parent 446a9be commit 0ddc83c

File tree

7 files changed

+73
-424
lines changed

7 files changed

+73
-424
lines changed

clang/include/clang/AST/ExprUtils.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,6 @@ class ExprUtil {
133133
static bool EqualValue(ASTContext &Ctx, Expr *E1, Expr *E2,
134134
EquivExprSets *EquivExprs);
135135

136-
// EqualTypes returns true if T1 and T2 are lexicographically equivalent.
137-
static bool EqualTypes(ASTContext &Ctx, QualType T1, QualType T2);
138-
139136
// CheckIsNonModifying suppresses diagnostics while checking
140137
// whether e is a non-modifying expression.
141138
static bool CheckIsNonModifying(Sema &S, Expr *E);

clang/include/clang/AST/NormalizeUtils.h

Lines changed: 0 additions & 91 deletions
This file was deleted.

clang/lib/AST/ExprUtils.cpp

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -262,11 +262,6 @@ bool ExprUtil::EqualValue(ASTContext &Ctx, Expr *E1, Expr *E2,
262262
return R == Lexicographic::Result::Equal;
263263
}
264264

265-
bool ExprUtil::EqualTypes(ASTContext &Ctx, QualType T1, QualType T2) {
266-
Lexicographic::Result R = Lexicographic(Ctx, nullptr).CompareType(T1, T2);
267-
return R == Lexicographic::Result::Equal;
268-
}
269-
270265
bool ExprUtil::CheckIsNonModifying(Sema &S, Expr *E) {
271266
return S.CheckIsNonModifying(E, Sema::NonModifyingContext::NMC_Unknown,
272267
Sema::NonModifyingMessage::NMM_None);
@@ -555,14 +550,14 @@ bool InverseUtil::IsBinaryOperatorInvertible(Sema &S, Expr *LValue,
555550
Expr *LHS = E->getLHS();
556551
Expr *RHS = E->getRHS();
557552

558-
// Addition and subtraction operations must be for checked pointer
559-
// arithmetic or unsigned integer arithmetic.
553+
// Addition and subtraction operations must be for pointer arithmetic
554+
// or unsigned integer arithmetic.
560555
if (Op == BinaryOperatorKind::BO_Add || Op == BinaryOperatorKind::BO_Sub) {
561-
// The operation is checked pointer arithmetic if either the LHS
562-
// or the RHS have checked pointer type.
563-
bool IsCheckedPtrArithmetic = LHS->getType()->isCheckedPointerType() ||
564-
RHS->getType()->isCheckedPointerType();
565-
if (!IsCheckedPtrArithmetic) {
556+
// The operation is pointer arithmetic if either the LHS or the RHS
557+
// have pointer type.
558+
bool IsPtrArithmetic = LHS->getType()->isPointerType() ||
559+
RHS->getType()->isPointerType();
560+
if (!IsPtrArithmetic) {
566561
// The operation is unsigned integer arithmetic if both the LHS
567562
// and the RHS have unsigned integer type.
568563
bool IsUnsignedArithmetic = LHS->getType()->isUnsignedIntegerType() &&

clang/lib/AST/NormalizeUtils.cpp

Lines changed: 0 additions & 195 deletions
This file was deleted.

0 commit comments

Comments
 (0)