[clang] [clang][Interp] Add IntegralAP for arbitrary-precision integers (PR #65844)
Timm =?utf-8?q?Bäder?= , Timm =?utf-8?q?Bäder?= , Timm =?utf-8?q?Bäder?= , Timm =?utf-8?q?Bäder?= , Timm =?utf-8?q?Bäder?= Message-ID: In-Reply-To: nico wrote: Better now, thanks! Next time, I'd be nice to mention this issue in the fixup commits so that they're all linked together. Linking them up manually from here: * dcb946a175ae98d432b0a6f8d92105afc992db3e * b52a5c636064ca7138eb996d74941bbe6f07080c https://github.com/llvm/llvm-project/pull/65844 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Add IntegralAP for arbitrary-precision integers (PR #65844)
Timm =?utf-8?q?B=C3=A4der?= , Timm =?utf-8?q?B=C3=A4der?= , Timm =?utf-8?q?B=C3=A4der?= , Timm =?utf-8?q?B=C3=A4der?= , Timm =?utf-8?q?B=C3=A4der?= Message-ID: In-Reply-To: tbaederr wrote: Sigh, will push a fix as soon as my local build is done. https://github.com/llvm/llvm-project/pull/65844 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Add IntegralAP for arbitrary-precision integers (PR #65844)
Timm =?utf-8?q?Bäder?= , Timm =?utf-8?q?Bäder?= , Timm =?utf-8?q?Bäder?= , Timm =?utf-8?q?Bäder?= , Timm =?utf-8?q?Bäder?= Message-ID: In-Reply-To: antmox wrote: Hello, Looks like this also broke lldb-aarch64-windows bot: https://lab.llvm.org/buildbot/#/builders/219/builds/6012 ... https://lab.llvm.org/buildbot/#/builders/219/builds/6041 https://github.com/llvm/llvm-project/pull/65844 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Add IntegralAP for arbitrary-precision integers (PR #65844)
Timm =?utf-8?q?B=C3=A4der?= , Timm =?utf-8?q?B=C3=A4der?= , Timm =?utf-8?q?B=C3=A4der?= , Timm =?utf-8?q?B=C3=A4der?= , Timm =?utf-8?q?B=C3=A4der?= Message-ID: In-Reply-To: nico wrote: Still broken: http://45.33.8.238/win/84419/step_4.txt https://github.com/llvm/llvm-project/pull/65844 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Add IntegralAP for arbitrary-precision integers (PR #65844)
Timm =?utf-8?q?B=C3=A4der?= , Timm =?utf-8?q?B=C3=A4der?= , Timm =?utf-8?q?B=C3=A4der?= , Timm =?utf-8?q?B=C3=A4der?= , Timm =?utf-8?q?B=C3=A4der?= Message-ID: In-Reply-To: tbaederr wrote: I pushed a fix that hopefully works, let me know if it doesn't. https://github.com/llvm/llvm-project/pull/65844 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Add IntegralAP for arbitrary-precision integers (PR #65844)
Timm =?utf-8?q?Bäder?= , Timm =?utf-8?q?Bäder?= , Timm =?utf-8?q?Bäder?= , Timm =?utf-8?q?Bäder?= , Timm =?utf-8?q?Bäder?= Message-ID: In-Reply-To: nico wrote: Looks like this doesn't build on windows: http://45.33.8.238/win/84383/step_4.txt Please take a look and revert for now if it takes a while to fix. https://github.com/llvm/llvm-project/pull/65844 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Add IntegralAP for arbitrary-precision integers (PR #65844)
Timm =?utf-8?q?Bäder?= , Timm =?utf-8?q?Bäder?= , Timm =?utf-8?q?Bäder?= , Timm =?utf-8?q?Bäder?= , Timm =?utf-8?q?Bäder?= Message-ID: In-Reply-To: @@ -26,6 +28,66 @@ static_assert(number != 10, ""); // expected-error{{failed}} \ // expected-note{{evaluates to}} \ // ref-note{{evaluates to}} + +namespace i128 { tbaederr wrote: Oof, sorry. Everything was fine this morning and then I left the house... Will fix immediately. https://github.com/llvm/llvm-project/pull/65844 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Add IntegralAP for arbitrary-precision integers (PR #65844)
Timm =?utf-8?q?Bäder?= , Timm =?utf-8?q?Bäder?= , Timm =?utf-8?q?Bäder?= , Timm =?utf-8?q?Bäder?= , Timm =?utf-8?q?Bäder?= Message-ID: In-Reply-To: @@ -26,6 +28,66 @@ static_assert(number != 10, ""); // expected-error{{failed}} \ // expected-note{{evaluates to}} \ // ref-note{{evaluates to}} + +namespace i128 { s-barannikov wrote: @tbaederr These tests fail on targets that do not have __int128 support. You can reporoduce the issue by adding -triple=avr to the RUN lines. https://github.com/llvm/llvm-project/pull/65844 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Add IntegralAP for arbitrary-precision integers (PR #65844)
Timm =?utf-8?q?Bäder?= , Timm =?utf-8?q?Bäder?= , Timm =?utf-8?q?Bäder?= , Timm =?utf-8?q?Bäder?= , Timm =?utf-8?q?Bäder?= Message-ID: In-Reply-To: https://github.com/tbaederr closed https://github.com/llvm/llvm-project/pull/65844 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Add IntegralAP for arbitrary-precision integers (PR #65844)
Timm =?utf-8?q?B=C3=A4der?= , Timm =?utf-8?q?B=C3=A4der?= , Timm =?utf-8?q?B=C3=A4der?= , Timm =?utf-8?q?B=C3=A4der?= , Timm =?utf-8?q?B=C3=A4der?= Message-ID: In-Reply-To: https://github.com/erichkeane approved this pull request. https://github.com/llvm/llvm-project/pull/65844 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Add IntegralAP for arbitrary-precision integers (PR #65844)
Timm =?utf-8?q?Bäder?= , Timm =?utf-8?q?Bäder?= , Timm =?utf-8?q?Bäder?= , Timm =?utf-8?q?Bäder?= , Timm =?utf-8?q?Bäder?= Message-ID: In-Reply-To: https://github.com/tbaederr updated https://github.com/llvm/llvm-project/pull/65844 >From 0d879e0dc2ae8bb24e396dc0cf1a6e7215fb1e2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Sat, 9 Sep 2023 10:34:26 +0200 Subject: [PATCH 1/6] [clang][Interp] Add IntegralAP for arbitrary-precision integers --- clang/lib/AST/Interp/ByteCodeExprGen.cpp | 11 +- clang/lib/AST/Interp/Context.cpp | 6 +- clang/lib/AST/Interp/Descriptor.cpp | 9 + clang/lib/AST/Interp/EvalEmitter.cpp | 1 + clang/lib/AST/Interp/Integral.h | 4 + clang/lib/AST/Interp/IntegralAP.h| 253 +++ clang/lib/AST/Interp/Interp.h| 21 +- clang/lib/AST/Interp/InterpStack.h | 5 + clang/lib/AST/Interp/Opcodes.td | 8 +- clang/lib/AST/Interp/PrimType.cpp| 1 + clang/lib/AST/Interp/PrimType.h | 13 ++ clang/test/AST/Interp/literals.cpp | 24 +++ 12 files changed, 343 insertions(+), 13 deletions(-) create mode 100644 clang/lib/AST/Interp/IntegralAP.h diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp index e813d4fa651ceaf..ca762e795ec6f4b 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -171,14 +171,17 @@ bool ByteCodeExprGen::VisitCastExpr(const CastExpr *CE) { return this->discard(SubExpr); std::optional FromT = classify(SubExpr->getType()); std::optional ToT = classify(CE->getType()); + if (!FromT || !ToT) return false; if (!this->visit(SubExpr)) return false; -if (FromT == ToT) +if (FromT == ToT) { + assert(ToT != PT_IntAP && ToT != PT_IntAPS); return true; +} return this->emitCast(*FromT, *ToT, CE); } @@ -1598,6 +1601,9 @@ bool ByteCodeExprGen::visitZeroInitializer(QualType QT, return this->emitZeroSint64(E); case PT_Uint64: return this->emitZeroUint64(E); + case PT_IntAP: + case PT_IntAPS: +assert(false); case PT_Ptr: return this->emitNullPtr(E); case PT_FnPtr: @@ -1837,6 +1843,9 @@ bool ByteCodeExprGen::emitConst(T Value, PrimType Ty, const Expr *E) { return this->emitConstSint64(Value, E); case PT_Uint64: return this->emitConstUint64(Value, E); + case PT_IntAP: + case PT_IntAPS: +assert(false); case PT_Bool: return this->emitConstBool(Value, E); case PT_Ptr: diff --git a/clang/lib/AST/Interp/Context.cpp b/clang/lib/AST/Interp/Context.cpp index e84c0f6aae7ee93..b94fd1ab6d53574 100644 --- a/clang/lib/AST/Interp/Context.cpp +++ b/clang/lib/AST/Interp/Context.cpp @@ -103,7 +103,8 @@ std::optional Context::classify(QualType T) const { case 8: return PT_Sint8; default: - return std::nullopt; + return PT_IntAPS; + // return std::nullopt; } } @@ -118,7 +119,8 @@ std::optional Context::classify(QualType T) const { case 8: return PT_Uint8; default: - return std::nullopt; + return PT_IntAP; + // return std::nullopt; } } diff --git a/clang/lib/AST/Interp/Descriptor.cpp b/clang/lib/AST/Interp/Descriptor.cpp index db49a569eff33ea..4ecb7466998e705 100644 --- a/clang/lib/AST/Interp/Descriptor.cpp +++ b/clang/lib/AST/Interp/Descriptor.cpp @@ -10,6 +10,7 @@ #include "Boolean.h" #include "Floating.h" #include "FunctionPointer.h" +#include "IntegralAP.h" #include "Pointer.h" #include "PrimType.h" #include "Record.h" @@ -182,6 +183,10 @@ static BlockCtorFn getCtorPrim(PrimType Type) { // constructor called. if (Type == PT_Float) return ctorTy::T>; + if (Type == PT_IntAP) +return ctorTy::T>; + if (Type == PT_IntAPS) +return ctorTy::T>; COMPOSITE_TYPE_SWITCH(Type, return ctorTy, return nullptr); } @@ -191,6 +196,10 @@ static BlockDtorFn getDtorPrim(PrimType Type) { // destructor called, since they might allocate memory. if (Type == PT_Float) return dtorTy::T>; + if (Type == PT_IntAP) +return dtorTy::T>; + if (Type == PT_IntAPS) +return dtorTy::T>; COMPOSITE_TYPE_SWITCH(Type, return dtorTy, return nullptr); } diff --git a/clang/lib/AST/Interp/EvalEmitter.cpp b/clang/lib/AST/Interp/EvalEmitter.cpp index bdf800c60f1723f..f46ef1067cf52a0 100644 --- a/clang/lib/AST/Interp/EvalEmitter.cpp +++ b/clang/lib/AST/Interp/EvalEmitter.cpp @@ -9,6 +9,7 @@ #include "EvalEmitter.h" #include "ByteCodeGenError.h" #include "Context.h" +#include "IntegralAP.h" #include "Interp.h" #include "Opcode.h" #include "clang/AST/DeclCXX.h" diff --git a/clang/lib/AST/Interp/Integral.h b/clang/lib/AST/Interp/Integral.h index 72285cabcbbf8ce..f8e529aa3392696 100644 --- a/clang/lib/AST/Interp/Integral.h +++ b/clang/lib/AST/Interp/Integral.h @@ -29,6 +29,8 @@ namespace interp { using APInt = llvm::APInt; using APSInt =
[clang] [clang][Interp] Add IntegralAP for arbitrary-precision integers (PR #65844)
Timm =?utf-8?q?Bäder?= , Timm =?utf-8?q?Bäder?= , Timm =?utf-8?q?Bäder?= , Timm =?utf-8?q?Bäder?= Message-ID: In-Reply-To: https://github.com/tbaederr resolved https://github.com/llvm/llvm-project/pull/65844 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Add IntegralAP for arbitrary-precision integers (PR #65844)
Timm =?utf-8?q?Bäder?= , Timm =?utf-8?q?Bäder?= , Timm =?utf-8?q?Bäder?= , Timm =?utf-8?q?Bäder?= Message-ID: In-Reply-To: @@ -0,0 +1,249 @@ +//===--- Integral.h - Wrapper for numeric types for the VM --*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +// Defines the VM types and helpers operating on types. +// +//===--===// + +#ifndef LLVM_CLANG_AST_INTERP_INTEGRAL_AP_H +#define LLVM_CLANG_AST_INTERP_INTEGRAL_AP_H + +#include "clang/AST/APValue.h" +#include "clang/AST/ComparisonCategories.h" +#include "llvm/ADT/APSInt.h" +#include "llvm/Support/MathExtras.h" +#include "llvm/Support/raw_ostream.h" +#include +#include + +#include "Primitives.h" + +namespace clang { +namespace interp { + +using APInt = llvm::APInt; +using APSInt = llvm::APSInt; +template class Integral; +class Boolean; + +template class IntegralAP final { +public: + APSInt V; + +public: + using AsUnsigned = IntegralAP; + + template + IntegralAP(T Value) : V(APInt(sizeof(T) * 8, Value, std::is_signed_v)) {} + + IntegralAP(APInt V) : V(V) {} + IntegralAP(APSInt V) : V(V) {} + /// Arbitrary value for initialized variables. + IntegralAP() : V(APSInt::getMaxValue(1024, Signed)) {} + + IntegralAP operator-() const { return IntegralAP(-V); } + bool operator>(IntegralAP RHS) const { return V > RHS.V; } + bool operator>=(IntegralAP RHS) const { return V >= RHS.V; } + bool operator<(IntegralAP RHS) const { return V < RHS.V; } + bool operator<=(IntegralAP RHS) const { return V <= RHS.V; } + + explicit operator bool() const { return !V.isZero(); } + explicit operator int8_t() const { return V.getSExtValue(); } + explicit operator uint8_t() const { return V.getZExtValue(); } + explicit operator int16_t() const { return V.getSExtValue(); } + explicit operator uint16_t() const { return V.getZExtValue(); } + explicit operator int32_t() const { return V.getSExtValue(); } + explicit operator uint32_t() const { return V.getZExtValue(); } + explicit operator int64_t() const { return V.getSExtValue(); } + explicit operator uint64_t() const { return V.getZExtValue(); } + + template static IntegralAP from(T Value, unsigned NumBits = 0) { +assert(NumBits > 0); +APSInt Copy = APSInt(APInt(NumBits, Value, Signed), !Signed); + +return IntegralAP(Copy); + } + + template + static IntegralAP from(IntegralAP V, unsigned NumBits = 0) { +if constexpr (Signed == InputSigned) + return V; + +APSInt Copy = V.V; +Copy.setIsSigned(Signed); + +return IntegralAP(Copy); + } + + template + static IntegralAP from(Integral I) { +// FIXME: Take bits parameter. +APSInt Copy = +APSInt(APInt(128, static_cast(I), InputSigned), !Signed); +Copy.setIsSigned(Signed); + +assert(Copy.isSigned() == Signed); +return IntegralAP(Copy); + } + static IntegralAP from(const Boolean ) { +assert(false); +return IntegralAP::zero(); + } + + static IntegralAP zero() { +assert(false); +return IntegralAP(0); + } + + static constexpr unsigned bitWidth() { return 128; } + + APSInt toAPSInt(unsigned Bits = 0) const { return V; } + APValue toAPValue() const { return APValue(V); } + + bool isZero() const { return V.isZero(); } + bool isPositive() const { return V.isNonNegative(); } + bool isNegative() const { return !V.isNonNegative(); } + bool isMin() const { return V.isMinValue(); } + bool isMax() const { return V.isMaxValue(); } + static bool isSigned() { return Signed; } + bool isMinusOne() const { return Signed && V == -1; } + + unsigned countLeadingZeros() const { return V.countl_zero(); } + + void print(llvm::raw_ostream ) const { OS << V; } + + IntegralAP truncate(unsigned bitWidth) const { return V; } erichkeane wrote: Can you 'assert false' everything that isn't implemented yet? At least that way it'll prevent really awkward to find bugs in the future. https://github.com/llvm/llvm-project/pull/65844 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Add IntegralAP for arbitrary-precision integers (PR #65844)
Timm =?utf-8?q?Bäder?= , Timm =?utf-8?q?Bäder?= , Timm =?utf-8?q?Bäder?= , Timm =?utf-8?q?Bäder?= Message-ID: In-Reply-To: https://github.com/tbaederr updated https://github.com/llvm/llvm-project/pull/65844 >From 41ea723998954938a00a0de482ef000f1f3af980 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Sat, 9 Sep 2023 10:34:26 +0200 Subject: [PATCH 1/5] [clang][Interp] Add IntegralAP for arbitrary-precision integers --- clang/lib/AST/Interp/ByteCodeExprGen.cpp | 11 +- clang/lib/AST/Interp/Context.cpp | 6 +- clang/lib/AST/Interp/Descriptor.cpp | 9 + clang/lib/AST/Interp/EvalEmitter.cpp | 1 + clang/lib/AST/Interp/Integral.h | 4 + clang/lib/AST/Interp/IntegralAP.h| 253 +++ clang/lib/AST/Interp/Interp.h| 21 +- clang/lib/AST/Interp/InterpStack.h | 5 + clang/lib/AST/Interp/Opcodes.td | 8 +- clang/lib/AST/Interp/PrimType.cpp| 1 + clang/lib/AST/Interp/PrimType.h | 13 ++ clang/test/AST/Interp/literals.cpp | 24 +++ 12 files changed, 343 insertions(+), 13 deletions(-) create mode 100644 clang/lib/AST/Interp/IntegralAP.h diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp index e813d4fa651ceaf..ca762e795ec6f4b 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -171,14 +171,17 @@ bool ByteCodeExprGen::VisitCastExpr(const CastExpr *CE) { return this->discard(SubExpr); std::optional FromT = classify(SubExpr->getType()); std::optional ToT = classify(CE->getType()); + if (!FromT || !ToT) return false; if (!this->visit(SubExpr)) return false; -if (FromT == ToT) +if (FromT == ToT) { + assert(ToT != PT_IntAP && ToT != PT_IntAPS); return true; +} return this->emitCast(*FromT, *ToT, CE); } @@ -1598,6 +1601,9 @@ bool ByteCodeExprGen::visitZeroInitializer(QualType QT, return this->emitZeroSint64(E); case PT_Uint64: return this->emitZeroUint64(E); + case PT_IntAP: + case PT_IntAPS: +assert(false); case PT_Ptr: return this->emitNullPtr(E); case PT_FnPtr: @@ -1837,6 +1843,9 @@ bool ByteCodeExprGen::emitConst(T Value, PrimType Ty, const Expr *E) { return this->emitConstSint64(Value, E); case PT_Uint64: return this->emitConstUint64(Value, E); + case PT_IntAP: + case PT_IntAPS: +assert(false); case PT_Bool: return this->emitConstBool(Value, E); case PT_Ptr: diff --git a/clang/lib/AST/Interp/Context.cpp b/clang/lib/AST/Interp/Context.cpp index 1c1aacbc8bb9e7d..e51c45329b9ead6 100644 --- a/clang/lib/AST/Interp/Context.cpp +++ b/clang/lib/AST/Interp/Context.cpp @@ -103,7 +103,8 @@ std::optional Context::classify(QualType T) const { case 8: return PT_Sint8; default: - return std::nullopt; + return PT_IntAPS; + // return std::nullopt; } } @@ -118,7 +119,8 @@ std::optional Context::classify(QualType T) const { case 8: return PT_Uint8; default: - return std::nullopt; + return PT_IntAP; + // return std::nullopt; } } diff --git a/clang/lib/AST/Interp/Descriptor.cpp b/clang/lib/AST/Interp/Descriptor.cpp index db49a569eff33ea..4ecb7466998e705 100644 --- a/clang/lib/AST/Interp/Descriptor.cpp +++ b/clang/lib/AST/Interp/Descriptor.cpp @@ -10,6 +10,7 @@ #include "Boolean.h" #include "Floating.h" #include "FunctionPointer.h" +#include "IntegralAP.h" #include "Pointer.h" #include "PrimType.h" #include "Record.h" @@ -182,6 +183,10 @@ static BlockCtorFn getCtorPrim(PrimType Type) { // constructor called. if (Type == PT_Float) return ctorTy::T>; + if (Type == PT_IntAP) +return ctorTy::T>; + if (Type == PT_IntAPS) +return ctorTy::T>; COMPOSITE_TYPE_SWITCH(Type, return ctorTy, return nullptr); } @@ -191,6 +196,10 @@ static BlockDtorFn getDtorPrim(PrimType Type) { // destructor called, since they might allocate memory. if (Type == PT_Float) return dtorTy::T>; + if (Type == PT_IntAP) +return dtorTy::T>; + if (Type == PT_IntAPS) +return dtorTy::T>; COMPOSITE_TYPE_SWITCH(Type, return dtorTy, return nullptr); } diff --git a/clang/lib/AST/Interp/EvalEmitter.cpp b/clang/lib/AST/Interp/EvalEmitter.cpp index bdf800c60f1723f..f46ef1067cf52a0 100644 --- a/clang/lib/AST/Interp/EvalEmitter.cpp +++ b/clang/lib/AST/Interp/EvalEmitter.cpp @@ -9,6 +9,7 @@ #include "EvalEmitter.h" #include "ByteCodeGenError.h" #include "Context.h" +#include "IntegralAP.h" #include "Interp.h" #include "Opcode.h" #include "clang/AST/DeclCXX.h" diff --git a/clang/lib/AST/Interp/Integral.h b/clang/lib/AST/Interp/Integral.h index 72285cabcbbf8ce..f8e529aa3392696 100644 --- a/clang/lib/AST/Interp/Integral.h +++ b/clang/lib/AST/Interp/Integral.h @@ -29,6 +29,8 @@ namespace interp { using APInt = llvm::APInt; using APSInt = llvm::APSInt; +template
[clang] [clang][Interp] Add IntegralAP for arbitrary-precision integers (PR #65844)
Timm =?utf-8?q?Bäder?= , Timm =?utf-8?q?Bäder?= , Timm =?utf-8?q?Bäder?= Message-ID: In-Reply-To: https://github.com/tbaederr resolved https://github.com/llvm/llvm-project/pull/65844 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Add IntegralAP for arbitrary-precision integers (PR #65844)
Timm =?utf-8?q?Bäder?= , Timm =?utf-8?q?Bäder?= , Timm =?utf-8?q?Bäder?= Message-ID: In-Reply-To: @@ -0,0 +1,249 @@ +//===--- Integral.h - Wrapper for numeric types for the VM --*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +// Defines the VM types and helpers operating on types. +// +//===--===// + +#ifndef LLVM_CLANG_AST_INTERP_INTEGRAL_AP_H +#define LLVM_CLANG_AST_INTERP_INTEGRAL_AP_H + +#include "clang/AST/APValue.h" +#include "clang/AST/ComparisonCategories.h" +#include "llvm/ADT/APSInt.h" +#include "llvm/Support/MathExtras.h" +#include "llvm/Support/raw_ostream.h" +#include +#include + +#include "Primitives.h" + +namespace clang { +namespace interp { + +using APInt = llvm::APInt; +using APSInt = llvm::APSInt; +template class Integral; +class Boolean; + +template class IntegralAP final { +public: + APSInt V; + +public: + using AsUnsigned = IntegralAP; + + template + IntegralAP(T Value) : V(APInt(sizeof(T) * 8, Value, std::is_signed_v)) {} + + IntegralAP(APInt V) : V(V) {} + IntegralAP(APSInt V) : V(V) {} + /// Arbitrary value for initialized variables. + IntegralAP() : V(APSInt::getMaxValue(1024, Signed)) {} + + IntegralAP operator-() const { return IntegralAP(-V); } + bool operator>(IntegralAP RHS) const { return V > RHS.V; } + bool operator>=(IntegralAP RHS) const { return V >= RHS.V; } + bool operator<(IntegralAP RHS) const { return V < RHS.V; } + bool operator<=(IntegralAP RHS) const { return V <= RHS.V; } + + explicit operator bool() const { return !V.isZero(); } + explicit operator int8_t() const { return V.getSExtValue(); } + explicit operator uint8_t() const { return V.getZExtValue(); } + explicit operator int16_t() const { return V.getSExtValue(); } + explicit operator uint16_t() const { return V.getZExtValue(); } + explicit operator int32_t() const { return V.getSExtValue(); } + explicit operator uint32_t() const { return V.getZExtValue(); } + explicit operator int64_t() const { return V.getSExtValue(); } + explicit operator uint64_t() const { return V.getZExtValue(); } + + template static IntegralAP from(T Value, unsigned NumBits = 0) { +assert(NumBits > 0); +APSInt Copy = APSInt(APInt(NumBits, Value, Signed), !Signed); + +return IntegralAP(Copy); + } + + template + static IntegralAP from(IntegralAP V, unsigned NumBits = 0) { +if constexpr (Signed == InputSigned) + return V; + +APSInt Copy = V.V; +Copy.setIsSigned(Signed); + +return IntegralAP(Copy); + } + + template + static IntegralAP from(Integral I) { +// FIXME: Take bits parameter. +APSInt Copy = +APSInt(APInt(128, static_cast(I), InputSigned), !Signed); +Copy.setIsSigned(Signed); + +assert(Copy.isSigned() == Signed); +return IntegralAP(Copy); + } + static IntegralAP from(const Boolean ) { +assert(false); +return IntegralAP::zero(); + } + + static IntegralAP zero() { +assert(false); +return IntegralAP(0); + } + + static constexpr unsigned bitWidth() { return 128; } + + APSInt toAPSInt(unsigned Bits = 0) const { return V; } + APValue toAPValue() const { return APValue(V); } + + bool isZero() const { return V.isZero(); } + bool isPositive() const { return V.isNonNegative(); } + bool isNegative() const { return !V.isNonNegative(); } + bool isMin() const { return V.isMinValue(); } + bool isMax() const { return V.isMaxValue(); } + static bool isSigned() { return Signed; } + bool isMinusOne() const { return Signed && V == -1; } + + unsigned countLeadingZeros() const { return V.countl_zero(); } + + void print(llvm::raw_ostream ) const { OS << V; } + + IntegralAP truncate(unsigned bitWidth) const { return V; } + IntegralAP toUnsigned() const { +APSInt Copy = V; +Copy.setIsSigned(false); +return IntegralAP(Copy); + } + + ComparisonCategoryResult compare(const IntegralAP ) const { +return Compare(V, RHS.V); + } + + static bool increment(IntegralAP A, IntegralAP *R) { +*R = IntegralAP(A.V - 1); tbaederr wrote: Yes, definitely. I'll fix this but it's not important until I implement increment operators. https://github.com/llvm/llvm-project/pull/65844 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Add IntegralAP for arbitrary-precision integers (PR #65844)
Timm =?utf-8?q?Bäder?= , Timm =?utf-8?q?Bäder?= , Timm =?utf-8?q?Bäder?= Message-ID: In-Reply-To: @@ -0,0 +1,249 @@ +//===--- Integral.h - Wrapper for numeric types for the VM --*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +// Defines the VM types and helpers operating on types. +// +//===--===// + +#ifndef LLVM_CLANG_AST_INTERP_INTEGRAL_AP_H +#define LLVM_CLANG_AST_INTERP_INTEGRAL_AP_H + +#include "clang/AST/APValue.h" +#include "clang/AST/ComparisonCategories.h" +#include "llvm/ADT/APSInt.h" +#include "llvm/Support/MathExtras.h" +#include "llvm/Support/raw_ostream.h" +#include +#include + +#include "Primitives.h" + +namespace clang { +namespace interp { + +using APInt = llvm::APInt; +using APSInt = llvm::APSInt; +template class Integral; +class Boolean; + +template class IntegralAP final { +public: + APSInt V; + +public: + using AsUnsigned = IntegralAP; + + template + IntegralAP(T Value) : V(APInt(sizeof(T) * 8, Value, std::is_signed_v)) {} + + IntegralAP(APInt V) : V(V) {} + IntegralAP(APSInt V) : V(V) {} + /// Arbitrary value for initialized variables. + IntegralAP() : V(APSInt::getMaxValue(1024, Signed)) {} + + IntegralAP operator-() const { return IntegralAP(-V); } + bool operator>(IntegralAP RHS) const { return V > RHS.V; } + bool operator>=(IntegralAP RHS) const { return V >= RHS.V; } + bool operator<(IntegralAP RHS) const { return V < RHS.V; } + bool operator<=(IntegralAP RHS) const { return V <= RHS.V; } + + explicit operator bool() const { return !V.isZero(); } + explicit operator int8_t() const { return V.getSExtValue(); } + explicit operator uint8_t() const { return V.getZExtValue(); } + explicit operator int16_t() const { return V.getSExtValue(); } + explicit operator uint16_t() const { return V.getZExtValue(); } + explicit operator int32_t() const { return V.getSExtValue(); } + explicit operator uint32_t() const { return V.getZExtValue(); } + explicit operator int64_t() const { return V.getSExtValue(); } + explicit operator uint64_t() const { return V.getZExtValue(); } + + template static IntegralAP from(T Value, unsigned NumBits = 0) { +assert(NumBits > 0); +APSInt Copy = APSInt(APInt(NumBits, Value, Signed), !Signed); + +return IntegralAP(Copy); + } + + template + static IntegralAP from(IntegralAP V, unsigned NumBits = 0) { +if constexpr (Signed == InputSigned) + return V; + +APSInt Copy = V.V; +Copy.setIsSigned(Signed); + +return IntegralAP(Copy); + } + + template + static IntegralAP from(Integral I) { +// FIXME: Take bits parameter. +APSInt Copy = +APSInt(APInt(128, static_cast(I), InputSigned), !Signed); +Copy.setIsSigned(Signed); + +assert(Copy.isSigned() == Signed); +return IntegralAP(Copy); + } + static IntegralAP from(const Boolean ) { +assert(false); +return IntegralAP::zero(); + } + + static IntegralAP zero() { +assert(false); +return IntegralAP(0); + } + + static constexpr unsigned bitWidth() { return 128; } + + APSInt toAPSInt(unsigned Bits = 0) const { return V; } + APValue toAPValue() const { return APValue(V); } + + bool isZero() const { return V.isZero(); } + bool isPositive() const { return V.isNonNegative(); } + bool isNegative() const { return !V.isNonNegative(); } + bool isMin() const { return V.isMinValue(); } + bool isMax() const { return V.isMaxValue(); } + static bool isSigned() { return Signed; } + bool isMinusOne() const { return Signed && V == -1; } + + unsigned countLeadingZeros() const { return V.countl_zero(); } + + void print(llvm::raw_ostream ) const { OS << V; } + + IntegralAP truncate(unsigned bitWidth) const { return V; } tbaederr wrote: Same reason as above - not yet :) https://github.com/llvm/llvm-project/pull/65844 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Add IntegralAP for arbitrary-precision integers (PR #65844)
Timm =?utf-8?q?Bäder?= , Timm =?utf-8?q?Bäder?= , Timm =?utf-8?q?Bäder?= Message-ID: In-Reply-To: @@ -1596,6 +1599,9 @@ bool ByteCodeExprGen::visitZeroInitializer(QualType QT, return this->emitZeroSint64(E); case PT_Uint64: return this->emitZeroUint64(E); + case PT_IntAP: + case PT_IntAPS: +assert(false); tbaederr wrote: All the `assert(false)` in this patch are just placeholders for things I need to implement in later patches. I'm trying to keep the patches smaller so they are easier to review. https://github.com/llvm/llvm-project/pull/65844 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Add IntegralAP for arbitrary-precision integers (PR #65844)
Timm =?utf-8?q?Bäder?= , Timm =?utf-8?q?Bäder?= , Timm =?utf-8?q?Bäder?= Message-ID: In-Reply-To: @@ -0,0 +1,249 @@ +//===--- Integral.h - Wrapper for numeric types for the VM --*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +// Defines the VM types and helpers operating on types. +// +//===--===// + +#ifndef LLVM_CLANG_AST_INTERP_INTEGRAL_AP_H +#define LLVM_CLANG_AST_INTERP_INTEGRAL_AP_H + +#include "clang/AST/APValue.h" +#include "clang/AST/ComparisonCategories.h" +#include "llvm/ADT/APSInt.h" +#include "llvm/Support/MathExtras.h" +#include "llvm/Support/raw_ostream.h" +#include +#include + +#include "Primitives.h" + +namespace clang { +namespace interp { + +using APInt = llvm::APInt; +using APSInt = llvm::APSInt; +template class Integral; +class Boolean; + +template class IntegralAP final { +public: + APSInt V; + +public: + using AsUnsigned = IntegralAP; + + template + IntegralAP(T Value) : V(APInt(sizeof(T) * 8, Value, std::is_signed_v)) {} + + IntegralAP(APInt V) : V(V) {} + IntegralAP(APSInt V) : V(V) {} + /// Arbitrary value for initialized variables. + IntegralAP() : V(APSInt::getMaxValue(1024, Signed)) {} + + IntegralAP operator-() const { return IntegralAP(-V); } + bool operator>(IntegralAP RHS) const { return V > RHS.V; } + bool operator>=(IntegralAP RHS) const { return V >= RHS.V; } + bool operator<(IntegralAP RHS) const { return V < RHS.V; } + bool operator<=(IntegralAP RHS) const { return V <= RHS.V; } + + explicit operator bool() const { return !V.isZero(); } + explicit operator int8_t() const { return V.getSExtValue(); } + explicit operator uint8_t() const { return V.getZExtValue(); } + explicit operator int16_t() const { return V.getSExtValue(); } + explicit operator uint16_t() const { return V.getZExtValue(); } + explicit operator int32_t() const { return V.getSExtValue(); } + explicit operator uint32_t() const { return V.getZExtValue(); } + explicit operator int64_t() const { return V.getSExtValue(); } + explicit operator uint64_t() const { return V.getZExtValue(); } + + template static IntegralAP from(T Value, unsigned NumBits = 0) { +assert(NumBits > 0); +APSInt Copy = APSInt(APInt(NumBits, Value, Signed), !Signed); + +return IntegralAP(Copy); + } + + template + static IntegralAP from(IntegralAP V, unsigned NumBits = 0) { +if constexpr (Signed == InputSigned) + return V; + +APSInt Copy = V.V; +Copy.setIsSigned(Signed); + +return IntegralAP(Copy); + } + + template + static IntegralAP from(Integral I) { +// FIXME: Take bits parameter. +APSInt Copy = +APSInt(APInt(128, static_cast(I), InputSigned), !Signed); +Copy.setIsSigned(Signed); + +assert(Copy.isSigned() == Signed); +return IntegralAP(Copy); + } + static IntegralAP from(const Boolean ) { +assert(false); +return IntegralAP::zero(); + } + + static IntegralAP zero() { +assert(false); +return IntegralAP(0); + } + + static constexpr unsigned bitWidth() { return 128; } + + APSInt toAPSInt(unsigned Bits = 0) const { return V; } + APValue toAPValue() const { return APValue(V); } + + bool isZero() const { return V.isZero(); } + bool isPositive() const { return V.isNonNegative(); } + bool isNegative() const { return !V.isNonNegative(); } + bool isMin() const { return V.isMinValue(); } + bool isMax() const { return V.isMaxValue(); } + static bool isSigned() { return Signed; } + bool isMinusOne() const { return Signed && V == -1; } + + unsigned countLeadingZeros() const { return V.countl_zero(); } + + void print(llvm::raw_ostream ) const { OS << V; } + + IntegralAP truncate(unsigned bitWidth) const { return V; } erichkeane wrote: Does this DO anything? https://github.com/llvm/llvm-project/pull/65844 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Add IntegralAP for arbitrary-precision integers (PR #65844)
Timm =?utf-8?q?Bäder?= , Timm =?utf-8?q?Bäder?= , Timm =?utf-8?q?Bäder?= Message-ID: In-Reply-To: @@ -0,0 +1,249 @@ +//===--- Integral.h - Wrapper for numeric types for the VM --*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +// Defines the VM types and helpers operating on types. +// +//===--===// + +#ifndef LLVM_CLANG_AST_INTERP_INTEGRAL_AP_H +#define LLVM_CLANG_AST_INTERP_INTEGRAL_AP_H + +#include "clang/AST/APValue.h" +#include "clang/AST/ComparisonCategories.h" +#include "llvm/ADT/APSInt.h" +#include "llvm/Support/MathExtras.h" +#include "llvm/Support/raw_ostream.h" +#include +#include + +#include "Primitives.h" + +namespace clang { +namespace interp { + +using APInt = llvm::APInt; +using APSInt = llvm::APSInt; +template class Integral; +class Boolean; + +template class IntegralAP final { +public: + APSInt V; + +public: + using AsUnsigned = IntegralAP; + + template + IntegralAP(T Value) : V(APInt(sizeof(T) * 8, Value, std::is_signed_v)) {} + + IntegralAP(APInt V) : V(V) {} + IntegralAP(APSInt V) : V(V) {} + /// Arbitrary value for initialized variables. + IntegralAP() : V(APSInt::getMaxValue(1024, Signed)) {} + + IntegralAP operator-() const { return IntegralAP(-V); } + bool operator>(IntegralAP RHS) const { return V > RHS.V; } + bool operator>=(IntegralAP RHS) const { return V >= RHS.V; } + bool operator<(IntegralAP RHS) const { return V < RHS.V; } + bool operator<=(IntegralAP RHS) const { return V <= RHS.V; } + + explicit operator bool() const { return !V.isZero(); } + explicit operator int8_t() const { return V.getSExtValue(); } + explicit operator uint8_t() const { return V.getZExtValue(); } + explicit operator int16_t() const { return V.getSExtValue(); } + explicit operator uint16_t() const { return V.getZExtValue(); } + explicit operator int32_t() const { return V.getSExtValue(); } + explicit operator uint32_t() const { return V.getZExtValue(); } + explicit operator int64_t() const { return V.getSExtValue(); } + explicit operator uint64_t() const { return V.getZExtValue(); } + + template static IntegralAP from(T Value, unsigned NumBits = 0) { +assert(NumBits > 0); +APSInt Copy = APSInt(APInt(NumBits, Value, Signed), !Signed); + +return IntegralAP(Copy); + } + + template + static IntegralAP from(IntegralAP V, unsigned NumBits = 0) { +if constexpr (Signed == InputSigned) + return V; + +APSInt Copy = V.V; +Copy.setIsSigned(Signed); + +return IntegralAP(Copy); + } + + template + static IntegralAP from(Integral I) { +// FIXME: Take bits parameter. +APSInt Copy = +APSInt(APInt(128, static_cast(I), InputSigned), !Signed); +Copy.setIsSigned(Signed); + +assert(Copy.isSigned() == Signed); +return IntegralAP(Copy); + } + static IntegralAP from(const Boolean ) { +assert(false); +return IntegralAP::zero(); + } + + static IntegralAP zero() { +assert(false); +return IntegralAP(0); + } + + static constexpr unsigned bitWidth() { return 128; } + + APSInt toAPSInt(unsigned Bits = 0) const { return V; } + APValue toAPValue() const { return APValue(V); } + + bool isZero() const { return V.isZero(); } + bool isPositive() const { return V.isNonNegative(); } + bool isNegative() const { return !V.isNonNegative(); } + bool isMin() const { return V.isMinValue(); } + bool isMax() const { return V.isMaxValue(); } + static bool isSigned() { return Signed; } + bool isMinusOne() const { return Signed && V == -1; } + + unsigned countLeadingZeros() const { return V.countl_zero(); } + + void print(llvm::raw_ostream ) const { OS << V; } + + IntegralAP truncate(unsigned bitWidth) const { return V; } + IntegralAP toUnsigned() const { +APSInt Copy = V; +Copy.setIsSigned(false); +return IntegralAP(Copy); + } + + ComparisonCategoryResult compare(const IntegralAP ) const { +return Compare(V, RHS.V); + } + + static bool increment(IntegralAP A, IntegralAP *R) { +*R = IntegralAP(A.V - 1); erichkeane wrote: Should this be +1? https://github.com/llvm/llvm-project/pull/65844 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Add IntegralAP for arbitrary-precision integers (PR #65844)
Timm =?utf-8?q?Bäder?= , Timm =?utf-8?q?Bäder?= , Timm =?utf-8?q?Bäder?= Message-ID: In-Reply-To: @@ -1596,6 +1599,9 @@ bool ByteCodeExprGen::visitZeroInitializer(QualType QT, return this->emitZeroSint64(E); case PT_Uint64: return this->emitZeroUint64(E); + case PT_IntAP: + case PT_IntAPS: +assert(false); erichkeane wrote: Should this be an `llvm_unreachable`? https://github.com/llvm/llvm-project/pull/65844 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Add IntegralAP for arbitrary-precision integers (PR #65844)
Timm =?utf-8?q?B=C3=A4der?= , Timm =?utf-8?q?B=C3=A4der?= , Timm =?utf-8?q?B=C3=A4der?= Message-ID: In-Reply-To: tbaederr wrote: Ping https://github.com/llvm/llvm-project/pull/65844 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Add IntegralAP for arbitrary-precision integers (PR #65844)
Timm =?utf-8?q?B=C3=A4der?= , Timm =?utf-8?q?B=C3=A4der?= , Timm =?utf-8?q?B=C3=A4der?= Message-ID: In-Reply-To: tbaederr wrote: Ping https://github.com/llvm/llvm-project/pull/65844 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Add IntegralAP for arbitrary-precision integers (PR #65844)
Timm =?utf-8?q?Bäder?= , Timm =?utf-8?q?Bäder?= , Timm =?utf-8?q?Bäder?= Message-ID: In-Reply-To: https://github.com/tbaederr updated https://github.com/llvm/llvm-project/pull/65844 >From 1e61f47f0978446915cf250b017ea68b0e271d2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Sat, 9 Sep 2023 10:34:26 +0200 Subject: [PATCH 1/4] [clang][Interp] Add IntegralAP for arbitrary-precision integers --- clang/lib/AST/Interp/ByteCodeExprGen.cpp | 11 +- clang/lib/AST/Interp/Context.cpp | 6 +- clang/lib/AST/Interp/Descriptor.cpp | 9 + clang/lib/AST/Interp/EvalEmitter.cpp | 1 + clang/lib/AST/Interp/Integral.h | 4 + clang/lib/AST/Interp/IntegralAP.h| 253 +++ clang/lib/AST/Interp/Interp.h| 21 +- clang/lib/AST/Interp/InterpStack.h | 5 + clang/lib/AST/Interp/Opcodes.td | 8 +- clang/lib/AST/Interp/PrimType.cpp| 1 + clang/lib/AST/Interp/PrimType.h | 13 ++ clang/test/AST/Interp/literals.cpp | 24 +++ 12 files changed, 343 insertions(+), 13 deletions(-) create mode 100644 clang/lib/AST/Interp/IntegralAP.h diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp index 823bef7a8c19e11..8cac71903002c74 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -171,14 +171,17 @@ bool ByteCodeExprGen::VisitCastExpr(const CastExpr *CE) { return this->discard(SubExpr); std::optional FromT = classify(SubExpr->getType()); std::optional ToT = classify(CE->getType()); + if (!FromT || !ToT) return false; if (!this->visit(SubExpr)) return false; -if (FromT == ToT) +if (FromT == ToT) { + assert(ToT != PT_IntAP && ToT != PT_IntAPS); return true; +} return this->emitCast(*FromT, *ToT, CE); } @@ -1596,6 +1599,9 @@ bool ByteCodeExprGen::visitZeroInitializer(QualType QT, return this->emitZeroSint64(E); case PT_Uint64: return this->emitZeroUint64(E); + case PT_IntAP: + case PT_IntAPS: +assert(false); case PT_Ptr: return this->emitNullPtr(E); case PT_FnPtr: @@ -1835,6 +1841,9 @@ bool ByteCodeExprGen::emitConst(T Value, PrimType Ty, const Expr *E) { return this->emitConstSint64(Value, E); case PT_Uint64: return this->emitConstUint64(Value, E); + case PT_IntAP: + case PT_IntAPS: +assert(false); case PT_Bool: return this->emitConstBool(Value, E); case PT_Ptr: diff --git a/clang/lib/AST/Interp/Context.cpp b/clang/lib/AST/Interp/Context.cpp index 1a732b6c1a092ac..ed2b23514e86665 100644 --- a/clang/lib/AST/Interp/Context.cpp +++ b/clang/lib/AST/Interp/Context.cpp @@ -102,7 +102,8 @@ std::optional Context::classify(QualType T) const { case 8: return PT_Sint8; default: - return std::nullopt; + return PT_IntAPS; + // return std::nullopt; } } @@ -117,7 +118,8 @@ std::optional Context::classify(QualType T) const { case 8: return PT_Uint8; default: - return std::nullopt; + return PT_IntAP; + // return std::nullopt; } } diff --git a/clang/lib/AST/Interp/Descriptor.cpp b/clang/lib/AST/Interp/Descriptor.cpp index db49a569eff33ea..4ecb7466998e705 100644 --- a/clang/lib/AST/Interp/Descriptor.cpp +++ b/clang/lib/AST/Interp/Descriptor.cpp @@ -10,6 +10,7 @@ #include "Boolean.h" #include "Floating.h" #include "FunctionPointer.h" +#include "IntegralAP.h" #include "Pointer.h" #include "PrimType.h" #include "Record.h" @@ -182,6 +183,10 @@ static BlockCtorFn getCtorPrim(PrimType Type) { // constructor called. if (Type == PT_Float) return ctorTy::T>; + if (Type == PT_IntAP) +return ctorTy::T>; + if (Type == PT_IntAPS) +return ctorTy::T>; COMPOSITE_TYPE_SWITCH(Type, return ctorTy, return nullptr); } @@ -191,6 +196,10 @@ static BlockDtorFn getDtorPrim(PrimType Type) { // destructor called, since they might allocate memory. if (Type == PT_Float) return dtorTy::T>; + if (Type == PT_IntAP) +return dtorTy::T>; + if (Type == PT_IntAPS) +return dtorTy::T>; COMPOSITE_TYPE_SWITCH(Type, return dtorTy, return nullptr); } diff --git a/clang/lib/AST/Interp/EvalEmitter.cpp b/clang/lib/AST/Interp/EvalEmitter.cpp index d26ee8e40a437b9..c9332d8b2364fa1 100644 --- a/clang/lib/AST/Interp/EvalEmitter.cpp +++ b/clang/lib/AST/Interp/EvalEmitter.cpp @@ -8,6 +8,7 @@ #include "EvalEmitter.h" #include "Context.h" +#include "IntegralAP.h" #include "Interp.h" #include "Opcode.h" #include "Program.h" diff --git a/clang/lib/AST/Interp/Integral.h b/clang/lib/AST/Interp/Integral.h index 72285cabcbbf8ce..f8e529aa3392696 100644 --- a/clang/lib/AST/Interp/Integral.h +++ b/clang/lib/AST/Interp/Integral.h @@ -29,6 +29,8 @@ namespace interp { using APInt = llvm::APInt; using APSInt = llvm::APSInt; +template class IntegralAP; + // Helper structure to select the
[clang] [clang][Interp] Add IntegralAP for arbitrary-precision integers (PR #65844)
Timm =?utf-8?q?Bäder?= , Timm =?utf-8?q?Bäder?= Message-ID: In-Reply-To: https://github.com/tbaederr updated https://github.com/llvm/llvm-project/pull/65844 >From db98faff4cfc86657ee8f47dac0e1e2a441049b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Sat, 9 Sep 2023 10:34:26 +0200 Subject: [PATCH 1/3] [clang][Interp] Add IntegralAP for arbitrary-precision integers --- clang/lib/AST/Interp/ByteCodeExprGen.cpp | 11 +- clang/lib/AST/Interp/Context.cpp | 6 +- clang/lib/AST/Interp/Descriptor.cpp | 9 + clang/lib/AST/Interp/EvalEmitter.cpp | 1 + clang/lib/AST/Interp/Integral.h | 4 + clang/lib/AST/Interp/IntegralAP.h| 253 +++ clang/lib/AST/Interp/Interp.h| 21 +- clang/lib/AST/Interp/InterpStack.h | 5 + clang/lib/AST/Interp/Opcodes.td | 8 +- clang/lib/AST/Interp/PrimType.cpp| 1 + clang/lib/AST/Interp/PrimType.h | 13 ++ clang/test/AST/Interp/literals.cpp | 24 +++ 12 files changed, 343 insertions(+), 13 deletions(-) create mode 100644 clang/lib/AST/Interp/IntegralAP.h diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp index e49dc80a5c9ce7c..1d7b8201ae92802 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -171,14 +171,17 @@ bool ByteCodeExprGen::VisitCastExpr(const CastExpr *CE) { return this->discard(SubExpr); std::optional FromT = classify(SubExpr->getType()); std::optional ToT = classify(CE->getType()); + if (!FromT || !ToT) return false; if (!this->visit(SubExpr)) return false; -if (FromT == ToT) +if (FromT == ToT) { + assert(ToT != PT_IntAP && ToT != PT_IntAPS); return true; +} return this->emitCast(*FromT, *ToT, CE); } @@ -1596,6 +1599,9 @@ bool ByteCodeExprGen::visitZeroInitializer(QualType QT, return this->emitZeroSint64(E); case PT_Uint64: return this->emitZeroUint64(E); + case PT_IntAP: + case PT_IntAPS: +assert(false); case PT_Ptr: return this->emitNullPtr(E); case PT_FnPtr: @@ -1835,6 +1841,9 @@ bool ByteCodeExprGen::emitConst(T Value, PrimType Ty, const Expr *E) { return this->emitConstSint64(Value, E); case PT_Uint64: return this->emitConstUint64(Value, E); + case PT_IntAP: + case PT_IntAPS: +assert(false); case PT_Bool: return this->emitConstBool(Value, E); case PT_Ptr: diff --git a/clang/lib/AST/Interp/Context.cpp b/clang/lib/AST/Interp/Context.cpp index 1a732b6c1a092ac..ed2b23514e86665 100644 --- a/clang/lib/AST/Interp/Context.cpp +++ b/clang/lib/AST/Interp/Context.cpp @@ -102,7 +102,8 @@ std::optional Context::classify(QualType T) const { case 8: return PT_Sint8; default: - return std::nullopt; + return PT_IntAPS; + // return std::nullopt; } } @@ -117,7 +118,8 @@ std::optional Context::classify(QualType T) const { case 8: return PT_Uint8; default: - return std::nullopt; + return PT_IntAP; + // return std::nullopt; } } diff --git a/clang/lib/AST/Interp/Descriptor.cpp b/clang/lib/AST/Interp/Descriptor.cpp index db49a569eff33ea..4ecb7466998e705 100644 --- a/clang/lib/AST/Interp/Descriptor.cpp +++ b/clang/lib/AST/Interp/Descriptor.cpp @@ -10,6 +10,7 @@ #include "Boolean.h" #include "Floating.h" #include "FunctionPointer.h" +#include "IntegralAP.h" #include "Pointer.h" #include "PrimType.h" #include "Record.h" @@ -182,6 +183,10 @@ static BlockCtorFn getCtorPrim(PrimType Type) { // constructor called. if (Type == PT_Float) return ctorTy::T>; + if (Type == PT_IntAP) +return ctorTy::T>; + if (Type == PT_IntAPS) +return ctorTy::T>; COMPOSITE_TYPE_SWITCH(Type, return ctorTy, return nullptr); } @@ -191,6 +196,10 @@ static BlockDtorFn getDtorPrim(PrimType Type) { // destructor called, since they might allocate memory. if (Type == PT_Float) return dtorTy::T>; + if (Type == PT_IntAP) +return dtorTy::T>; + if (Type == PT_IntAPS) +return dtorTy::T>; COMPOSITE_TYPE_SWITCH(Type, return dtorTy, return nullptr); } diff --git a/clang/lib/AST/Interp/EvalEmitter.cpp b/clang/lib/AST/Interp/EvalEmitter.cpp index d26ee8e40a437b9..c9332d8b2364fa1 100644 --- a/clang/lib/AST/Interp/EvalEmitter.cpp +++ b/clang/lib/AST/Interp/EvalEmitter.cpp @@ -8,6 +8,7 @@ #include "EvalEmitter.h" #include "Context.h" +#include "IntegralAP.h" #include "Interp.h" #include "Opcode.h" #include "Program.h" diff --git a/clang/lib/AST/Interp/Integral.h b/clang/lib/AST/Interp/Integral.h index 72285cabcbbf8ce..f8e529aa3392696 100644 --- a/clang/lib/AST/Interp/Integral.h +++ b/clang/lib/AST/Interp/Integral.h @@ -29,6 +29,8 @@ namespace interp { using APInt = llvm::APInt; using APSInt = llvm::APSInt; +template class IntegralAP; + // Helper structure to select the representation. template
[clang] [clang][Interp] Add IntegralAP for arbitrary-precision integers (PR #65844)
Timm =?utf-8?q?Bäder?= https://github.com/tbaederr updated https://github.com/llvm/llvm-project/pull/65844: >From 4e49f66c7bc814510f2dc923129eab8bcca5eca0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Sat, 9 Sep 2023 10:34:26 +0200 Subject: [PATCH 1/2] [clang][Interp] Add IntegralAP for arbitrary-precision integers --- clang/lib/AST/Interp/ByteCodeExprGen.cpp | 11 +- clang/lib/AST/Interp/Context.cpp | 6 +- clang/lib/AST/Interp/Descriptor.cpp | 9 + clang/lib/AST/Interp/EvalEmitter.cpp | 1 + clang/lib/AST/Interp/Integral.h | 4 + clang/lib/AST/Interp/IntegralAP.h| 253 +++ clang/lib/AST/Interp/Interp.h| 21 +- clang/lib/AST/Interp/InterpStack.h | 5 + clang/lib/AST/Interp/Opcodes.td | 8 +- clang/lib/AST/Interp/PrimType.cpp| 1 + clang/lib/AST/Interp/PrimType.h | 13 ++ clang/test/AST/Interp/literals.cpp | 24 +++ 12 files changed, 343 insertions(+), 13 deletions(-) create mode 100644 clang/lib/AST/Interp/IntegralAP.h diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp index 17cf15d8676eb86..ec2ece71b301382 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -171,14 +171,17 @@ bool ByteCodeExprGen::VisitCastExpr(const CastExpr *CE) { return this->discard(SubExpr); std::optional FromT = classify(SubExpr->getType()); std::optional ToT = classify(CE->getType()); + if (!FromT || !ToT) return false; if (!this->visit(SubExpr)) return false; -if (FromT == ToT) +if (FromT == ToT) { + assert(ToT != PT_IntAP && ToT != PT_IntAPS); return true; +} return this->emitCast(*FromT, *ToT, CE); } @@ -1548,6 +1551,9 @@ bool ByteCodeExprGen::visitZeroInitializer(QualType QT, return this->emitZeroSint64(E); case PT_Uint64: return this->emitZeroUint64(E); + case PT_IntAP: + case PT_IntAPS: +assert(false); case PT_Ptr: return this->emitNullPtr(E); case PT_FnPtr: @@ -1787,6 +1793,9 @@ bool ByteCodeExprGen::emitConst(T Value, PrimType Ty, const Expr *E) { return this->emitConstSint64(Value, E); case PT_Uint64: return this->emitConstUint64(Value, E); + case PT_IntAP: + case PT_IntAPS: +assert(false); case PT_Bool: return this->emitConstBool(Value, E); case PT_Ptr: diff --git a/clang/lib/AST/Interp/Context.cpp b/clang/lib/AST/Interp/Context.cpp index 1a732b6c1a092ac..ed2b23514e86665 100644 --- a/clang/lib/AST/Interp/Context.cpp +++ b/clang/lib/AST/Interp/Context.cpp @@ -102,7 +102,8 @@ std::optional Context::classify(QualType T) const { case 8: return PT_Sint8; default: - return std::nullopt; + return PT_IntAPS; + // return std::nullopt; } } @@ -117,7 +118,8 @@ std::optional Context::classify(QualType T) const { case 8: return PT_Uint8; default: - return std::nullopt; + return PT_IntAP; + // return std::nullopt; } } diff --git a/clang/lib/AST/Interp/Descriptor.cpp b/clang/lib/AST/Interp/Descriptor.cpp index db49a569eff33ea..4ecb7466998e705 100644 --- a/clang/lib/AST/Interp/Descriptor.cpp +++ b/clang/lib/AST/Interp/Descriptor.cpp @@ -10,6 +10,7 @@ #include "Boolean.h" #include "Floating.h" #include "FunctionPointer.h" +#include "IntegralAP.h" #include "Pointer.h" #include "PrimType.h" #include "Record.h" @@ -182,6 +183,10 @@ static BlockCtorFn getCtorPrim(PrimType Type) { // constructor called. if (Type == PT_Float) return ctorTy::T>; + if (Type == PT_IntAP) +return ctorTy::T>; + if (Type == PT_IntAPS) +return ctorTy::T>; COMPOSITE_TYPE_SWITCH(Type, return ctorTy, return nullptr); } @@ -191,6 +196,10 @@ static BlockDtorFn getDtorPrim(PrimType Type) { // destructor called, since they might allocate memory. if (Type == PT_Float) return dtorTy::T>; + if (Type == PT_IntAP) +return dtorTy::T>; + if (Type == PT_IntAPS) +return dtorTy::T>; COMPOSITE_TYPE_SWITCH(Type, return dtorTy, return nullptr); } diff --git a/clang/lib/AST/Interp/EvalEmitter.cpp b/clang/lib/AST/Interp/EvalEmitter.cpp index d26ee8e40a437b9..c9332d8b2364fa1 100644 --- a/clang/lib/AST/Interp/EvalEmitter.cpp +++ b/clang/lib/AST/Interp/EvalEmitter.cpp @@ -8,6 +8,7 @@ #include "EvalEmitter.h" #include "Context.h" +#include "IntegralAP.h" #include "Interp.h" #include "Opcode.h" #include "Program.h" diff --git a/clang/lib/AST/Interp/Integral.h b/clang/lib/AST/Interp/Integral.h index 8d5edbb5b764eda..20c632cbac3f096 100644 --- a/clang/lib/AST/Interp/Integral.h +++ b/clang/lib/AST/Interp/Integral.h @@ -29,6 +29,8 @@ namespace interp { using APInt = llvm::APInt; using APSInt = llvm::APSInt; +template class IntegralAP; + // Helper structure to select the representation. template struct Repr; template <> struct Repr<8, false> {
[clang] [clang][Interp] Add IntegralAP for arbitrary-precision integers (PR #65844)
Timm =?utf-8?q?Bäder?= https://github.com/tbaederr resolved https://github.com/llvm/llvm-project/pull/65844 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Add IntegralAP for arbitrary-precision integers (PR #65844)
Timm =?utf-8?q?Bäder?= https://github.com/tbaederr resolved https://github.com/llvm/llvm-project/pull/65844 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Add IntegralAP for arbitrary-precision integers (PR #65844)
Timm =?utf-8?q?Bäder?= https://github.com/tbaederr resolved https://github.com/llvm/llvm-project/pull/65844 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Add IntegralAP for arbitrary-precision integers (PR #65844)
Timm =?utf-8?q?Bäder?= https://github.com/tbaederr updated https://github.com/llvm/llvm-project/pull/65844: >From 4e49f66c7bc814510f2dc923129eab8bcca5eca0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Sat, 9 Sep 2023 10:34:26 +0200 Subject: [PATCH 1/2] [clang][Interp] Add IntegralAP for arbitrary-precision integers --- clang/lib/AST/Interp/ByteCodeExprGen.cpp | 11 +- clang/lib/AST/Interp/Context.cpp | 6 +- clang/lib/AST/Interp/Descriptor.cpp | 9 + clang/lib/AST/Interp/EvalEmitter.cpp | 1 + clang/lib/AST/Interp/Integral.h | 4 + clang/lib/AST/Interp/IntegralAP.h| 253 +++ clang/lib/AST/Interp/Interp.h| 21 +- clang/lib/AST/Interp/InterpStack.h | 5 + clang/lib/AST/Interp/Opcodes.td | 8 +- clang/lib/AST/Interp/PrimType.cpp| 1 + clang/lib/AST/Interp/PrimType.h | 13 ++ clang/test/AST/Interp/literals.cpp | 24 +++ 12 files changed, 343 insertions(+), 13 deletions(-) create mode 100644 clang/lib/AST/Interp/IntegralAP.h diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp index 17cf15d8676eb86..ec2ece71b301382 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -171,14 +171,17 @@ bool ByteCodeExprGen::VisitCastExpr(const CastExpr *CE) { return this->discard(SubExpr); std::optional FromT = classify(SubExpr->getType()); std::optional ToT = classify(CE->getType()); + if (!FromT || !ToT) return false; if (!this->visit(SubExpr)) return false; -if (FromT == ToT) +if (FromT == ToT) { + assert(ToT != PT_IntAP && ToT != PT_IntAPS); return true; +} return this->emitCast(*FromT, *ToT, CE); } @@ -1548,6 +1551,9 @@ bool ByteCodeExprGen::visitZeroInitializer(QualType QT, return this->emitZeroSint64(E); case PT_Uint64: return this->emitZeroUint64(E); + case PT_IntAP: + case PT_IntAPS: +assert(false); case PT_Ptr: return this->emitNullPtr(E); case PT_FnPtr: @@ -1787,6 +1793,9 @@ bool ByteCodeExprGen::emitConst(T Value, PrimType Ty, const Expr *E) { return this->emitConstSint64(Value, E); case PT_Uint64: return this->emitConstUint64(Value, E); + case PT_IntAP: + case PT_IntAPS: +assert(false); case PT_Bool: return this->emitConstBool(Value, E); case PT_Ptr: diff --git a/clang/lib/AST/Interp/Context.cpp b/clang/lib/AST/Interp/Context.cpp index 1a732b6c1a092ac..ed2b23514e86665 100644 --- a/clang/lib/AST/Interp/Context.cpp +++ b/clang/lib/AST/Interp/Context.cpp @@ -102,7 +102,8 @@ std::optional Context::classify(QualType T) const { case 8: return PT_Sint8; default: - return std::nullopt; + return PT_IntAPS; + // return std::nullopt; } } @@ -117,7 +118,8 @@ std::optional Context::classify(QualType T) const { case 8: return PT_Uint8; default: - return std::nullopt; + return PT_IntAP; + // return std::nullopt; } } diff --git a/clang/lib/AST/Interp/Descriptor.cpp b/clang/lib/AST/Interp/Descriptor.cpp index db49a569eff33ea..4ecb7466998e705 100644 --- a/clang/lib/AST/Interp/Descriptor.cpp +++ b/clang/lib/AST/Interp/Descriptor.cpp @@ -10,6 +10,7 @@ #include "Boolean.h" #include "Floating.h" #include "FunctionPointer.h" +#include "IntegralAP.h" #include "Pointer.h" #include "PrimType.h" #include "Record.h" @@ -182,6 +183,10 @@ static BlockCtorFn getCtorPrim(PrimType Type) { // constructor called. if (Type == PT_Float) return ctorTy::T>; + if (Type == PT_IntAP) +return ctorTy::T>; + if (Type == PT_IntAPS) +return ctorTy::T>; COMPOSITE_TYPE_SWITCH(Type, return ctorTy, return nullptr); } @@ -191,6 +196,10 @@ static BlockDtorFn getDtorPrim(PrimType Type) { // destructor called, since they might allocate memory. if (Type == PT_Float) return dtorTy::T>; + if (Type == PT_IntAP) +return dtorTy::T>; + if (Type == PT_IntAPS) +return dtorTy::T>; COMPOSITE_TYPE_SWITCH(Type, return dtorTy, return nullptr); } diff --git a/clang/lib/AST/Interp/EvalEmitter.cpp b/clang/lib/AST/Interp/EvalEmitter.cpp index d26ee8e40a437b9..c9332d8b2364fa1 100644 --- a/clang/lib/AST/Interp/EvalEmitter.cpp +++ b/clang/lib/AST/Interp/EvalEmitter.cpp @@ -8,6 +8,7 @@ #include "EvalEmitter.h" #include "Context.h" +#include "IntegralAP.h" #include "Interp.h" #include "Opcode.h" #include "Program.h" diff --git a/clang/lib/AST/Interp/Integral.h b/clang/lib/AST/Interp/Integral.h index 8d5edbb5b764eda..20c632cbac3f096 100644 --- a/clang/lib/AST/Interp/Integral.h +++ b/clang/lib/AST/Interp/Integral.h @@ -29,6 +29,8 @@ namespace interp { using APInt = llvm::APInt; using APSInt = llvm::APSInt; +template class IntegralAP; + // Helper structure to select the representation. template struct Repr; template <> struct Repr<8, false> {
[clang] [clang][Interp] Add IntegralAP for arbitrary-precision integers (PR #65844)
https://github.com/tbaederr resolved https://github.com/llvm/llvm-project/pull/65844 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Add IntegralAP for arbitrary-precision integers (PR #65844)
https://github.com/tbaederr resolved https://github.com/llvm/llvm-project/pull/65844 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Add IntegralAP for arbitrary-precision integers (PR #65844)
https://github.com/tbaederr resolved https://github.com/llvm/llvm-project/pull/65844 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Add IntegralAP for arbitrary-precision integers (PR #65844)
@@ -0,0 +1,253 @@ +//===--- Integral.h - Wrapper for numeric types for the VM --*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +// Defines the VM types and helpers operating on types. +// +//===--===// + +#ifndef LLVM_CLANG_AST_INTERP_INTEGRAL_AP_H +#define LLVM_CLANG_AST_INTERP_INTEGRAL_AP_H + +#include "clang/AST/APValue.h" +#include "clang/AST/ComparisonCategories.h" +#include "llvm/ADT/APSInt.h" +#include "llvm/Support/MathExtras.h" +#include "llvm/Support/raw_ostream.h" +#include +#include + +#include "Primitives.h" + +namespace clang { +namespace interp { + +using APInt = llvm::APInt; +using APSInt = llvm::APSInt; +template class Integral; +class Boolean; + +template class IntegralAP final { +public: + APSInt V; + +public: + using AsUnsigned = IntegralAP; + + template + IntegralAP(T Value) : V(APInt(sizeof(T) * 8, Value, std::is_signed_v)) {} + + IntegralAP(APInt V) : V(V) {} + IntegralAP(APSInt V) : V(V) {} + IntegralAP(bool b) : V(APInt(8, b, Signed)) {} cor3ntin wrote: should you make this constructor explicit? https://github.com/llvm/llvm-project/pull/65844 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Add IntegralAP for arbitrary-precision integers (PR #65844)
@@ -0,0 +1,253 @@ +//===--- Integral.h - Wrapper for numeric types for the VM --*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +// Defines the VM types and helpers operating on types. +// +//===--===// + +#ifndef LLVM_CLANG_AST_INTERP_INTEGRAL_AP_H +#define LLVM_CLANG_AST_INTERP_INTEGRAL_AP_H + +#include "clang/AST/APValue.h" +#include "clang/AST/ComparisonCategories.h" +#include "llvm/ADT/APSInt.h" +#include "llvm/Support/MathExtras.h" +#include "llvm/Support/raw_ostream.h" +#include +#include + +#include "Primitives.h" + +namespace clang { +namespace interp { + +using APInt = llvm::APInt; +using APSInt = llvm::APSInt; +template class Integral; +class Boolean; + +template class IntegralAP final { +public: + APSInt V; + +public: + using AsUnsigned = IntegralAP; + + template + IntegralAP(T Value) : V(APInt(sizeof(T) * 8, Value, std::is_signed_v)) {} + + IntegralAP(APInt V) : V(V) {} + IntegralAP(APSInt V) : V(V) {} + IntegralAP(bool b) : V(APInt(8, b, Signed)) {} + /// Bullshit value for initialized variables. + IntegralAP() : V(APSInt::getMaxValue(1024, Signed)) {} + + IntegralAP operator-() const { return IntegralAP(-V); } + // bool operator <=> (const IntegralAP ) const = default; + bool operator>(IntegralAP RHS) const { return V > RHS.V; } + bool operator>=(IntegralAP RHS) const { return V >= RHS.V; } + bool operator<(IntegralAP RHS) const { return V < RHS.V; } + bool operator<=(IntegralAP RHS) const { return V <= RHS.V; } + + explicit operator bool() const { return !V.isZero(); } + explicit operator int8_t() const { return V.getSExtValue(); } + explicit operator uint8_t() const { return V.getZExtValue(); } + explicit operator int16_t() const { return V.getSExtValue(); } + explicit operator uint16_t() const { return V.getZExtValue(); } + explicit operator int32_t() const { return V.getSExtValue(); } + explicit operator uint32_t() const { return V.getZExtValue(); } + explicit operator int64_t() const { return V.getSExtValue(); } + explicit operator uint64_t() const { return V.getZExtValue(); } + + template static IntegralAP from(T Value, unsigned NumBits = 0) { +assert(NumBits > 0); +APSInt Copy = APSInt(APInt(NumBits, Value, Signed), !Signed); + +return IntegralAP(Copy); + } + + template + static IntegralAP from(IntegralAP V, unsigned NumBits = 0) { +if constexpr (Signed == InputSigned) + return V; + +APSInt Copy = V.V; +Copy.setIsSigned(Signed); + +return IntegralAP(Copy); + } + + template + static IntegralAP from(Integral I) { +assert(InputSigned); +/// TODO: Take bits parameter. +APSInt Copy = +APSInt(APInt(128, static_cast(I), InputSigned), !Signed); +Copy.setIsSigned(Signed); + +assert(Copy.isSigned() == Signed); +return IntegralAP(Copy); + } + static IntegralAP from(const Boolean ) { +assert(false); +return IntegralAP::zero(); + } + + static IntegralAP zero() { +assert(false); +return IntegralAP(0); + } + + static constexpr unsigned bitWidth() { return 128; } + + APSInt toAPSInt(unsigned Bits = 0) const { return V; } + APValue toAPValue() const { return APValue(V); } + + bool isZero() const { return false; } + bool isPositive() const { return true; } + bool isNegative() const { return false; } + bool isMin() const { return false; } + bool isMax() const { return false; } + static bool isSigned() { return Signed; } + bool isMinusOne() const { return false; } cor3ntin wrote: This can be implemented through APInt methods, right? https://github.com/llvm/llvm-project/pull/65844 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Add IntegralAP for arbitrary-precision integers (PR #65844)
@@ -0,0 +1,253 @@ +//===--- Integral.h - Wrapper for numeric types for the VM --*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +// Defines the VM types and helpers operating on types. +// +//===--===// + +#ifndef LLVM_CLANG_AST_INTERP_INTEGRAL_AP_H +#define LLVM_CLANG_AST_INTERP_INTEGRAL_AP_H + +#include "clang/AST/APValue.h" +#include "clang/AST/ComparisonCategories.h" +#include "llvm/ADT/APSInt.h" +#include "llvm/Support/MathExtras.h" +#include "llvm/Support/raw_ostream.h" +#include +#include + +#include "Primitives.h" + +namespace clang { +namespace interp { + +using APInt = llvm::APInt; +using APSInt = llvm::APSInt; +template class Integral; +class Boolean; + +template class IntegralAP final { +public: + APSInt V; + +public: + using AsUnsigned = IntegralAP; + + template + IntegralAP(T Value) : V(APInt(sizeof(T) * 8, Value, std::is_signed_v)) {} + + IntegralAP(APInt V) : V(V) {} + IntegralAP(APSInt V) : V(V) {} + IntegralAP(bool b) : V(APInt(8, b, Signed)) {} + /// Bullshit value for initialized variables. cor3ntin wrote: Maybe find a synonym :) https://github.com/llvm/llvm-project/pull/65844 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Add IntegralAP for arbitrary-precision integers (PR #65844)
@@ -0,0 +1,253 @@ +//===--- Integral.h - Wrapper for numeric types for the VM --*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +// +// Defines the VM types and helpers operating on types. +// +//===--===// + +#ifndef LLVM_CLANG_AST_INTERP_INTEGRAL_AP_H +#define LLVM_CLANG_AST_INTERP_INTEGRAL_AP_H + +#include "clang/AST/APValue.h" +#include "clang/AST/ComparisonCategories.h" +#include "llvm/ADT/APSInt.h" +#include "llvm/Support/MathExtras.h" +#include "llvm/Support/raw_ostream.h" +#include +#include + +#include "Primitives.h" + +namespace clang { +namespace interp { + +using APInt = llvm::APInt; +using APSInt = llvm::APSInt; +template class Integral; +class Boolean; + +template class IntegralAP final { +public: + APSInt V; + +public: + using AsUnsigned = IntegralAP; + + template + IntegralAP(T Value) : V(APInt(sizeof(T) * 8, Value, std::is_signed_v)) {} + + IntegralAP(APInt V) : V(V) {} + IntegralAP(APSInt V) : V(V) {} + IntegralAP(bool b) : V(APInt(8, b, Signed)) {} + /// Bullshit value for initialized variables. + IntegralAP() : V(APSInt::getMaxValue(1024, Signed)) {} + + IntegralAP operator-() const { return IntegralAP(-V); } + // bool operator <=> (const IntegralAP ) const = default; + bool operator>(IntegralAP RHS) const { return V > RHS.V; } + bool operator>=(IntegralAP RHS) const { return V >= RHS.V; } + bool operator<(IntegralAP RHS) const { return V < RHS.V; } + bool operator<=(IntegralAP RHS) const { return V <= RHS.V; } + + explicit operator bool() const { return !V.isZero(); } + explicit operator int8_t() const { return V.getSExtValue(); } + explicit operator uint8_t() const { return V.getZExtValue(); } + explicit operator int16_t() const { return V.getSExtValue(); } + explicit operator uint16_t() const { return V.getZExtValue(); } + explicit operator int32_t() const { return V.getSExtValue(); } + explicit operator uint32_t() const { return V.getZExtValue(); } + explicit operator int64_t() const { return V.getSExtValue(); } + explicit operator uint64_t() const { return V.getZExtValue(); } + + template static IntegralAP from(T Value, unsigned NumBits = 0) { +assert(NumBits > 0); +APSInt Copy = APSInt(APInt(NumBits, Value, Signed), !Signed); + +return IntegralAP(Copy); + } + + template + static IntegralAP from(IntegralAP V, unsigned NumBits = 0) { +if constexpr (Signed == InputSigned) + return V; + +APSInt Copy = V.V; +Copy.setIsSigned(Signed); + +return IntegralAP(Copy); + } + + template + static IntegralAP from(Integral I) { +assert(InputSigned); +/// TODO: Take bits parameter. +APSInt Copy = +APSInt(APInt(128, static_cast(I), InputSigned), !Signed); +Copy.setIsSigned(Signed); + +assert(Copy.isSigned() == Signed); +return IntegralAP(Copy); + } + static IntegralAP from(const Boolean ) { +assert(false); +return IntegralAP::zero(); + } + + static IntegralAP zero() { +assert(false); +return IntegralAP(0); + } + + static constexpr unsigned bitWidth() { return 128; } + + APSInt toAPSInt(unsigned Bits = 0) const { return V; } + APValue toAPValue() const { return APValue(V); } + + bool isZero() const { return false; } + bool isPositive() const { return true; } + bool isNegative() const { return false; } + bool isMin() const { return false; } + bool isMax() const { return false; } + static bool isSigned() { return Signed; } + bool isMinusOne() const { return false; } + + unsigned countLeadingZeros() const { return V.countl_zero(); } + + void print(llvm::raw_ostream ) const { OS << V; } + + IntegralAP truncate(unsigned bitWidth) const { return V; } + IntegralAP toUnsigned() const { +APSInt Copy = V; +Copy.setIsSigned(false); +return IntegralAP(Copy); + } + + ComparisonCategoryResult compare(const IntegralAP ) const { +return Compare(V, RHS.V); + } + + static bool increment(IntegralAP A, IntegralAP *R) { +*R = IntegralAP(A.V - 1); +return false; + } + + static bool decrement(IntegralAP A, IntegralAP *R) { +*R = IntegralAP(A.V - 1); +return false; + } + + static bool add(IntegralAP A, IntegralAP B, unsigned OpBits, IntegralAP *R) { +/// TODO: Gotta check if the result fits into OpBits bits. erichkeane wrote: Typically these would be "FIXME", TODOs generally shouldn't be upstreamed. https://github.com/llvm/llvm-project/pull/65844 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Add IntegralAP for arbitrary-precision integers (PR #65844)
@@ -102,7 +102,8 @@ std::optional Context::classify(QualType T) const { case 8: return PT_Sint8; default: - return std::nullopt; + return PT_IntAPS; + // return std::nullopt; erichkeane wrote: If we're removing these, I wonder if we need a 'LLVM_FALLTHROUGH' in case others add to it later? https://github.com/llvm/llvm-project/pull/65844 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Add IntegralAP for arbitrary-precision integers (PR #65844)
@@ -117,7 +118,8 @@ std::optional Context::classify(QualType T) const { case 8: return PT_Uint8; default: - return std::nullopt; + return PT_IntAP; + // return std::nullopt; tbaederr wrote: Yes. There are a few such comments left in the patch I think. https://github.com/llvm/llvm-project/pull/65844 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Add IntegralAP for arbitrary-precision integers (PR #65844)
@@ -117,7 +118,8 @@ std::optional Context::classify(QualType T) const { case 8: return PT_Uint8; default: - return std::nullopt; + return PT_IntAP; + // return std::nullopt; yronglin wrote: Can this comment be remove? https://github.com/llvm/llvm-project/pull/65844 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Add IntegralAP for arbitrary-precision integers (PR #65844)
llvmbot wrote: @llvm/pr-subscribers-clang Changes This adds `IntegralAP` backing the two new primtypes `IntAP` (unsinged arbitrary-precision int) and `IntAPS` (same but signed). We use this for `int128` support (which isn't available on all host systems we support AFAIK) and I think we can also use this for `_BitInt` later. -- Patch is 20.14 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/65844.diff 12 Files Affected: - (modified) clang/lib/AST/Interp/ByteCodeExprGen.cpp (+10-1) - (modified) clang/lib/AST/Interp/Context.cpp (+4-2) - (modified) clang/lib/AST/Interp/Descriptor.cpp (+9) - (modified) clang/lib/AST/Interp/EvalEmitter.cpp (+1) - (modified) clang/lib/AST/Interp/Integral.h (+4) - (added) clang/lib/AST/Interp/IntegralAP.h (+253) - (modified) clang/lib/AST/Interp/Interp.h (+14-7) - (modified) clang/lib/AST/Interp/InterpStack.h (+5) - (modified) clang/lib/AST/Interp/Opcodes.td (+5-3) - (modified) clang/lib/AST/Interp/PrimType.cpp (+1) - (modified) clang/lib/AST/Interp/PrimType.h (+13) - (modified) clang/test/AST/Interp/literals.cpp (+24) diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp index 17cf15d8676eb8..ec2ece71b30138 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -171,14 +171,17 @@ bool ByteCodeExprGen::VisitCastExpr(const CastExpr *CE) { return this->discard(SubExpr); std::optional FromT = classify(SubExpr->getType()); std::optional ToT = classify(CE->getType()); + if (!FromT || !ToT) return false; if (!this->visit(SubExpr)) return false; -if (FromT == ToT) +if (FromT == ToT) { + assert(ToT != PT_IntAP && ToT != PT_IntAPS); return true; +} return this->emitCast(*FromT, *ToT, CE); } @@ -1548,6 +1551,9 @@ bool ByteCodeExprGen::visitZeroInitializer(QualType QT, return this->emitZeroSint64(E); case PT_Uint64: return this->emitZeroUint64(E); + case PT_IntAP: + case PT_IntAPS: +assert(false); case PT_Ptr: return this->emitNullPtr(E); case PT_FnPtr: @@ -1787,6 +1793,9 @@ bool ByteCodeExprGen::emitConst(T Value, PrimType Ty, const Expr *E) { return this->emitConstSint64(Value, E); case PT_Uint64: return this->emitConstUint64(Value, E); + case PT_IntAP: + case PT_IntAPS: +assert(false); case PT_Bool: return this->emitConstBool(Value, E); case PT_Ptr: diff --git a/clang/lib/AST/Interp/Context.cpp b/clang/lib/AST/Interp/Context.cpp index 1a732b6c1a092a..ed2b23514e8666 100644 --- a/clang/lib/AST/Interp/Context.cpp +++ b/clang/lib/AST/Interp/Context.cpp @@ -102,7 +102,8 @@ std::optional Context::classify(QualType T) const { case 8: return PT_Sint8; default: - return std::nullopt; + return PT_IntAPS; + // return std::nullopt; } } @@ -117,7 +118,8 @@ std::optional Context::classify(QualType T) const { case 8: return PT_Uint8; default: - return std::nullopt; + return PT_IntAP; + // return std::nullopt; } } diff --git a/clang/lib/AST/Interp/Descriptor.cpp b/clang/lib/AST/Interp/Descriptor.cpp index db49a569eff33e..4ecb7466998e70 100644 --- a/clang/lib/AST/Interp/Descriptor.cpp +++ b/clang/lib/AST/Interp/Descriptor.cpp @@ -10,6 +10,7 @@ #include "Boolean.h" #include "Floating.h" #include "FunctionPointer.h" +#include "IntegralAP.h" #include "Pointer.h" #include "PrimType.h" #include "Record.h" @@ -182,6 +183,10 @@ static BlockCtorFn getCtorPrim(PrimType Type) { // constructor called. if (Type == PT_Float) return ctorTy::T>; + if (Type == PT_IntAP) +return ctorTy::T>; + if (Type == PT_IntAPS) +return ctorTy::T>; COMPOSITE_TYPE_SWITCH(Type, return ctorTy, return nullptr); } @@ -191,6 +196,10 @@ static BlockDtorFn getDtorPrim(PrimType Type) { // destructor called, since they might allocate memory. if (Type == PT_Float) return dtorTy::T>; + if (Type == PT_IntAP) +return dtorTy::T>; + if (Type == PT_IntAPS) +return dtorTy::T>; COMPOSITE_TYPE_SWITCH(Type, return dtorTy, return nullptr); } diff --git a/clang/lib/AST/Interp/EvalEmitter.cpp b/clang/lib/AST/Interp/EvalEmitter.cpp index d26ee8e40a437b..c9332d8b2364fa 100644 --- a/clang/lib/AST/Interp/EvalEmitter.cpp +++ b/clang/lib/AST/Interp/EvalEmitter.cpp @@ -8,6 +8,7 @@ #include "EvalEmitter.h" #include "Context.h" +#include "IntegralAP.h" #include "Interp.h" #include "Opcode.h" #include "Program.h" diff --git a/clang/lib/AST/Interp/Integral.h b/clang/lib/AST/Interp/Integral.h index 8d5edbb5b764ed..20c632cbac3f09 100644 --- a/clang/lib/AST/Interp/Integral.h +++ b/clang/lib/AST/Interp/Integral.h @@ -29,6 +29,8 @@ namespace interp { using APInt = llvm::APInt; using APSInt = llvm::APSInt; +template class IntegralAP; + // Helper structure to select the representation. template struct Repr;
[clang] [clang][Interp] Add IntegralAP for arbitrary-precision integers (PR #65844)
https://github.com/llvmbot labeled https://github.com/llvm/llvm-project/pull/65844 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Add IntegralAP for arbitrary-precision integers (PR #65844)
https://github.com/llvmbot labeled https://github.com/llvm/llvm-project/pull/65844 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Add IntegralAP for arbitrary-precision integers (PR #65844)
https://github.com/tbaederr review_requested https://github.com/llvm/llvm-project/pull/65844 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Add IntegralAP for arbitrary-precision integers (PR #65844)
https://github.com/tbaederr review_requested https://github.com/llvm/llvm-project/pull/65844 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Add IntegralAP for arbitrary-precision integers (PR #65844)
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/65844: This adds `IntegralAP` backing the two new primtypes `IntAP` (unsinged arbitrary-precision int) and `IntAPS` (same but signed). We use this for `int128` support (which isn't available on all host systems we support AFAIK) and I think we can also use this for `_BitInt` later. >From 4e49f66c7bc814510f2dc923129eab8bcca5eca0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Sat, 9 Sep 2023 10:34:26 +0200 Subject: [PATCH] [clang][Interp] Add IntegralAP for arbitrary-precision integers --- clang/lib/AST/Interp/ByteCodeExprGen.cpp | 11 +- clang/lib/AST/Interp/Context.cpp | 6 +- clang/lib/AST/Interp/Descriptor.cpp | 9 + clang/lib/AST/Interp/EvalEmitter.cpp | 1 + clang/lib/AST/Interp/Integral.h | 4 + clang/lib/AST/Interp/IntegralAP.h| 253 +++ clang/lib/AST/Interp/Interp.h| 21 +- clang/lib/AST/Interp/InterpStack.h | 5 + clang/lib/AST/Interp/Opcodes.td | 8 +- clang/lib/AST/Interp/PrimType.cpp| 1 + clang/lib/AST/Interp/PrimType.h | 13 ++ clang/test/AST/Interp/literals.cpp | 24 +++ 12 files changed, 343 insertions(+), 13 deletions(-) create mode 100644 clang/lib/AST/Interp/IntegralAP.h diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp index 17cf15d8676eb86..ec2ece71b301382 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -171,14 +171,17 @@ bool ByteCodeExprGen::VisitCastExpr(const CastExpr *CE) { return this->discard(SubExpr); std::optional FromT = classify(SubExpr->getType()); std::optional ToT = classify(CE->getType()); + if (!FromT || !ToT) return false; if (!this->visit(SubExpr)) return false; -if (FromT == ToT) +if (FromT == ToT) { + assert(ToT != PT_IntAP && ToT != PT_IntAPS); return true; +} return this->emitCast(*FromT, *ToT, CE); } @@ -1548,6 +1551,9 @@ bool ByteCodeExprGen::visitZeroInitializer(QualType QT, return this->emitZeroSint64(E); case PT_Uint64: return this->emitZeroUint64(E); + case PT_IntAP: + case PT_IntAPS: +assert(false); case PT_Ptr: return this->emitNullPtr(E); case PT_FnPtr: @@ -1787,6 +1793,9 @@ bool ByteCodeExprGen::emitConst(T Value, PrimType Ty, const Expr *E) { return this->emitConstSint64(Value, E); case PT_Uint64: return this->emitConstUint64(Value, E); + case PT_IntAP: + case PT_IntAPS: +assert(false); case PT_Bool: return this->emitConstBool(Value, E); case PT_Ptr: diff --git a/clang/lib/AST/Interp/Context.cpp b/clang/lib/AST/Interp/Context.cpp index 1a732b6c1a092ac..ed2b23514e86665 100644 --- a/clang/lib/AST/Interp/Context.cpp +++ b/clang/lib/AST/Interp/Context.cpp @@ -102,7 +102,8 @@ std::optional Context::classify(QualType T) const { case 8: return PT_Sint8; default: - return std::nullopt; + return PT_IntAPS; + // return std::nullopt; } } @@ -117,7 +118,8 @@ std::optional Context::classify(QualType T) const { case 8: return PT_Uint8; default: - return std::nullopt; + return PT_IntAP; + // return std::nullopt; } } diff --git a/clang/lib/AST/Interp/Descriptor.cpp b/clang/lib/AST/Interp/Descriptor.cpp index db49a569eff33ea..4ecb7466998e705 100644 --- a/clang/lib/AST/Interp/Descriptor.cpp +++ b/clang/lib/AST/Interp/Descriptor.cpp @@ -10,6 +10,7 @@ #include "Boolean.h" #include "Floating.h" #include "FunctionPointer.h" +#include "IntegralAP.h" #include "Pointer.h" #include "PrimType.h" #include "Record.h" @@ -182,6 +183,10 @@ static BlockCtorFn getCtorPrim(PrimType Type) { // constructor called. if (Type == PT_Float) return ctorTy::T>; + if (Type == PT_IntAP) +return ctorTy::T>; + if (Type == PT_IntAPS) +return ctorTy::T>; COMPOSITE_TYPE_SWITCH(Type, return ctorTy, return nullptr); } @@ -191,6 +196,10 @@ static BlockDtorFn getDtorPrim(PrimType Type) { // destructor called, since they might allocate memory. if (Type == PT_Float) return dtorTy::T>; + if (Type == PT_IntAP) +return dtorTy::T>; + if (Type == PT_IntAPS) +return dtorTy::T>; COMPOSITE_TYPE_SWITCH(Type, return dtorTy, return nullptr); } diff --git a/clang/lib/AST/Interp/EvalEmitter.cpp b/clang/lib/AST/Interp/EvalEmitter.cpp index d26ee8e40a437b9..c9332d8b2364fa1 100644 --- a/clang/lib/AST/Interp/EvalEmitter.cpp +++ b/clang/lib/AST/Interp/EvalEmitter.cpp @@ -8,6 +8,7 @@ #include "EvalEmitter.h" #include "Context.h" +#include "IntegralAP.h" #include "Interp.h" #include "Opcode.h" #include "Program.h" diff --git a/clang/lib/AST/Interp/Integral.h b/clang/lib/AST/Interp/Integral.h index 8d5edbb5b764eda..20c632cbac3f096 100644 --- a/clang/lib/AST/Interp/Integral.h +++
[clang] [clang][Interp] Add IntegralAP for arbitrary-precision integers (PR #65844)
https://github.com/tbaederr review_requested https://github.com/llvm/llvm-project/pull/65844 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Add IntegralAP for arbitrary-precision integers (PR #65844)
https://github.com/tbaederr review_requested https://github.com/llvm/llvm-project/pull/65844 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Interp] Add IntegralAP for arbitrary-precision integers (PR #65844)
https://github.com/tbaederr review_requested https://github.com/llvm/llvm-project/pull/65844 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits