<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, May 5, 2014 at 1:21 PM, Rafael Espindola <span dir="ltr"><<a href="mailto:rafael.espindola@gmail.com" target="_blank">rafael.espindola@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: rafael<br>
Date: Mon May 5 15:21:03 2014<br>
New Revision: 207997<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=207997&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=207997&view=rev</a><br>
Log:<br>
Fix pr19653.<br>
<br>
Warn if an alias requests a section other than the aliasee section.<br>
<br>
Modified:<br>
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td<br>
cfe/trunk/lib/CodeGen/CodeGenModule.cpp<br>
cfe/trunk/lib/CodeGen/CodeGenModule.h<br>
cfe/trunk/test/CodeGen/alias.c<br>
cfe/trunk/test/Sema/attr-alias-elf.c<br>
<br>
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=207997&r1=207996&r2=207997&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=207997&r1=207996&r2=207997&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)<br>
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon May 5 15:21:03 2014<br>
@@ -2106,6 +2106,9 @@ def err_alias_to_undefined : Error<<br>
def warn_alias_to_weak_alias : Warning<<br>
"alias will always resolve to %0 even if weak definition of alias %1 is overridden">,<br>
InGroup<IgnoredAttributes>;<br>
+def warn_alias_with_section : Warning<<br>
+ "alias will not be in section '%0' but in the same section as the aliasee">,<br></blockquote><div><br></div><div>I was hoping we'd say which section the alias would end up in here -- the requested section should be obvious from the snippet.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+ InGroup<IgnoredAttributes>;<br>
def err_duplicate_mangled_name : Error<<br>
"definition with same mangled name as another definition">;<br>
def err_cyclic_alias : Error<<br>
<br>
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=207997&r1=207996&r2=207997&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=207997&r1=207996&r2=207997&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)<br>
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Mon May 5 15:21:03 2014<br>
@@ -238,11 +238,6 @@ void CodeGenModule::checkAliases() {<br>
Diags.Report(AA->getLocation(), diag::err_alias_to_undefined);<br>
}<br>
<br>
- // We have to handle alias to weak aliases in here. LLVM itself disallows<br>
- // this since the object semantics would not match the IL one. For<br>
- // compatibility with gcc we implement it by just pointing the alias<br>
- // to its aliasee's aliasee. We also warn, since the user is probably<br>
- // expecting the link to be weak.<br>
llvm::Constant *Aliasee = Alias->getAliasee();<br>
llvm::GlobalValue *AliaseeGV;<br>
if (auto CE = dyn_cast<llvm::ConstantExpr>(Aliasee)) {<br>
@@ -253,6 +248,19 @@ void CodeGenModule::checkAliases() {<br>
} else {<br>
AliaseeGV = cast<llvm::GlobalValue>(Aliasee);<br>
}<br>
+<br>
+ if (const SectionAttr *SA = D->getAttr<SectionAttr>()) {<br>
+ StringRef AliasSection = SA->getName();<br>
+ if (AliasSection != AliaseeGV->getSection())<br>
+ Diags.Report(SA->getLocation(), diag::warn_alias_with_section)<br>
+ << AliasSection;<br>
+ }<br>
+<br>
+ // We have to handle alias to weak aliases in here. LLVM itself disallows<br>
+ // this since the object semantics would not match the IL one. For<br>
+ // compatibility with gcc we implement it by just pointing the alias<br>
+ // to its aliasee's aliasee. We also warn, since the user is probably<br>
+ // expecting the link to be weak.<br>
if (auto GA = dyn_cast<llvm::GlobalAlias>(AliaseeGV)) {<br>
if (GA->mayBeOverridden()) {<br>
Diags.Report(AA->getLocation(), diag::warn_alias_to_weak_alias)<br>
@@ -585,7 +593,7 @@ CodeGenModule::getFunctionLinkage(Global<br>
/// variables (these details are set in EmitGlobalVarDefinition for variables).<br>
void CodeGenModule::SetFunctionDefinitionAttributes(const FunctionDecl *D,<br>
llvm::GlobalValue *GV) {<br>
- SetCommonAttributes(D, GV);<br>
+ setNonAliasAttributes(D, GV);<br>
}<br>
<br>
void CodeGenModule::SetLLVMFunctionAttributes(const Decl *D,<br>
@@ -711,13 +719,17 @@ void CodeGenModule::SetCommonAttributes(<br>
<br>
if (D->hasAttr<UsedAttr>())<br>
addUsedGlobal(GV);<br>
+}<br>
+<br>
+void CodeGenModule::setNonAliasAttributes(const Decl *D,<br>
+ llvm::GlobalValue *GV) {<br>
+ assert(!isa<llvm::GlobalAlias>(GV));<br>
+ SetCommonAttributes(D, GV);<br>
<br>
if (const SectionAttr *SA = D->getAttr<SectionAttr>())<br>
GV->setSection(SA->getName());<br>
<br>
- // Alias cannot have attributes. Filter them here.<br>
- if (!isa<llvm::GlobalAlias>(GV))<br>
- getTargetCodeGenInfo().SetTargetAttributes(D, GV, *this);<br>
+ getTargetCodeGenInfo().SetTargetAttributes(D, GV, *this);<br>
}<br>
<br>
void CodeGenModule::SetInternalFunctionAttributes(const Decl *D,<br>
@@ -728,7 +740,7 @@ void CodeGenModule::SetInternalFunctionA<br>
<br>
F->setLinkage(llvm::Function::InternalLinkage);<br>
<br>
- SetCommonAttributes(D, F);<br>
+ setNonAliasAttributes(D, F);<br>
}<br>
<br>
static void setLinkageAndVisibilityForGV(llvm::GlobalValue *GV,<br>
@@ -1879,7 +1891,7 @@ void CodeGenModule::EmitGlobalVarDefinit<br>
// common vars aren't constant even if declared const.<br>
GV->setConstant(false);<br>
<br>
- SetCommonAttributes(D, GV);<br>
+ setNonAliasAttributes(D, GV);<br>
<br>
// Emit the initializer function if necessary.<br>
if (NeedsGlobalCtor || NeedsGlobalDtor)<br>
<br>
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.h?rev=207997&r1=207996&r2=207997&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.h?rev=207997&r1=207996&r2=207997&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/CodeGen/CodeGenModule.h (original)<br>
+++ cfe/trunk/lib/CodeGen/CodeGenModule.h Mon May 5 15:21:03 2014<br>
@@ -1050,6 +1050,8 @@ private:<br>
/// NOTE: This should only be called for definitions.<br>
void SetCommonAttributes(const Decl *D, llvm::GlobalValue *GV);<br>
<br>
+ void setNonAliasAttributes(const Decl *D, llvm::GlobalValue *GV);<br>
+<br>
/// SetFunctionDefinitionAttributes - Set attributes for a global definition.<br>
void SetFunctionDefinitionAttributes(const FunctionDecl *D,<br>
llvm::GlobalValue *GV);<br>
<br>
Modified: cfe/trunk/test/CodeGen/alias.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/alias.c?rev=207997&r1=207996&r2=207997&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/alias.c?rev=207997&r1=207996&r2=207997&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/CodeGen/alias.c (original)<br>
+++ cfe/trunk/test/CodeGen/alias.c Mon May 5 15:21:03 2014<br>
@@ -16,6 +16,7 @@ extern void f1(void) __attribute((alias(<br>
// CHECKBASIC-DAG: @f1 = alias void ()* @f0<br>
// CHECKBASIC-DAG: @test8_foo = alias weak bitcast (void ()* @test8_bar to void (...)*)<br>
// CHECKBASIC-DAG: @test8_zed = alias bitcast (void ()* @test8_bar to void (...)*)<br>
+// CHECKBASIC-DAG: @test9_zed = alias void ()* @test9_bar<br>
// CHECKBASIC: define void @f0() [[NUW:#[0-9]+]] {<br>
<br>
// Make sure that aliases cause referenced values to be emitted.<br>
@@ -54,3 +55,7 @@ int outer_weak(int a) { return inner_wea<br>
void test8_bar() {}<br>
void test8_foo() __attribute__((weak, alias("test8_bar")));<br>
void test8_zed() __attribute__((alias("test8_foo")));<br>
+<br>
+void test9_bar(void) { }<br>
+void test9_zed(void) __attribute__((section("test")));<br>
+void test9_zed(void) __attribute__((alias("test9_bar")));<br>
<br>
Modified: cfe/trunk/test/Sema/attr-alias-elf.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-alias-elf.c?rev=207997&r1=207996&r2=207997&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-alias-elf.c?rev=207997&r1=207996&r2=207997&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/Sema/attr-alias-elf.c (original)<br>
+++ cfe/trunk/test/Sema/attr-alias-elf.c Mon May 5 15:21:03 2014<br>
@@ -56,3 +56,11 @@ typedef int b4;<br>
void test2_bar() {}<br>
void test2_foo() __attribute__((weak, alias("test2_bar")));<br>
void test2_zed() __attribute__((alias("test2_foo"))); // expected-warning {{alias will always resolve to test2_bar even if weak definition of alias test2_foo is overridden}}<br>
+<br>
+void test3_bar() { }<br>
+void test3_foo() __attribute__((section("test"))); // expected-warning {{alias will not be in section 'test' but in the same section as the aliasee}}<br>
+void test3_foo() __attribute__((alias("test3_bar")));<br>
+<br>
+__attribute__((section("test"))) void test4_bar() { }<br>
+void test4_foo() __attribute__((section("test")));<br>
+void test4_foo() __attribute__((alias("test4_bar")));<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div></div>