<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Sep 21, 2015 at 11:03 AM, Duncan P. N. Exon Smith <span dir="ltr"><<a href="mailto:dexonsmith@apple.com" target="_blank">dexonsmith@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class=""><div class="h5"><br>
> On 2015-Sep-21, at 01:42, Akira Hatanaka via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a>> wrote:<br>
><br>
> ahatanak created this revision.<br>
> ahatanak added a subscriber: cfe-commits.<br>
><br>
> An assert is triggered when the test case program is compiled with -Oz:<br>
><br>
> Assertion failed: (!F->hasFnAttribute(llvm::Attribute::OptimizeForSize) && "OptimizeNone and OptimizeForSize on same function!"), function SetLLVMFunctionAttributesForDefinition, file /Users/ahatanaka/projects/llvm/git/llvm/tools/clang/lib/CodeGen/CodeGenModule.cpp, line 831.<br>
><br>
> This patch fixes the assert by clearing the attribute set attached to IR function foo1 and creating it again when the function's definition is parsed.<br>
><br>
> <a href="http://reviews.llvm.org/D13004" rel="noreferrer" target="_blank">http://reviews.llvm.org/D13004</a><br>
><br>
> Files:<br>
>  lib/CodeGen/CodeGenModule.cpp<br>
>  test/CodeGen/attr-func-def.c<br>
><br>
> Index: test/CodeGen/attr-func-def.c<br>
> ===================================================================<br>
> --- /dev/null<br>
> +++ test/CodeGen/attr-func-def.c<br>
> @@ -0,0 +1,18 @@<br>
> +// RUN: %clang_cc1 -triple x86_64-apple-macosx10.10.0 -emit-llvm -Oz -o - %s | FileCheck %s<br>
> +<br>
> +// CHECK: define i32 @foo2(i32 %a) [[ATTRS2:#[0-9]+]] {<br>
> +// CHECK: define i32 @foo1(i32 %a) [[ATTRS1:#[0-9]+]] {<br>
> +<br>
> +int foo1(int);<br>
> +<br>
> +int foo2(int a) {<br>
> +  return foo1(a + 2);<br>
> +}<br>
> +<br>
> +__attribute__((optnone))<br>
> +int foo1(int a) {<br>
> +    return a + 1;<br>
> +}<br>
> +<br>
> +// CHECK: attributes [[ATTRS2]] = { {{.*}}optsize{{.*}} }<br>
> +// CHECK: attributes [[ATTRS1]] = { {{.*}}optnone{{.*}} }<br>
> Index: lib/CodeGen/CodeGenModule.cpp<br>
> ===================================================================<br>
> --- lib/CodeGen/CodeGenModule.cpp<br>
> +++ lib/CodeGen/CodeGenModule.cpp<br>
> @@ -2643,6 +2643,11 @@<br>
><br>
>   maybeSetTrivialComdat(*D, *Fn);<br>
><br>
> +  // Create the attribute set of the function definition because it might differ<br>
> +  // from that of the function declaration. SetLLVMFunctionAttributes cannot be<br>
> +  // called after GenerateCode is called as it might remove the parameter<br>
> +  // attributes attached by GenerateCode.<br>
> +  SetLLVMFunctionAttributes(D, FI, Fn);<br>
<br>
</div></div>I'm a bit worried this could have a compile-time impact, since it will<br>
regenerate all the attributes.  Why don't you just remove optsize if it's<br>
attached to the function?<br>
<br>
(All this attribute-setting is pretty horrible; one of us should fix it<br>
soon.)<br>
<span class=""><br></span></blockquote><div><div><br></div><div>Removing the conflicting attributes should fix the crash too. I'll come up with a patch and commit it shortly.</div></div><div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class="">
>   CodeGenFunction(*this).GenerateCode(D, Fn, FI);<br>
><br>
>   setFunctionDefinitionAttributes(D, Fn);<br>
><br>
><br>
</span>> <D13004.35214.patch>_______________________________________________<br>
> cfe-commits mailing list<br>
> <a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a><br>
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
<br>
</blockquote></div><br></div></div>