Skip to content

Commit bd992b0

Browse files
committed
Address memory addressing problems in vla (2)
1 parent 8fae6ac commit bd992b0

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

clang/tools/sotoc/src/TargetCode.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ void TargetCode::generateFunctionPrologue(TargetCodeRegion *TCR,
103103
Out << "void " << generateFunctionName(TCR) << "(";
104104
for (auto i = TCR->getCapturedVarsBegin(), e = TCR->getCapturedVarsEnd();
105105
i != e; ++i) {
106+
std::string VarName = (*i)->getDeclName().getAsString();
106107
auto C = TCR->GetReferredOMPClause(*i);
107108
if (!first) {
108109
Out << ", ";
@@ -117,10 +118,10 @@ void TargetCode::generateFunctionPrologue(TargetCodeRegion *TCR,
117118
int dim = 0;
118119

119120
std::vector<int> VariableDimensions;
120-
handleArrays(&t, DimString, dim, VariableDimensions, TCR, elemType);
121+
handleArrays(&t, DimString, dim, VariableDimensions, TCR, elemType, VarName);
121122

122123
for (int d : VariableDimensions) {
123-
Out << "unsigned long long __sotoc_vla_dim" << d << "_" << (*i)->getDeclName().getAsString() << ", ";
124+
Out << "unsigned long long __sotoc_vla_dim" << d << "_" << VarName << ", ";
124125
}
125126

126127
// set type to void* to avoid warnings from the compiler
@@ -140,7 +141,7 @@ void TargetCode::generateFunctionPrologue(TargetCodeRegion *TCR,
140141
}
141142
}
142143
}
143-
Out << (*i)->getDeclName().getAsString();
144+
Out << VarName;
144145
}
145146
Out << ")\n{\n";
146147

@@ -260,7 +261,8 @@ void TargetCode::handleArrays(const clang::ArrayType **t,
260261
std::list<std::string> &DimString, int &dim,
261262
std::vector<int> &VariableDims,
262263
TargetCodeRegion *TCR,
263-
std::string &elemType) {
264+
std::string &elemType,
265+
const std::string &ArrayName) {
264266
auto OrigT = *t;
265267

266268
if (!t) {
@@ -281,8 +283,7 @@ void TargetCode::handleArrays(const clang::ArrayType **t,
281283
DEBUGP("ArrayType VAT");
282284
std::string PrettyStr = "";
283285
llvm::raw_string_ostream PrettyOS(PrettyStr);
284-
clang::PrintingPolicy PP(TCR->GetLangOpts());
285-
t1->getSizeExpr()->printPretty(PrettyOS, NULL, PP);
286+
PrettyOS << "__sotoc_vla_dim" << dim << "_" << ArrayName;
286287
DimString.push_back(PrettyOS.str());
287288
VariableDims.push_back(dim);
288289
++dim;
@@ -298,6 +299,6 @@ void TargetCode::handleArrays(const clang::ArrayType **t,
298299
OrigT->getElementType().getTypePtr());
299300
if (*t) {
300301
// Recursively handle all dimensions
301-
handleArrays(t, DimString, dim, VariableDims, TCR, elemType);
302+
handleArrays(t, DimString, dim, VariableDims, TCR, elemType, ArrayName);
302303
}
303304
}

clang/tools/sotoc/src/TargetCode.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,5 +86,6 @@ class TargetCode {
8686
void handleArrays(const clang::ArrayType **t,
8787
std::list<std::string> &DimString, int &dim,
8888
std::vector<int> &VariableDimensions,
89-
TargetCodeRegion *TCR, std::string &elemType);
89+
TargetCodeRegion *TCR, std::string &elemType,
90+
const std::string &ArrayName);
9091
};

0 commit comments

Comments
 (0)