r355627 - Recommit "Support attribute used in member funcs of class templates"

Petr Hosek via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 8 12:02:01 PST 2019


This seems to have broke the 2-stage LTO build of LLVM, the error is:

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.

The invocation this came from is:

/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

On Thu, Mar 7, 2019 at 11:13 AM Rafael Auler via cfe-commits <
cfe-commits at lists.llvm.org> wrote:

> Author: rafauler
> Date: Thu Mar  7 11:14:30 2019
> New Revision: 355627
>
> URL: http://llvm.org/viewvc/llvm-project?rev=355627&view=rev
> Log:
> Recommit "Support attribute used in member funcs of class templates"
>
> The patch originally broke code that was incompatible with GCC, but
> we want to follow GCC behavior here according to the discussion in
> https://reviews.llvm.org/D58216
>
> Original commit message:
> As PR17480 describes, clang does not support the used attribute
> for member functions of class templates. This means that if the member
> function is not used, its definition is never instantiated. This patch
> changes clang to emit the definition if it has the used attribute.
>
> Test Plan: Added a testcase
>
> Reviewed By: aaron.ballman
>
> Differential Revision: https://reviews.llvm.org/D56928
>
> Added:
>
> cfe/trunk/test/CodeGenCXX/attr-used-member-function-implicit-instantiation.cpp
> Modified:
>     cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
>
> Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=355627&r1=355626&r2=355627&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Thu Mar  7 11:14:30
> 2019
> @@ -2232,6 +2232,20 @@ TemplateDeclInstantiator::VisitCXXMethod
>      Owner->addDecl(Method);
>    }
>
> +  // PR17480: Honor the used attribute to instantiate member function
> +  // definitions
> +  if (Method->hasAttr<UsedAttr>()) {
> +    if (const auto *A = dyn_cast<CXXRecordDecl>(Owner)) {
> +      SourceLocation Loc;
> +      if (const MemberSpecializationInfo *MSInfo =
> +              A->getMemberSpecializationInfo())
> +        Loc = MSInfo->getPointOfInstantiation();
> +      else if (const auto *Spec =
> dyn_cast<ClassTemplateSpecializationDecl>(A))
> +        Loc = Spec->getPointOfInstantiation();
> +      SemaRef.MarkFunctionReferenced(Loc, Method);
> +    }
> +  }
> +
>    return Method;
>  }
>
>
> Added:
> cfe/trunk/test/CodeGenCXX/attr-used-member-function-implicit-instantiation.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/attr-used-member-function-implicit-instantiation.cpp?rev=355627&view=auto
>
> ==============================================================================
> ---
> cfe/trunk/test/CodeGenCXX/attr-used-member-function-implicit-instantiation.cpp
> (added)
> +++
> cfe/trunk/test/CodeGenCXX/attr-used-member-function-implicit-instantiation.cpp
> Thu Mar  7 11:14:30 2019
> @@ -0,0 +1,19 @@
> +// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s |
> FileCheck %s
> +
> +// Check that PR17480 is fixed: __attribute__((used)) ignored in templated
> +// classes
> +namespace InstantiateUsedMemberDefinition {
> +template <typename T>
> +struct S {
> +  int __attribute__((used)) f() {
> +    return 0;
> +  }
> +};
> +
> +void test() {
> +  // Check that InstantiateUsedMemberDefinition::S<int>::f() is defined
> +  // as a result of the S class template implicit instantiation
> +  // CHECK: define linkonce_odr i32
> @_ZN31InstantiateUsedMemberDefinition1SIiE1fEv
> +  S<int> inst;
> +}
> +} // namespace InstantiateUsedMemberDefinition
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190308/8bf3254f/attachment.html>


More information about the cfe-commits mailing list