Skip to content

Commit 8e2e8c2

Browse files
committed
simplify hasWrappingOperand with QualType additions
Signed-off-by: Justin Stitt <[email protected]>
1 parent 7c6581f commit 8e2e8c2

File tree

4 files changed

+9
-16
lines changed

4 files changed

+9
-16
lines changed

clang/include/clang/AST/Type.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,6 +1239,8 @@ class QualType {
12391239
return getQualifiers().hasStrongOrWeakObjCLifetime();
12401240
}
12411241

1242+
bool hasWrapsAttr() const;
1243+
12421244
// true when Type is objc's weak and weak is enabled but ARC isn't.
12431245
bool isNonWeakInMRRWithObjCWeak(const ASTContext &Context) const;
12441246

clang/lib/AST/Expr.cpp

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2238,18 +2238,8 @@ bool BinaryOperator::isNullPointerArithmeticExtension(ASTContext &Ctx,
22382238
}
22392239

22402240
bool BinaryOperator::hasWrappingOperand(const ASTContext &Ctx) const {
2241-
llvm::SmallVector<Expr *, 2> Both = {getLHS(), getRHS()};
2242-
2243-
for (const Expr *oneOf : Both) {
2244-
if (!oneOf)
2245-
continue;
2246-
if (auto *TypePtr =
2247-
oneOf->IgnoreParenImpCasts()->getType().getTypePtrOrNull())
2248-
if (TypePtr->hasAttr(attr::Wraps)) {
2249-
return true;
2250-
}
2251-
}
2252-
return false;
2241+
return getLHS()->getType().hasWrapsAttr() ||
2242+
getRHS()->getType().hasWrapsAttr();
22532243
}
22542244

22552245
SourceLocExpr::SourceLocExpr(const ASTContext &Ctx, SourceLocIdentKind Kind,

clang/lib/AST/Type.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2807,6 +2807,10 @@ bool QualType::isTriviallyEqualityComparableType(
28072807
CanonicalType, /*CheckIfTriviallyCopyable=*/false);
28082808
}
28092809

2810+
bool QualType::hasWrapsAttr() const {
2811+
return !isNull() && getTypePtr()->hasAttr(attr::Wraps);
2812+
}
2813+
28102814
bool QualType::isNonWeakInMRRWithObjCWeak(const ASTContext &Context) const {
28112815
return !Context.getLangOpts().ObjCAutoRefCount &&
28122816
Context.getLangOpts().ObjCWeak &&

clang/lib/CodeGen/CGExprScalar.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,7 @@ struct BinOpInfo {
160160
/// Does the BinaryOperator have the wraps attribute?
161161
/// If so, we can ellide overflow sanitizer checks.
162162
bool hasWrappingOperand() const {
163-
const Type *TyPtr = E->getType().getTypePtrOrNull();
164-
if (TyPtr)
165-
return TyPtr->hasAttr(attr::Wraps);
166-
return false;
163+
return E->getType().hasWrapsAttr();
167164
}
168165
};
169166

0 commit comments

Comments
 (0)