aboutsummaryrefslogtreecommitdiffstats
path: root/slang_rs_object_ref_count.cpp
diff options
context:
space:
mode:
authorStephen Hines <srhines@google.com>2011-09-16 16:26:29 -0700
committerStephen Hines <srhines@google.com>2011-09-16 16:31:03 -0700
commit3f175af8a0644fb5fc53aa90e01c24f75855c5f7 (patch)
treec70b9d69f8e17c14daaa84f487a3901a898a585b /slang_rs_object_ref_count.cpp
parent154e54e438e464a814ac33d10cb43686a068ed5d (diff)
downloadframeworks_compile_slang-3f175af8a0644fb5fc53aa90e01c24f75855c5f7.tar.gz
frameworks_compile_slang-3f175af8a0644fb5fc53aa90e01c24f75855c5f7.tar.bz2
frameworks_compile_slang-3f175af8a0644fb5fc53aa90e01c24f75855c5f7.zip
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
Diffstat (limited to 'slang_rs_object_ref_count.cpp')
-rw-r--r--slang_rs_object_ref_count.cpp29
1 files changed, 18 insertions, 11 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);