lebedev.ri added a comment. Hmm, i keep coming up with things here, sorry :/
I think we should take one more step - explicitly call out that the result of `__builtin_align_*` is, well, aligned :) For that, we need to add `__attribute__((alloc_align(2)))` attribute. Despite the name, it does not imply anything about provenance/aliasing/etc, only about alignment: https://godbolt.org/z/9bAjxK ================ Comment at: clang/docs/LanguageExtensions.rst:2854-2855 +qualifiers such as ``const``) with an adjusted address. +When aligning pointers up or down, the resulting value must be within the same +underlyig allocation (or one past the end), i.e., arbitrary integer values +stored in pointer-type variables must not be passed to these builtins. ---------------- Might be worth explicitly calling out C17 6.5.6p8, C++ [expr.add]? ================ Comment at: clang/lib/CodeGen/CGBuiltin.cpp:14329-14330 + // can use an inbounds GEP to enable better optimization. + Result = Builder.CreateInBoundsGEP(EmitCastToVoidPtr(Args.Src), Difference, + "aligned_result"); + Result = Builder.CreatePointerCast(Result, Args.SrcType); ---------------- I would suspect this should follow suit of the rest of clang codegen, i.e. do ``` Value* Base = EmitCastToVoidPtr(Args.Src); if (CGF.getLangOpts().isSignedOverflowDefined()) Result = Builder.CreateGEP(Base, Difference, "aligned_result"); else Result = CGF.EmitCheckedInBoundsGEP(Base, Difference, /*SignedIndices=*/true, /*isSubtraction*/=false, E->getExprLoc(), "aligned_result"); ``` Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D71499/new/ https://reviews.llvm.org/D71499 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits