<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Dec 17, 2015 at 3:59 PM, Nick Lewycky via cfe-commits <span dir="ltr"><<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</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"><span class="">On 12/17/2015 10:47 AM, Kostya Serebryany 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">
I am now observing this error message when building glibc with clang<br>
(from trunk):<br>
../include/string.h:101:28: error: cannot apply asm label to function<br>
after its first use<br>
libc_hidden_builtin_proto (memcpy)<br>
(many more instances)<br>
<br>
<br>
Do you think this is a bug in glibc code, or the error message could be<br>
more relaxed?<br>
</blockquote>
<br></span>
Could you email me a .i copy of a failing build? That will help me decide whether it's a bug in the error or in glibc.</blockquote><div><br></div><div>Also PR22830 comment 1 seems relevant here.</div><div> </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"><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="">
On Fri, Dec 11, 2015 at 1:28 PM, Nick Lewycky via cfe-commits<br></span><div><div class="h5">
<<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a> <mailto:<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>>> wrote:<br>
<br>
Author: nicholas<br>
Date: Fri Dec 11 15:28:55 2015<br>
New Revision: 255371<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=255371&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=255371&view=rev</a><br>
Log:<br>
Error on redeclaring with a conflicting asm label and on redeclaring<br>
with an asm label after the first ODR-use. Detects problems like the<br>
one in PR22830 where gcc and clang both compiled the file but with<br>
different behaviour.<br>
<br>
Added:<br>
cfe/trunk/test/Sema/asm-label.c<br>
Modified:<br>
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td<br>
cfe/trunk/lib/Sema/SemaDecl.cpp<br>
<br>
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td<br>
URL:<br>
<a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=255371&r1=255370&r2=255371&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=255371&r1=255370&r2=255371&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)<br>
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Dec 11<br>
15:28:55 2015<br>
@@ -4259,6 +4259,9 @@ def err_tag_definition_of_typedef : Erro<br>
def err_conflicting_types : Error<"conflicting types for %0">;<br>
def err_different_pass_object_size_params : Error<<br>
"conflicting pass_object_size attributes on parameters">;<br>
+def err_late_asm_label_name : Error<<br>
+ "cannot apply asm label to %select{variable|function}0 after its<br>
first use">;<br>
+def err_different_asm_label : Error<"conflicting asm label">;<br>
def err_nested_redefinition : Error<"nested redefinition of %0">;<br>
def err_use_with_wrong_tag : Error<<br>
"use of %0 with tag type that does not match previous declaration">;<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp<br>
URL:<br>
<a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=255371&r1=255370&r2=255371&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=255371&r1=255370&r2=255371&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Dec 11 15:28:55 2015<br>
@@ -2379,9 +2379,24 @@ void Sema::mergeDeclAttributes(NamedDecl<br>
if (!Old->hasAttrs() && !New->hasAttrs())<br>
return;<br>
<br>
- // attributes declared post-definition are currently ignored<br>
+ // Attributes declared post-definition are currently ignored.<br>
checkNewAttributesAfterDef(*this, New, Old);<br>
<br>
+ if (AsmLabelAttr *NewA = New->getAttr<AsmLabelAttr>()) {<br>
+ if (AsmLabelAttr *OldA = Old->getAttr<AsmLabelAttr>()) {<br>
+ if (OldA->getLabel() != NewA->getLabel()) {<br>
+ // This redeclaration changes __asm__ label.<br>
+ Diag(New->getLocation(), diag::err_different_asm_label);<br>
+ Diag(OldA->getLocation(), diag::note_previous_declaration);<br>
+ }<br>
+ } else if (Old->isUsed()) {<br>
+ // This redeclaration adds an __asm__ label to a declaration<br>
that has<br>
+ // already been ODR-used.<br>
+ Diag(New->getLocation(), diag::err_late_asm_label_name)<br>
+ << isa<FunctionDecl>(Old) <<<br>
New->getAttr<AsmLabelAttr>()->getRange();<br>
+ }<br>
+ }<br>
+<br>
if (!Old->hasAttrs())<br>
return;<br>
<br>
<br>
Added: cfe/trunk/test/Sema/asm-label.c<br>
URL:<br>
<a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/asm-label.c?rev=255371&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/asm-label.c?rev=255371&view=auto</a><br>
==============================================================================<br>
--- cfe/trunk/test/Sema/asm-label.c (added)<br>
+++ cfe/trunk/test/Sema/asm-label.c Fri Dec 11 15:28:55 2015<br>
@@ -0,0 +1,30 @@<br>
+// RUN: %clang_cc1 -verify %s<br>
+<br>
+void f();<br>
+void f() __asm__("fish");<br>
+void g();<br>
+<br>
+void f() {<br>
+ g();<br>
+}<br>
+void g() __asm__("gold"); // expected-error{{cannot apply asm<br>
label to function after its first use}}<br>
+<br>
+void h() __asm__("hose"); // expected-note{{previous declaration<br>
is here}}<br>
+void h() __asm__("hair"); // expected-error{{conflicting asm label}}<br>
+<br>
+int x;<br>
+int x __asm__("xenon");<br>
+int y;<br>
+<br>
+int test() { return y; }<br>
+<br>
+int y __asm__("yacht"); // expected-error{{cannot apply asm label<br>
to variable after its first use}}<br>
+<br>
+int z __asm__("zebra"); // expected-note{{previous declaration is<br>
here}}<br>
+int z __asm__("zooms"); // expected-error{{conflicting asm label}}<br>
+<br>
+<br>
+// No diagnostics on the following.<br>
+void __real_readlink() __asm("readlink");<br>
+void readlink() __asm("__protected_readlink");<br>
+void readlink() { __real_readlink(); }<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br></div></div>
<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a> <mailto:<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">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>
<br>
</blockquote><div class=""><div class="h5">
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">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>
</div></div></blockquote></div><br></div></div>