There was even a TODO for this.
The main motivation is to make use of call-site based
__attribute__((alloc_align(param_idx))) validation (D72996).
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Ah right, hmm, posted too soon.
I actually need to synthesize the size/align arguments.
Not only do we need to 'insert' size implicit argument,
but we may need to insert alignment implicit argument.
And while for size we can only insert nullptr,
for alignment we can actually insert the correct value.
It would be really useful to provide these extra parameters to FindAllocationFunctions too. For example, we could support direct dispatch to a size-class-specific allocation function:
void *operator new(std::size_t n) __attribute__((enable_if(n == 16, "optimized allocator for 16-byte objects")));
clang/lib/AST/ExprConstant.cpp | ||
---|---|---|
14464 | This is wrong and may result in user-visible non-conformance; an expression of type std::align_val_t should never return true from isIntegerConstantExpr, because align_val_t is a scoped enumeration. Can we instead change the caller (presumably the checking for the alloc_align attribute) to call a more general evaluation function rather than requiring an ICE? | |
clang/lib/Sema/SemaExprCXX.cpp | ||
2084–2086 | If this is not an array new, or it's an array new with a constant array bound, we can pass in a correct size. For the remaining (runtime array bound) cases, please conjure up an OpaqueValueExpr as the corresponding argument here rather than working around the nullptr argument in EvaluateWithSubstitution. | |
2095–2102 | Please put these on the stack rather than ASTContext-allocating them. Both of these classes already support stack allocation. |
Looks good if you change the error to a warning.
clang/lib/Sema/SemaChecking.cpp | ||
---|---|---|
4482–4486 | Oh, I wasn't aware we gave an error for this case. We can't issue an error for passing a bad alignment to operator new -- it's valid for code to pass a bad alignment, but results in undefined behavior. The same is true for aligned_alloc and posix_memalign, so we should presumably just downgrade this from an error to a warning in general rather than (say) treating operator new as a special case. For example, this is valid and may be reasonable in some cases: 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>(); |
clang/lib/Sema/SemaChecking.cpp | ||
---|---|---|
4482–4486 | Hmm. |
Rebased ontop of patch demoting call-site-based align attr checking from error into a warning, NFC.
I'm going to treat that as an implicit accept since the error got changed into a warning.
Will commit this soon.
This is wrong and may result in user-visible non-conformance; an expression of type std::align_val_t should never return true from isIntegerConstantExpr, because align_val_t is a scoped enumeration.
Can we instead change the caller (presumably the checking for the alloc_align attribute) to call a more general evaluation function rather than requiring an ICE?