[cfe-dev] Overflow(?) issue with ASTContext::getConstantArrayType
Keane, Erich via cfe-dev
cfe-dev at lists.llvm.org
Thu Dec 16 07:59:47 PST 2021
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?
-----Original Message-----
From: cfe-dev <cfe-dev-bounces at lists.llvm.org> On Behalf Of Francesco Bertolaccini via cfe-dev
Sent: Thursday, December 16, 2021 7:48 AM
To: cfe-dev at lists.llvm.org
Subject: [cfe-dev] Overflow(?) issue with ASTContext::getConstantArrayType
Hi everyone,
When using clang's API to generate C source code, I can create array types of size up to 1 << 26, but anything more than that results in a 0-sized array:
// This works ok
auto type1 = ast_ctx.getConstantArrayType(
elm_type, llvm::APInt(64, 1ull << 26), nullptr,
clang::ArrayType::ArraySizeModifier::Normal, 0);
// This generates a 0-sized array type
auto type2 = ast_ctx.getConstantArrayType(
elm_type, llvm::APInt(64, 1ull << 27), nullptr,
clang::ArrayType::ArraySizeModifier::Normal, 0);
Is this a known bug or am I holding the API wrong?
Thanks,
Francesco
_______________________________________________
cfe-dev mailing list
cfe-dev at lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
More information about the cfe-dev
mailing list