Changeset View
Standalone View
clang/lib/CodeGen/CGCall.cpp
Show First 20 Lines • Show All 4,552 Lines • ▼ Show 20 Lines | public: | ||||
/// If we can, materialize the alignment as an attribute on return value. | /// If we can, materialize the alignment as an attribute on return value. | ||||
LLVM_NODISCARD llvm::AttributeList | LLVM_NODISCARD llvm::AttributeList | ||||
TryEmitAsCallSiteAttribute(const llvm::AttributeList &Attrs) { | TryEmitAsCallSiteAttribute(const llvm::AttributeList &Attrs) { | ||||
if (!AA || OffsetCI || CGF.SanOpts.has(SanitizerKind::Alignment)) | if (!AA || OffsetCI || CGF.SanOpts.has(SanitizerKind::Alignment)) | ||||
return Attrs; | return Attrs; | ||||
const auto *AlignmentCI = dyn_cast<llvm::ConstantInt>(Alignment); | const auto *AlignmentCI = dyn_cast<llvm::ConstantInt>(Alignment); | ||||
if (!AlignmentCI) | if (!AlignmentCI) | ||||
return Attrs; | return Attrs; | ||||
// We may legitimately have non-power-of-2 alignment here. | // Non power-of-2 alignment is UB and rejected by the IR verifier. | ||||
// If so, this is UB land, emit it via `@llvm.assume` instead. | if (!AlignmentCI->getValue().isPowerOf2()) { | ||||
if (!AlignmentCI->getValue().isPowerOf2()) | AA = nullptr; // We're done. Disallow doing anything else. | ||||
return Attrs; | return Attrs; | ||||
} | |||||
lebedev.ri: No, we should emit it as a simple assumption. | |||||
rmansfieldAuthorUnsubmitted Thanks for the feedback. Sorry for misunderstanding, from earlier comments I thought that no llvm.assume should be emitted for non-power-of-2 alignments. Can you elaborate on what you mean by simple assumption should be emitted? rmansfield: Thanks for the feedback. Sorry for misunderstanding, from earlier comments I thought that no… | |||||
lebedev.riUnsubmitted Not Done ReplyInline ActionsJust remove AA = nullptr; // We're done. Disallow doing anything else. here and you'll see lebedev.ri: Just remove `AA = nullptr; // We're done. Disallow doing anything else.` here and you'll see | |||||
rmansfieldAuthorUnsubmitted Sorry I didn't understand this comment and I haven't had time to revisit it to fully understand. I'm confused because if I remove the AA = nullptr; there's no change to clang and it will continue to generate an assume that the IR verifier is now being changed to reject. e.g. in clang/test/CodeGen/non-power-of-2-alignment-assumptions.c alloc(7); would generate %call = call i8* @alloc(i32 7) call void @llvm.assume(i1 true) [ "align"(i8* %call, i64 7) ] which would now be backend error: e.g alignment must be a power of 2 call void @llvm.assume(i1 true) [ "align"(i8* %call, i64 7) ] in function t1 fatal error: error in backend: Broken function found, compilation aborted! If you could explain what you would expect clang to emit in this case, I think that would help me and I can have another look. rmansfield: Sorry I didn't understand this comment and I haven't had time to revisit it to fully understand. | |||||
llvm::AttributeList NewAttrs = maybeRaiseRetAlignmentAttribute( | llvm::AttributeList NewAttrs = maybeRaiseRetAlignmentAttribute( | ||||
CGF.getLLVMContext(), Attrs, | CGF.getLLVMContext(), Attrs, | ||||
llvm::Align( | llvm::Align( | ||||
AlignmentCI->getLimitedValue(llvm::Value::MaximumAlignment))); | AlignmentCI->getLimitedValue(llvm::Value::MaximumAlignment))); | ||||
AA = nullptr; // We're done. Disallow doing anything else. | AA = nullptr; // We're done. Disallow doing anything else. | ||||
return NewAttrs; | return NewAttrs; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 974 Lines • Show Last 20 Lines |
No, we should emit it as a simple assumption.