Skip to content

Commit 2116d67

Browse files
committed
Only handle dimensions of VLA which are variable
1 parent bc30e45 commit 2116d67

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

clang/tools/sotoc/src/TargetCode.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ void TargetCode::generateCode(llvm::raw_ostream &Out) {
7777
if (TCR) {
7878
generateFunctionPrologue(TCR, Out);
7979
}
80-
80+
8181
Out << Frag->PrintPretty();
8282

8383
if (TCR) {
@@ -116,13 +116,11 @@ void TargetCode::generateFunctionPrologue(TargetCodeRegion *TCR,
116116
DEBUGP("Generating code for array type");
117117
int dim = 0;
118118

119-
auto *type_for_dim = t;
120-
handleArrays(&type_for_dim, DimString, dim, TCR, elemType);
119+
std::vector<int> VariableDimensions;
120+
handleArrays(&t, DimString, dim, VariableDimensions, TCR, elemType);
121121

122-
if (llvm::dyn_cast<clang::VariableArrayType>(t)) {
123-
for (int d = 0; d < dim; ++d) {
124-
Out << "unsigned long long __sotoc_vla_dim" << d << "_" << (*i)->getDeclName().getAsString() << ", ";
125-
}
122+
for (int d : VariableDimensions) {
123+
Out << "unsigned long long __sotoc_vla_dim" << d << "_" << (*i)->getDeclName().getAsString() << ", ";
126124
}
127125

128126
// set type to void* to avoid warnings from the compiler
@@ -260,7 +258,9 @@ std::string TargetCode::generateFunctionName(TargetCodeRegion *TCR) {
260258

261259
void TargetCode::handleArrays(const clang::ArrayType **t,
262260
std::list<std::string> &DimString, int &dim,
263-
TargetCodeRegion *TCR, std::string &elemType) {
261+
std::vector<int> &VariableDims,
262+
TargetCodeRegion *TCR,
263+
std::string &elemType) {
264264
auto OrigT = *t;
265265

266266
if (!t) {
@@ -284,6 +284,7 @@ void TargetCode::handleArrays(const clang::ArrayType **t,
284284
clang::PrintingPolicy PP(TCR->GetLangOpts());
285285
t1->getSizeExpr()->printPretty(PrettyOS, NULL, PP);
286286
DimString.push_back(PrettyOS.str());
287+
VariableDims.push_back(dim);
287288
++dim;
288289

289290
} else {
@@ -297,6 +298,6 @@ void TargetCode::handleArrays(const clang::ArrayType **t,
297298
OrigT->getElementType().getTypePtr());
298299
if (*t) {
299300
// Recursively handle all dimensions
300-
handleArrays(t, DimString, dim, TCR, elemType);
301+
handleArrays(t, DimString, dim, VariableDims, TCR, elemType);
301302
}
302303
}

clang/tools/sotoc/src/TargetCode.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,6 @@ class TargetCode {
8585
/// \param returns the last element type (i.e., the type of the array)
8686
void handleArrays(const clang::ArrayType **t,
8787
std::list<std::string> &DimString, int &dim,
88+
std::vector<int> &VariableDimensions,
8889
TargetCodeRegion *TCR, std::string &elemType);
8990
};

0 commit comments

Comments
 (0)