Skip to content

Commit 2090416

Browse files
author
z1.cciauto
committed
merge main into amd-staging
2 parents f0e500a + 8ec96cc commit 2090416

File tree

86 files changed

+1314
-600
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+1314
-600
lines changed

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3518,7 +3518,7 @@ bool Compiler<Emitter>::VisitCXXNewExpr(const CXXNewExpr *E) {
35183518
// ++Iter;
35193519
if (!this->emitGetPtrLocal(Iter, E))
35203520
return false;
3521-
if (!this->emitIncPop(SizeT, E))
3521+
if (!this->emitIncPop(SizeT, false, E))
35223522
return false;
35233523

35243524
if (!this->jump(StartLabel))
@@ -5957,7 +5957,8 @@ bool Compiler<Emitter>::VisitUnaryOperator(const UnaryOperator *E) {
59575957
: this->emitIncf(getFPOptions(E), E);
59585958
}
59595959

5960-
return DiscardResult ? this->emitIncPop(*T, E) : this->emitInc(*T, E);
5960+
return DiscardResult ? this->emitIncPop(*T, E->canOverflow(), E)
5961+
: this->emitInc(*T, E->canOverflow(), E);
59615962
}
59625963
case UO_PostDec: { // x--
59635964
if (!Ctx.getLangOpts().CPlusPlus14)
@@ -5980,7 +5981,8 @@ bool Compiler<Emitter>::VisitUnaryOperator(const UnaryOperator *E) {
59805981
: this->emitDecf(getFPOptions(E), E);
59815982
}
59825983

5983-
return DiscardResult ? this->emitDecPop(*T, E) : this->emitDec(*T, E);
5984+
return DiscardResult ? this->emitDecPop(*T, E->canOverflow(), E)
5985+
: this->emitDec(*T, E->canOverflow(), E);
59845986
}
59855987
case UO_PreInc: { // ++x
59865988
if (!Ctx.getLangOpts().CPlusPlus14)
@@ -6005,7 +6007,7 @@ bool Compiler<Emitter>::VisitUnaryOperator(const UnaryOperator *E) {
60056007
if (DiscardResult) {
60066008
if (T == PT_Float)
60076009
return this->emitIncfPop(getFPOptions(E), E);
6008-
return this->emitIncPop(*T, E);
6010+
return this->emitIncPop(*T, E->canOverflow(), E);
60096011
}
60106012

60116013
if (T == PT_Float) {
@@ -6020,13 +6022,7 @@ bool Compiler<Emitter>::VisitUnaryOperator(const UnaryOperator *E) {
60206022
return false;
60216023
} else {
60226024
assert(isIntegralType(*T));
6023-
if (!this->emitLoad(*T, E))
6024-
return false;
6025-
if (!this->emitConst(1, E))
6026-
return false;
6027-
if (!this->emitAdd(*T, E))
6028-
return false;
6029-
if (!this->emitStore(*T, E))
6025+
if (!this->emitPreInc(*T, E->canOverflow(), E))
60306026
return false;
60316027
}
60326028
return E->isGLValue() || this->emitLoadPop(*T, E);
@@ -6054,7 +6050,7 @@ bool Compiler<Emitter>::VisitUnaryOperator(const UnaryOperator *E) {
60546050
if (DiscardResult) {
60556051
if (T == PT_Float)
60566052
return this->emitDecfPop(getFPOptions(E), E);
6057-
return this->emitDecPop(*T, E);
6053+
return this->emitDecPop(*T, E->canOverflow(), E);
60586054
}
60596055

60606056
if (T == PT_Float) {
@@ -6069,13 +6065,7 @@ bool Compiler<Emitter>::VisitUnaryOperator(const UnaryOperator *E) {
60696065
return false;
60706066
} else {
60716067
assert(isIntegralType(*T));
6072-
if (!this->emitLoad(*T, E))
6073-
return false;
6074-
if (!this->emitConst(1, E))
6075-
return false;
6076-
if (!this->emitSub(*T, E))
6077-
return false;
6078-
if (!this->emitStore(*T, E))
6068+
if (!this->emitPreDec(*T, E->canOverflow(), E))
60796069
return false;
60806070
}
60816071
return E->isGLValue() || this->emitLoadPop(*T, E);

clang/lib/AST/ByteCode/Interp.h

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,8 @@ enum class IncDecOp {
765765
};
766766

767767
template <typename T, IncDecOp Op, PushVal DoPush>
768-
bool IncDecHelper(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
768+
bool IncDecHelper(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
769+
bool CanOverflow) {
769770
assert(!Ptr.isDummy());
770771

771772
if constexpr (std::is_same_v<T, Boolean>) {
@@ -780,16 +781,17 @@ bool IncDecHelper(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
780781
S.Stk.push<T>(Value);
781782

782783
if constexpr (Op == IncDecOp::Inc) {
783-
if (!T::increment(Value, &Result)) {
784+
if (!T::increment(Value, &Result) || !CanOverflow) {
784785
Ptr.deref<T>() = Result;
785786
return true;
786787
}
787788
} else {
788-
if (!T::decrement(Value, &Result)) {
789+
if (!T::decrement(Value, &Result) || !CanOverflow) {
789790
Ptr.deref<T>() = Result;
790791
return true;
791792
}
792793
}
794+
assert(CanOverflow);
793795

794796
// Something went wrong with the previous operation. Compute the
795797
// result with another bit of precision.
@@ -812,7 +814,6 @@ bool IncDecHelper(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
812814
<< Trunc << Type << E->getSourceRange();
813815
return true;
814816
}
815-
816817
return handleOverflow(S, OpPC, APResult);
817818
}
818819

@@ -821,49 +822,69 @@ bool IncDecHelper(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
821822
/// 3) Writes the value increased by one back to the pointer
822823
/// 4) Pushes the original (pre-inc) value on the stack.
823824
template <PrimType Name, class T = typename PrimConv<Name>::T>
824-
bool Inc(InterpState &S, CodePtr OpPC) {
825+
bool Inc(InterpState &S, CodePtr OpPC, bool CanOverflow) {
825826
const Pointer &Ptr = S.Stk.pop<Pointer>();
826827
if (!CheckLoad(S, OpPC, Ptr, AK_Increment))
827828
return false;
828829

829-
return IncDecHelper<T, IncDecOp::Inc, PushVal::Yes>(S, OpPC, Ptr);
830+
return IncDecHelper<T, IncDecOp::Inc, PushVal::Yes>(S, OpPC, Ptr,
831+
CanOverflow);
830832
}
831833

832834
/// 1) Pops a pointer from the stack
833835
/// 2) Load the value from the pointer
834836
/// 3) Writes the value increased by one back to the pointer
835837
template <PrimType Name, class T = typename PrimConv<Name>::T>
836-
bool IncPop(InterpState &S, CodePtr OpPC) {
838+
bool IncPop(InterpState &S, CodePtr OpPC, bool CanOverflow) {
837839
const Pointer &Ptr = S.Stk.pop<Pointer>();
838840
if (!CheckLoad(S, OpPC, Ptr, AK_Increment))
839841
return false;
840842

841-
return IncDecHelper<T, IncDecOp::Inc, PushVal::No>(S, OpPC, Ptr);
843+
return IncDecHelper<T, IncDecOp::Inc, PushVal::No>(S, OpPC, Ptr, CanOverflow);
844+
}
845+
846+
template <PrimType Name, class T = typename PrimConv<Name>::T>
847+
bool PreInc(InterpState &S, CodePtr OpPC, bool CanOverflow) {
848+
const Pointer &Ptr = S.Stk.peek<Pointer>();
849+
if (!CheckLoad(S, OpPC, Ptr, AK_Increment))
850+
return false;
851+
852+
return IncDecHelper<T, IncDecOp::Inc, PushVal::No>(S, OpPC, Ptr, CanOverflow);
842853
}
843854

844855
/// 1) Pops a pointer from the stack
845856
/// 2) Load the value from the pointer
846857
/// 3) Writes the value decreased by one back to the pointer
847858
/// 4) Pushes the original (pre-dec) value on the stack.
848859
template <PrimType Name, class T = typename PrimConv<Name>::T>
849-
bool Dec(InterpState &S, CodePtr OpPC) {
860+
bool Dec(InterpState &S, CodePtr OpPC, bool CanOverflow) {
850861
const Pointer &Ptr = S.Stk.pop<Pointer>();
851862
if (!CheckLoad(S, OpPC, Ptr, AK_Decrement))
852863
return false;
853864

854-
return IncDecHelper<T, IncDecOp::Dec, PushVal::Yes>(S, OpPC, Ptr);
865+
return IncDecHelper<T, IncDecOp::Dec, PushVal::Yes>(S, OpPC, Ptr,
866+
CanOverflow);
855867
}
856868

857869
/// 1) Pops a pointer from the stack
858870
/// 2) Load the value from the pointer
859871
/// 3) Writes the value decreased by one back to the pointer
860872
template <PrimType Name, class T = typename PrimConv<Name>::T>
861-
bool DecPop(InterpState &S, CodePtr OpPC) {
873+
bool DecPop(InterpState &S, CodePtr OpPC, bool CanOverflow) {
862874
const Pointer &Ptr = S.Stk.pop<Pointer>();
863875
if (!CheckLoad(S, OpPC, Ptr, AK_Decrement))
864876
return false;
865877

866-
return IncDecHelper<T, IncDecOp::Dec, PushVal::No>(S, OpPC, Ptr);
878+
return IncDecHelper<T, IncDecOp::Dec, PushVal::No>(S, OpPC, Ptr, CanOverflow);
879+
}
880+
881+
template <PrimType Name, class T = typename PrimConv<Name>::T>
882+
bool PreDec(InterpState &S, CodePtr OpPC, bool CanOverflow) {
883+
const Pointer &Ptr = S.Stk.peek<Pointer>();
884+
if (!CheckLoad(S, OpPC, Ptr, AK_Decrement))
885+
return false;
886+
887+
return IncDecHelper<T, IncDecOp::Dec, PushVal::No>(S, OpPC, Ptr, CanOverflow);
867888
}
868889

869890
template <IncDecOp Op, PushVal DoPush>

clang/lib/AST/ByteCode/Opcodes.td

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -593,10 +593,18 @@ def Shr : Opcode {
593593
def Inv: Opcode;
594594

595595
// Increment and decrement.
596-
def Inc: AluOpcode;
597-
def IncPop : AluOpcode;
598-
def Dec: AluOpcode;
599-
def DecPop: AluOpcode;
596+
class OverflowOpcode : Opcode {
597+
let Types = [AluTypeClass];
598+
let Args = [ArgBool];
599+
let HasGroup = 1;
600+
}
601+
602+
def Inc : OverflowOpcode;
603+
def IncPop : OverflowOpcode;
604+
def PreInc : OverflowOpcode;
605+
def Dec : OverflowOpcode;
606+
def DecPop : OverflowOpcode;
607+
def PreDec : OverflowOpcode;
600608

601609
// Float increment and decrement.
602610
def Incf: FloatOpcode;

clang/test/AST/ByteCode/literals.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,32 @@ namespace IncDec {
598598
static_assert(UnderFlow() == -1, ""); // both-error {{not an integral constant expression}} \
599599
// both-note {{in call to 'UnderFlow()'}}
600600

601+
/// This UnaryOperator can't overflow, so we shouldn't diagnose any overflow.
602+
constexpr int CanOverflow() {
603+
char c = 127;
604+
char p;
605+
++c;
606+
c++;
607+
p = ++c;
608+
p = c++;
609+
610+
c = -128;
611+
--c;
612+
c--;
613+
p = --c;
614+
p = ++c;
615+
616+
return 0;
617+
}
618+
static_assert(CanOverflow() == 0, "");
619+
620+
constexpr char OverflownChar() {
621+
char c = 127;
622+
c++;
623+
return c;
624+
}
625+
static_assert(OverflownChar() == -128, "");
626+
601627
constexpr int getTwo() {
602628
int i = 1;
603629
return (i += 1);

compiler-rt/cmake/base-config-ix.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
109109
extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" lib)
110110
set(COMPILER_RT_INSTALL_LIBRARY_DIR "${default_install_path}" CACHE PATH
111111
"Path where built compiler-rt libraries should be installed.")
112-
else()
112+
else(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
113113
set(COMPILER_RT_OUTPUT_LIBRARY_DIR
114114
${COMPILER_RT_OUTPUT_DIR}/lib/${COMPILER_RT_OS_DIR})
115115
extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" "lib/${COMPILER_RT_OS_DIR}")

libc/config/gpu/amdgpu/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
548548
libc.src.math.fabsf16
549549
libc.src.math.fdimf16
550550
libc.src.math.floorf16
551+
libc.src.math.fmaf16
551552
libc.src.math.fmaxf16
552553
libc.src.math.fmaximum_mag_numf16
553554
libc.src.math.fmaximum_magf16

libc/config/gpu/nvptx/entrypoints.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
550550
libc.src.math.fabsf16
551551
libc.src.math.fdimf16
552552
libc.src.math.floorf16
553+
libc.src.math.fmaf16
553554
libc.src.math.fmaxf16
554555
libc.src.math.fmaximum_mag_numf16
555556
libc.src.math.fmaximum_magf16

libc/config/linux/aarch64/entrypoints.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,7 @@ endif()
645645
if(LIBC_TYPES_HAS_FLOAT16)
646646
list(APPEND TARGET_LIBM_ENTRYPOINTS
647647
# math.h C23 _Float16 entrypoints
648+
libc.src.math.acoshf16
648649
libc.src.math.canonicalizef16
649650
libc.src.math.ceilf16
650651
libc.src.math.copysignf16
@@ -677,6 +678,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
677678
libc.src.math.ffma
678679
libc.src.math.ffmal
679680
libc.src.math.floorf16
681+
libc.src.math.fmaf16
680682
libc.src.math.fmaxf16
681683
libc.src.math.fmaximum_mag_numf16
682684
libc.src.math.fmaximum_magf16

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
654654
# math.h C23 _Float16 entrypoints
655655
libc.src.math.asinf16
656656
libc.src.math.acosf16
657+
libc.src.math.acoshf16
657658
libc.src.math.canonicalizef16
658659
libc.src.math.ceilf16
659660
libc.src.math.copysignf16
@@ -687,6 +688,7 @@ if(LIBC_TYPES_HAS_FLOAT16)
687688
libc.src.math.fabsf16
688689
libc.src.math.fdimf16
689690
libc.src.math.floorf16
691+
libc.src.math.fmaf16
690692
libc.src.math.fmaxf16
691693
libc.src.math.fmaximum_mag_numf16
692694
libc.src.math.fmaximum_magf16

libc/docs/headers/math/index.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ Higher Math Functions
251251
+===========+==================+=================+========================+======================+========================+========================+============================+
252252
| acos | |check| | | | |check| | | 7.12.4.1 | F.10.1.1 |
253253
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
254-
| acosh | |check| | | | | | 7.12.5.1 | F.10.2.1 |
254+
| acosh | |check| | | | |check| | | 7.12.5.1 | F.10.2.1 |
255255
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
256256
| acospi | | | | | | 7.12.4.8 | F.10.1.8 |
257257
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
@@ -299,7 +299,7 @@ Higher Math Functions
299299
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
300300
| expm1 | |check| | |check| | | |check| | | 7.12.6.6 | F.10.3.6 |
301301
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
302-
| fma | |check| | |check| | | | | 7.12.13.1 | F.10.10.1 |
302+
| fma | |check| | |check| | | |check| | | 7.12.13.1 | F.10.10.1 |
303303
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
304304
| f16sqrt | |check|\* | |check|\* | |check|\* | N/A | |check| | 7.12.14.6 | F.10.11 |
305305
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+

0 commit comments

Comments
 (0)