<div dir="ltr"><div dir="ltr">This seems to have broke the 2-stage LTO build of LLVM, the error is:<div><br></div><div>ld.lld: /usr/local/google/home/phosek/clang-llvm/llvm-project/llvm/lib/IR/Constants.cpp:995: static llvm::Constant *llvm::ConstantArray::getImpl(llvm::ArrayType *, ArrayRef<llvm::Constant *>): Assertion `V[i]->getType() == Ty->getElementType() && "Wrong type in array element initializer"' failed.</div><div><br></div><div>The invocation this came from is:</div><div><br></div><div>/usr/local/google/home/phosek/clang-llvm/llvm-project/llvm-build/fuchsia/./bin/clang++  -fPIC -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -std=c++11 -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wstring-conversion -fdiagnostics-color -ffunction-sections -fdata-sections -flto -O3 -gline-tables-only  -ldl -lpthread -fuse-ld=lld -Wl,--color-diagnostics -Wl,-allow-shlib-undefined    -Wl,-O3 -Wl,--gc-sections tools/llvm-cov/CMakeFiles/llvm-cov.dir/llvm-cov.cpp.o tools/llvm-cov/CMakeFiles/llvm-cov.dir/gcov.cpp.o tools/llvm-cov/CMakeFiles/llvm-cov.dir/CodeCoverage.cpp.o tools/llvm-cov/CMakeFiles/llvm-cov.dir/CoverageExporterJson.cpp.o tools/llvm-cov/CMakeFiles/llvm-cov.dir/CoverageExporterLcov.cpp.o tools/llvm-cov/CMakeFiles/llvm-cov.dir/CoverageFilters.cpp.o tools/llvm-cov/CMakeFiles/llvm-cov.dir/CoverageReport.cpp.o tools/llvm-cov/CMakeFiles/llvm-cov.dir/CoverageSummaryInfo.cpp.o tools/llvm-cov/CMakeFiles/llvm-cov.dir/SourceCoverageView.cpp.o tools/llvm-cov/CMakeFiles/llvm-cov.dir/SourceCoverageViewHTML.cpp.o tools/llvm-cov/CMakeFiles/llvm-cov.dir/SourceCoverageViewText.cpp.o tools/llvm-cov/CMakeFiles/llvm-cov.dir/TestingSupport.cpp.o  -o bin/llvm-cov  -Wl,-rpath,"\$ORIGIN/../lib" lib/libLLVMCore.a lib/libLLVMSupport.a lib/libLLVMObject.a lib/libLLVMCoverage.a lib/libLLVMProfileData.a lib/libLLVMObject.a lib/libLLVMBitReader.a lib/libLLVMMCParser.a lib/libLLVMMC.a lib/libLLVMDebugInfoCodeView.a lib/libLLVMDebugInfoMSF.a lib/libLLVMCore.a lib/libLLVMBinaryFormat.a lib/libLLVMSupport.a -lz -lrt -ldl -lm lib/libLLVMDemangle.a</div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Mar 7, 2019 at 11:13 AM Rafael Auler via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Author: rafauler<br>
Date: Thu Mar  7 11:14:30 2019<br>
New Revision: 355627<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=355627&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=355627&view=rev</a><br>
Log:<br>
Recommit "Support attribute used in member funcs of class templates"<br>
<br>
The patch originally broke code that was incompatible with GCC, but<br>
we want to follow GCC behavior here according to the discussion in<br>
<a href="https://reviews.llvm.org/D58216" rel="noreferrer" target="_blank">https://reviews.llvm.org/D58216</a><br>
<br>
Original commit message:<br>
As PR17480 describes, clang does not support the used attribute<br>
for member functions of class templates. This means that if the member<br>
function is not used, its definition is never instantiated. This patch<br>
changes clang to emit the definition if it has the used attribute.<br>
<br>
Test Plan: Added a testcase<br>
<br>
Reviewed By: aaron.ballman<br>
<br>
Differential Revision: <a href="https://reviews.llvm.org/D56928" rel="noreferrer" target="_blank">https://reviews.llvm.org/D56928</a><br>
<br>
Added:<br>
    cfe/trunk/test/CodeGenCXX/attr-used-member-function-implicit-instantiation.cpp<br>
Modified:<br>
    cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=355627&r1=355626&r2=355627&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=355627&r1=355626&r2=355627&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Thu Mar  7 11:14:30 2019<br>
@@ -2232,6 +2232,20 @@ TemplateDeclInstantiator::VisitCXXMethod<br>
     Owner->addDecl(Method);<br>
   }<br>
<br>
+  // PR17480: Honor the used attribute to instantiate member function<br>
+  // definitions<br>
+  if (Method->hasAttr<UsedAttr>()) {<br>
+    if (const auto *A = dyn_cast<CXXRecordDecl>(Owner)) {<br>
+      SourceLocation Loc;<br>
+      if (const MemberSpecializationInfo *MSInfo =<br>
+              A->getMemberSpecializationInfo())<br>
+        Loc = MSInfo->getPointOfInstantiation();<br>
+      else if (const auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(A))<br>
+        Loc = Spec->getPointOfInstantiation();<br>
+      SemaRef.MarkFunctionReferenced(Loc, Method);<br>
+    }<br>
+  }<br>
+<br>
   return Method;<br>
 }<br>
<br>
<br>
Added: cfe/trunk/test/CodeGenCXX/attr-used-member-function-implicit-instantiation.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/attr-used-member-function-implicit-instantiation.cpp?rev=355627&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/attr-used-member-function-implicit-instantiation.cpp?rev=355627&view=auto</a><br>
==============================================================================<br>
--- cfe/trunk/test/CodeGenCXX/attr-used-member-function-implicit-instantiation.cpp (added)<br>
+++ cfe/trunk/test/CodeGenCXX/attr-used-member-function-implicit-instantiation.cpp Thu Mar  7 11:14:30 2019<br>
@@ -0,0 +1,19 @@<br>
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s | FileCheck %s<br>
+<br>
+// Check that PR17480 is fixed: __attribute__((used)) ignored in templated<br>
+// classes<br>
+namespace InstantiateUsedMemberDefinition {<br>
+template <typename T><br>
+struct S {<br>
+  int __attribute__((used)) f() {<br>
+    return 0;<br>
+  }<br>
+};<br>
+<br>
+void test() {<br>
+  // Check that InstantiateUsedMemberDefinition::S<int>::f() is defined<br>
+  // as a result of the S class template implicit instantiation<br>
+  // CHECK: define linkonce_odr i32 @_ZN31InstantiateUsedMemberDefinition1SIiE1fEv<br>
+  S<int> inst;<br>
+}<br>
+} // namespace InstantiateUsedMemberDefinition<br>
<br>
<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="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
</blockquote></div>