Skip to content

Commit 27ac891

Browse files
committed
implement ASTReader and ASTWriter methods, use auto, rename OBKind enum field
Signed-off-by: Justin Stitt <[email protected]>
1 parent f299de8 commit 27ac891

File tree

8 files changed

+21
-17
lines changed

8 files changed

+21
-17
lines changed

clang/include/clang/AST/TypeBase.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9057,8 +9057,7 @@ inline bool Type::isIntegralOrEnumerationType() const {
90579057
if (const auto *ET = dyn_cast<EnumType>(CanonicalType))
90589058
return IsEnumDeclComplete(ET->getOriginalDecl());
90599059

9060-
if (const OverflowBehaviorType *OBT =
9061-
dyn_cast<OverflowBehaviorType>(CanonicalType))
9060+
if (const auto *OBT = dyn_cast<OverflowBehaviorType>(CanonicalType))
90629061
return OBT->getUnderlyingType()->isIntegralOrEnumerationType();
90639062

90649063
return isBitIntType();

clang/include/clang/Basic/LangOptions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ class LangOptionsBase {
128128
// by sanitizers (PR82432). This field is needed to disambiguate canonical
129129
// wrapping type behaviors from -fwrapv behaviors.
130130
// -fwrapv
131-
OB_FWrapv
131+
OB_SignedAndDefined
132132
};
133133

134134
// FIXME: Unify with TUKind.

clang/lib/AST/Type.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2137,9 +2137,8 @@ bool Type::isIntegralOrUnscopedEnumerationType() const {
21372137
if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType))
21382138
return BT->isInteger();
21392139

2140-
if (const OverflowBehaviorType *OBT =
2141-
dyn_cast<OverflowBehaviorType>(CanonicalType))
2142-
return OBT->getUnderlyingType()->isIntegralOrUnscopedEnumerationType();
2140+
if (const auto *OBT = dyn_cast<OverflowBehaviorType>(CanonicalType))
2141+
return OBT->getUnderlyingType()->isIntegerType();
21432142

21442143
if (isBitIntType())
21452144
return true;

clang/lib/CodeGen/CGExprScalar.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ getOverflowBehaviorConsideringType(const CodeGenFunction &CGF,
217217

218218
switch (CGF.getLangOpts().getSignedOverflowBehavior()) {
219219
case LangOptions::SignedOverflowBehaviorTy::SOB_Defined:
220-
return LangOptions::OverflowBehaviorKind::OB_FWrapv;
220+
return LangOptions::OverflowBehaviorKind::OB_SignedAndDefined;
221221
case LangOptions::SignedOverflowBehaviorTy::SOB_Undefined:
222222
return LangOptions::OverflowBehaviorKind::OB_Unset;
223223
case LangOptions::SignedOverflowBehaviorTy::SOB_Trapping:
@@ -820,7 +820,7 @@ class ScalarExprEmitter
820820
switch (getOverflowBehaviorConsideringType(CGF, Ops.Ty)) {
821821
case LangOptions::OB_Wrap:
822822
return Builder.CreateMul(Ops.LHS, Ops.RHS, "mul");
823-
case LangOptions::OB_FWrapv:
823+
case LangOptions::OB_SignedAndDefined:
824824
if (!hasSan)
825825
return Builder.CreateMul(Ops.LHS, Ops.RHS, "mul");
826826
[[fallthrough]];
@@ -3058,7 +3058,7 @@ llvm::Value *ScalarExprEmitter::EmitIncDecConsiderOverflowBehavior(
30583058
switch (getOverflowBehaviorConsideringType(CGF, Ty)) {
30593059
case LangOptions::OB_Wrap:
30603060
return Builder.CreateAdd(InVal, Amount, Name);
3061-
case LangOptions::OB_FWrapv:
3061+
case LangOptions::OB_SignedAndDefined:
30623062
if (!hasSan)
30633063
return Builder.CreateAdd(InVal, Amount, Name);
30643064
[[fallthrough]];
@@ -4533,7 +4533,7 @@ Value *ScalarExprEmitter::EmitAdd(const BinOpInfo &op) {
45334533
switch (getOverflowBehaviorConsideringType(CGF, op.Ty)) {
45344534
case LangOptions::OB_Wrap:
45354535
return Builder.CreateAdd(op.LHS, op.RHS, "add");
4536-
case LangOptions::OB_FWrapv:
4536+
case LangOptions::OB_SignedAndDefined:
45374537
if (!hasSan)
45384538
return Builder.CreateAdd(op.LHS, op.RHS, "add");
45394539
[[fallthrough]];
@@ -4693,7 +4693,7 @@ Value *ScalarExprEmitter::EmitSub(const BinOpInfo &op) {
46934693
switch (getOverflowBehaviorConsideringType(CGF, op.Ty)) {
46944694
case LangOptions::OB_Wrap:
46954695
return Builder.CreateSub(op.LHS, op.RHS, "sub");
4696-
case LangOptions::OB_FWrapv:
4696+
case LangOptions::OB_SignedAndDefined:
46974697
if (!hasSan)
46984698
return Builder.CreateSub(op.LHS, op.RHS, "sub");
46994699
[[fallthrough]];

clang/lib/Sema/SemaExpr.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1416,8 +1416,8 @@ static QualType handleOverflowBehaviorTypeConversion(Sema &S, ExprResult &LHS,
14161416
QualType LHSType = LHS.get()->getType().getUnqualifiedType();
14171417
QualType RHSType = RHS.get()->getType().getUnqualifiedType();
14181418

1419-
const OverflowBehaviorType *LhsOBT = LHSType->getAs<OverflowBehaviorType>();
1420-
const OverflowBehaviorType *RhsOBT = RHSType->getAs<OverflowBehaviorType>();
1419+
const auto *LhsOBT = LHSType->getAs<OverflowBehaviorType>();
1420+
const auto *RhsOBT = RHSType->getAs<OverflowBehaviorType>();
14211421

14221422
assert(LHSType->isIntegerType() && RHSType->isIntegerType() &&
14231423
"Non-integer type conversion not supported for OverflowBehaviorTypes");
@@ -1697,9 +1697,8 @@ QualType Sema::UsualArithmeticConversions(ExprResult &LHS, ExprResult &RHS,
16971697
LHSType = AtomicLHS->getValueType();
16981698

16991699
// If both types are identical, no conversion is needed.
1700-
if (Context.hasSameType(LHSType, RHSType)) {
1700+
if (Context.hasSameType(LHSType, RHSType))
17011701
return Context.getCommonSugaredType(LHSType, RHSType);
1702-
}
17031702

17041703
// If either side is a non-arithmetic type (e.g. a pointer), we are done.
17051704
// The caller can deal with this (e.g. pointer + int).

clang/lib/Serialization/ASTReader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7478,7 +7478,7 @@ void TypeLocReader::VisitBTFTagAttributedTypeLoc(BTFTagAttributedTypeLoc TL) {
74787478
}
74797479

74807480
void TypeLocReader::VisitOverflowBehaviorTypeLoc(OverflowBehaviorTypeLoc TL) {
7481-
// Nothing to do.
7481+
TL.setAttrLoc(readSourceLocation());
74827482
}
74837483

74847484
void TypeLocReader::VisitHLSLAttributedResourceTypeLoc(

clang/lib/Serialization/ASTWriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ void TypeLocWriter::VisitBTFTagAttributedTypeLoc(BTFTagAttributedTypeLoc TL) {
605605
}
606606

607607
void TypeLocWriter::VisitOverflowBehaviorTypeLoc(OverflowBehaviorTypeLoc TL) {
608-
// Nothing to do.
608+
addSourceLocation(TL.getAttrLoc());
609609
}
610610

611611
void TypeLocWriter::VisitHLSLAttributedResourceTypeLoc(
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// RUN: %clang_cc1 -foverflow-behavior-types -std=c++11 -ast-print %s -o - | FileCheck %s
2+
3+
extern int __attribute__((overflow_behavior(no_wrap))) a;
4+
extern int __attribute__((overflow_behavior(wrap))) b;
5+
6+
// CHECK: extern __no_wrap int a;
7+
// CHECK: extern __wrap int b;

0 commit comments

Comments
 (0)