[clang] [clang] Implement C2y stdc_load8_* endian-aware 8-bit load functions (PR #203666)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Sun Sep 6 00:01:19 PDT 2026
================
@@ -2103,6 +2103,91 @@ static bool isOneByteCharacterType(QualType T) {
return T->isCharType() || T->isChar8Type();
}
+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>();
+
+ if (Ptr.isZero()) {
+ S.FFDiag(S.Current->getSource(OpPC), diag::note_constexpr_access_null)
+ << AK_Read;
+ return false;
+ }
+
+ if (!isReadable(Ptr) && !Ptr.isOnePastEnd())
+ return false;
+
+ if (IsAligned) {
+ CharUnits RequiredAlign =
+ S.getASTContext().getTypeAlignInChars(Call->getType());
+ APValue AV = Ptr.toAPValue(S.getASTContext());
+ CharUnits BaseAlignment =
+ GetBaseAlignment(S.getASTContext(), AV.getLValueBase());
----------------
tbaederr wrote:
We basically already have an implementation of `getBaseAlignment()` in here: https://github.com/llvm/llvm-project/blob/cb25e7ca7cef9e84db077fe36f3d27b269394c65/clang/lib/AST/ByteCode/InterpBuiltin.cpp#L1424-L1428
https://github.com/llvm/llvm-project/pull/203666
More information about the cfe-commits
mailing list