Skip to content

Commit 5f77e77

Browse files
[InstCombine] Fixed crash when setting align attr for memalign
1 parent ddfbdbf commit 5f77e77

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2077,10 +2077,12 @@ void InstCombinerImpl::annotateAnyAllocSite(CallBase &Call, const TargetLibraryI
20772077
if (Op0C && Op0C->getValue().ult(llvm::Value::MaximumAlignment) &&
20782078
isKnownNonZero(Call.getOperand(1), DL, 0, &AC, &Call, &DT)) {
20792079
uint64_t AlignmentVal = Op0C->getZExtValue();
2080-
if (llvm::isPowerOf2_64(AlignmentVal))
2080+
if (llvm::isPowerOf2_64(AlignmentVal)) {
2081+
Call.removeAttribute(AttributeList::ReturnIndex, Attribute::Alignment);
20812082
Call.addAttribute(AttributeList::ReturnIndex,
20822083
Attribute::getWithAlignment(Call.getContext(),
20832084
Align(AlignmentVal)));
2085+
}
20842086
}
20852087
} else if (isReallocLikeFn(&Call, TLI) && Op1C) {
20862088
Call.addAttribute(AttributeList::ReturnIndex,

llvm/test/Transforms/InstCombine/deref-alloc-fns.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ declare noalias nonnull i8* @_Znam(i64) ; throwing version of 'new'
1010
declare noalias nonnull i8* @_Znwm(i64) ; throwing version of 'new'
1111
declare noalias i8* @strdup(i8*)
1212
declare noalias i8* @aligned_alloc(i64, i64)
13-
declare noalias i8* @memalign(i64, i64)
13+
declare noalias align 16 i8* @memalign(i64, i64)
1414

1515
@.str = private unnamed_addr constant [6 x i8] c"hello\00", align 1
1616

0 commit comments

Comments
 (0)