aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CGCall.cpp
diff options
context:
space:
mode:
authorRoman Lebedev <lebedev.ri@gmail.com>2020-02-20 16:39:26 +0300
committerRoman Lebedev <lebedev.ri@gmail.com>2020-02-20 16:39:26 +0300
commit9ea5d17cc9544838c73e593de4ef224d54fa1cff (patch)
treea1f5865f8e80e3ba63d1f6a1e76c6dbfcc1a5588 /clang/lib/CodeGen/CGCall.cpp
parentc7b7f76ae6ae2a5f3d9753b37ef811da15386cd4 (diff)
downloadllvm-9ea5d17cc9544838c73e593de4ef224d54fa1cff.zip
llvm-9ea5d17cc9544838c73e593de4ef224d54fa1cff.tar.gz
llvm-9ea5d17cc9544838c73e593de4ef224d54fa1cff.tar.bz2
[Sema] Demote call-site-based 'alignment is a power of two' check for AllocAlignAttr into a warning
Summary: As @rsmith notes in https://reviews.llvm.org/D73020#inline-672219 while that is certainly UB land, it may not be actually reachable at runtime, e.g.: ``` template<int N> void *make() { if ((N & (N-1)) == 0) return operator new(N, std::align_val_t(N)); else return operator new(N); } void *p = make<7>(); ``` and we shouldn't really error-out there. That being said, i'm not really following the logic here. Which ones of these cases should remain being an error? Reviewers: rsmith, erichkeane Reviewed By: erichkeane Subscribers: cfe-commits, rsmith Tags: #clang Differential Revision: https://reviews.llvm.org/D73996
Diffstat (limited to 'clang/lib/CodeGen/CGCall.cpp')
-rw-r--r--clang/lib/CodeGen/CGCall.cpp4
1 files changed, 4 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 6cc0154..98365db 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -3892,6 +3892,10 @@ public:
const auto *AlignmentCI = dyn_cast<llvm::ConstantInt>(Alignment);
if (!AlignmentCI)
return Attrs;
+ // We may legitimately have non-power-of-2 alignment here.
+ // If so, this is UB land, emit it via `@llvm.assume` instead.
+ if (!AlignmentCI->getValue().isPowerOf2())
+ return Attrs;
llvm::AttributeList NewAttrs = maybeRaiseRetAlignmentAttribute(
CGF.getLLVMContext(), Attrs,
llvm::Align(