[cfe-commits] r106441 - in /cfe/trunk/lib: CodeGen/CGDeclCXX.cpp CodeGen/CodeGenModule.h Sema/SemaDeclAttr.cpp
Fariborz Jahanian
fjahanian at apple.com
Mon Jun 21 11:45:05 PDT 2010
Author: fjahanian
Date: Mon Jun 21 13:45:05 2010
New Revision: 106441
URL: http://llvm.org/viewvc/llvm-project?rev=106441&view=rev
Log:
IRGen for implementation of init-priority attribute.
Test case will be checked in llvm test suite.
(finishes off radar 8076356).
Modified:
cfe/trunk/lib/CodeGen/CGDeclCXX.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.h
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
Modified: cfe/trunk/lib/CodeGen/CGDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDeclCXX.cpp?rev=106441&r1=106440&r2=106441&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDeclCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDeclCXX.cpp Mon Jun 21 13:45:05 2010
@@ -171,12 +171,17 @@
CodeGenFunction(*this).GenerateCXXGlobalVarDeclInitFunc(Fn, D);
- CXXGlobalInits.push_back(Fn);
+ if (D->hasAttr<InitPriorityAttr>()) {
+ unsigned int order = D->getAttr<InitPriorityAttr>()->getPriority();
+ PrioritizedCXXGlobalInits.push_back(std::make_pair(order,Fn));
+ }
+ else
+ CXXGlobalInits.push_back(Fn);
}
void
CodeGenModule::EmitCXXGlobalInitFunc() {
- if (CXXGlobalInits.empty())
+ if (CXXGlobalInits.empty() && PrioritizedCXXGlobalInits.empty())
return;
const llvm::FunctionType *FTy
@@ -187,9 +192,24 @@
llvm::Function *Fn =
CreateGlobalInitOrDestructFunction(*this, FTy, "_GLOBAL__I_a");
- CodeGenFunction(*this).GenerateCXXGlobalInitFunc(Fn,
- &CXXGlobalInits[0],
- CXXGlobalInits.size());
+ if (!PrioritizedCXXGlobalInits.empty()) {
+ std::vector<llvm::Constant*> LocalCXXGlobalInits;
+ std::sort(PrioritizedCXXGlobalInits.begin(),
+ PrioritizedCXXGlobalInits.end());
+ for (unsigned i = 0; i < PrioritizedCXXGlobalInits.size(); i++) {
+ llvm::Function *Fn = PrioritizedCXXGlobalInits[i].second;
+ LocalCXXGlobalInits.push_back(Fn);
+ }
+ for (unsigned i = 0; i < CXXGlobalInits.size(); i++)
+ LocalCXXGlobalInits.push_back(CXXGlobalInits[i]);
+ CodeGenFunction(*this).GenerateCXXGlobalInitFunc(Fn,
+ &LocalCXXGlobalInits[0],
+ LocalCXXGlobalInits.size());
+ }
+ else
+ CodeGenFunction(*this).GenerateCXXGlobalInitFunc(Fn,
+ &CXXGlobalInits[0],
+ CXXGlobalInits.size());
AddGlobalCtor(Fn);
}
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.h?rev=106441&r1=106440&r2=106441&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.h Mon Jun 21 13:45:05 2010
@@ -139,6 +139,11 @@
/// CXXGlobalInits - Global variables with initializers that need to run
/// before main.
std::vector<llvm::Constant*> CXXGlobalInits;
+
+ /// - Global variables with initializers whose order of initialization
+ /// is set by init_priority attribute.
+ llvm::SmallVector<std::pair<unsigned int, llvm::Function*>, 8>
+ PrioritizedCXXGlobalInits;
/// CXXGlobalDtors - Global destructor functions and arguments that need to
/// run on termination.
Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=106441&r1=106440&r2=106441&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Mon Jun 21 13:45:05 2010
@@ -1218,7 +1218,7 @@
Attr.setInvalid();
return;
}
- unsigned prioritynum = static_cast<unsigned>(priority.getZExtValue() * 8);
+ unsigned prioritynum = priority.getZExtValue();
if (prioritynum < 101 || prioritynum > 65535) {
S.Diag(Attr.getLoc(), diag::err_attribute_argument_outof_range)
<< priorityExpr->getSourceRange();
More information about the cfe-commits
mailing list