Issue |
132077
|
Summary |
llvm::ConstantStruct::get returns a zero initialiser
|
Labels |
new issue
|
Assignees |
|
Reporter |
aldrinmathew
|
LLVM Version: 19
OS: Ubuntu 24.04 LTS
Target Triple: x86_64-unknown-linux-gnu
When `llvm::ConstantStruct::get` is called with a named struct type and zero value members, the `llvm::Constant*` returned is automatically a `zeroinitialiser`
```cpp
llvm::ConstantStruct::get(
llvm::dyn_cast<llvm::StructType>(finalTy->get_llvm_type()),
{llvm::ConstantPointerNull::get(llPtrTy),
llvm::ConstantInt::get(
llvm::Type::getIntNTy(
ctx->irCtx->llctx,
ctx->irCtx->clangTargetInfo->getTypeWidth(
ctx->irCtx->clangTargetInfo->getSizeType()
)
),
0u
)}
)
```
I can understand the sentiment behind this.
Later in the code when I use `constVal->getAggregateElement(0u)`, it fails saying that the value is not an aggregate.
I see two possible solutions:
1. Change the API so that the structural integrity of the constant value is maintained - The values are stored as is.
2. Update `getAggregateElement` to consider this edge case and return a zero value of the element type instead.
I don't know if this was already found or fixed. If so, kindly ignore and close the issue.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs