[clang] [compiler-rt] Ubsan minimum assumed alignment (PR #166755)
Eli Friedman via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 6 08:59:14 PST 2025
================
@@ -1749,17 +1751,32 @@ llvm::Value *CodeGenFunction::EmitCXXNewExpr(const CXXNewExpr *E) {
allocator->isReservedGlobalPlacementOperator())
result = Builder.CreateLaunderInvariantGroup(result);
+ // Check the default alignment of the type and why. Users may incorrectly
+ // return misaligned memory from a replaced operator new without knowing
+ // about default alignment.
+ TypeCheckKind checkKind = CodeGenFunction::TCK_ConstructorCall;
+ CharUnits checkAlignment = result.getAlignment();
+ const TargetInfo &TI = getContext().getTargetInfo();
+ unsigned DefaultTargetAlignment = TI.getNewAlign() / TI.getCharWidth();
+ if (SanOpts.has(SanitizerKind::Alignment) &&
+ (DefaultTargetAlignment >
+ CGM.getContext().getTypeAlignInChars(allocType).getQuantity()) &&
+ !result.getAlignment().isOne() &&
----------------
efriedma-quic wrote:
Why do we need to check `!result.getAlignment().isOne()`?
https://github.com/llvm/llvm-project/pull/166755
More information about the llvm-commits
mailing list