diff --git a/project/src/transpiler/transpile_helper.cpp b/project/src/transpiler/transpile_helper.cpp index 6b958fc1..335b3771 100644 --- a/project/src/transpiler/transpile_helper.cpp +++ b/project/src/transpiler/transpile_helper.cpp @@ -537,7 +537,7 @@ EOObject GetInitListEOObject(const clang::InitListExpr *list) { ->getElementType(); } elementTypeName = GetTypeName(elementQualType); - elementSize *= context->getTypeInfo(elementQualType).Align / byte_size; + elementSize *= context->getTypeInfo(elementQualType).Width / byte_size; } else if (qualType->isRecordType()) { auto *recordType = transpiler.record_manager_.GetById( qualType->getAsRecordDecl()->getID()); @@ -932,10 +932,24 @@ std::pair getMultiDimArrayTypeSize( continue; } auto qt = decl_ref_expr->getType(); + auto n = decl_ref_expr->getStmtClassName(); EOObject arr_name = GetStmtEOObject(op->getBase()); - size_t sz = - decl_ref_expr->getDecl()->getASTContext().getTypeInfo(qt).Align / - byte_size; + size_t sz; + if (qt->isArrayType()) { + const auto *arr = qt->getAsArrayTypeUnsafe(); + if (arr->isConstantArrayType()) { + const auto *const_arr = dyn_cast(qt); + auto qelem_qt = const_arr->getElementType(); + sz = decl_ref_expr->getDecl() + ->getASTContext() + .getTypeInfo(qelem_qt) + .Width / + byte_size; + } + } else { + sz = decl_ref_expr->getDecl()->getASTContext().getTypeInfo(qt).Align / + byte_size; + } return std::make_pair(sz, arr_name); } if (stmt_class == Stmt::ArraySubscriptExprClass) { diff --git a/project/tests/main/types/type_formats/formats1.c b/project/tests/main/types/type_formats/formats1.c new file mode 100644 index 00000000..278b1469 --- /dev/null +++ b/project/tests/main/types/type_formats/formats1.c @@ -0,0 +1,15 @@ +#include + +int i1 = 555, i2 = 32; +unsigned int ui1 = 1111; +long long ll1 = 2222; + +int main() { + printf("%d\n", i1); + printf("%u\n", ui1); + printf("%lld\n", ll1); + printf("%o\n", i2); + printf("%x\n", i2); + return 0; +} +