[Sema] Try 2: Attempt to perform call-size-specific `__attribute__((alloc_align(param...
authorRoman Lebedev <lebedev.ri@gmail.com>
Thu, 23 Jan 2020 19:49:50 +0000 (22:49 +0300)
committerRoman Lebedev <lebedev.ri@gmail.com>
Fri, 24 Jan 2020 11:42:45 +0000 (14:42 +0300)
commitba545c814bc19c3b1ec9ce88a7f13575e0e4ce1d
tree818f31747586210f2f9be9914ad23f398f8f10b7
parent1af6209d64dc503800797b647f9c281cc2c4ec87
[Sema] Try 2: Attempt to perform call-size-specific `__attribute__((alloc_align(param_idx)))` validation

Summary:
`alloc_align` attribute takes parameter number, not the alignment itself,
so given **just** the attribute/function declaration we can't do any
sanity checking for said alignment.

However, at call site, given the actual `Expr` that is passed
into that parameter, we //might// be able to evaluate said `Expr`
as Integer Constant Expression, and perform the sanity checks.
But since there is no requirement for that argument to be an immediate,
we may fail, and that's okay.

However if we did evaluate, we should enforce the same constraints
as with `__builtin_assume_aligned()`/`__attribute__((assume_aligned(imm)))`:
said alignment is a power of two, and is not greater than our magic threshold

This was initially committed in c2a9061ac5166e48fe85ea2b6dbce9457c964958
but reverted in 00756b182398b92abe16559287467079087aa631 because of
suspicious bot failures.

Reviewers: erichkeane, aaron.ballman, hfinkel, rsmith, jdoerfert

Reviewed By: erichkeane

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D72996
clang/lib/Sema/SemaChecking.cpp
clang/test/Sema/alloc-align-attr.c
clang/test/SemaCXX/alloc-align-attr.cpp