llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-codegen
@llvm/pr-subscribers-clang
Author: NagaChaitanya Vellanki (chaitanyav)
<details>
<summary>Changes</summary>
Implement all 32 stdc_store8_* functions from C2y:
stdc_store8_le{u,s}{8,16,32,64}
stdc_store8_be{u,s}{8,16,32,64}
stdc_store8_aligned_le{u,s}{8,16,32,64}
stdc_store8_aligned_be{u,s}{8,16,32,64}
These write an N-bit integer to N/8 bytes of an unsigned char* in little- or
big-endian byte order.
Constexpr evaluation is supported in both the AST and bytecode interpreters.
Codegen emits an integer store, preceded by llvm.bswap when the requested byte
order differs from the target's.
The load8 and store8 evaluators now share their pointer checks and byte
iteration. No change to stdc_load8_* behavior.
---
Patch is 76.44 KiB, truncated to 20.00 KiB below, full version:
https://github.com/llvm/llvm-project/pull/241419.diff
10 Files Affected:
- (modified) clang/docs/ReleaseNotes.md (+7)
- (modified) clang/include/clang/Basic/Builtins.td (+48-10)
- (modified) clang/lib/AST/ByteCode/InterpBuiltin.cpp (+146-31)
- (modified) clang/lib/AST/ExprConstant.cpp (+134-25)
- (modified) clang/lib/CodeGen/CGBuiltin.cpp (+95)
- (modified) clang/lib/Sema/SemaChecking.cpp (+64)
- (added) clang/test/CodeGen/builtin-stdc-store8.c (+481)
- (modified) clang/test/Sema/Inputs/stdbit.h (+40)
- (added) clang/test/Sema/builtin-stdc-store8.c (+128)
- (added) clang/test/SemaCXX/constexpr-builtin-stdc-store8.cpp (+282)
``````````diff
diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index 0f9e7e01636d7..6063e306021ab 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -327,6 +327,13 @@ documentation](CIR/index.md) for more information
regarding ClangIR's status and
and assemble them into an integer using little-endian or big-endian
byte order.
+- Implemented the C2y `<stdbit.h>` endian-aware 8-bit store functions
+ `stdc_store8_{le,be}{u,s}{8,16,32,64}` and their aligned counterparts
+ `stdc_store8_aligned_{le,be}{u,s}{8,16,32,64}`. These functions write an
+ integer to N/8 bytes of an `unsigned char *` using little-endian or
+ big-endian byte order. They can be evaluated in constant expressions
+ through their `__builtin_` spellings.
+
- Clang now diagnoses the use of the same identifier with both internal and
external linkage within a translation unit, as made ill-formed by
[N3410](https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3410.pdf).
diff --git a/clang/include/clang/Basic/Builtins.td
b/clang/include/clang/Basic/Builtins.td
index 15693d2fe128e..cb5ca9225408b 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -38,11 +38,11 @@ class MemReverse8Template : Template<
["uint8_t", "uint16_t", "uint32_t", "uint64_t"],
["u8", "u16", "u32", "u64"]>;
-class Load8UnsignedTemplate : Template<
+class Load8Store8UnsignedTemplate : Template<
["uint_least8_t", "uint_least16_t", "uint_least32_t", "uint_least64_t"],
["8", "16", "32", "64"]>;
-class Load8SignedTemplate : Template<
+class Load8Store8SignedTemplate : Template<
["int_least8_t", "int_least16_t", "int_least32_t", "int_least64_t"],
["8", "16", "32", "64"]>;
@@ -1016,38 +1016,76 @@ class Load8Common : LibBuiltin<"stdbit.h", "C2Y_LANG"> {
let Prototype = "T(const unsigned char*)";
}
-def StdcLoad8LeU : Load8Common, Load8UnsignedTemplate {
+def StdcLoad8LeU : Load8Common, Load8Store8UnsignedTemplate {
let Spellings = ["stdc_load8_leu"];
}
-def StdcLoad8BeU : Load8Common, Load8UnsignedTemplate {
+def StdcLoad8BeU : Load8Common, Load8Store8UnsignedTemplate {
let Spellings = ["stdc_load8_beu"];
}
-def StdcLoad8AlignedLeU : Load8Common, Load8UnsignedTemplate {
+def StdcLoad8AlignedLeU : Load8Common, Load8Store8UnsignedTemplate {
let Spellings = ["stdc_load8_aligned_leu"];
}
-def StdcLoad8AlignedBeU : Load8Common, Load8UnsignedTemplate {
+def StdcLoad8AlignedBeU : Load8Common, Load8Store8UnsignedTemplate {
let Spellings = ["stdc_load8_aligned_beu"];
}
-def StdcLoad8LeS : Load8Common, Load8SignedTemplate {
+def StdcLoad8LeS : Load8Common, Load8Store8SignedTemplate {
let Spellings = ["stdc_load8_les"];
}
-def StdcLoad8BeS : Load8Common, Load8SignedTemplate {
+def StdcLoad8BeS : Load8Common, Load8Store8SignedTemplate {
let Spellings = ["stdc_load8_bes"];
}
-def StdcLoad8AlignedLeS : Load8Common, Load8SignedTemplate {
+def StdcLoad8AlignedLeS : Load8Common, Load8Store8SignedTemplate {
let Spellings = ["stdc_load8_aligned_les"];
}
-def StdcLoad8AlignedBeS : Load8Common, Load8SignedTemplate {
+def StdcLoad8AlignedBeS : Load8Common, Load8Store8SignedTemplate {
let Spellings = ["stdc_load8_aligned_bes"];
}
+class Store8Common : LibBuiltin<"stdbit.h", "C2Y_LANG"> {
+ let Attributes = [NoThrow, Constexpr, NonNull<NonOptimizing, [1]>];
+ let Prototype = "void(T, unsigned char*)";
+ let AddBuiltinPrefixedAlias = 1;
+}
+
+def StdcStore8LeU : Store8Common, Load8Store8UnsignedTemplate {
+ let Spellings = ["stdc_store8_leu"];
+}
+
+def StdcStore8BeU : Store8Common, Load8Store8UnsignedTemplate {
+ let Spellings = ["stdc_store8_beu"];
+}
+
+def StdcStore8AlignedLeU : Store8Common, Load8Store8UnsignedTemplate {
+ let Spellings = ["stdc_store8_aligned_leu"];
+}
+
+def StdcStore8AlignedBeU : Store8Common, Load8Store8UnsignedTemplate {
+ let Spellings = ["stdc_store8_aligned_beu"];
+}
+
+def StdcStore8LeS : Store8Common, Load8Store8SignedTemplate {
+ let Spellings = ["stdc_store8_les"];
+}
+
+def StdcStore8BeS : Store8Common, Load8Store8SignedTemplate {
+ let Spellings = ["stdc_store8_bes"];
+}
+
+def StdcStore8AlignedLeS : Store8Common, Load8Store8SignedTemplate {
+ let Spellings = ["stdc_store8_aligned_les"];
+}
+
+def StdcStore8AlignedBeS : Store8Common, Load8Store8SignedTemplate {
+ let Spellings = ["stdc_store8_aligned_bes"];
+}
+
// Random GCC builtins
// FIXME: The builtins marked FunctionWithBuiltinPrefix below should be
diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index e35e198da0dcb..80c64be959f34 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -2240,15 +2240,20 @@ static bool
interp__builtin_stdc_memreverse8(InterpState &S, CodePtr OpPC,
return true;
}
-static bool interp__builtin_load8(InterpState &S, CodePtr OpPC,
- const InterpFrame *Frame,
- const CallExpr *Call, bool IsBigEndian,
- bool IsAligned) {
- Pointer Ptr = S.Stk.pop<Pointer>();
-
+/// Checks that the bytes of a ValueTy at Ptr can be accessed with AK, then
+/// calls Fn(BytePtr, ElemT, Shift) for each byte in memory order. The
aligned_*
+/// variants also require Ptr to be aligned to ValueTy. With N the bit width of
+/// ValueTy, the byte at Ptr[I] is placed at bit Shift of the value, where
+/// Shift is 8 * I for little-endian and 8 * (N/8 - I - 1) for big-endian. This
+/// matches the b_index mapping in §7.18.21 (loads) and the index sequence in
+/// §7.18.22 (stores).
+static bool forEachLoad8Store8Byte(
+ InterpState &S, CodePtr OpPC, const CallExpr *Call, Pointer Ptr,
+ QualType ValueTy, AccessKinds AK, bool IsBigEndian, bool IsAligned,
+ llvm::function_ref<bool(const Pointer &, PrimType, unsigned)> Fn) {
if (Ptr.isZero()) {
S.FFDiag(S.Current->getSource(OpPC), diag::note_constexpr_access_null)
- << AK_Read;
+ << AK;
return false;
}
@@ -2259,8 +2264,7 @@ static bool interp__builtin_load8(InterpState &S, CodePtr
OpPC,
return false;
if (IsAligned) {
- CharUnits RequiredAlign =
- S.getASTContext().getTypeAlignInChars(Call->getType());
+ CharUnits RequiredAlign = S.getASTContext().getTypeAlignInChars(ValueTy);
CharUnits BaseAlignment = getBaseAlignment(S.getASTContext(), Ptr);
std::optional<size_t> LayoutOffset =
Ptr.computeLayoutOffset(S.getASTContext());
@@ -2289,7 +2293,7 @@ static bool interp__builtin_load8(InterpState &S, CodePtr
OpPC,
uint64_t ArraySize = Ptr.getNumElems();
uint64_t RemainingElems = ArraySize - BaseIdx;
- unsigned ByteWidth = S.getASTContext().getTypeSize(Call->getType()) / 8;
+ unsigned ByteWidth = S.getASTContext().getTypeSize(ValueTy) / 8;
if (ByteWidth > RemainingElems) {
uint64_t LastIndex = llvm::SaturatingAdd(BaseIdx, uint64_t(ByteWidth - 1));
S.FFDiag(S.Current->getSource(OpPC), diag::note_constexpr_array_index)
@@ -2300,34 +2304,68 @@ static bool interp__builtin_load8(InterpState &S,
CodePtr OpPC,
OptPrimType ElemT = S.getContext().classify(ElemTy);
if (!ElemT || !isIntegerOrBoolType(*ElemT))
return false;
- uint64_t Result = 0;
+ assert((IsArray || ByteWidth == 1) &&
+ "non-array pointer, expected a 1-byte access");
- if (IsArray) {
- // C2y §7.18.21: result = sum(b_index * 2^(8*index)) for index in [0, N/8)
- // where b_index = ptr[index] (LE) or ptr[N/8 - index - 1] (BE).
- for (unsigned I = 0; I != ByteWidth; ++I) {
- size_t SrcIdx = IsBigEndian ? (ByteWidth - I - 1) : I;
- Pointer BytePtr = Ptr.atIndex(BaseIdx + SrcIdx);
- if (!CheckLoad(S, OpPC, BytePtr, AK_Read))
- return false;
- INT_TYPE_SWITCH(*ElemT, {
- Result |= BytePtr.load<T>().toAPSInt().getZExtValue() << (8 * I);
- });
- }
- } else {
- assert(ByteWidth == 1 && "non-array pointer, expected a 1-byte load");
- if (!CheckLoad(S, OpPC, Ptr, AK_Read))
+ for (unsigned I = 0; I != ByteWidth; ++I) {
+ Pointer BytePtr = IsArray ? Ptr.atIndex(BaseIdx + I) : Ptr;
+ unsigned Shift = 8 * (IsBigEndian ? ByteWidth - I - 1 : I);
+ if (!Fn(BytePtr, *ElemT, Shift))
return false;
- INT_TYPE_SWITCH(*ElemT,
- { Result = Ptr.load<T>().toAPSInt().getZExtValue(); });
}
+ return true;
+}
- bool IsSigned = Call->getType()->isSignedIntegerType();
- pushInteger(S, APSInt(APInt(ByteWidth * 8, Result), !IsSigned),
- Call->getType());
+static bool interp__builtin_load8(InterpState &S, CodePtr OpPC,
+ const InterpFrame *Frame,
+ const CallExpr *Call, bool IsBigEndian,
+ bool IsAligned) {
+ Pointer Ptr = S.Stk.pop<Pointer>();
+ QualType ResultTy = Call->getType();
+
+ uint64_t Result = 0;
+ if (!forEachLoad8Store8Byte(
+ S, OpPC, Call, Ptr, ResultTy, AK_Read, IsBigEndian, IsAligned,
+ [&](const Pointer &BytePtr, PrimType ElemT, unsigned Shift) {
+ if (!CheckLoad(S, OpPC, BytePtr, AK_Read))
+ return false;
+ INT_TYPE_SWITCH(ElemT, {
+ Result |= BytePtr.load<T>().toAPSInt().getZExtValue() << Shift;
+ });
+ return true;
+ }))
+ return false;
+
+ unsigned BitWidth = S.getASTContext().getTypeSize(ResultTy);
+ pushInteger(S,
+ APSInt(APInt(BitWidth, Result),
!ResultTy->isSignedIntegerType()),
+ ResultTy);
return true;
}
+static bool interp__builtin_store8(InterpState &S, CodePtr OpPC,
+ const InterpFrame *Frame,
+ const CallExpr *Call, bool IsBigEndian,
+ bool IsAligned) {
+ Pointer Ptr = S.Stk.pop<Pointer>();
+ QualType ValueTy = Call->getArg(0)->getType();
+ uint64_t ValueBits;
+ if (!popToUInt64(S, Call->getArg(0), ValueBits))
+ return false;
+
+ return forEachLoad8Store8Byte(
+ S, OpPC, Call, Ptr, ValueTy, AK_Assign, IsBigEndian, IsAligned,
+ [&](const Pointer &BytePtr, PrimType ElemT, unsigned Shift) {
+ if (!CheckStore(S, OpPC, BytePtr))
+ return false;
+ uint8_t Byte = ValueBits >> Shift;
+ FIXED_SIZE_INT_TYPE_SWITCH(ElemT,
+ { BytePtr.deref<T>() = T::from(Byte); });
+ BytePtr.initialize();
+ return true;
+ });
+}
+
static bool interp__builtin_memcmp(InterpState &S, CodePtr OpPC,
const InterpFrame *Frame,
const CallExpr *Call, unsigned ID) {
@@ -4808,6 +4846,7 @@ static bool interp__builtin_meta_is_type(InterpState &S,
CodePtr OpPC,
bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
uint32_t BuiltinID) {
const InterpFrame *Frame = S.Current;
+
switch (BuiltinID) {
case Builtin::BI__builtin_is_constant_evaluated:
return interp__builtin_is_constant_evaluated(S, OpPC, Frame, Call);
@@ -5384,6 +5423,82 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC,
const CallExpr *Call,
return interp__builtin_load8(S, OpPC, Frame, Call, /*IsBigEndian=*/true,
/*IsAligned=*/true);
+ case Builtin::BIstdc_store8_leu8:
+ case Builtin::BI__builtin_stdc_store8_leu8:
+ case Builtin::BIstdc_store8_leu16:
+ case Builtin::BI__builtin_stdc_store8_leu16:
+ case Builtin::BIstdc_store8_leu32:
+ case Builtin::BI__builtin_stdc_store8_leu32:
+ case Builtin::BIstdc_store8_leu64:
+ case Builtin::BI__builtin_stdc_store8_leu64:
+ case Builtin::BIstdc_store8_les8:
+ case Builtin::BI__builtin_stdc_store8_les8:
+ case Builtin::BIstdc_store8_les16:
+ case Builtin::BI__builtin_stdc_store8_les16:
+ case Builtin::BIstdc_store8_les32:
+ case Builtin::BI__builtin_stdc_store8_les32:
+ case Builtin::BIstdc_store8_les64:
+ case Builtin::BI__builtin_stdc_store8_les64:
+ return interp__builtin_store8(S, OpPC, Frame, Call, /*IsBigEndian=*/false,
+ /*IsAligned=*/false);
+
+ case Builtin::BIstdc_store8_aligned_leu8:
+ case Builtin::BI__builtin_stdc_store8_aligned_leu8:
+ case Builtin::BIstdc_store8_aligned_leu16:
+ case Builtin::BI__builtin_stdc_store8_aligned_leu16:
+ case Builtin::BIstdc_store8_aligned_leu32:
+ case Builtin::BI__builtin_stdc_store8_aligned_leu32:
+ case Builtin::BIstdc_store8_aligned_leu64:
+ case Builtin::BI__builtin_stdc_store8_aligned_leu64:
+ case Builtin::BIstdc_store8_aligned_les8:
+ case Builtin::BI__builtin_stdc_store8_aligned_les8:
+ case Builtin::BIstdc_store8_aligned_les16:
+ case Builtin::BI__builtin_stdc_store8_aligned_les16:
+ case Builtin::BIstdc_store8_aligned_les32:
+ case Builtin::BI__builtin_stdc_store8_aligned_les32:
+ case Builtin::BIstdc_store8_aligned_les64:
+ case Builtin::BI__builtin_stdc_store8_aligned_les64:
+ return interp__builtin_store8(S, OpPC, Frame, Call, /*IsBigEndian=*/false,
+ /*IsAligned=*/true);
+
+ case Builtin::BIstdc_store8_beu8:
+ case Builtin::BI__builtin_stdc_store8_beu8:
+ case Builtin::BIstdc_store8_beu16:
+ case Builtin::BI__builtin_stdc_store8_beu16:
+ case Builtin::BIstdc_store8_beu32:
+ case Builtin::BI__builtin_stdc_store8_beu32:
+ case Builtin::BIstdc_store8_beu64:
+ case Builtin::BI__builtin_stdc_store8_beu64:
+ case Builtin::BIstdc_store8_bes8:
+ case Builtin::BI__builtin_stdc_store8_bes8:
+ case Builtin::BIstdc_store8_bes16:
+ case Builtin::BI__builtin_stdc_store8_bes16:
+ case Builtin::BIstdc_store8_bes32:
+ case Builtin::BI__builtin_stdc_store8_bes32:
+ case Builtin::BIstdc_store8_bes64:
+ case Builtin::BI__builtin_stdc_store8_bes64:
+ return interp__builtin_store8(S, OpPC, Frame, Call, /*IsBigEndian=*/true,
+ /*IsAligned=*/false);
+
+ case Builtin::BIstdc_store8_aligned_beu8:
+ case Builtin::BI__builtin_stdc_store8_aligned_beu8:
+ case Builtin::BIstdc_store8_aligned_beu16:
+ case Builtin::BI__builtin_stdc_store8_aligned_beu16:
+ case Builtin::BIstdc_store8_aligned_beu32:
+ case Builtin::BI__builtin_stdc_store8_aligned_beu32:
+ case Builtin::BIstdc_store8_aligned_beu64:
+ case Builtin::BI__builtin_stdc_store8_aligned_beu64:
+ case Builtin::BIstdc_store8_aligned_bes8:
+ case Builtin::BI__builtin_stdc_store8_aligned_bes8:
+ case Builtin::BIstdc_store8_aligned_bes16:
+ case Builtin::BI__builtin_stdc_store8_aligned_bes16:
+ case Builtin::BIstdc_store8_aligned_bes32:
+ case Builtin::BI__builtin_stdc_store8_aligned_bes32:
+ case Builtin::BIstdc_store8_aligned_bes64:
+ case Builtin::BI__builtin_stdc_store8_aligned_bes64:
+ return interp__builtin_store8(S, OpPC, Frame, Call, /*IsBigEndian=*/true,
+ /*IsAligned=*/true);
+
case Builtin::BI__atomic_always_lock_free:
case Builtin::BI__atomic_is_lock_free:
return interp__builtin_atomic_lock_free(S, OpPC, Frame, Call, BuiltinID);
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 57d5bb475d0f9..690d0349b2cc6 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -17161,25 +17161,29 @@ static bool getBuiltinAlignArguments(const CallExpr
*E, EvalInfo &Info,
return true;
}
-// Implements the C2y §7.18.21 stdc_load8_* family: reads N bytes from
-// E->getArg(0) and assembles them per IsBE into a value of E's type. The
-// aligned_* variants additionally require the pointer to be aligned to the
-// natural alignment of E's type.
-static bool EvaluateStdcLoad8(EvalInfo &Info, const CallExpr *E, bool IsBE,
- bool IsAligned, APSInt &Result) {
+/// Evaluates PtrArg and checks that the bytes of a ValueTy it points to can be
+/// accessed with AK, then calls Fn(BytePtr, CharTy, Shift) for each byte in
+/// memory order. The aligned_* variants also require the pointer to be aligned
+/// to ValueTy. With N the bit width of ValueTy, the byte at Ptr[I] is placed
at
+/// bit Shift of the value, where Shift is 8 * I for little-endian and
+/// 8 * (N/8 - I - 1) for big-endian. This matches the b_index mapping in
+/// §7.18.21 (loads) and the index sequence in §7.18.22 (stores).
+static bool ForEachStdcLoadStore8Byte(
+ EvalInfo &Info, const CallExpr *E, const Expr *PtrArg, QualType ValueTy,
+ AccessKinds AK, bool IsBE, bool IsAligned,
+ llvm::function_ref<bool(const LValue &, QualType, unsigned)> Fn) {
LValue Ptr;
- if (!EvaluatePointer(E->getArg(0), Ptr, Info))
+ if (!EvaluatePointer(PtrArg, Ptr, Info))
return false;
- if (!Ptr.checkNullPointerForFoldAccess(Info, E, AK_Read) ||
- Ptr.Designator.Invalid)
+ if (!Ptr.checkNullPointerForFoldAccess(Info, E, AK) ||
Ptr.Designator.Invalid)
return false;
if (Ptr.Designator.isMostDerivedAnUnsizedArray())
return false;
if (IsAligned) {
- CharUnits RequiredAlign = Info.Ctx.getTypeAlignInChars(E->getType());
+ CharUnits RequiredAlign = Info.Ctx.getTypeAlignInChars(ValueTy);
CharUnits BaseAlignment = getBaseAlignment(Info, Ptr);
CharUnits PtrAlign = BaseAlignment.alignmentAtOffset(Ptr.Offset);
if (PtrAlign < RequiredAlign) {
@@ -17191,7 +17195,7 @@ static bool EvaluateStdcLoad8(EvalInfo &Info, const
CallExpr *E, bool IsBE,
}
QualType CharTy = Ptr.Designator.getType(Info.Ctx);
- unsigned ByteWidth = Info.Ctx.getTypeSize(E->getType()) / 8;
+ unsigned ByteWidth = Info.Ctx.getTypeSize(ValueTy) / 8;
uint64_t RemainingElems = Ptr.Designator.validIndexAdjustments().second;
if (ByteWidth > RemainingElems) {
uint64_t ArrayIndex = Ptr.Designator.MostDerivedIsArrayElement
@@ -17202,27 +17206,60 @@ static bool EvaluateStdcLoad8(EvalInfo &Info, const
CallExpr *E, bool IsBE,
return false;
}
- // Load the bytes and assemble them per C2y §7.18.21:
- // result = sum(b_index * 2^(8*index)) where b_index = ptr[index] (LE)
- // or ptr[N/8 - index - 1] (BE).
- uint64_t ResultBits = 0;
- LValue BytePtr = Ptr;
for (unsigned I = 0; I < ByteWidth; ++I) {
- APValue ByteVal;
- if (!handleLValueToRValueConversion(Info, E, CharTy, BytePtr, ByteVal))
- return false;
unsigned Shift = 8 * (IsBE ? ByteWidth - I - 1 : I);
- ResultBits |= ByteVal.getInt().getZExtValue() << Shift;
- if (I + 1 < ByteWidth)
- if (!HandleLValueArrayAdjustment(Info, E, BytePtr, CharTy, 1))
- return false;
+ if (!Fn(Ptr, CharTy, Shift))
+ return false;
+ if (I + 1 < ByteWidth &&
+ !HandleLValueArrayAdjustment(Info, E, Ptr, CharTy, 1))
+ return false;
}
+ return true;
+}
+
+// Implements the C2y §7.18.21 stdc_load8_* family: reads N bytes from
+// E->getArg(0) and assembles them per IsBE into a value of E's type.
+static bool EvaluateStdcLoad8(EvalInfo &Info, const CallExpr *E, bool IsBE,
+ bool IsAligned, APSInt &Result) {
+ QualType ResultTy = E->getType();
+ uint64_t ResultBits = 0;
+ if (!ForEachStdcLoadStore8Byte(
+ Info, E, E->getArg(0), ResultTy, AK_Read, IsBE, IsAligned,
+ [&](const LValue &BytePtr, QualType CharTy, unsigned Shift) {
+ APValue ByteVal;
+ if (!handleLValueToRValueConversion(Info, E, CharTy, BytePtr,
+ ByteVal))
+ return false;
+ ResultBits |= ByteVal.getInt().getZExtValue() << Shift;
+ return true;
+ }))
+ return false;
- bool IsSigned = E->getType()->isSignedIntegerType();
- Result = APSInt(APInt(ByteWidth * 8, ResultBits), !IsSigned);
+ unsigned BitWidth = Info.Ctx.getTypeSize(ResultTy);
+ Result =
+ APSInt(APInt(BitWidth, ResultBits), !ResultTy->isSignedIntegerType());
return true;
}
+// Implements the C2y §7.18.22 stdc_store8_* family: writes the N-bit value
+// E->getArg(0) to the bytes at E->getArg(1) per IsBE.
+static bool EvaluateStdcStore8(EvalInfo &Info, const CallExpr *E, bool IsBE,
+ bool IsAligned) {
+ const Expr *ValueArg = E->getArg(0);
+ APSInt Value;
+ if (!EvaluateInteger(ValueArg, Value, Info))
+ return false;
+
+ uint64_t ValueBits = Value.getZExtValue();
+ return ForEachStdcLoadStore8Byte(
+ Info, E, E->getArg(1), ValueArg->getType(), AK_As...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/241419
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits