Add a bunch of attributes, patch by Nuno Lopes.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@47837 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/CodeGen/CodeGenFunction.cpp b/CodeGen/CodeGenFunction.cpp
index c2a303c..6701b71 100644
--- a/CodeGen/CodeGenFunction.cpp
+++ b/CodeGen/CodeGenFunction.cpp
@@ -18,6 +18,7 @@
#include "llvm/Constants.h"
#include "llvm/DerivedTypes.h"
#include "llvm/Function.h"
+#include "llvm/ParamAttrsList.h"
#include "llvm/Analysis/Verifier.h"
#include "llvm/Support/CFG.h"
using namespace clang;
@@ -67,11 +68,33 @@
// TODO: Set up linkage and many other things. Note, this is a simple
// approximation of what we really want.
- if (FD->getStorageClass() == FunctionDecl::Static)
- CurFn->setLinkage(llvm::Function::InternalLinkage);
- else if (FD->isInline())
+ if (FD->getAttr<DLLImportAttr>())
+ CurFn->setLinkage(llvm::Function::DLLImportLinkage);
+ else if (FD->getAttr<DLLExportAttr>())
+ CurFn->setLinkage(llvm::Function::DLLExportLinkage);
+ else if (FD->getAttr<WeakAttr>() || FD->isInline())
CurFn->setLinkage(llvm::Function::WeakLinkage);
-
+ else if (FD->getStorageClass() == FunctionDecl::Static)
+ CurFn->setLinkage(llvm::Function::InternalLinkage);
+
+ if (const VisibilityAttr *attr = FD->getAttr<VisibilityAttr>())
+ CurFn->setVisibility(attr->getVisibility());
+ // FIXME: else handle -fvisibility
+
+
+ llvm::ParamAttrsVector ParamAttrsVec;
+
+ if (FD->getAttr<NoThrowAttr>())
+ ParamAttrsVec.push_back(
+ llvm::ParamAttrsWithIndex::get(ParamAttrsVec.size(), llvm::ParamAttr::NoUnwind));
+ if (FD->getAttr<NoReturnAttr>())
+ ParamAttrsVec.push_back(
+ llvm::ParamAttrsWithIndex::get(ParamAttrsVec.size(), llvm::ParamAttr::NoReturn));
+
+ if (!ParamAttrsVec.empty())
+ CurFn->setParamAttrs(llvm::ParamAttrsList::get(ParamAttrsVec));
+
+
llvm::BasicBlock *EntryBB = new llvm::BasicBlock("entry", CurFn);
// Create a marker to make it easy to insert allocas into the entryblock
diff --git a/CodeGen/CodeGenModule.cpp b/CodeGen/CodeGenModule.cpp
index 5e63a80..1a69796 100644
--- a/CodeGen/CodeGenModule.cpp
+++ b/CodeGen/CodeGenModule.cpp
@@ -242,25 +242,38 @@
assert(GV->getType()->getElementType() == Init->getType() &&
"Initializer codegen type mismatch!");
GV->setInitializer(Init);
+
+ if (const VisibilityAttr *attr = D->getAttr<VisibilityAttr>())
+ GV->setVisibility(attr->getVisibility());
+ // FIXME: else handle -fvisibility
// Set the llvm linkage type as appropriate.
- // FIXME: This isn't right. This should handle common linkage and other
- // stuff.
- switch (D->getStorageClass()) {
- case VarDecl::Auto:
- case VarDecl::Register:
- assert(0 && "Can't have auto or register globals");
- case VarDecl::None:
- if (!D->getInit())
- GV->setLinkage(llvm::GlobalVariable::WeakLinkage);
- break;
- case VarDecl::Extern:
- case VarDecl::PrivateExtern:
- // todo: common
- break;
- case VarDecl::Static:
- GV->setLinkage(llvm::GlobalVariable::InternalLinkage);
- break;
+ if (D->getAttr<DLLImportAttr>())
+ GV->setLinkage(llvm::Function::DLLImportLinkage);
+ else if (D->getAttr<DLLExportAttr>())
+ GV->setLinkage(llvm::Function::DLLExportLinkage);
+ else if (D->getAttr<WeakAttr>()) {
+ GV->setLinkage(llvm::GlobalVariable::WeakLinkage);
+
+ } else {
+ // FIXME: This isn't right. This should handle common linkage and other
+ // stuff.
+ switch (D->getStorageClass()) {
+ case VarDecl::Auto:
+ case VarDecl::Register:
+ assert(0 && "Can't have auto or register globals");
+ case VarDecl::None:
+ if (!D->getInit())
+ GV->setLinkage(llvm::GlobalVariable::WeakLinkage);
+ break;
+ case VarDecl::Extern:
+ case VarDecl::PrivateExtern:
+ // todo: common
+ break;
+ case VarDecl::Static:
+ GV->setLinkage(llvm::GlobalVariable::InternalLinkage);
+ break;
+ }
}
}