aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Sams <jsams@google.com>2011-09-19 14:09:48 -0700
committerJason Sams <jsams@google.com>2011-09-19 14:09:48 -0700
commit6329130ea0fb68c1bf26695cec2f884738f19a25 (patch)
treec70b9d69f8e17c14daaa84f487a3901a898a585b
parent154e54e438e464a814ac33d10cb43686a068ed5d (diff)
downloadframeworks_compile_slang-6329130ea0fb68c1bf26695cec2f884738f19a25.tar.gz
frameworks_compile_slang-6329130ea0fb68c1bf26695cec2f884738f19a25.tar.bz2
frameworks_compile_slang-6329130ea0fb68c1bf26695cec2f884738f19a25.zip
DO NOT MERGE, cherry-pick from master
Fix .rs.dtor scoping bug. BUG=5267595 This change makes sure to scope any helper variables (like rsIntIter) to the enclosing function (and not make them global). Prior to this change, if an array iterator was created, it would be marked as a global symbol. The libbcc library then sometimes removed this global as it was not able to determine that it was actually used (.rs.dtor is not guaranteed to be called). A fix should be made to libbcc as well, but the proper fix for llvm-rs-cc is to scope any helper variable declarations to the calling function. Change-Id: Ia46654cb0a114f6f5495e32ad1508d7d01e2084b
-rw-r--r--slang_rs_object_ref_count.cpp29
-rw-r--r--slang_rs_object_ref_count.h3
2 files changed, 20 insertions, 12 deletions
diff --git a/slang_rs_object_ref_count.cpp b/slang_rs_object_ref_count.cpp
index e35c677..88ffc62 100644
--- a/slang_rs_object_ref_count.cpp
+++ b/slang_rs_object_ref_count.cpp
@@ -1230,7 +1230,7 @@ void RSObjectRefCount::Scope::InsertLocalVarDestructors() {
I != E;
I++) {
clang::VarDecl *VD = *I;
- clang::Stmt *RSClearObjectCall = ClearRSObject(VD);
+ clang::Stmt *RSClearObjectCall = ClearRSObject(VD, VD->getDeclContext());
if (RSClearObjectCall) {
DestructorVisitor DV((*mRSO.begin())->getASTContext(),
mCS,
@@ -1243,10 +1243,11 @@ void RSObjectRefCount::Scope::InsertLocalVarDestructors() {
return;
}
-clang::Stmt *RSObjectRefCount::Scope::ClearRSObject(clang::VarDecl *VD) {
+clang::Stmt *RSObjectRefCount::Scope::ClearRSObject(
+ clang::VarDecl *VD,
+ clang::DeclContext *DC) {
slangAssert(VD);
clang::ASTContext &C = VD->getASTContext();
- clang::DeclContext *DC = VD->getDeclContext();
clang::SourceLocation Loc = VD->getLocation();
clang::SourceLocation StartLoc = VD->getInnerLocStart();
const clang::Type *T = RSExportType::GetTypeOfDecl(VD);
@@ -1494,6 +1495,13 @@ clang::FunctionDecl *RSObjectRefCount::CreateStaticGlobalDtor() {
clang::DeclContext *DC = mCtx.getTranslationUnitDecl();
clang::SourceLocation loc;
+ llvm::StringRef SR(".rs.dtor");
+ clang::IdentifierInfo &II = mCtx.Idents.get(SR);
+ clang::DeclarationName N(&II);
+ clang::FunctionProtoType::ExtProtoInfo EPI;
+ clang::QualType T = mCtx.getFunctionType(mCtx.VoidTy, NULL, 0, EPI);
+ clang::FunctionDecl *FD = NULL;
+
// Generate rsClearObject() call chains for every global variable
// (whether static or extern).
std::list<clang::Stmt *> StmtList;
@@ -1502,7 +1510,13 @@ clang::FunctionDecl *RSObjectRefCount::CreateStaticGlobalDtor() {
clang::VarDecl *VD = llvm::dyn_cast<clang::VarDecl>(*I);
if (VD) {
if (CountRSObjectTypes(mCtx, VD->getType().getTypePtr(), loc)) {
- clang::Stmt *RSClearObjectCall = Scope::ClearRSObject(VD);
+ if (!FD) {
+ // Only create FD if we are going to use it.
+ FD = clang::FunctionDecl::Create(mCtx, DC, loc, loc, N, T, NULL);
+ }
+ // Make sure to create any helpers within the function's DeclContext,
+ // not the one associated with the global translation unit.
+ clang::Stmt *RSClearObjectCall = Scope::ClearRSObject(VD, FD);
StmtList.push_back(RSClearObjectCall);
}
}
@@ -1513,13 +1527,6 @@ clang::FunctionDecl *RSObjectRefCount::CreateStaticGlobalDtor() {
return NULL;
}
- llvm::StringRef SR(".rs.dtor");
- clang::IdentifierInfo &II = mCtx.Idents.get(SR);
- clang::DeclarationName N(&II);
- clang::FunctionProtoType::ExtProtoInfo EPI;
- clang::QualType T = mCtx.getFunctionType(mCtx.VoidTy, NULL, 0, EPI);
- clang::FunctionDecl *FD = clang::FunctionDecl::Create(mCtx, DC, loc, loc, N,
- T, NULL);
clang::CompoundStmt *CS = BuildCompoundStmt(mCtx, StmtList, loc);
FD->setBody(CS);
diff --git a/slang_rs_object_ref_count.h b/slang_rs_object_ref_count.h
index 15be35f..1e87ca1 100644
--- a/slang_rs_object_ref_count.h
+++ b/slang_rs_object_ref_count.h
@@ -68,7 +68,8 @@ class RSObjectRefCount : public clang::StmtVisitor<RSObjectRefCount> {
void InsertLocalVarDestructors();
- static clang::Stmt *ClearRSObject(clang::VarDecl *VD);
+ static clang::Stmt *ClearRSObject(clang::VarDecl *VD,
+ clang::DeclContext *DC);
};
clang::ASTContext &mCtx;