Skip to content

Commit 59e7294

Browse files
committed
Merge branch 'sotoc-remove-static-vars' into 'aurora_offloading_prototype'
Remove 'static' from global vars. Closes llvm#26 See merge request NEC-RWTH-Projects/clang!25
2 parents 72f2103 + 0145a0d commit 59e7294

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

clang/tools/sotoc/src/TargetCodeFragment.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,26 @@ std::string TargetCodeDecl::PrintPretty() {
270270

271271
TargetRegionPrinterHelper Helper(PP);
272272

273+
// This hack removes the 'static' keyword from globalVarDecls, because we
274+
// cannot find variables from the host if they are static.
275+
bool HasStaticKeyword = false;
276+
if (auto *VarDeclNode = llvm::dyn_cast<clang::VarDecl>(DeclNode)) {
277+
if (VarDeclNode->getStorageClass() == clang::SC_Static) {
278+
HasStaticKeyword = true;
279+
VarDeclNode->setStorageClass(clang::SC_None);
280+
}
281+
}
282+
273283
DeclNode->print(PrettyOS, LocalPP, 0, false, &Helper);
274284

285+
// Add static storage class back so (hopefully) this doesnt break anyting
286+
// (but it totally will).
287+
if (auto *VarDeclNode = llvm::dyn_cast<clang::VarDecl>(DeclNode)) {
288+
if (HasStaticKeyword) {
289+
VarDeclNode->setStorageClass(clang::SC_Static);
290+
}
291+
}
292+
275293
// This hack removes '#pragma omp declare target' from the output
276294
std::string outString = PrettyOS.str();
277295
const char *declareTargetPragma = "#pragma omp declare target";

0 commit comments

Comments
 (0)