summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen/CodeGenModule.cpp
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2014-05-05 20:21:03 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2014-05-05 20:21:03 +0000
commit502f65ae54d0fd7272e64988c162af8d1958f35c (patch)
tree6bd2a1d9499c502363dbc0487fbc8128be26b658 /clang/lib/CodeGen/CodeGenModule.cpp
parent9c8c96f08a39496805a63f67761e0dc42b43e9cc (diff)
downloadbcm5719-llvm-502f65ae54d0fd7272e64988c162af8d1958f35c.tar.gz
bcm5719-llvm-502f65ae54d0fd7272e64988c162af8d1958f35c.zip
Fix pr19653.
Warn if an alias requests a section other than the aliasee section. llvm-svn: 207997
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r--clang/lib/CodeGen/CodeGenModule.cpp34
1 files changed, 23 insertions, 11 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index caa4f24899f..9c60eb55f87 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -238,11 +238,6 @@ void CodeGenModule::checkAliases() {
Diags.Report(AA->getLocation(), diag::err_alias_to_undefined);
}
- // We have to handle alias to weak aliases in here. LLVM itself disallows
- // this since the object semantics would not match the IL one. For
- // compatibility with gcc we implement it by just pointing the alias
- // to its aliasee's aliasee. We also warn, since the user is probably
- // expecting the link to be weak.
llvm::Constant *Aliasee = Alias->getAliasee();
llvm::GlobalValue *AliaseeGV;
if (auto CE = dyn_cast<llvm::ConstantExpr>(Aliasee)) {
@@ -253,6 +248,19 @@ void CodeGenModule::checkAliases() {
} else {
AliaseeGV = cast<llvm::GlobalValue>(Aliasee);
}
+
+ if (const SectionAttr *SA = D->getAttr<SectionAttr>()) {
+ StringRef AliasSection = SA->getName();
+ if (AliasSection != AliaseeGV->getSection())
+ Diags.Report(SA->getLocation(), diag::warn_alias_with_section)
+ << AliasSection;
+ }
+
+ // We have to handle alias to weak aliases in here. LLVM itself disallows
+ // this since the object semantics would not match the IL one. For
+ // compatibility with gcc we implement it by just pointing the alias
+ // to its aliasee's aliasee. We also warn, since the user is probably
+ // expecting the link to be weak.
if (auto GA = dyn_cast<llvm::GlobalAlias>(AliaseeGV)) {
if (GA->mayBeOverridden()) {
Diags.Report(AA->getLocation(), diag::warn_alias_to_weak_alias)
@@ -585,7 +593,7 @@ CodeGenModule::getFunctionLinkage(GlobalDecl GD) {
/// variables (these details are set in EmitGlobalVarDefinition for variables).
void CodeGenModule::SetFunctionDefinitionAttributes(const FunctionDecl *D,
llvm::GlobalValue *GV) {
- SetCommonAttributes(D, GV);
+ setNonAliasAttributes(D, GV);
}
void CodeGenModule::SetLLVMFunctionAttributes(const Decl *D,
@@ -711,13 +719,17 @@ void CodeGenModule::SetCommonAttributes(const Decl *D,
if (D->hasAttr<UsedAttr>())
addUsedGlobal(GV);
+}
+
+void CodeGenModule::setNonAliasAttributes(const Decl *D,
+ llvm::GlobalValue *GV) {
+ assert(!isa<llvm::GlobalAlias>(GV));
+ SetCommonAttributes(D, GV);
if (const SectionAttr *SA = D->getAttr<SectionAttr>())
GV->setSection(SA->getName());
- // Alias cannot have attributes. Filter them here.
- if (!isa<llvm::GlobalAlias>(GV))
- getTargetCodeGenInfo().SetTargetAttributes(D, GV, *this);
+ getTargetCodeGenInfo().SetTargetAttributes(D, GV, *this);
}
void CodeGenModule::SetInternalFunctionAttributes(const Decl *D,
@@ -728,7 +740,7 @@ void CodeGenModule::SetInternalFunctionAttributes(const Decl *D,
F->setLinkage(llvm::Function::InternalLinkage);
- SetCommonAttributes(D, F);
+ setNonAliasAttributes(D, F);
}
static void setLinkageAndVisibilityForGV(llvm::GlobalValue *GV,
@@ -1879,7 +1891,7 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D) {
// common vars aren't constant even if declared const.
GV->setConstant(false);
- SetCommonAttributes(D, GV);
+ setNonAliasAttributes(D, GV);
// Emit the initializer function if necessary.
if (NeedsGlobalCtor || NeedsGlobalDtor)
OpenPOWER on IntegriCloud