Skip to content

Commit 17ba7e8

Browse files
committed
apint only
1 parent 5bcc82d commit 17ba7e8

File tree

39 files changed

+125
-74
lines changed

39 files changed

+125
-74
lines changed

clang/lib/AST/ByteCode/IntegralAP.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ template <bool Signed> class IntegralAP final {
6161

6262
IntegralAP(APInt V) : V(V) {}
6363
/// Arbitrary value for uninitialized variables.
64-
IntegralAP() : IntegralAP(-1, 3) {}
64+
IntegralAP() : IntegralAP(Signed ? -1 : 7, 3) {}
6565

6666
IntegralAP operator-() const { return IntegralAP(-V); }
6767
IntegralAP operator-(const IntegralAP &Other) const {
@@ -112,7 +112,9 @@ template <bool Signed> class IntegralAP final {
112112

113113
template <unsigned Bits, bool InputSigned>
114114
static IntegralAP from(Integral<Bits, InputSigned> I, unsigned BitWidth) {
115-
APInt Copy = APInt(BitWidth, static_cast<uint64_t>(I), InputSigned);
115+
// TODO: Avoid implicit trunc?
116+
APInt Copy = APInt(BitWidth, static_cast<uint64_t>(I), InputSigned,
117+
/*implicitTrunc=*/true);
116118

117119
return IntegralAP<Signed>(Copy);
118120
}

clang/lib/CodeGen/CGVTT.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,9 @@ CodeGenVTables::EmitVTTDefinition(llvm::GlobalVariable *VTT,
8585
cast<llvm::StructType>(VTable->getValueType())
8686
->getElementType(AddressPoint.VTableIndex));
8787
unsigned Offset = ComponentSize * AddressPoint.AddressPointIndex;
88-
llvm::ConstantRange InRange(llvm::APInt(32, -Offset, true),
89-
llvm::APInt(32, VTableSize - Offset, true));
88+
llvm::ConstantRange InRange(
89+
llvm::APInt(32, (int)-Offset, true),
90+
llvm::APInt(32, (int)(VTableSize - Offset), true));
9091
llvm::Constant *Init = llvm::ConstantExpr::getGetElementPtr(
9192
VTable->getValueType(), VTable, Idxs, /*InBounds=*/true, InRange);
9293

clang/lib/CodeGen/ItaniumCXXABI.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2099,8 +2099,9 @@ ItaniumCXXABI::getVTableAddressPoint(BaseSubobject Base,
20992099
unsigned VTableSize =
21002100
ComponentSize * Layout.getVTableSize(AddressPoint.VTableIndex);
21012101
unsigned Offset = ComponentSize * AddressPoint.AddressPointIndex;
2102-
llvm::ConstantRange InRange(llvm::APInt(32, -Offset, true),
2103-
llvm::APInt(32, VTableSize - Offset, true));
2102+
llvm::ConstantRange InRange(
2103+
llvm::APInt(32, (int)-Offset, true),
2104+
llvm::APInt(32, (int)(VTableSize - Offset), true));
21042105
return llvm::ConstantExpr::getGetElementPtr(
21052106
VTable->getValueType(), VTable, Indices, /*InBounds=*/true, InRange);
21062107
}

clang/lib/Parse/ParseInit.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,9 @@ ExprResult Parser::createEmbedExpr() {
437437
SourceLocation StartLoc = ConsumeAnnotationToken();
438438
if (Data->BinaryData.size() == 1) {
439439
Res = IntegerLiteral::Create(Context,
440-
llvm::APInt(CHAR_BIT, Data->BinaryData.back()),
440+
llvm::APInt(CHAR_BIT, Data->BinaryData.back(),
441+
/*isSigned=*/false,
442+
/*implicitTrunc=*/true),
441443
Context.UnsignedCharTy, StartLoc);
442444
} else {
443445
auto CreateStringLiteralFromStringRef = [&](StringRef Str, QualType Ty) {

clang/lib/Sema/SemaExpr.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3590,8 +3590,11 @@ ExprResult Sema::ActOnCharacterConstant(const Token &Tok, Scope *UDLScope) {
35903590

35913591
ExprResult Sema::ActOnIntegerConstant(SourceLocation Loc, uint64_t Val) {
35923592
unsigned IntSize = Context.getTargetInfo().getIntWidth();
3593-
return IntegerLiteral::Create(Context, llvm::APInt(IntSize, Val),
3594-
Context.IntTy, Loc);
3593+
// TODO: Avoid implicit trunc?
3594+
return IntegerLiteral::Create(
3595+
Context,
3596+
llvm::APInt(IntSize, Val, /*isSigned=*/false, /*implicitTrunc=*/true),
3597+
Context.IntTy, Loc);
35953598
}
35963599

35973600
static Expr *BuildFloatingLiteral(Sema &S, NumericLiteralParser &Literal,

clang/lib/Sema/SemaOpenMP.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5699,7 +5699,9 @@ StmtResult SemaOpenMP::ActOnOpenMPCanonicalLoop(Stmt *AStmt) {
56995699
llvm_unreachable("unhandled unary increment operator");
57005700
}
57015701
Step = IntegerLiteral::Create(
5702-
Ctx, llvm::APInt(Ctx.getIntWidth(LogicalTy), Direction), LogicalTy, {});
5702+
Ctx,
5703+
llvm::APInt(Ctx.getIntWidth(LogicalTy), Direction, /*isSigned=*/true),
5704+
LogicalTy, {});
57035705
} else if (auto *IncBin = dyn_cast<BinaryOperator>(Inc)) {
57045706
if (IncBin->getOpcode() == BO_AddAssign) {
57055707
Step = IncBin->getRHS();

lldb/source/Expression/DWARFExpression.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -860,10 +860,11 @@ llvm::Expected<Value> DWARFExpression::Evaluate(
860860
// TODO: Implement a real typed stack, and store the genericness of the value
861861
// there.
862862
auto to_generic = [&](auto v) {
863+
// TODO: Avoid implicit trunc?
863864
bool is_signed = std::is_signed<decltype(v)>::value;
864-
return Scalar(llvm::APSInt(
865-
llvm::APInt(8 * opcodes.GetAddressByteSize(), v, is_signed),
866-
!is_signed));
865+
return Scalar(llvm::APSInt(llvm::APInt(8 * opcodes.GetAddressByteSize(), v,
866+
is_signed, /*implicitTrunc=*/true),
867+
!is_signed));
867868
};
868869

869870
// The default kind is a memory location. This is updated by any

llvm/include/llvm/ADT/APFixedPoint.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,9 @@ class APFixedPoint {
159159
}
160160

161161
APFixedPoint(uint64_t Val, const FixedPointSemantics &Sema)
162-
: APFixedPoint(APInt(Sema.getWidth(), Val, Sema.isSigned()), Sema) {}
162+
: APFixedPoint(APInt(Sema.getWidth(), Val, Sema.isSigned(),
163+
/*implicitTrunc=*/true),
164+
Sema) {}
163165

164166
// Zero initialization.
165167
APFixedPoint(const FixedPointSemantics &Sema) : APFixedPoint(0, Sema) {}

llvm/lib/Analysis/ConstantFolding.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,8 @@ Constant *SymbolicallyEvaluateGEP(const GEPOperator *GEP,
887887
APInt Offset = APInt(
888888
BitWidth,
889889
DL.getIndexedOffsetInType(
890-
SrcElemTy, ArrayRef((Value *const *)Ops.data() + 1, Ops.size() - 1)));
890+
SrcElemTy, ArrayRef((Value *const *)Ops.data() + 1, Ops.size() - 1)),
891+
/*isSigned=*/true, /*implicitTrunc=*/true);
891892

892893
std::optional<ConstantRange> InRange = GEP->getInRange();
893894
if (InRange)

llvm/lib/Analysis/Loads.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,8 @@ static bool isDereferenceableAndAlignedPointer(
9595

9696
auto IsKnownDeref = [&]() {
9797
bool CheckForNonNull, CheckForFreed;
98-
APInt KnownDerefBytes(Size.getBitWidth(),
99-
V->getPointerDereferenceableBytes(DL, CheckForNonNull,
100-
CheckForFreed));
101-
if (!KnownDerefBytes.getBoolValue() || !KnownDerefBytes.uge(Size) ||
98+
if (!Size.ule(V->getPointerDereferenceableBytes(DL, CheckForNonNull,
99+
CheckForFreed)) ||
102100
CheckForFreed)
103101
return false;
104102
if (CheckForNonNull &&

0 commit comments

Comments
 (0)