r207997 - Fix pr19653.
Richard Smith
richard at metafoo.co.uk
Mon May 5 14:07:28 PDT 2014
On Mon, May 5, 2014 at 1:21 PM, Rafael Espindola <rafael.espindola at gmail.com
> wrote:
> Author: rafael
> Date: Mon May 5 15:21:03 2014
> New Revision: 207997
>
> URL: http://llvm.org/viewvc/llvm-project?rev=207997&view=rev
> Log:
> Fix pr19653.
>
> Warn if an alias requests a section other than the aliasee section.
>
> Modified:
> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> cfe/trunk/lib/CodeGen/CodeGenModule.cpp
> cfe/trunk/lib/CodeGen/CodeGenModule.h
> cfe/trunk/test/CodeGen/alias.c
> cfe/trunk/test/Sema/attr-alias-elf.c
>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=207997&r1=207996&r2=207997&view=diff
>
> ==============================================================================
> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon May 5
> 15:21:03 2014
> @@ -2106,6 +2106,9 @@ def err_alias_to_undefined : Error<
> def warn_alias_to_weak_alias : Warning<
> "alias will always resolve to %0 even if weak definition of alias %1 is
> overridden">,
> InGroup<IgnoredAttributes>;
> +def warn_alias_with_section : Warning<
> + "alias will not be in section '%0' but in the same section as the
> aliasee">,
>
I was hoping we'd say which section the alias would end up in here -- the
requested section should be obvious from the snippet.
> + InGroup<IgnoredAttributes>;
> def err_duplicate_mangled_name : Error<
> "definition with same mangled name as another definition">;
> def err_cyclic_alias : Error<
>
> Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=207997&r1=207996&r2=207997&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Mon May 5 15:21:03 2014
> @@ -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(Global
> /// 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(
>
> 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::SetInternalFunctionA
>
> F->setLinkage(llvm::Function::InternalLinkage);
>
> - SetCommonAttributes(D, F);
> + setNonAliasAttributes(D, F);
> }
>
> static void setLinkageAndVisibilityForGV(llvm::GlobalValue *GV,
> @@ -1879,7 +1891,7 @@ void CodeGenModule::EmitGlobalVarDefinit
> // 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)
>
> Modified: cfe/trunk/lib/CodeGen/CodeGenModule.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.h?rev=207997&r1=207996&r2=207997&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CodeGenModule.h (original)
> +++ cfe/trunk/lib/CodeGen/CodeGenModule.h Mon May 5 15:21:03 2014
> @@ -1050,6 +1050,8 @@ private:
> /// NOTE: This should only be called for definitions.
> void SetCommonAttributes(const Decl *D, llvm::GlobalValue *GV);
>
> + void setNonAliasAttributes(const Decl *D, llvm::GlobalValue *GV);
> +
> /// SetFunctionDefinitionAttributes - Set attributes for a global
> definition.
> void SetFunctionDefinitionAttributes(const FunctionDecl *D,
> llvm::GlobalValue *GV);
>
> Modified: cfe/trunk/test/CodeGen/alias.c
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/alias.c?rev=207997&r1=207996&r2=207997&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/CodeGen/alias.c (original)
> +++ cfe/trunk/test/CodeGen/alias.c Mon May 5 15:21:03 2014
> @@ -16,6 +16,7 @@ extern void f1(void) __attribute((alias(
> // CHECKBASIC-DAG: @f1 = alias void ()* @f0
> // CHECKBASIC-DAG: @test8_foo = alias weak bitcast (void ()* @test8_bar
> to void (...)*)
> // CHECKBASIC-DAG: @test8_zed = alias bitcast (void ()* @test8_bar to
> void (...)*)
> +// CHECKBASIC-DAG: @test9_zed = alias void ()* @test9_bar
> // CHECKBASIC: define void @f0() [[NUW:#[0-9]+]] {
>
> // Make sure that aliases cause referenced values to be emitted.
> @@ -54,3 +55,7 @@ int outer_weak(int a) { return inner_wea
> void test8_bar() {}
> void test8_foo() __attribute__((weak, alias("test8_bar")));
> void test8_zed() __attribute__((alias("test8_foo")));
> +
> +void test9_bar(void) { }
> +void test9_zed(void) __attribute__((section("test")));
> +void test9_zed(void) __attribute__((alias("test9_bar")));
>
> Modified: cfe/trunk/test/Sema/attr-alias-elf.c
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-alias-elf.c?rev=207997&r1=207996&r2=207997&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/Sema/attr-alias-elf.c (original)
> +++ cfe/trunk/test/Sema/attr-alias-elf.c Mon May 5 15:21:03 2014
> @@ -56,3 +56,11 @@ typedef int b4;
> void test2_bar() {}
> void test2_foo() __attribute__((weak, alias("test2_bar")));
> 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}}
> +
> +void test3_bar() { }
> +void test3_foo() __attribute__((section("test"))); // expected-warning
> {{alias will not be in section 'test' but in the same section as the
> aliasee}}
> +void test3_foo() __attribute__((alias("test3_bar")));
> +
> +__attribute__((section("test"))) void test4_bar() { }
> +void test4_foo() __attribute__((section("test")));
> +void test4_foo() __attribute__((alias("test4_bar")));
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140505/49a01498/attachment.html>
More information about the cfe-commits
mailing list