[cfe-dev] Overflow(?) issue with ASTContext::getConstantArrayType
Francesco Bertolaccini via cfe-dev
cfe-dev at lists.llvm.org
Thu Dec 16 09:02:53 PST 2021
On 16-Dec-21 16:59, Keane, Erich wrote:
> The ConstantArrayType stores the APInt it is given directly, HOWEVER, there is a modification of the size to 'max pointer width' on your target. When you try to create this outside of the API, we error when this is the case, though for the platforms I looked into, the lowest was 1 <<30 that caused problems.
>
> ASTContext.getConstantArrayType is zeroExtOrTrunc'ing the APInt you pass down to the "MaxPointerWidth" size for the target, though I only see ones that would cut it down to 64/32, or 16, not 26 (though AMDGPU and NVPTX do some funny business).
>
> Can you try confirming what happens when you do (1ull << 27 + 5)? If so, line 3488 here (https://clang.llvm.org/doxygen/ASTContext_8cpp_source.html#l03472) might be what is changing your type size. What target are you compiling for?
>
I've tried pinpointing the exact value with this
for (auto i{1ull << 26}; i < (1ull << 27); ++i) {
llvm::APInt sz{64, i};
auto& ast_ctx{ast_unit->getASTContext()};
auto type{ast_ctx.getConstantArrayType(
ast_ctx.CharTy, sz, nullptr,
clang::ArrayType::ArraySizeModifier::Normal, 0)};
auto atype{ast_ctx.getAsArrayType(type)};
auto catype{clang::cast<clang::ConstantArrayType>(atype)};
CHECK_EQ(catype->getSize().getZExtValue(), i);
}
which unfortunately didn't work, which I guess tells me the bug lies
somewhere else in the path from type to generating declarations.
I shall investigate more and report back! Thanks for now!
Francesco
More information about the cfe-dev
mailing list