Skip to content

Commit 61c7e1d

Browse files
committed
[Clang][CodeGen] Add comments. NFC.
1 parent 2796472 commit 61c7e1d

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

clang/lib/CodeGen/CGExprScalar.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4238,6 +4238,13 @@ static Value *emitPointerArithmetic(CodeGenFunction &CGF,
42384238
else
42394239
elemTy = CGF.ConvertTypeForMem(elementType);
42404240

4241+
// Some versions of glibc __PTR_ALIGN macro use idioms that add an index to a
4242+
// null pointer in order to cast the aligned integer value back to a pointer.
4243+
// This is undefined behavior, but we have to add a workaround for it.
4244+
//
4245+
// Unlike the above check `BinaryOperator::isNullPointerArithmeticExtension`,
4246+
// we still generate a GEP with a null-pointer base instead of inttoptr.
4247+
// This means that it's also UB to dereference a pointer created that way.
42414248
if (CGF.getLangOpts().PointerOverflowDefined ||
42424249
(!CGF.SanOpts.has(SanitizerKind::PointerOverflow) &&
42434250
CGF.isUnderlyingBasePointerConstantNull(pointerOperand)))

0 commit comments

Comments
 (0)